refactor(core): 移除模块系统及相关功能
删除模块系统实现及相关代码,包括Module类、Application中的模块管理功能 移除AGENTS.md中关于模块模式的文档
This commit is contained in:
@@ -181,13 +181,6 @@ Frostbite2D/
|
|||||||
|
|
||||||
## Key Patterns
|
## Key Patterns
|
||||||
|
|
||||||
### Module Pattern
|
|
||||||
```cpp
|
|
||||||
void Application::use(Module& m) {
|
|
||||||
modules_.push_back(&m);
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### Configuration Pattern
|
### Configuration Pattern
|
||||||
Use configuration structs with default values:
|
Use configuration structs with default values:
|
||||||
```cpp
|
```cpp
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <frostbite2D/core/window.h>
|
#include <frostbite2D/core/window.h>
|
||||||
#include <frostbite2D/module/module.h>
|
|
||||||
#include <frostbite2D/types/type_alias.h>
|
#include <frostbite2D/types/type_alias.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
@@ -64,18 +63,6 @@ public:
|
|||||||
Application(const Application&) = delete;
|
Application(const Application&) = delete;
|
||||||
Application& operator=(const Application&) = delete;
|
Application& operator=(const Application&) = delete;
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief 添加模块
|
|
||||||
* @param m 模块引用
|
|
||||||
*/
|
|
||||||
void use(Module& m);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief 批量添加模块
|
|
||||||
* @param modules 模块指针列表
|
|
||||||
*/
|
|
||||||
void use(std::initializer_list<Module*> modules);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 使用默认配置初始化
|
* @brief 使用默认配置初始化
|
||||||
* @return 初始化成功返回 true
|
* @return 初始化成功返回 true
|
||||||
@@ -172,16 +159,6 @@ private:
|
|||||||
*/
|
*/
|
||||||
bool initCoreModules();
|
bool initCoreModules();
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief 设置所有模块
|
|
||||||
*/
|
|
||||||
void setupAllModules();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief 销毁所有模块
|
|
||||||
*/
|
|
||||||
void destroyAllModules();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 主循环
|
* @brief 主循环
|
||||||
*/
|
*/
|
||||||
@@ -197,7 +174,6 @@ private:
|
|||||||
*/
|
*/
|
||||||
void render();
|
void render();
|
||||||
|
|
||||||
std::vector<Module*> modules_;
|
|
||||||
Window* window_ = nullptr;
|
Window* window_ = nullptr;
|
||||||
class Renderer* renderer_ = nullptr;
|
class Renderer* renderer_ = nullptr;
|
||||||
AppConfig config_;
|
AppConfig config_;
|
||||||
|
|||||||
@@ -1,93 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
namespace frostbite2D {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief 模块基类
|
|
||||||
* 所有模块只需继承此类,实现需要的生命周期方法
|
|
||||||
*/
|
|
||||||
class Module {
|
|
||||||
public:
|
|
||||||
/**
|
|
||||||
* @brief 虚析构函数
|
|
||||||
*/
|
|
||||||
virtual ~Module() = default;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief 设置模块(初始化)
|
|
||||||
* 在 Application::run() 开始前调用
|
|
||||||
*/
|
|
||||||
virtual void setupModule() {}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief 销毁模块
|
|
||||||
* 在 Application 关闭时调用
|
|
||||||
*/
|
|
||||||
virtual void destroyModule() {}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief 更新时
|
|
||||||
* 每帧调用
|
|
||||||
* @param ctx 更新上下文
|
|
||||||
*/
|
|
||||||
virtual void onUpdate() { }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief 渲染前
|
|
||||||
* 在渲染开始前调用
|
|
||||||
* @param ctx 渲染上下文
|
|
||||||
*/
|
|
||||||
virtual void beforeRender() { }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief 渲染时
|
|
||||||
* 在渲染阶段调用
|
|
||||||
* @param ctx 渲染上下文
|
|
||||||
*/
|
|
||||||
virtual void onRender() {}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief 渲染后
|
|
||||||
* 在渲染完成后调用
|
|
||||||
* @param ctx 渲染上下文
|
|
||||||
*/
|
|
||||||
virtual void afterRender() { }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief 事件处理
|
|
||||||
* 处理系统事件
|
|
||||||
* @param ctx 事件上下文
|
|
||||||
*/
|
|
||||||
virtual void handleEvent() { }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief 获取模块名称
|
|
||||||
* @return 模块名称字符串
|
|
||||||
*/
|
|
||||||
virtual const char *getName() const = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief 获取模块优先级
|
|
||||||
* 数值越小越先执行
|
|
||||||
* @return 优先级值
|
|
||||||
*/
|
|
||||||
virtual int getPriority() const { return 0; }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief 检查模块是否已初始化
|
|
||||||
* @return 已初始化返回 true
|
|
||||||
*/
|
|
||||||
bool isInitialized() const { return initialized_; }
|
|
||||||
|
|
||||||
protected:
|
|
||||||
friend class Application;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief 设置初始化状态
|
|
||||||
* @param initialized 初始化状态
|
|
||||||
*/
|
|
||||||
void setInitialized(bool initialized) { initialized_ = initialized; }
|
|
||||||
|
|
||||||
bool initialized_ = false;
|
|
||||||
};
|
|
||||||
} // namespace frostbite2D
|
|
||||||
@@ -12,23 +12,6 @@ Application &Application::get() {
|
|||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::use(Module &m) {
|
|
||||||
for (auto *existing : modules_) {
|
|
||||||
if (existing == &m) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
modules_.push_back(&m);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Application::use(std::initializer_list<Module *> modules) {
|
|
||||||
for (auto *m : modules) {
|
|
||||||
if (m) {
|
|
||||||
use(*m);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Application::init() {
|
bool Application::init() {
|
||||||
AppConfig cfg;
|
AppConfig cfg;
|
||||||
return init(cfg);
|
return init(cfg);
|
||||||
@@ -73,8 +56,6 @@ void Application::shutdown() {
|
|||||||
running_ = false;
|
running_ = false;
|
||||||
shouldQuit_ = true;
|
shouldQuit_ = true;
|
||||||
|
|
||||||
destroyAllModules();
|
|
||||||
|
|
||||||
// 关闭渲染器
|
// 关闭渲染器
|
||||||
if (renderer_) {
|
if (renderer_) {
|
||||||
renderer_->shutdown();
|
renderer_->shutdown();
|
||||||
@@ -130,29 +111,6 @@ bool Application::initCoreModules() {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::setupAllModules() {
|
|
||||||
SDL_Log("Setting up modules (%zu)...", modules_.size());
|
|
||||||
|
|
||||||
for (auto* module : modules_) {
|
|
||||||
if (module && !module->isInitialized()) {
|
|
||||||
module->setupModule();
|
|
||||||
module->setInitialized(true);
|
|
||||||
SDL_Log("Module '%s' initialized", module->getName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Application::destroyAllModules() {
|
|
||||||
SDL_Log("Destroying modules (%zu)...", modules_.size());
|
|
||||||
|
|
||||||
for (auto* module : modules_) {
|
|
||||||
if (module && module->isInitialized()) {
|
|
||||||
module->destroyModule();
|
|
||||||
module->setInitialized(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Application::run() {
|
void Application::run() {
|
||||||
if (!initialized_) {
|
if (!initialized_) {
|
||||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Application not initialized!");
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Application not initialized!");
|
||||||
@@ -169,8 +127,6 @@ void Application::run() {
|
|||||||
shouldQuit_ = false;
|
shouldQuit_ = false;
|
||||||
paused_ = false;
|
paused_ = false;
|
||||||
|
|
||||||
setupAllModules();
|
|
||||||
|
|
||||||
lastFrameTime_ = SDL_GetPerformanceCounter() / static_cast<double>(SDL_GetPerformanceFrequency());
|
lastFrameTime_ = SDL_GetPerformanceCounter() / static_cast<double>(SDL_GetPerformanceFrequency());
|
||||||
totalTime_ = 0.0f;
|
totalTime_ = 0.0f;
|
||||||
deltaTime_ = 0.0f;
|
deltaTime_ = 0.0f;
|
||||||
@@ -180,7 +136,6 @@ void Application::run() {
|
|||||||
|
|
||||||
mainLoop();
|
mainLoop();
|
||||||
|
|
||||||
destroyAllModules();
|
|
||||||
running_ = false;
|
running_ = false;
|
||||||
SDL_Log("Application stopped");
|
SDL_Log("Application stopped");
|
||||||
}
|
}
|
||||||
@@ -213,11 +168,6 @@ void Application::mainLoop() {
|
|||||||
shouldQuit_ = true;
|
shouldQuit_ = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
for (auto* module : modules_) {
|
|
||||||
if (module && module->isInitialized()) {
|
|
||||||
module->handleEvent();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!paused_) {
|
if (!paused_) {
|
||||||
@@ -234,12 +184,6 @@ void Application::update() {
|
|||||||
lastFrameTime_ = currentTime;
|
lastFrameTime_ = currentTime;
|
||||||
totalTime_ += deltaTime_;
|
totalTime_ += deltaTime_;
|
||||||
|
|
||||||
for (auto* module : modules_) {
|
|
||||||
if (module && module->isInitialized()) {
|
|
||||||
module->onUpdate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
frameCount_++;
|
frameCount_++;
|
||||||
fpsTimer_ += deltaTime_;
|
fpsTimer_ += deltaTime_;
|
||||||
if (fpsTimer_ >= fpsUpdateInterval_) {
|
if (fpsTimer_ >= fpsUpdateInterval_) {
|
||||||
@@ -250,24 +194,6 @@ void Application::update() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Application::render() {
|
void Application::render() {
|
||||||
for (auto* module : modules_) {
|
|
||||||
if (module && module->isInitialized()) {
|
|
||||||
module->beforeRender();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (auto* module : modules_) {
|
|
||||||
if (module && module->isInitialized()) {
|
|
||||||
module->onRender();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (auto* module : modules_) {
|
|
||||||
if (module && module->isInitialized()) {
|
|
||||||
module->afterRender();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (window_) {
|
if (window_) {
|
||||||
window_->swap();
|
window_->swap();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user