remake UTF-8 and I forgot what I have done in this commit

This commit is contained in:
EmsiaetKadosh
2025-03-11 18:37:34 +08:00
parent 7e63aa1217
commit a1d0f11032
32 changed files with 254 additions and 6 deletions
BIN
View File
Binary file not shown.
+156
View File
@@ -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<double>(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<double>(progress) / duration; }
template <typename T>
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<long long>(temp * val);
temp += fr & 0xff000000;
if (temp > 0xffffffffLL) ret = 0xff000000;
else ret = temp & 0xff000000;
temp = (t & 0x00ff0000) - (fr & 0x00ff0000);
temp = static_cast<long long>(temp * val);
temp += fr & 0x00ff0000;
if (temp > 0xffffffLL) ret |= 0x00ff0000;
else ret |= temp & 0x00ff0000;
temp = (t & 0x0000ff00) - (fr & 0x0000ff00);
temp = static_cast<long long>(temp * val);
temp += fr & 0x0000ff00;
if (temp > 0xffffLL) ret |= 0x0000ff00;
else ret |= temp & 0x0000ff00;
temp = (t & 0x000000ff) - (fr & 0x000000ff);
temp = static_cast<long long>(temp * val);
temp += fr & 0x000000ff;
if (temp > 0xffLL) ret |= 0x000000ff;
else ret |= temp & 0x000000ff;
return ret;
}
};
+7 -1
View File
@@ -5,7 +5,7 @@ add_definitions(-DUNICODE)
add_definitions(-D_UNICODE) add_definitions(-D_UNICODE)
add_definitions(-DCINTERFACE) add_definitions(-DCINTERFACE)
add_definitions(-D__CARLBEKS_CMAKE_VSCODE__) add_definitions(-D__CARLBEKS_CMAKE_VSCODE__)
set(CMAKE_CXX_STANDARD 23) set(CMAKE_CXX_STANDARD 26)
set(CMAKE_WIN32_EXECUTABLE true) set(CMAKE_WIN32_EXECUTABLE true)
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
add_compile_options(${PROJECT_NAME} -Wno-microsoft-string-literal-from-predefined) 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_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION}) 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) include(CPack)
BIN
View File
Binary file not shown.
+83
View File
@@ -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);
}
};
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
+5 -2
View File
@@ -17,7 +17,7 @@ public:
explicit Task(const Function<void(Task& self)>& func) : func(func) {} explicit Task(const Function<void(Task& self)>& func) : func(func) {}
explicit Task(Function<void(Task& self)>&& func) : func(std::move(func)) {} explicit Task(Function<void(Task& self)>&& func) : func(std::move(func)) {}
void schedulePop(const bool pop) noexcept { reserved[0] = pop; } 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 { int pop() noexcept override {
schedulePop(true); schedulePop(true);
@@ -32,7 +32,10 @@ public:
void runAll() { void runAll() {
for (Task& task : tasks) { for (Task& task : tasks) {
task.func(task); task.func(task);
if (task.scheduledPop()) tasks.pop(&task); if (task.scheduledPop()) {
task.schedulePop(false);
tasks.pop(&task);
}
} }
} }
BIN
View File
Binary file not shown.
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
+3 -3
View File
@@ -29,8 +29,8 @@ private:
AnywhereEditable* prev = nullptr; AnywhereEditable* prev = nullptr;
AnywhereEditable* next = nullptr; AnywhereEditable* next = nullptr;
AnywhereEditableList<T, L>* list = nullptr; // 指示自身属于某个列表 AnywhereEditableList<T, L>* list = nullptr; // 指示自身属于某个列表
protected:
bool managedByList = false; // 指示是否在列表内管理内存,而非列表外管理内存 bool managedByList = false; // 指示是否在列表内管理内存,而非列表外管理内存
public:
byte reserved[7]{}; // reserved[0]: Task::schedulePop byte reserved[7]{}; // reserved[0]: Task::schedulePop
public: public:
@@ -146,9 +146,9 @@ public:
int pushNewed(T* value) noexcept; int pushNewed(T* value) noexcept;
virtual int pop(T* value) noexcept; virtual int pop(T* value) noexcept;
AnywhereIterator<T, L> begin() noexcept { return AnywhereIterator<T, L>(head.next); } AnywhereIterator<T, L> begin() noexcept { return AnywhereIterator<T, L>(head.next); }
AnywhereIteratorEnd end() noexcept { return AnywhereIteratorEnd(); } [[nodiscard]] AnywhereIteratorEnd end() noexcept { return {}; }
AnywhereIterator<T, L> begin() const noexcept { return AnywhereIterator<T, L>(head.next); } AnywhereIterator<T, L> begin() const noexcept { return AnywhereIterator<T, L>(head.next); }
AnywhereIteratorEnd end() const noexcept { return AnywhereIteratorEnd(); } [[nodiscard]] AnywhereIteratorEnd end() const noexcept { return {}; }
AnywhereEditable<T, L>* front() const noexcept { return head.next == &tail ? nullptr : head.next; } AnywhereEditable<T, L>* front() const noexcept { return head.next == &tail ? nullptr : head.next; }
AnywhereEditable<T, L>* back() const noexcept { return tail.prev == &head ? nullptr : tail.prev; } AnywhereEditable<T, L>* back() const noexcept { return tail.prev == &head ? nullptr : tail.prev; }
}; };
BIN
View File
Binary file not shown.