Extra2D/Extra2D/include/extra2d/app/application.h

144 lines
2.8 KiB
C
Raw Normal View History

2026-02-11 19:40:26 +08:00
#pragma once
#include <extra2d/core/types.h>
#include <extra2d/core/module.h>
#include <extra2d/core/registry.h>
#include <extra2d/core/service_locator.h>
#include <extra2d/config/app_config.h>
#include <string>
2026-02-11 19:40:26 +08:00
namespace extra2d {
class IWindow;
class IInput;
class RenderBackend;
class WindowModule;
class RenderModule;
class InputModule;
2026-02-11 19:40:26 +08:00
/**
* @brief
*/
2026-02-11 19:40:26 +08:00
class Application {
public:
static Application& get();
Application(const Application&) = delete;
Application& operator=(const Application&) = delete;
/**
* @brief
* @tparam T
* @tparam Args
* @return
*/
template<typename T, typename... Args>
T* use(Args&&... args) {
return Registry::instance().use<T>(std::forward<Args>(args)...);
}
/**
* @brief
* @tparam T
* @return
*/
template<typename T>
T* get() const {
return Registry::instance().get<T>();
}
/**
* @brief
* @return true
*/
bool init();
/**
* @brief
* @param config
* @return true
*/
bool init(const AppConfig& config);
/**
* @brief
*/
void shutdown();
/**
* @brief
*/
void run();
/**
* @brief 退
*/
void quit();
/**
* @brief
*/
void pause();
/**
* @brief
*/
void resume();
bool isPaused() const { return paused_; }
bool isRunning() const { return running_; }
/**
* @brief
* @return
*/
IWindow* window();
/**
* @brief
* @return
*/
RenderBackend* renderer();
/**
* @brief
* @return
*/
IInput* input();
/**
* @brief
* @param scene
*/
void enterScene(Ptr<class Scene> scene);
float deltaTime() const { return deltaTime_; }
float totalTime() const { return totalTime_; }
int fps() const { return currentFps_; }
2026-02-11 19:40:26 +08:00
private:
Application();
~Application();
void mainLoop();
void update();
void render();
void registerCoreServices();
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;
AppConfig appConfig_;
2026-02-11 19:40:26 +08:00
};
} // namespace extra2d