#pragma once #include #include namespace extra2d { // 前向声明 class ModuleRegistry; class PluginLoader; class TimerModule; class RendererModule; /** * @brief 引擎上下文 * * 管理引擎的核心生命周期,包含模块注册表、插件加载器和定时器模块 * 非单例设计,支持创建多个独立的引擎实例 */ class Context { public: Context(); ~Context(); // 禁止拷贝 Context(const Context&) = delete; Context& operator=(const Context&) = delete; // 允许移动 Context(Context&&) noexcept; Context& operator=(Context&&) noexcept; /** * @brief 创建上下文(工厂方法) */ static std::unique_ptr create(); /** * @brief 初始化引擎 * @return 初始化是否成功 */ bool init(); /** * @brief 关闭引擎 */ void shutdown(); /** * @brief 主循环单帧更新 * @param dt 帧间隔时间(秒) */ void tick(float dt); /** * @brief 获取模块注册表 */ ModuleRegistry& modules(); /** * @brief 获取插件加载器 */ PluginLoader& plugins(); /** * @brief 获取定时器模块 */ TimerModule& timer(); /** * @brief 获取渲染器模块 */ RendererModule& renderer(); private: /** * @brief 获取总运行时间 */ float totalTime() const { return totalTime_; } /** * @brief 获取帧数 */ uint64 frameCount() const { return frameCount_; } /** * @brief 检查是否正在运行 */ bool isRunning() const { return running_; } /** * @brief 请求停止引擎 */ void stop() { running_ = false; } private: std::unique_ptr pluginLoader_; float totalTime_ = 0.0f; uint64 frameCount_ = 0; bool running_ = false; bool inited_ = false; }; } // namespace extra2d