2026-02-11 19:40:26 +08:00
|
|
|
#pragma once
|
|
|
|
|
|
2026-02-25 06:23:53 +08:00
|
|
|
#include <core/types.h>
|
2026-02-26 20:21:55 +08:00
|
|
|
#include <string>
|
2026-02-11 19:40:26 +08:00
|
|
|
#include <memory>
|
2026-02-26 00:59:16 +08:00
|
|
|
#include <platform/window.h>
|
|
|
|
|
|
2026-02-11 19:40:26 +08:00
|
|
|
namespace extra2d {
|
|
|
|
|
|
|
|
|
|
// 前向声明
|
|
|
|
|
class Input;
|
|
|
|
|
class TimerManager;
|
|
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
|
// Application 配置
|
|
|
|
|
// ============================================================================
|
|
|
|
|
|
2026-02-26 00:59:16 +08:00
|
|
|
enum class PlatformType { Auto = 0, PC, Switch };
|
2026-02-11 19:40:26 +08:00
|
|
|
|
|
|
|
|
struct AppConfig {
|
|
|
|
|
std::string title = "Easy2D 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;
|
2026-02-27 19:12:24 +08:00
|
|
|
bool enableCursors = true;
|
|
|
|
|
bool enableDpiScale = false;
|
2026-02-11 19:40:26 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
|
// Application 单例 - 应用主控
|
|
|
|
|
// ============================================================================
|
|
|
|
|
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_; }
|
|
|
|
|
|
|
|
|
|
Window &window() { return *window_; }
|
|
|
|
|
Input &input();
|
|
|
|
|
TimerManager &timers();
|
|
|
|
|
|
|
|
|
|
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_;
|
|
|
|
|
|
|
|
|
|
UniquePtr<Window> window_;
|
|
|
|
|
UniquePtr<TimerManager> timerManager_;
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace extra2d
|