diff --git a/game/src/game.cpp b/game/src/game.cpp index 4a02b89..9b5445b 100644 --- a/game/src/game.cpp +++ b/game/src/game.cpp @@ -4,11 +4,11 @@ class Game : public Inferno::Application { public: - Game() {}; - ~Game() {}; + Game() : Application({}) {} + ~Game() {} }; -Inferno::Application* Inferno::createApplication() +Inferno::Application& Inferno::getApplication() { - return new Game(); + return Game::the(); } diff --git a/inferno/src/inferno/application.cpp b/inferno/src/inferno/application.cpp index 97daa74..4fb442c 100644 --- a/inferno/src/inferno/application.cpp +++ b/inferno/src/inferno/application.cpp @@ -21,13 +21,8 @@ namespace Inferno { - Application* Application::s_instance = nullptr; - - Application::Application() + Application::Application(s) { - ASSERT(!s_instance, "Application already exists!"); - s_instance = this; - // Initialize Settings::initialize(); diff --git a/inferno/src/inferno/application.h b/inferno/src/inferno/application.h index 9700cfe..70af757 100644 --- a/inferno/src/inferno/application.h +++ b/inferno/src/inferno/application.h @@ -3,6 +3,8 @@ #include // std::unique_ptr, std::shared_ptr +#include "inferno/singleton.h" + namespace Inferno { class Event; @@ -14,12 +16,9 @@ namespace Inferno { class WindowCloseEvent; class WindowResizeEvent; - class VertexArray; - class Shader; - - class Application { + class Application : public Singleton { public: - Application(); + Application(s); virtual ~Application(); int run(); @@ -30,31 +29,24 @@ namespace Inferno { bool onKeyPress(KeyPressEvent& e); bool onMousePosition(MousePositionEvent& e); -// ----------------------------------------- - inline void setStatus(int status) { m_status = status; } inline Window& getWindow() const { return *m_window; } - static inline Application& the() { return *s_instance; } - private: - std::unique_ptr m_window; - std::shared_ptr m_scene; + int m_status = 0; + float m_lastFrameTime { 0.0f }; - float m_lastFrameTime = 0.0f; + std::unique_ptr m_window { nullptr }; + std::shared_ptr m_scene { nullptr }; // - std::shared_ptr m_font; + std::shared_ptr m_font { nullptr }; // - - int m_status = 0; - - static Application* s_instance; }; // To be defined in the game - extern Application* createApplication(); + extern Application& getApplication(); } diff --git a/inferno/src/inferno/entrypoint.h b/inferno/src/inferno/entrypoint.h index d5b42d4..a0d3600 100644 --- a/inferno/src/inferno/entrypoint.h +++ b/inferno/src/inferno/entrypoint.h @@ -15,13 +15,7 @@ int main(int argc, char* argv[]) (void)argc; (void)argv; - auto app = Inferno::createApplication(); - - int status = app->run(); - - delete app; - - return status; + return Inferno::getApplication().run(); } #endif // ENTRYPOINT_H