Revert application and remove singleton class, it breaks object lifetime?
This commit is contained in:
+3
-3
@@ -4,11 +4,11 @@
|
|||||||
class Game : public Inferno::Application
|
class Game : public Inferno::Application
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Game() : Application({}) {}
|
Game() {}
|
||||||
~Game() {}
|
~Game() {}
|
||||||
};
|
};
|
||||||
|
|
||||||
Inferno::Application& Inferno::getApplication()
|
Inferno::Application* Inferno::createApplication()
|
||||||
{
|
{
|
||||||
return Game::the();
|
return new Game();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,8 +21,13 @@
|
|||||||
|
|
||||||
namespace Inferno {
|
namespace Inferno {
|
||||||
|
|
||||||
Application::Application(s)
|
Application* Application::s_instance = nullptr;
|
||||||
|
|
||||||
|
Application::Application()
|
||||||
{
|
{
|
||||||
|
ASSERT(!s_instance, "Application already exists!");
|
||||||
|
s_instance = this;
|
||||||
|
|
||||||
// Initialize
|
// Initialize
|
||||||
|
|
||||||
Settings::initialize();
|
Settings::initialize();
|
||||||
|
|||||||
@@ -3,8 +3,6 @@
|
|||||||
|
|
||||||
#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;
|
||||||
@@ -16,9 +14,9 @@ namespace Inferno {
|
|||||||
class WindowCloseEvent;
|
class WindowCloseEvent;
|
||||||
class WindowResizeEvent;
|
class WindowResizeEvent;
|
||||||
|
|
||||||
class Application : public Singleton<Application> {
|
class Application {
|
||||||
public:
|
public:
|
||||||
Application(s);
|
Application();
|
||||||
virtual ~Application();
|
virtual ~Application();
|
||||||
|
|
||||||
int run();
|
int run();
|
||||||
@@ -33,20 +31,23 @@ namespace Inferno {
|
|||||||
|
|
||||||
inline Window& getWindow() const { return *m_window; }
|
inline Window& getWindow() const { return *m_window; }
|
||||||
|
|
||||||
|
static inline Application& the() { return *s_instance; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int m_status = 0;
|
int m_status { 0 };
|
||||||
float m_lastFrameTime { 0.0f };
|
float m_lastFrameTime { 0.0f };
|
||||||
|
|
||||||
std::unique_ptr<Window> m_window { nullptr };
|
std::unique_ptr<Window> m_window;
|
||||||
std::shared_ptr<Scene> m_scene { nullptr };
|
std::shared_ptr<Scene> m_scene;
|
||||||
|
|
||||||
//
|
//
|
||||||
std::shared_ptr<Font> m_font { nullptr };
|
std::shared_ptr<Font> m_font;
|
||||||
//
|
|
||||||
|
static Application* s_instance;
|
||||||
};
|
};
|
||||||
|
|
||||||
// To be defined in the game
|
// To be defined in the game
|
||||||
extern Application& getApplication();
|
extern Application* createApplication();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,13 @@ int main(int argc, char* argv[])
|
|||||||
(void)argc;
|
(void)argc;
|
||||||
(void)argv;
|
(void)argv;
|
||||||
|
|
||||||
return Inferno::getApplication().run();
|
auto app = Inferno::createApplication();
|
||||||
|
|
||||||
|
int status = app->run();
|
||||||
|
|
||||||
|
delete app;
|
||||||
|
|
||||||
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // ENTRYPOINT_H
|
#endif // ENTRYPOINT_H
|
||||||
|
|||||||
@@ -16,6 +16,10 @@ namespace Inferno {
|
|||||||
|
|
||||||
void Input::initialize()
|
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";
|
info() << "Input initialized";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,31 +0,0 @@
|
|||||||
#ifndef SINGLETON_H
|
|
||||||
#define SINGLETON_H
|
|
||||||
|
|
||||||
#include <memory> // std::unique_ptr
|
|
||||||
|
|
||||||
namespace Inferno {
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
class Singleton {
|
|
||||||
public:
|
|
||||||
static inline T& the() {
|
|
||||||
static const std::unique_ptr<T> 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
|
|
||||||
Reference in New Issue
Block a user