Implement singleton class into application
This commit is contained in:
+4
-4
@@ -4,11 +4,11 @@
|
|||||||
class Game : public Inferno::Application
|
class Game : public Inferno::Application
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Game() {};
|
Game() : Application({}) {}
|
||||||
~Game() {};
|
~Game() {}
|
||||||
};
|
};
|
||||||
|
|
||||||
Inferno::Application* Inferno::createApplication()
|
Inferno::Application& Inferno::getApplication()
|
||||||
{
|
{
|
||||||
return new Game();
|
return Game::the();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,13 +21,8 @@
|
|||||||
|
|
||||||
namespace Inferno {
|
namespace Inferno {
|
||||||
|
|
||||||
Application* Application::s_instance = nullptr;
|
Application::Application(s)
|
||||||
|
|
||||||
Application::Application()
|
|
||||||
{
|
{
|
||||||
ASSERT(!s_instance, "Application already exists!");
|
|
||||||
s_instance = this;
|
|
||||||
|
|
||||||
// Initialize
|
// Initialize
|
||||||
|
|
||||||
Settings::initialize();
|
Settings::initialize();
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
|
|
||||||
#include <memory> // std::unique_ptr, std::shared_ptr
|
#include <memory> // std::unique_ptr, std::shared_ptr
|
||||||
|
|
||||||
|
#include "inferno/singleton.h"
|
||||||
|
|
||||||
namespace Inferno {
|
namespace Inferno {
|
||||||
|
|
||||||
class Event;
|
class Event;
|
||||||
@@ -14,12 +16,9 @@ namespace Inferno {
|
|||||||
class WindowCloseEvent;
|
class WindowCloseEvent;
|
||||||
class WindowResizeEvent;
|
class WindowResizeEvent;
|
||||||
|
|
||||||
class VertexArray;
|
class Application : public Singleton<Application> {
|
||||||
class Shader;
|
|
||||||
|
|
||||||
class Application {
|
|
||||||
public:
|
public:
|
||||||
Application();
|
Application(s);
|
||||||
virtual ~Application();
|
virtual ~Application();
|
||||||
|
|
||||||
int run();
|
int run();
|
||||||
@@ -30,31 +29,24 @@ namespace Inferno {
|
|||||||
bool onKeyPress(KeyPressEvent& e);
|
bool onKeyPress(KeyPressEvent& e);
|
||||||
bool onMousePosition(MousePositionEvent& e);
|
bool onMousePosition(MousePositionEvent& e);
|
||||||
|
|
||||||
// -----------------------------------------
|
|
||||||
|
|
||||||
inline void setStatus(int status) { m_status = status; }
|
inline void setStatus(int status) { m_status = status; }
|
||||||
|
|
||||||
inline Window& getWindow() const { return *m_window; }
|
inline Window& getWindow() const { return *m_window; }
|
||||||
|
|
||||||
static inline Application& the() { return *s_instance; }
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<Window> m_window;
|
|
||||||
std::shared_ptr<Scene> m_scene;
|
|
||||||
|
|
||||||
float m_lastFrameTime = 0.0f;
|
|
||||||
|
|
||||||
//
|
|
||||||
std::shared_ptr<Font> m_font;
|
|
||||||
//
|
|
||||||
|
|
||||||
int m_status = 0;
|
int m_status = 0;
|
||||||
|
float m_lastFrameTime { 0.0f };
|
||||||
|
|
||||||
static Application* s_instance;
|
std::unique_ptr<Window> m_window { nullptr };
|
||||||
|
std::shared_ptr<Scene> m_scene { nullptr };
|
||||||
|
|
||||||
|
//
|
||||||
|
std::shared_ptr<Font> m_font { nullptr };
|
||||||
|
//
|
||||||
};
|
};
|
||||||
|
|
||||||
// To be defined in the game
|
// To be defined in the game
|
||||||
extern Application* createApplication();
|
extern Application& getApplication();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,13 +15,7 @@ int main(int argc, char* argv[])
|
|||||||
(void)argc;
|
(void)argc;
|
||||||
(void)argv;
|
(void)argv;
|
||||||
|
|
||||||
auto app = Inferno::createApplication();
|
return Inferno::getApplication().run();
|
||||||
|
|
||||||
int status = app->run();
|
|
||||||
|
|
||||||
delete app;
|
|
||||||
|
|
||||||
return status;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // ENTRYPOINT_H
|
#endif // ENTRYPOINT_H
|
||||||
|
|||||||
Reference in New Issue
Block a user