refactor(core): 移除模块系统及相关功能
删除模块系统实现及相关代码,包括Module类、Application中的模块管理功能 移除AGENTS.md中关于模块模式的文档
This commit is contained in:
@@ -181,13 +181,6 @@ Frostbite2D/
|
||||
|
||||
## Key Patterns
|
||||
|
||||
### Module Pattern
|
||||
```cpp
|
||||
void Application::use(Module& m) {
|
||||
modules_.push_back(&m);
|
||||
}
|
||||
```
|
||||
|
||||
### Configuration Pattern
|
||||
Use configuration structs with default values:
|
||||
```cpp
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <frostbite2D/core/window.h>
|
||||
#include <frostbite2D/module/module.h>
|
||||
#include <frostbite2D/types/type_alias.h>
|
||||
#include <string>
|
||||
|
||||
@@ -64,18 +63,6 @@ public:
|
||||
Application(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 使用默认配置初始化
|
||||
* @return 初始化成功返回 true
|
||||
@@ -172,16 +159,6 @@ private:
|
||||
*/
|
||||
bool initCoreModules();
|
||||
|
||||
/**
|
||||
* @brief 设置所有模块
|
||||
*/
|
||||
void setupAllModules();
|
||||
|
||||
/**
|
||||
* @brief 销毁所有模块
|
||||
*/
|
||||
void destroyAllModules();
|
||||
|
||||
/**
|
||||
* @brief 主循环
|
||||
*/
|
||||
@@ -197,7 +174,6 @@ private:
|
||||
*/
|
||||
void render();
|
||||
|
||||
std::vector<Module*> modules_;
|
||||
Window* window_ = nullptr;
|
||||
class Renderer* renderer_ = nullptr;
|
||||
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,29 +12,12 @@ Application &Application::get() {
|
||||
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() {
|
||||
AppConfig cfg;
|
||||
return init(cfg);
|
||||
}
|
||||
|
||||
bool Application::init(const AppConfig &config) {
|
||||
bool Application::init(const AppConfig& config) {
|
||||
if (initialized_) {
|
||||
return true;
|
||||
}
|
||||
@@ -42,9 +25,9 @@ bool Application::init(const AppConfig &config) {
|
||||
config_ = config;
|
||||
|
||||
// 平台相关初始化
|
||||
#ifdef __SWITCH__
|
||||
#ifdef __SWITCH__
|
||||
switchInit();
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// 使用SDL2创建窗口
|
||||
this->window_ = new Window();
|
||||
@@ -73,8 +56,6 @@ void Application::shutdown() {
|
||||
running_ = false;
|
||||
shouldQuit_ = true;
|
||||
|
||||
destroyAllModules();
|
||||
|
||||
// 关闭渲染器
|
||||
if (renderer_) {
|
||||
renderer_->shutdown();
|
||||
@@ -87,9 +68,9 @@ void Application::shutdown() {
|
||||
}
|
||||
|
||||
// 平台相关清理
|
||||
#ifdef __SWITCH__
|
||||
#ifdef __SWITCH__
|
||||
switchShutdown();
|
||||
#endif
|
||||
#endif
|
||||
|
||||
initialized_ = false;
|
||||
running_ = false;
|
||||
@@ -105,15 +86,15 @@ bool Application::initCoreModules() {
|
||||
auto &asset = Asset::get();
|
||||
|
||||
// 平台相关 switch平台不可以获取当前工作目录
|
||||
#ifndef __SWITCH__
|
||||
#ifndef __SWITCH__
|
||||
// 获取程序工作目录
|
||||
std::string workingDir = SDL_GetBasePath();
|
||||
asset.setWorkingDirectory(workingDir);
|
||||
SDL_Log("Asset working directory: %s", workingDir.c_str());
|
||||
#else
|
||||
#else
|
||||
asset.setWorkingDirectory("/switch/Frostbite2D/" + config_.appName);
|
||||
SDL_Log("Asset working directory: %s", asset.getWorkingDirectory().c_str());
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// 初始化渲染器
|
||||
renderer_ = &Renderer::get();
|
||||
@@ -130,29 +111,6 @@ bool Application::initCoreModules() {
|
||||
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() {
|
||||
if (!initialized_) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Application not initialized!");
|
||||
@@ -169,8 +127,6 @@ void Application::run() {
|
||||
shouldQuit_ = false;
|
||||
paused_ = false;
|
||||
|
||||
setupAllModules();
|
||||
|
||||
lastFrameTime_ = SDL_GetPerformanceCounter() / static_cast<double>(SDL_GetPerformanceFrequency());
|
||||
totalTime_ = 0.0f;
|
||||
deltaTime_ = 0.0f;
|
||||
@@ -180,7 +136,6 @@ void Application::run() {
|
||||
|
||||
mainLoop();
|
||||
|
||||
destroyAllModules();
|
||||
running_ = false;
|
||||
SDL_Log("Application stopped");
|
||||
}
|
||||
@@ -213,11 +168,6 @@ void Application::mainLoop() {
|
||||
shouldQuit_ = true;
|
||||
break;
|
||||
}
|
||||
for (auto* module : modules_) {
|
||||
if (module && module->isInitialized()) {
|
||||
module->handleEvent();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!paused_) {
|
||||
@@ -234,12 +184,6 @@ void Application::update() {
|
||||
lastFrameTime_ = currentTime;
|
||||
totalTime_ += deltaTime_;
|
||||
|
||||
for (auto* module : modules_) {
|
||||
if (module && module->isInitialized()) {
|
||||
module->onUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
frameCount_++;
|
||||
fpsTimer_ += deltaTime_;
|
||||
if (fpsTimer_ >= fpsUpdateInterval_) {
|
||||
@@ -250,24 +194,6 @@ void Application::update() {
|
||||
}
|
||||
|
||||
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_) {
|
||||
window_->swap();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user