2026-02-11 19:40:26 +08:00
|
|
|
#pragma once
|
|
|
|
|
|
2026-02-25 06:23:53 +08:00
|
|
|
#include <core/string.h>
|
|
|
|
|
#include <core/types.h>
|
2026-02-26 19:57:16 +08:00
|
|
|
#include <renderer/renderer.h>
|
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 AudioEngine;
|
|
|
|
|
class SceneManager;
|
|
|
|
|
class ResourceManager;
|
|
|
|
|
class TimerManager;
|
|
|
|
|
class EventQueue;
|
|
|
|
|
class EventDispatcher;
|
|
|
|
|
class Camera;
|
|
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
|
// 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;
|
2026-02-26 00:59:16 +08:00
|
|
|
BackendType Renderer = BackendType::OpenGL;
|
2026-02-11 19:40:26 +08:00
|
|
|
int msaaSamples = 0;
|
|
|
|
|
PlatformType platform = PlatformType::Auto;
|
2026-02-12 14:29:50 +08:00
|
|
|
// 窗口高级配置
|
2026-02-26 00:59:16 +08:00
|
|
|
bool enableCursors = true; // 是否启用光标
|
|
|
|
|
bool enableDpiScale = false; // 是否启用DPI缩放
|
2026-02-11 19:40:26 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
|
// Application 单例 - 应用主控
|
|
|
|
|
// ============================================================================
|
|
|
|
|
class Application {
|
|
|
|
|
public:
|
|
|
|
|
// Meyer's 单例
|
|
|
|
|
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_; }
|
2026-02-26 00:59:16 +08:00
|
|
|
Renderer &renderer() { return *renderer_; }
|
2026-02-11 19:40:26 +08:00
|
|
|
Input &input();
|
|
|
|
|
AudioEngine &audio();
|
|
|
|
|
SceneManager &scenes();
|
|
|
|
|
ResourceManager &resources();
|
|
|
|
|
TimerManager &timers();
|
|
|
|
|
EventQueue &eventQueue();
|
|
|
|
|
EventDispatcher &eventDispatcher();
|
|
|
|
|
Camera &camera();
|
|
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
|
// 便捷方法
|
|
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
|
void enterScene(Ptr<class Scene> scene);
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
void render();
|
|
|
|
|
|
|
|
|
|
// 配置
|
|
|
|
|
AppConfig config_;
|
|
|
|
|
|
|
|
|
|
// 子系统
|
|
|
|
|
UniquePtr<Window> window_;
|
2026-02-26 00:59:16 +08:00
|
|
|
UniquePtr<Renderer> renderer_;
|
2026-02-11 19:40:26 +08:00
|
|
|
UniquePtr<SceneManager> sceneManager_;
|
|
|
|
|
UniquePtr<ResourceManager> resourceManager_;
|
|
|
|
|
UniquePtr<TimerManager> timerManager_;
|
|
|
|
|
UniquePtr<EventQueue> eventQueue_;
|
|
|
|
|
UniquePtr<EventDispatcher> eventDispatcher_;
|
|
|
|
|
UniquePtr<Camera> camera_;
|
|
|
|
|
|
|
|
|
|
// 状态
|
|
|
|
|
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
|