diff --git a/.clang-format b/.clang-format index aecc7e3..302e0fe 100644 Binary files a/.clang-format and b/.clang-format differ diff --git a/Animation.h b/Animation.h new file mode 100644 index 0000000..9a0fbc7 --- /dev/null +++ b/Animation.h @@ -0,0 +1,156 @@ +// +// Created by EmsiaetKadosh on 25-3-7. +// + +#pragma once + +#include "def.h" + +class Animation { +public: + enum Depend : unsigned char { + AD_TIME, AD_GET + }; + + enum Style : unsigned short { + AS_LINEAR = 0, + AS_SIN_IN = 0x1, AS_SIN_OUT = 0x100, AS_SIN = 0x101, + AS_QUADRATIC_IN = 0x2, AS_QUADRATIC_OUT = 0x200, AS_QUADRATIC = 0x202, + AS_CUBIC_IN = 0x3, AS_CUBIC_OUT = 0x300, AS_CUBIC = 0x303, + }; + +private: + mutable int progress = 0; + int duration = 20; + Style style = AS_LINEAR; + Depend depend = AD_GET; + bool positiveSuperAllowed = false; + bool negativeSuperAllowed = false; + bool doLoop = false; + bool doReverse = true; + +public: + Animation() noexcept {} + + Animation& allowPositiveSuper(const bool val = true) noexcept { + positiveSuperAllowed = val; + return *this; + } + + Animation& allowNegativeSuper(const bool val = true) noexcept { + negativeSuperAllowed = val; + return *this; + } + + Animation& depends(Depend depend) noexcept { + this->depend = depend; + return *this; + } + + Animation& features(Style style) noexcept { + this->style = style; + return *this; + } + + Animation& loop(const bool val = true) noexcept { + doLoop = val; + return *this; + } + + Animation& includeReverse(const bool val = true) noexcept { + doReverse = val; + return *this; + } + + Animation& setDuration(const unsigned int val) noexcept { + if (duration == 0) duration = 1; + duration = val; + return *this; + } + + void reset() const noexcept { progress = 0; } + + double weight(double x) const noexcept { + if (x <= 0.0) return 0.0; + if (x >= 1.0) return 1.0; + x *= 2; + return x < 1.0 ? pow(x, 5.0) * 0.5 : 1.0 + pow(x - 2.0, 5.0) * 0.5; + } + + double calculateNext() const noexcept { + if (++progress > duration) progress = doReverse ? 1 - duration : 0; + double p = static_cast(progress < 0 ? -progress : progress) / duration; + const double w = weight(p); + double val1 = 0, val2 = 0; + switch (style & 0xff) { + case AS_SIN_IN: + val1 = 1 - cos(p * 1.5707963267948966192313216916398); + break; + case AS_QUADRATIC_IN: + val1 = p * p; + break; + case AS_CUBIC_IN: + val1 = p * p * p; + break; + case AS_LINEAR: + default: + val1 = p; + break; + } + switch (style & 0xff00) { + case AS_SIN_OUT: + val2 = sin(p * 1.5707963267948966192313216916398); + break; + case AS_QUADRATIC_OUT: + p = 1 - p; + val2 = 1 - p * p; + break; + case AS_CUBIC_OUT: + p = 1 - p; + val2 = 1 + p * p * p; + break; + case AS_LINEAR: + default: + val2 = p; + break; + } + return val1 * (1 - w) + val2 * w; + } + + double getValue() const noexcept { return static_cast(progress) / duration; } + + template + double adapts(T from, T to) const noexcept { + const double val = calculateNext(); + return (to - from) * val + from; + } + + unsigned int adaptsColor(const unsigned int from, const unsigned int to) const noexcept { + const double val = calculateNext(); + const long long fr = from; + const long long t = to; + unsigned int ret = 0; + long long temp = 0; + temp = (t & 0xff000000) - (fr & 0xff000000); + temp = static_cast(temp * val); + temp += fr & 0xff000000; + if (temp > 0xffffffffLL) ret = 0xff000000; + else ret = temp & 0xff000000; + temp = (t & 0x00ff0000) - (fr & 0x00ff0000); + temp = static_cast(temp * val); + temp += fr & 0x00ff0000; + if (temp > 0xffffffLL) ret |= 0x00ff0000; + else ret |= temp & 0x00ff0000; + temp = (t & 0x0000ff00) - (fr & 0x0000ff00); + temp = static_cast(temp * val); + temp += fr & 0x0000ff00; + if (temp > 0xffffLL) ret |= 0x0000ff00; + else ret |= temp & 0x0000ff00; + temp = (t & 0x000000ff) - (fr & 0x000000ff); + temp = static_cast(temp * val); + temp += fr & 0x000000ff; + if (temp > 0xffLL) ret |= 0x000000ff; + else ret |= temp & 0x000000ff; + return ret; + } +}; diff --git a/CMakeLists.txt b/CMakeLists.txt index bff4f24..819751b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,7 @@ add_definitions(-DUNICODE) add_definitions(-D_UNICODE) add_definitions(-DCINTERFACE) add_definitions(-D__CARLBEKS_CMAKE_VSCODE__) -set(CMAKE_CXX_STANDARD 23) +set(CMAKE_CXX_STANDARD 26) set(CMAKE_WIN32_EXECUTABLE true) if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") add_compile_options(${PROJECT_NAME} -Wno-microsoft-string-literal-from-predefined) @@ -47,5 +47,11 @@ add_executable(${PROJECT_NAME} ) set(CPACK_PROJECT_NAME ${PROJECT_NAME}) set(CPACK_PROJECT_VERSION ${PROJECT_VERSION}) + +set_target_properties(${PROJECT_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/../exenv/") +set_target_properties(${PROJECT_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_BINARY_DIR}/../exenv/") +set_target_properties(${PROJECT_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY_RELEASE "${CMAKE_BINARY_DIR}/../exenv/") +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/../exenv/") + include(CPack) diff --git a/Chars.h b/Chars.h index fbb6729..04c816f 100644 Binary files a/Chars.h and b/Chars.h differ diff --git a/File.h b/File.h new file mode 100644 index 0000000..e7fe83a --- /dev/null +++ b/File.h @@ -0,0 +1,83 @@ +// +// Created by EmsiaetKadosh on 25-3-7. +// + +#pragma once + + +class File { +public: + std::wfstream file; + explicit File(const std::wstring& path) : file(path, std::ios::in | std::ios::out | std::ios::binary) {} + ~File() { if (file.is_open()) file.close(); } +}; + +class Data { +public: + enum class DataType : int { + Integer, Double, String, Boolean, Null, List, Object + }; + +private: + String name; + String value; + DataType type; + +public: + Data(String&& name, String&& value, const DataType type): name(std::move(name)), value(std::move(value)), type(type) {} +}; + +class DataLoader { + File file; + + int parseString(int& line, String& string) { + while (!file.file.eof()) { + wchar c = file.file.get(); + if (c == L'\"') Success(); + if (c == L'\\') { + c = file.file.get(); + } + } + errorInfo = L"Error: String never ends. EOF comes before a '\"'"; + Failed(); + } + + int loadUntil(int& line, wchar at = 0) { + String name = {}; + String val = {}; + enum { identifier, eq, value, end } status = identifier; + while (!file.file.eof()) { + const wchar c = file.file.get(); + if (c == L'\n') ++line; + switch (status) { + case identifier: + if (!isspace(c)) name.append(1, c); + else if (!name.empty()) status = eq; + break; + case eq: + if (c == L'=') status = value; + else if (!isspace(c)) { + errorInfo = L"Error: expected '=' after identifier at line " + std::to_wstring(line); + Failed(); + } + break; + case value: + if (!isspace(c)) { if (c == L'\"') {} } + break; + case end: + break; + } + } + } + +public: + String errorInfo = {}; + explicit DataLoader(const String& path) : file(path) {} + DataLoader(const DataLoader&) = delete; + DataLoader(DataLoader&&) = delete; + + int load() { + int line = 1; + return loadUntil(line); + } +}; diff --git a/Game.cpp b/Game.cpp index 5a2c13c..686b908 100644 Binary files a/Game.cpp and b/Game.cpp differ diff --git a/Game.h b/Game.h index 2a2b1df..27dbbaf 100644 Binary files a/Game.h and b/Game.h differ diff --git a/Hud.cpp b/Hud.cpp index e2b0281..bc030c0 100644 Binary files a/Hud.cpp and b/Hud.cpp differ diff --git a/Hud.h b/Hud.h index 7791094..d4638f6 100644 Binary files a/Hud.h and b/Hud.h differ diff --git a/IText.cpp b/IText.cpp index 10af54c..62efb93 100644 Binary files a/IText.cpp and b/IText.cpp differ diff --git a/IText.h b/IText.h index b3543ad..b3fb99f 100644 Binary files a/IText.h and b/IText.h differ diff --git a/InteractManager.cpp b/InteractManager.cpp index c8b27b2..3b69791 100644 Binary files a/InteractManager.cpp and b/InteractManager.cpp differ diff --git a/InteractManager.h b/InteractManager.h index 81cc607..eaaeb45 100644 Binary files a/InteractManager.h and b/InteractManager.h differ diff --git a/LICENSE b/LICENSE index 353318c..17d79f2 100644 Binary files a/LICENSE and b/LICENSE differ diff --git a/Renderer.cpp b/Renderer.cpp index 3b49ecd..449e607 100644 Binary files a/Renderer.cpp and b/Renderer.cpp differ diff --git a/Renderer.h b/Renderer.h index 24d2730..75b045a 100644 Binary files a/Renderer.h and b/Renderer.h differ diff --git a/Task.h b/Task.h index a31825d..de9bcf3 100644 --- a/Task.h +++ b/Task.h @@ -17,7 +17,7 @@ public: explicit Task(const Function& func) : func(func) {} explicit Task(Function&& func) : func(std::move(func)) {} void schedulePop(const bool pop) noexcept { reserved[0] = pop; } - bool scheduledPop() const noexcept { return reserved[0]; } + [[nodiscard]] bool scheduledPop() const noexcept { return reserved[0]; } int pop() noexcept override { schedulePop(true); @@ -32,7 +32,10 @@ public: void runAll() { for (Task& task : tasks) { task.func(task); - if (task.scheduledPop()) tasks.pop(&task); + if (task.scheduledPop()) { + task.schedulePop(false); + tasks.pop(&task); + } } } diff --git a/TestCode.h b/TestCode.h index 06a1968..3d05f6a 100644 Binary files a/TestCode.h and b/TestCode.h differ diff --git a/TextureManager.cpp b/TextureManager.cpp index b21bb73..108b7a5 100644 Binary files a/TextureManager.cpp and b/TextureManager.cpp differ diff --git a/TextureManager.h b/TextureManager.h index f1b48a8..0d0049b 100644 Binary files a/TextureManager.h and b/TextureManager.h differ diff --git a/Window.cpp b/Window.cpp index cbcff94..e08ae7f 100644 Binary files a/Window.cpp and b/Window.cpp differ diff --git a/Window.h b/Window.h index 98288d3..1565631 100644 Binary files a/Window.h and b/Window.h differ diff --git a/def.cpp b/def.cpp index 4defbef..f246991 100644 Binary files a/def.cpp and b/def.cpp differ diff --git a/def.h b/def.h index 46cee1d..fb55d3d 100644 Binary files a/def.h and b/def.h differ diff --git a/dev.md b/dev.md index b84f169..a659cbb 100644 Binary files a/dev.md and b/dev.md differ diff --git a/exception.cpp b/exception.cpp index c23b1a3..9601749 100644 Binary files a/exception.cpp and b/exception.cpp differ diff --git a/exception.h b/exception.h index 2952734..f70438b 100644 Binary files a/exception.h and b/exception.h differ diff --git a/hbp.h b/hbp.h index 40ab450..1d51664 100644 Binary files a/hbp.h and b/hbp.h differ diff --git a/includes.h b/includes.h index 307b69e..2344b9f 100644 Binary files a/includes.h and b/includes.h differ diff --git a/main.cpp b/main.cpp index a40cc84..ea08995 100644 Binary files a/main.cpp and b/main.cpp differ diff --git a/utils.h b/utils.h index e7c0eb4..f7f05f7 100644 --- a/utils.h +++ b/utils.h @@ -29,8 +29,8 @@ private: AnywhereEditable* prev = nullptr; AnywhereEditable* next = nullptr; AnywhereEditableList* list = nullptr; // 指示自身属于某个列表 -protected: bool managedByList = false; // 指示是否在列表内管理内存,而非列表外管理内存 +public: byte reserved[7]{}; // reserved[0]: Task::schedulePop public: @@ -146,9 +146,9 @@ public: int pushNewed(T* value) noexcept; virtual int pop(T* value) noexcept; AnywhereIterator begin() noexcept { return AnywhereIterator(head.next); } - AnywhereIteratorEnd end() noexcept { return AnywhereIteratorEnd(); } + [[nodiscard]] AnywhereIteratorEnd end() noexcept { return {}; } AnywhereIterator begin() const noexcept { return AnywhereIterator(head.next); } - AnywhereIteratorEnd end() const noexcept { return AnywhereIteratorEnd(); } + [[nodiscard]] AnywhereIteratorEnd end() const noexcept { return {}; } AnywhereEditable* front() const noexcept { return head.next == &tail ? nullptr : head.next; } AnywhereEditable* back() const noexcept { return tail.prev == &head ? nullptr : tail.prev; } }; diff --git a/xWindows.h b/xWindows.h index 28bdde6..0ca2b89 100644 Binary files a/xWindows.h and b/xWindows.h differ