Extra2D/include/app/application.h

162 lines
3.0 KiB
C
Raw Normal View History

2026-02-11 19:40:26 +08:00
#pragma once
#include <config/app_config.h>
#include <module/module.h>
#include <memory>
#include <vector>
2026-02-11 19:40:26 +08:00
namespace extra2d {
// 前向声明
class Context;
class WindowModule;
class InputModule;
/**
* @brief -
*
*
*
*/
2026-02-11 19:40:26 +08:00
class Application {
public:
/**
* @brief
*/
static std::unique_ptr<Application> create();
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
Application(Application&&) noexcept;
Application& operator=(Application&&) noexcept;
~Application();
/**
* @brief
*/
bool init(const AppConfig& config);
/**
* @brief
*/
void shutdown();
/**
* @brief
*/
void run();
/**
* @brief 退
*/
void quit();
2026-02-11 19:40:26 +08:00
/**
* @brief
*/
void pause();
/**
* @brief
*/
void resume();
/**
* @brief
*/
bool isPaused() const { return paused_; }
/**
* @brief
*/
bool isRunning() const { return running_; }
2026-02-11 19:40:26 +08:00
/**
* @brief
*/
float deltaTime() const { return deltaTime_; }
/**
* @brief
*/
float totalTime() const { return totalTime_; }
/**
* @brief FPS
*/
int32 fps() const { return 0; } // TODO: 使用 SDL 计算 FPS
/**
* @brief
*/
const AppConfig& getConfig() const { return config_; }
2026-02-11 19:40:26 +08:00
/**
* @brief
*/
Context* getContext() const { return context_.get(); }
/**
* @brief
*/
WindowModule* getWindow() const;
/**
* @brief
*/
InputModule* getInput() const;
/**
* @brief
* @tparam T
* @return nullptr
*/
template<typename T>
T* getModule() const {
for (const auto& module : modules_) {
if (auto* ptr = dynamic_cast<T*>(module.get())) {
return ptr;
}
}
return nullptr;
}
/**
* @brief
*/
int32 getWindowWidth() const;
/**
* @brief
*/
int32 getWindowHeight() const;
/**
* @brief
*/
const char* getWindowTitle() const;
2026-02-11 19:40:26 +08:00
private:
Application();
2026-02-11 19:40:26 +08:00
void update();
void initModules();
2026-02-11 19:40:26 +08:00
std::unique_ptr<Context> context_;
std::vector<std::unique_ptr<Module>> modules_;
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;
2026-02-11 19:40:26 +08:00
};
} // namespace extra2d