From 20f63c22bf284826eb9d4190260ec41845e2996f Mon Sep 17 00:00:00 2001 From: Earth_Studio Date: Fri, 24 Apr 2026 12:22:39 +0800 Subject: [PATCH 1/8] EventBus: fix deadlock issue when add/remove Listener in another Listener --- src/engine/animation/Animation.cpp | 9 +++++++++ src/engine/animation/Animation.h | 19 +++++++++++++++++++ src/engine/component/IComponent.cpp | 3 ++- src/engine/eventbus/EventBus.cpp | 19 ++++++++++++------- 4 files changed, 42 insertions(+), 8 deletions(-) create mode 100644 src/engine/animation/Animation.cpp create mode 100644 src/engine/animation/Animation.h diff --git a/src/engine/animation/Animation.cpp b/src/engine/animation/Animation.cpp new file mode 100644 index 0000000..028f87c --- /dev/null +++ b/src/engine/animation/Animation.cpp @@ -0,0 +1,9 @@ +// +// Created by Earth_Studio on 2026/4/22. +// + +#include "Animation.h" + +namespace cmaterial::animation { + +} diff --git a/src/engine/animation/Animation.h b/src/engine/animation/Animation.h new file mode 100644 index 0000000..73716f3 --- /dev/null +++ b/src/engine/animation/Animation.h @@ -0,0 +1,19 @@ +// +// Created by Earth_Studio on 2026/4/22. +// + +#ifndef CMATERIAL_ANIMATION_H +#define CMATERIAL_ANIMATION_H + + +namespace cmaterial::animation { + class Animation{ + public: + void setState(); + void setStateAnimation(); + }; +} + + + +#endif //CMATERIAL_ANIMATION_H diff --git a/src/engine/component/IComponent.cpp b/src/engine/component/IComponent.cpp index eff227d..05daba7 100644 --- a/src/engine/component/IComponent.cpp +++ b/src/engine/component/IComponent.cpp @@ -6,6 +6,7 @@ #include "GLFW/glfw3.h" #include "engine/eventbus/EventBus.h" +#include "engine/eventbus/internal/event/EmptyEvent.hpp" namespace cmaterial::component { void IComponent::addComponent(IComponent *component) { @@ -16,7 +17,7 @@ namespace cmaterial::component { return; components.insert({component->name, component}); - glfwPostEmptyEvent(); + event::EventBus::postEvent(new event::internal::EmptyEvent); } bool IComponent::getIsDead() { diff --git a/src/engine/eventbus/EventBus.cpp b/src/engine/eventbus/EventBus.cpp index 5d26b91..967db50 100644 --- a/src/engine/eventbus/EventBus.cpp +++ b/src/engine/eventbus/EventBus.cpp @@ -54,17 +54,21 @@ namespace cmaterial::event { processingQueue.swap(eventQueue); } - std::lock_guard lock(registerMutex); - for (auto* event : processingQueue) { const void* type = event->getEventType(); + + std::vector handlersToCall; + + std::lock_guard lock(registerMutex); if (subscriberMap.contains(type)) { - for (auto* handler : subscriberMap[type]) { - // 支持取消逻辑 - if (event->getIsCancelled()) break; - handler->execute(event); - } + handlersToCall = subscriberMap[type]; } + + for (auto* handler : handlersToCall) { + if (event->getIsCancelled()) break; + handler->execute(event); + } + delete event; } @@ -101,6 +105,7 @@ namespace cmaterial::event { for (IListener* listener : registeredListeners) { delete listener; } + registeredListeners.clear(); } EventBus::~EventBus() { From 6e7cfc73ab153e148cc803d75cf48e88fc0f97df Mon Sep 17 00:00:00 2001 From: Earth_Studio Date: Mon, 27 Apr 2026 00:36:28 +0800 Subject: [PATCH 2/8] Windows Resource support --- CMakeLists.txt | 3 +++ version.rc | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 version.rc diff --git a/CMakeLists.txt b/CMakeLists.txt index d8e8b93..5a03336 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -47,7 +47,9 @@ file(GLOB_RECURSE APP_SOURCES CONFIGURE_DEPENDS add_executable(CMaterial src/main.cpp src/main.h + src/gl.c + include/imgui/imgui.cpp include/imgui/imgui_draw.cpp include/imgui/imgui_tables.cpp @@ -95,6 +97,7 @@ if(MSVC AND CMAKE_BUILD_TYPE MATCHES "Release") ) set_target_properties(CMaterial PROPERTIES LINK_FLAGS "/INCLUDE:malloc") + target_sources(CMaterial PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/version.rc) elseif((CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") AND CMAKE_BUILD_TYPE MATCHES "Release") target_compile_options(CMaterial PRIVATE diff --git a/version.rc b/version.rc new file mode 100644 index 0000000..0085c10 --- /dev/null +++ b/version.rc @@ -0,0 +1,42 @@ +// +// Created by Earth_Studio on 2026/4/26. +// + +#include // 需要的宏定义 + +// 语言和字符集 +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US +#pragma code_page(65001) + +VS_VERSION_INFO VERSIONINFO +FILEVERSION 1,0,0,0 +PRODUCTVERSION 1,0,0,0 +FILEFLAGSMASK VS_FFI_FILEFLAGSMASK +#ifdef _DEBUG +FILEFLAGS VS_FF_DEBUG +#else +FILEFLAGS 0 +#endif +FILEOS VOS__WINDOWS32 +FILETYPE VFT_APP +FILESUBTYPE 0 +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904E4" // 英文 (美国) Unicode + BEGIN + VALUE "CompanyName", "Earth Studio" + VALUE "FileDescription", "CMaterial Demo" + VALUE "FileVersion", "1.0.0.0" + VALUE "InternalName", "CMaterialEngine" + VALUE "LegalCopyright", "Copyright (C) 2026, Earth Studio" + VALUE "OriginalFilename", "CMaterial.exe" + VALUE "ProductName", "CMaterial Demo" + VALUE "ProductVersion", "1.0.0.0" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x0409, 0x04E4 // 英语美国 , 多字节->Unicode + END +END \ No newline at end of file From d57256ecc8b8714b91c733580da8e8ec0ebe0258 Mon Sep 17 00:00:00 2001 From: Earth_Studio Date: Mon, 27 Apr 2026 00:39:06 +0800 Subject: [PATCH 3/8] Animation System --- src/engine/animation/Animation.cpp | 9 ---- src/engine/animation/Animation.h | 19 ------- src/engine/animation/IAnimation.cpp | 32 ++++++++++++ src/engine/animation/IAnimation.h | 34 +++++++++++++ src/engine/animation/Player.cpp | 77 +++++++++++++++++++++++++++++ src/engine/animation/Player.h | 34 +++++++++++++ 6 files changed, 177 insertions(+), 28 deletions(-) delete mode 100644 src/engine/animation/Animation.cpp delete mode 100644 src/engine/animation/Animation.h create mode 100644 src/engine/animation/IAnimation.cpp create mode 100644 src/engine/animation/IAnimation.h create mode 100644 src/engine/animation/Player.cpp create mode 100644 src/engine/animation/Player.h diff --git a/src/engine/animation/Animation.cpp b/src/engine/animation/Animation.cpp deleted file mode 100644 index 028f87c..0000000 --- a/src/engine/animation/Animation.cpp +++ /dev/null @@ -1,9 +0,0 @@ -// -// Created by Earth_Studio on 2026/4/22. -// - -#include "Animation.h" - -namespace cmaterial::animation { - -} diff --git a/src/engine/animation/Animation.h b/src/engine/animation/Animation.h deleted file mode 100644 index 73716f3..0000000 --- a/src/engine/animation/Animation.h +++ /dev/null @@ -1,19 +0,0 @@ -// -// Created by Earth_Studio on 2026/4/22. -// - -#ifndef CMATERIAL_ANIMATION_H -#define CMATERIAL_ANIMATION_H - - -namespace cmaterial::animation { - class Animation{ - public: - void setState(); - void setStateAnimation(); - }; -} - - - -#endif //CMATERIAL_ANIMATION_H diff --git a/src/engine/animation/IAnimation.cpp b/src/engine/animation/IAnimation.cpp new file mode 100644 index 0000000..4c26009 --- /dev/null +++ b/src/engine/animation/IAnimation.cpp @@ -0,0 +1,32 @@ +// +// Created by Earth_Studio on 2026/4/26. +// + +#include "IAnimation.h" + +#include + +#include "tween.h" + +namespace cmaterial::animation { + void IAnimation::reset() { + for (auto binder : animationBinders) { + if (_isReverse) + binder.second->seek(1); + else + binder.second->seek(0); + } + } + + std::unordered_map *>* IAnimation::getAnimationBinders() { + return &animationBinders; + } + + void IAnimation::bind(double* property, tweeny::tween* tween) { + animationBinders[property] = tween; + } + + IAnimation::~IAnimation() { + animationBinders.clear(); + } +} \ No newline at end of file diff --git a/src/engine/animation/IAnimation.h b/src/engine/animation/IAnimation.h new file mode 100644 index 0000000..c29a336 --- /dev/null +++ b/src/engine/animation/IAnimation.h @@ -0,0 +1,34 @@ +// +// Created by Earth_Studio on 2026/4/26. +// + +#ifndef CMATERIAL_IANIMATION_H +#define CMATERIAL_IANIMATION_H + + +#include + +#include "tween.h" + + +namespace cmaterial::animation { + class IAnimation { + public: + virtual ~IAnimation(); + + void reset(); + std::unordered_map *>* getAnimationBinders(); + + bool isLoop = false; + bool _isReverse = false; + + private: + void bind(double* property, tweeny::tween* tween); + + std::unordered_map *> animationBinders; + }; +} + + + +#endif //CMATERIAL_IANIMATION_H diff --git a/src/engine/animation/Player.cpp b/src/engine/animation/Player.cpp new file mode 100644 index 0000000..835a87e --- /dev/null +++ b/src/engine/animation/Player.cpp @@ -0,0 +1,77 @@ +// +// Created by Earth_Studio on 2026/4/22. +// + +#include "Player.h" + +#include +#include + +namespace cmaterial::animation { + std::vector Player::playingAnimations; + std::vector Player::finishedAnimations; + + void Player::play(IAnimation *animation) { + if (!animation) return; + + playingAnimations.push_back(animation); + } + + void Player::reverse(IAnimation *animation) { + if (!animation) return; + + for (auto binder : *animation->getAnimationBinders()) { + if (!animation->_isReverse) + binder.second->backward(); + else + binder.second->forward(); + } + + animation->_isReverse = !animation->_isReverse; + } + + void Player::stop(IAnimation *animation) { + if (!animation) return; + + animation->reset(); + std::erase(playingAnimations, animation); + } + + bool Player::update() { + if (playingAnimations.empty()) + return false; + + int dtTime = static_cast(ImGui::GetIO().DeltaTime * 100000.0f); + if (dtTime <= 0) dtTime = 1; // 1 step = 0.01 ms + + for (auto animation : playingAnimations) { + bool allTweensFinished = true; + for (auto binder : *animation->getAnimationBinders()) { + *binder.first = binder.second->step(dtTime); + + if (!binder.second->isFinished()) { + allTweensFinished = false; + } + } + + if (allTweensFinished) { + if (animation->isLoop) { + animation->reset(); + } else + finishedAnimations.push_back(animation); + } + } + + for (auto animation : finishedAnimations) { + std::erase(playingAnimations, animation); + } + + finishedAnimations.clear(); + + return true; + } + + Player::~Player() { + playingAnimations.clear(); + } +} diff --git a/src/engine/animation/Player.h b/src/engine/animation/Player.h new file mode 100644 index 0000000..870d6e8 --- /dev/null +++ b/src/engine/animation/Player.h @@ -0,0 +1,34 @@ +// +// Created by Earth_Studio on 2026/4/22. +// + +#ifndef CMATERIAL_ANIMATION_H +#define CMATERIAL_ANIMATION_H + + +#include + +#include "IAnimation.h" + + +namespace cmaterial::animation { + class Player{ + public: + Player() = default; + ~Player(); + + static void play(IAnimation* animation); + static void reverse(IAnimation* animation); + static void stop(IAnimation* animation); + + static bool update(); + + private: + static std::vector playingAnimations; + static std::vector finishedAnimations; + }; +} + + + +#endif //CMATERIAL_ANIMATION_H From 0fd52923d8c0f299af06a235095b55817655d47f Mon Sep 17 00:00:00 2001 From: Earth_Studio Date: Mon, 27 Apr 2026 01:30:19 +0800 Subject: [PATCH 4/8] OptiRender: full implement --- .../window/BasicWindow/BasicWindow.cpp | 6 +++ src/content/window/BasicWindow/BasicWindow.h | 1 - src/engine/framework/Framework.cpp | 30 ++++++++--- src/engine/framework/Framework.h | 2 + src/engine/window/IWindow.cpp | 52 +++++++++++++++---- src/engine/window/IWindow.h | 7 ++- 6 files changed, 78 insertions(+), 20 deletions(-) diff --git a/src/content/window/BasicWindow/BasicWindow.cpp b/src/content/window/BasicWindow/BasicWindow.cpp index 383d357..8f6e63c 100644 --- a/src/content/window/BasicWindow/BasicWindow.cpp +++ b/src/content/window/BasicWindow/BasicWindow.cpp @@ -15,6 +15,9 @@ namespace cmaterial::window { void BasicWindow::render(ImGuiIO *io) { ImGuiWindowFlags flags = ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoSavedSettings; + ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 10.0f); + ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f); + ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 1.0f); if (ImGui::Begin(this->name.c_str(), nullptr, flags)) { ImGui::Text("Hello, Engine!"); ImGui::Text("Frame time: %.3f ms/frame (%.1f FPS)", 1000.0f / io->Framerate, io->Framerate); @@ -39,5 +42,8 @@ namespace cmaterial::window { } ImGui::End(); + ImGui::PopStyleVar(); + ImGui::PopStyleVar(); + ImGui::PopStyleVar(); } } \ No newline at end of file diff --git a/src/content/window/BasicWindow/BasicWindow.h b/src/content/window/BasicWindow/BasicWindow.h index 8a7b245..dda1d68 100644 --- a/src/content/window/BasicWindow/BasicWindow.h +++ b/src/content/window/BasicWindow/BasicWindow.h @@ -5,7 +5,6 @@ #ifndef CMATERIAL_BASICWINDOW_H #define CMATERIAL_BASICWINDOW_H -#include "engine/component/IComponent.h" #include "engine/window/IWindow.h" #include "imgui.h" diff --git a/src/engine/framework/Framework.cpp b/src/engine/framework/Framework.cpp index 99b1c1a..08c46f6 100644 --- a/src/engine/framework/Framework.cpp +++ b/src/engine/framework/Framework.cpp @@ -19,6 +19,8 @@ #include #include +#include "engine/animation/Player.h" + using EventBus = cmaterial::event::EventBus; namespace cmaterial { @@ -29,7 +31,7 @@ namespace cmaterial { glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); - glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); // disabled for debug only + glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); hiddenWindow = glfwCreateWindow(1, 1, "CMaterial Engine", nullptr, nullptr); if (!hiddenWindow) { @@ -43,11 +45,12 @@ namespace cmaterial { if (!gladLoadGL(glfwGetProcAddress)) return GLAD_LOAD_GL_FAILED; - IMGUI_CHECKVERSION(); fontAtlas = IM_NEW(ImFontAtlas)(); - fontAtlas->AddFontDefault(); + hiddenImgui = ImGui::CreateContext(fontAtlas); + ImGui::SetCurrentContext(hiddenImgui); + isInitialized = true; return OK; @@ -59,10 +62,16 @@ namespace cmaterial { EventBus::postEvent(new event::internal::EmptyEvent); while (!glfwWindowShouldClose(hiddenWindow) && !windows.empty()) { - if (!EventBus::dispatch()) + bool isEventBusy = EventBus::dispatch(); + bool isAnimationBusy = animation::Player::update(); + + if (!(isEventBusy || isAnimationBusy)) glfwWaitEvents(); + ImFontAtlasUpdateNewFrame(fontAtlas, ++globalFrameCount, true); + for (std::pair &pair : windows) { + bool isSizeChange = pair.second->_isSizeChange; pair.second->update(); if (pair.second->isDead) { @@ -70,13 +79,18 @@ namespace cmaterial { continue; } - if (!pair.second->isHovered()) { + if (!isSizeChange && !pair.second->isHovered()) { if (!pair.second->isInitialized) pair.second->isInitialized = true; else continue; } - pair.second->drawWindow(); + pair.second->drawWindow(!isAnimationBusy); + } + + if (!deadWindows.empty()) { + glfwMakeContextCurrent(hiddenWindow); + ImGui::SetCurrentContext(hiddenImgui); } for (std::string &name : deadWindows) { @@ -96,6 +110,10 @@ namespace cmaterial { Framework::~Framework() { EventBus::shutdown(); + animation::Player::shutdown(); + glfwMakeContextCurrent(hiddenWindow); + ImGui::SetCurrentContext(hiddenImgui); + ImGui::DestroyContext(hiddenImgui); glfwDestroyWindow(hiddenWindow); glfwTerminate(); } diff --git a/src/engine/framework/Framework.h b/src/engine/framework/Framework.h index 1fad831..88adc63 100644 --- a/src/engine/framework/Framework.h +++ b/src/engine/framework/Framework.h @@ -32,8 +32,10 @@ namespace cmaterial { private: bool isInitialized = false; + int globalFrameCount = 0; GLFWwindow* hiddenWindow = nullptr; + ImGuiContext* hiddenImgui = nullptr; ImFontAtlas* fontAtlas = nullptr; std::unordered_map windows; std::vector deadWindows; diff --git a/src/engine/window/IWindow.cpp b/src/engine/window/IWindow.cpp index 27b7b84..cfd3793 100644 --- a/src/engine/window/IWindow.cpp +++ b/src/engine/window/IWindow.cpp @@ -11,9 +11,19 @@ #include "GLFW/glfw3.h" #include "engine/eventbus/EventBus.h" +#include "engine/eventbus/internal/event/EmptyEvent.hpp" #include "imgui_internal.h" namespace cmaterial::window { + void window_size_callback(GLFWwindow* window, int width, int height) { + auto* instance = static_cast(glfwGetWindowUserPointer(window)); + + if (instance) { + glfwPostEmptyEvent(); + instance->_isSizeChange = true; + } + } + IWindow::IWindow(const std::string &name, int width, int height) { this->name = name; this->width = width; @@ -33,6 +43,16 @@ namespace cmaterial::window { ImGui::SetCurrentContext(imguiContext); glfwSwapInterval(1); + glfwSetWindowUserPointer(glfwWindow, this); + glfwSetWindowSizeCallback(glfwWindow, window_size_callback); + + glfwSetWindowRefreshCallback(glfwWindow, [](GLFWwindow *w) { + auto *win = (IWindow *) glfwGetWindowUserPointer(w); + if (win) { + win->drawWindow(false); + } + }); + ImGui_ImplGlfw_InitForOpenGL(glfwWindow, true); ImGui_ImplOpenGL3_Init("#version 330"); @@ -41,6 +61,8 @@ namespace cmaterial::window { io->IniFilename = nullptr; io->LogFilename = nullptr; + + postInit(io); } void IWindow::update() { @@ -53,31 +75,39 @@ namespace cmaterial::window { glfwGetCursorPos(glfwWindow, &mouse_x, &mouse_y); ImGui::GetIO().AddMousePosEvent((float)mouse_x, (float)mouse_y); + + _isSizeChange = false; + + postUpdate(); } - void IWindow::drawWindow() { - glfwMakeContextCurrent(glfwWindow); - ImGui::SetCurrentContext(imguiContext); + void IWindow::drawWindow(bool isVirtual) { + if (!isVirtual) + glfwMakeContextCurrent(glfwWindow); - ImFontAtlasUpdateNewFrame(fontAtlas, ++global_frame_count, true); + ImGui::SetCurrentContext(imguiContext); - ImGui_ImplOpenGL3_NewFrame(); + if (!isVirtual) + ImGui_ImplOpenGL3_NewFrame(); ImGui_ImplGlfw_NewFrame(); ImGui::NewFrame(); ImGui::SetNextWindowPos(ImVec2(0, 0)); ImGui::SetNextWindowSize(io->DisplaySize); + this->render(io); ImGui::Render(); - int dw, dh; - glfwGetFramebufferSize(glfwWindow, &dw, &dh); - glViewport(0, 0, dw, dh); - glClear(GL_COLOR_BUFFER_BIT); + if (!isVirtual) { + int dw, dh; + glfwGetFramebufferSize(glfwWindow, &dw, &dh); + glViewport(0, 0, dw, dh); + glClear(GL_COLOR_BUFFER_BIT); - ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); - glfwSwapBuffers(glfwWindow); + ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); + glfwSwapBuffers(glfwWindow); + } } void IWindow::addComponent(component::IComponent* comp) { diff --git a/src/engine/window/IWindow.h b/src/engine/window/IWindow.h index 7dbe18d..6e8a382 100644 --- a/src/engine/window/IWindow.h +++ b/src/engine/window/IWindow.h @@ -23,8 +23,10 @@ namespace cmaterial::window { virtual ~IWindow(); void initialize(GLFWwindow* window, ImFontAtlas* fontAtlas); - void drawWindow(); + void drawWindow(bool isVirtual); // isVirtual: Is only force ImGui update private states? + virtual void postInit(ImGuiIO *io) {}; + virtual void postUpdate() {}; virtual void update(); virtual void render(ImGuiIO* io) = 0; void addComponent(component::IComponent *comp); @@ -35,6 +37,8 @@ namespace cmaterial::window { bool isDead = false; bool isInitialized = false; + bool _isSizeChange = false; + bool isHovered() const; protected: @@ -42,7 +46,6 @@ namespace cmaterial::window { ImGuiContext* imguiContext = nullptr; ImGuiIO* io = nullptr; ImFontAtlas* fontAtlas = nullptr; - int global_frame_count = 0; std::unordered_map components; std::vector deadComponents; From e52111cba017162d2c15d4f7542019b856c0d936 Mon Sep 17 00:00:00 2001 From: Earth_Studio Date: Mon, 27 Apr 2026 01:30:50 +0800 Subject: [PATCH 5/8] EventBus: fix memory leak --- src/engine/eventbus/EventBus.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/engine/eventbus/EventBus.cpp b/src/engine/eventbus/EventBus.cpp index 967db50..992427a 100644 --- a/src/engine/eventbus/EventBus.cpp +++ b/src/engine/eventbus/EventBus.cpp @@ -102,6 +102,8 @@ namespace cmaterial::event { for (auto* e : eventQueue) delete e; eventQueue.clear(); + subscriberMap.clear(); + for (IListener* listener : registeredListeners) { delete listener; } From c419d5c0e0010813f0e504b57d08fad398d5c98a Mon Sep 17 00:00:00 2001 From: Earth_Studio Date: Mon, 27 Apr 2026 01:31:31 +0800 Subject: [PATCH 6/8] Animation: fix memory leak --- src/engine/animation/Player.cpp | 7 ++++++- src/engine/animation/Player.h | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/engine/animation/Player.cpp b/src/engine/animation/Player.cpp index 835a87e..8efa118 100644 --- a/src/engine/animation/Player.cpp +++ b/src/engine/animation/Player.cpp @@ -71,7 +71,12 @@ namespace cmaterial::animation { return true; } - Player::~Player() { + void Player::shutdown() { playingAnimations.clear(); + finishedAnimations.clear(); + } + + Player::~Player() { + shutdown(); } } diff --git a/src/engine/animation/Player.h b/src/engine/animation/Player.h index 870d6e8..74ce66f 100644 --- a/src/engine/animation/Player.h +++ b/src/engine/animation/Player.h @@ -23,6 +23,8 @@ namespace cmaterial::animation { static bool update(); + static void shutdown(); + private: static std::vector playingAnimations; static std::vector finishedAnimations; From 30db1594b0a51f41c5f8bde78c5300b37f818580 Mon Sep 17 00:00:00 2001 From: Earth_Studio Date: Mon, 27 Apr 2026 01:31:57 +0800 Subject: [PATCH 7/8] Component: first step of rebuild --- src/engine/component/IComponent.h | 5 +++++ src/engine/component/ILayer.cpp | 9 +++++++++ src/engine/component/ILayer.h | 25 +++++++++++++++++++++++++ 3 files changed, 39 insertions(+) create mode 100644 src/engine/component/ILayer.cpp create mode 100644 src/engine/component/ILayer.h diff --git a/src/engine/component/IComponent.h b/src/engine/component/IComponent.h index 2199a14..85020cf 100644 --- a/src/engine/component/IComponent.h +++ b/src/engine/component/IComponent.h @@ -12,6 +12,8 @@ #include #include +#include "ILayer.h" + namespace cmaterial::component { class IComponent { @@ -20,6 +22,8 @@ namespace cmaterial::component { virtual void render(ImGuiIO *io) = 0; virtual void addComponent(IComponent *component); + void addLayer(); + bool getIsDead(); std::string name; @@ -30,6 +34,7 @@ namespace cmaterial::component { protected: bool isDead = false; std::unordered_map components; + std::vector layers; }; } diff --git a/src/engine/component/ILayer.cpp b/src/engine/component/ILayer.cpp new file mode 100644 index 0000000..be70242 --- /dev/null +++ b/src/engine/component/ILayer.cpp @@ -0,0 +1,9 @@ +// +// Created by Earth_Studio on 2026/4/26. +// + +#include "ILayer.h" + +namespace cmaterial::component { + +} \ No newline at end of file diff --git a/src/engine/component/ILayer.h b/src/engine/component/ILayer.h new file mode 100644 index 0000000..bb27561 --- /dev/null +++ b/src/engine/component/ILayer.h @@ -0,0 +1,25 @@ +// +// Created by Earth_Studio on 2026/4/26. +// + +#ifndef CMATERIAL_ILAYER_H +#define CMATERIAL_ILAYER_H + + +#include "imgui.h" + + +namespace cmaterial::component { + class ILayer { + public: + virtual ~ILayer() = default; + + virtual ImDrawData render() = 0; + + int priority = 0; + }; +} + + + +#endif //CMATERIAL_ILAYER_H From 56d930f92c0563c35639fd79d5e4806130f5129f Mon Sep 17 00:00:00 2001 From: Earth_Studio Date: Mon, 27 Apr 2026 01:38:00 +0800 Subject: [PATCH 8/8] fix include error --- src/engine/component/IComponent.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/engine/component/IComponent.h b/src/engine/component/IComponent.h index 85020cf..6a461d8 100644 --- a/src/engine/component/IComponent.h +++ b/src/engine/component/IComponent.h @@ -10,6 +10,7 @@ #include "imgui.h" #include +#include #include #include "ILayer.h"