Extra2D/include/app/application.h

77 lines
1.6 KiB
C++

#pragma once
#include <string>
#include <types/base/types.h>
namespace extra2d {
enum class PlatformType { Auto = 0, PC, Switch };
struct AppConfig {
std::string title = "Extra2D Application";
int width = 800;
int height = 600;
bool fullscreen = false;
bool resizable = true;
bool vsync = true;
int fpsLimit = 0;
int msaaSamples = 0;
PlatformType platform = PlatformType::Auto;
bool enableCursors = true;
bool enableDpiScale = false;
};
/**
* @brief 应用程序主控类
*
* 管理应用程序生命周期、窗口和主循环
*/
class Application {
public:
static Application& instance();
Application(const Application&) = delete;
Application& operator=(const Application&) = delete;
bool init(const AppConfig& config);
void shutdown();
void run();
void quit();
void pause();
void resume();
bool isPaused() const { return paused_; }
bool isRunning() const { return running_; }
float deltaTime() const { return deltaTime_; }
float totalTime() const { return totalTime_; }
int fps() const { return currentFps_; }
const AppConfig& getConfig() const { return config_; }
private:
Application() = default;
~Application();
void mainLoop();
void update();
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;
int frameCount_ = 0;
float fpsTimer_ = 0.0f;
int currentFps_ = 0;
};
#define APP extra2d::Application::instance()
} // namespace extra2d