Extra2D/include/app/application.h

168 lines
3.1 KiB
C++

#pragma once
#include <string>
#include <types/base/types.h>
#include <memory>
namespace extra2d {
// 前向声明
class Context;
class WindowModule;
class InputModule;
/**
* @brief 应用程序配置
*/
struct AppConfig {
std::string title = "Extra2D Application";
int32 width = 1280;
int32 height = 720;
bool fullscreen = false;
bool resizable = true;
bool vsync = true;
int32 fpsLimit = 0;
int32 glMajor = 3;
int32 glMinor = 3;
bool enableCursors = true;
bool enableDpiScale = false;
};
/**
* @brief 应用程序主控类
*
* 管理应用程序生命周期、窗口和主循环
* 基于新的 Context 架构,支持多实例
*/
class Application {
public:
/**
* @brief 创建应用程序实例
*/
static std::unique_ptr<Application> 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 currentFps_; }
/**
* @brief 获取配置
*/
const AppConfig& getConfig() const { return config_; }
/**
* @brief 获取引擎上下文
*/
Context* getContext() const { return context_.get(); }
/**
* @brief 获取窗口模块
*/
WindowModule* getWindow() const { return windowModule_.get(); }
/**
* @brief 获取输入模块
*/
InputModule* getInput() const { return inputModule_.get(); }
/**
* @brief 获取窗口宽度
*/
int32 getWindowWidth() const;
/**
* @brief 获取窗口高度
*/
int32 getWindowHeight() const;
/**
* @brief 获取窗口标题
*/
const char* getWindowTitle() const;
private:
Application();
void mainLoop();
void update();
std::unique_ptr<Context> context_;
std::unique_ptr<WindowModule> windowModule_;
std::unique_ptr<InputModule> inputModule_;
AppConfig config_;
bool initialized_ = false;
bool running_ = false;
bool paused_ = false;
bool shouldQuit_ = false;
float deltaTime_ = 0.0f;
float totalTime_ = 0.0f;
double lastFrameTime_ = 0.0;
int32 frameCount_ = 0;
float fpsTimer_ = 0.0f;
int32 currentFps_ = 0;
};
} // namespace extra2d