Extra2D/include/app/application.h

77 lines
1.6 KiB
C
Raw Normal View History

2026-02-11 19:40:26 +08:00
#pragma once
#include <string>
#include <types/base/types.h>
2026-02-11 19:40:26 +08:00
namespace extra2d {
enum class PlatformType { Auto = 0, PC, Switch };
2026-02-11 19:40:26 +08:00
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;
2026-02-11 19:40:26 +08:00
};
/**
* @brief
*
*
*/
2026-02-11 19:40:26 +08:00
class Application {
public:
static Application& instance();
2026-02-11 19:40:26 +08:00
Application(const Application&) = delete;
Application& operator=(const Application&) = delete;
2026-02-11 19:40:26 +08:00
bool init(const AppConfig& config);
void shutdown();
void run();
void quit();
2026-02-11 19:40:26 +08:00
void pause();
void resume();
bool isPaused() const { return paused_; }
bool isRunning() const { return running_; }
2026-02-11 19:40:26 +08:00
float deltaTime() const { return deltaTime_; }
float totalTime() const { return totalTime_; }
int fps() const { return currentFps_; }
2026-02-11 19:40:26 +08:00
const AppConfig& getConfig() const { return config_; }
2026-02-11 19:40:26 +08:00
private:
Application() = default;
~Application();
2026-02-11 19:40:26 +08:00
void mainLoop();
void update();
2026-02-11 19:40:26 +08:00
AppConfig config_;
2026-02-11 19:40:26 +08:00
bool initialized_ = false;
bool running_ = false;
bool paused_ = false;
bool shouldQuit_ = false;
2026-02-11 19:40:26 +08:00
float deltaTime_ = 0.0f;
float totalTime_ = 0.0f;
double lastFrameTime_ = 0.0;
int frameCount_ = 0;
float fpsTimer_ = 0.0f;
int currentFps_ = 0;
2026-02-11 19:40:26 +08:00
};
#define APP extra2d::Application::instance()
2026-02-11 19:40:26 +08:00
} // namespace extra2d