Frostbite2D/Fostbite2D/include/fostbite2D/app/application.h

216 lines
4.2 KiB
C
Raw Normal View History

2026-02-17 13:28:38 +08:00
#pragma once
#include <fostbite2D/module/module.h>
#include <fostbite2D/config/app_config.h>
#include <fostbite2D/platform/window.h>
#include <string>
namespace frostbite2D {
/**
* @brief
*/
class Application {
public:
/**
* @brief
* @return
*/
static Application& get();
Application(const Application&) = delete;
Application& operator=(const Application&) = delete;
/**
* @brief
* @param m
*/
void use(Module& m);
/**
* @brief
* @param modules
*/
void use(std::initializer_list<Module*> modules);
/**
* @brief 使
* @return true
*/
bool init();
/**
* @brief 使
* @param config
* @return true
*/
bool init(const AppConfig& config);
/**
* @brief 使
* @param configPath
* @return true
*/
bool init(const std::string& configPath);
/**
* @brief
*/
void shutdown();
/**
* @brief
*/
void run();
/**
* @brief 退
*/
void quit();
/**
* @brief
*/
void pause();
/**
* @brief
*/
void resume();
/**
* @brief
* @return true
*/
bool isPaused() const { return paused_; }
/**
* @brief
* @return true
*/
bool isRunning() const { return running_; }
// /**
// * @brief 获取窗口
// * @return 窗口引用
// */
// IWindow& window() { return *window_; }
// /**
// * @brief 获取渲染器
// * @return 渲染器引用
// */
// RenderBackend& renderer();
// /**
// * @brief 获取场景服务
// * @return 场景服务共享指针
// */
// SharedPtr<class ISceneService> scenes();
// /**
// * @brief 获取计时器服务
// * @return 计时器服务共享指针
// */
// SharedPtr<class ITimerService> timers();
// /**
// * @brief 获取事件服务
// * @return 事件服务共享指针
// */
// SharedPtr<class IEventService> events();
// /**
// * @brief 获取相机服务
// * @return 相机服务共享指针
// */
// SharedPtr<class ICameraService> camera();
// /**
// * @brief 进入场景
// * @param scene 场景指针
// */
// void enterScene(Ptr<class Scene> scene);
/**
* @brief
* @return
*/
float deltaTime() const { return deltaTime_; }
/**
* @brief
* @return
*/
float totalTime() const { return totalTime_; }
/**
* @brief
* @return
*/
int fps() const { return currentFps_; }
/**
* @brief
* @return
*/
const AppConfig& getConfig() const;
private:
Application() = default;
~Application();
/**
* @brief
* @return true
*/
bool initCoreModules();
/**
* @brief
*/
void setupAllModules();
/**
* @brief
*/
void destroyAllModules();
/**
* @brief
*/
void registerCoreServices();
/**
* @brief
*/
void mainLoop();
/**
* @brief
*/
void update();
/**
* @brief
*/
void render();
std::vector<Module*> modules_;
Window* window_ = nullptr;
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;
};
}