diff --git a/game/src/game.cpp b/game/src/game.cpp index 9b5445b..38c8f32 100644 --- a/game/src/game.cpp +++ b/game/src/game.cpp @@ -4,11 +4,11 @@ class Game : public Inferno::Application { public: - Game() : Application({}) {} + Game() {} ~Game() {} }; -Inferno::Application& Inferno::getApplication() +Inferno::Application* Inferno::createApplication() { - return Game::the(); + return new Game(); } diff --git a/inferno/src/inferno/application.cpp b/inferno/src/inferno/application.cpp index 4fb442c..97daa74 100644 --- a/inferno/src/inferno/application.cpp +++ b/inferno/src/inferno/application.cpp @@ -21,8 +21,13 @@ namespace Inferno { - Application::Application(s) + Application* Application::s_instance = nullptr; + + Application::Application() { + 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 70af757..7ece88f 100644 --- a/inferno/src/inferno/application.h +++ b/inferno/src/inferno/application.h @@ -3,8 +3,6 @@ #include // std::unique_ptr, std::shared_ptr -#include "inferno/singleton.h" - namespace Inferno { class Event; @@ -16,9 +14,9 @@ namespace Inferno { class WindowCloseEvent; class WindowResizeEvent; - class Application : public Singleton { + class Application { public: - Application(s); + Application(); virtual ~Application(); int run(); @@ -33,20 +31,23 @@ namespace Inferno { inline Window& getWindow() const { return *m_window; } + static inline Application& the() { return *s_instance; } + private: - int m_status = 0; + int m_status { 0 }; float m_lastFrameTime { 0.0f }; - std::unique_ptr m_window { nullptr }; - std::shared_ptr m_scene { nullptr }; + std::unique_ptr m_window; + std::shared_ptr m_scene; // - std::shared_ptr m_font { nullptr }; - // + std::shared_ptr m_font; + + static Application* s_instance; }; // To be defined in the game - extern Application& getApplication(); + extern Application* createApplication(); } diff --git a/inferno/src/inferno/entrypoint.h b/inferno/src/inferno/entrypoint.h index a0d3600..d5b42d4 100644 --- a/inferno/src/inferno/entrypoint.h +++ b/inferno/src/inferno/entrypoint.h @@ -15,7 +15,13 @@ int main(int argc, char* argv[]) (void)argc; (void)argv; - return Inferno::getApplication().run(); + auto app = Inferno::createApplication(); + + int status = app->run(); + + delete app; + + return status; } #endif // ENTRYPOINT_H diff --git a/inferno/src/inferno/io/input.cpp b/inferno/src/inferno/io/input.cpp index aaf6909..33e587b 100644 --- a/inferno/src/inferno/io/input.cpp +++ b/inferno/src/inferno/io/input.cpp @@ -16,6 +16,10 @@ namespace Inferno { void Input::initialize() { + // Set cursor in the middle of the screen + m_xPosLast = Application::the().getWindow().getWidth() / 2.0f; + m_yPosLast = Application::the().getWindow().getHeight() / 2.0f; + info() << "Input initialized"; } diff --git a/inferno/src/inferno/singleton.h b/inferno/src/inferno/singleton.h deleted file mode 100644 index 568f3dc..0000000 --- a/inferno/src/inferno/singleton.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef SINGLETON_H -#define SINGLETON_H - -#include // std::unique_ptr - -namespace Inferno { - - template - class Singleton { - public: - static inline T& the() { - static const std::unique_ptr instance { new T { s {} } }; - return *instance; - } - - // Remove copy constructor and copy assignment operator - Singleton(const Singleton&) = delete; - Singleton& operator=(const Singleton&) = delete; - Singleton(Singleton&&) = delete; - Singleton& operator=(Singleton&&) = delete; - - protected: - Singleton() {} - - // Constructor token - struct s {}; - }; - -} // namespace Inferno - -#endif // SINGLETON_H