2026-02-11 19:40:26 +08:00
|
|
|
#pragma once
|
|
|
|
|
|
2026-02-26 20:21:55 +08:00
|
|
|
#include <string>
|
2026-02-27 20:46:16 +08:00
|
|
|
#include <types/base/types.h>
|
2026-02-26 00:59:16 +08:00
|
|
|
|
2026-02-11 19:40:26 +08:00
|
|
|
namespace extra2d {
|
|
|
|
|
|
2026-02-27 22:59:17 +08:00
|
|
|
/**
|
|
|
|
|
* @brief 应用程序配置
|
|
|
|
|
*/
|
2026-02-11 19:40:26 +08:00
|
|
|
struct AppConfig {
|
2026-02-27 20:46:16 +08:00
|
|
|
std::string title = "Extra2D Application";
|
2026-02-27 22:59:17 +08:00
|
|
|
int32 width = 1280;
|
|
|
|
|
int32 height = 720;
|
2026-02-27 20:46:16 +08:00
|
|
|
bool fullscreen = false;
|
|
|
|
|
bool resizable = true;
|
|
|
|
|
bool vsync = true;
|
2026-02-27 22:59:17 +08:00
|
|
|
int32 fpsLimit = 0;
|
|
|
|
|
int32 glMajor = 3;
|
|
|
|
|
int32 glMinor = 3;
|
2026-02-27 20:46:16 +08:00
|
|
|
bool enableCursors = true;
|
|
|
|
|
bool enableDpiScale = false;
|
2026-02-11 19:40:26 +08:00
|
|
|
};
|
|
|
|
|
|
2026-02-27 20:46:16 +08:00
|
|
|
/**
|
|
|
|
|
* @brief 应用程序主控类
|
|
|
|
|
*
|
|
|
|
|
* 管理应用程序生命周期、窗口和主循环
|
|
|
|
|
*/
|
2026-02-11 19:40:26 +08:00
|
|
|
class Application {
|
|
|
|
|
public:
|
2026-02-27 22:59:17 +08:00
|
|
|
/**
|
|
|
|
|
* @brief 获取单例实例
|
|
|
|
|
*/
|
2026-02-27 20:46:16 +08:00
|
|
|
static Application& instance();
|
2026-02-11 19:40:26 +08:00
|
|
|
|
2026-02-27 20:46:16 +08:00
|
|
|
Application(const Application&) = delete;
|
|
|
|
|
Application& operator=(const Application&) = delete;
|
2026-02-11 19:40:26 +08:00
|
|
|
|
2026-02-27 22:59:17 +08:00
|
|
|
/**
|
|
|
|
|
* @brief 初始化应用程序
|
|
|
|
|
*/
|
2026-02-27 20:46:16 +08:00
|
|
|
bool init(const AppConfig& config);
|
2026-02-27 22:59:17 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief 关闭应用程序
|
|
|
|
|
*/
|
2026-02-27 20:46:16 +08:00
|
|
|
void shutdown();
|
2026-02-27 22:59:17 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief 运行主循环
|
|
|
|
|
*/
|
2026-02-27 20:46:16 +08:00
|
|
|
void run();
|
2026-02-27 22:59:17 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief 请求退出
|
|
|
|
|
*/
|
2026-02-27 20:46:16 +08:00
|
|
|
void quit();
|
2026-02-11 19:40:26 +08:00
|
|
|
|
2026-02-27 22:59:17 +08:00
|
|
|
/**
|
|
|
|
|
* @brief 暂停应用
|
|
|
|
|
*/
|
2026-02-27 20:46:16 +08:00
|
|
|
void pause();
|
2026-02-27 22:59:17 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief 恢复应用
|
|
|
|
|
*/
|
2026-02-27 20:46:16 +08:00
|
|
|
void resume();
|
2026-02-27 22:59:17 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief 是否暂停
|
|
|
|
|
*/
|
2026-02-27 20:46:16 +08:00
|
|
|
bool isPaused() const { return paused_; }
|
2026-02-27 22:59:17 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief 是否运行中
|
|
|
|
|
*/
|
2026-02-27 20:46:16 +08:00
|
|
|
bool isRunning() const { return running_; }
|
2026-02-11 19:40:26 +08:00
|
|
|
|
2026-02-27 22:59:17 +08:00
|
|
|
/**
|
|
|
|
|
* @brief 获取帧时间
|
|
|
|
|
*/
|
2026-02-27 20:46:16 +08:00
|
|
|
float deltaTime() const { return deltaTime_; }
|
2026-02-27 22:59:17 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief 获取总运行时间
|
|
|
|
|
*/
|
2026-02-27 20:46:16 +08:00
|
|
|
float totalTime() const { return totalTime_; }
|
2026-02-27 22:59:17 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief 获取当前 FPS
|
|
|
|
|
*/
|
|
|
|
|
int32 fps() const { return currentFps_; }
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief 获取配置
|
|
|
|
|
*/
|
2026-02-27 20:46:16 +08:00
|
|
|
const AppConfig& getConfig() const { return config_; }
|
2026-02-11 19:40:26 +08:00
|
|
|
|
|
|
|
|
private:
|
2026-02-27 20:46:16 +08:00
|
|
|
Application() = default;
|
|
|
|
|
~Application();
|
2026-02-11 19:40:26 +08:00
|
|
|
|
2026-02-27 20:46:16 +08:00
|
|
|
void mainLoop();
|
|
|
|
|
void update();
|
2026-02-11 19:40:26 +08:00
|
|
|
|
2026-02-27 20:46:16 +08:00
|
|
|
AppConfig config_;
|
2026-02-11 19:40:26 +08:00
|
|
|
|
2026-02-27 20:46:16 +08:00
|
|
|
bool initialized_ = false;
|
|
|
|
|
bool running_ = false;
|
|
|
|
|
bool paused_ = false;
|
|
|
|
|
bool shouldQuit_ = false;
|
2026-02-11 19:40:26 +08:00
|
|
|
|
2026-02-27 20:46:16 +08:00
|
|
|
float deltaTime_ = 0.0f;
|
|
|
|
|
float totalTime_ = 0.0f;
|
|
|
|
|
double lastFrameTime_ = 0.0;
|
2026-02-27 22:59:17 +08:00
|
|
|
int32 frameCount_ = 0;
|
2026-02-27 20:46:16 +08:00
|
|
|
float fpsTimer_ = 0.0f;
|
2026-02-27 22:59:17 +08:00
|
|
|
int32 currentFps_ = 0;
|
2026-02-11 19:40:26 +08:00
|
|
|
};
|
|
|
|
|
|
2026-02-27 20:46:16 +08:00
|
|
|
#define APP extra2d::Application::instance()
|
|
|
|
|
|
2026-02-11 19:40:26 +08:00
|
|
|
} // namespace extra2d
|