#pragma once #include #include #include #include namespace extra2d { // 前向声明 class Context; class WindowModule; class InputModule; /** * @brief 应用程序主控类 - 简化版 * * 管理应用程序生命周期、窗口和主循环 * 自动管理模块的创建和销毁 */ class Application { public: /** * @brief 创建应用程序实例 */ static std::unique_ptr create(); Application(const Application&) = delete; Application& operator=(const Application&) = delete; Application(Application&&) noexcept; Application& operator=(Application&&) noexcept; ~Application(); /** * @brief 初始化应用程序 */ bool init(const AppConfig& config); /** * @brief 关闭应用程序 */ void shutdown(); /** * @brief 运行主循环 */ void run(); /** * @brief 请求退出 */ void quit(); /** * @brief 暂停应用 */ void pause(); /** * @brief 恢复应用 */ void resume(); /** * @brief 是否暂停 */ bool isPaused() const { return paused_; } /** * @brief 是否运行中 */ bool isRunning() const { return running_; } /** * @brief 获取帧时间 */ float deltaTime() const { return deltaTime_; } /** * @brief 获取总运行时间 */ float totalTime() const { return totalTime_; } /** * @brief 获取当前 FPS */ int32 fps() const { return 0; } // TODO: 使用 SDL 计算 FPS /** * @brief 获取配置 */ const AppConfig& getConfig() const { return config_; } /** * @brief 获取引擎上下文 */ Context* getContext() const { return context_.get(); } /** * @brief 获取窗口模块 */ WindowModule* getWindow() const; /** * @brief 获取输入模块 */ InputModule* getInput() const; /** * @brief 获取指定类型的模块 * @tparam T 模块类型 * @return 模块指针,未找到返回 nullptr */ template T* getModule() const { for (const auto& module : modules_) { if (auto* ptr = dynamic_cast(module.get())) { return ptr; } } return nullptr; } /** * @brief 获取窗口宽度 */ int32 getWindowWidth() const; /** * @brief 获取窗口高度 */ int32 getWindowHeight() const; /** * @brief 获取窗口标题 */ const char* getWindowTitle() const; private: Application(); void update(); void initModules(); std::unique_ptr context_; std::vector> modules_; AppConfig config_; bool initialized_ = false; bool running_ = false; bool paused_ = false; bool shouldQuit_ = false; float deltaTime_ = 0.0f; float totalTime_ = 0.0f; }; } // namespace extra2d