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
|
||||
{
|
||||
public:
|
||||
Game() : Application({}) {}
|
||||
Game() {}
|
||||
~Game() {}
|
||||
};
|
||||
|
||||
Inferno::Application& Inferno::getApplication()
|
||||
Inferno::Application* Inferno::createApplication()
|
||||
{
|
||||
return Game::the();
|
||||
return new Game();
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -3,8 +3,6 @@
|
||||
|
||||
#include <memory> // 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<Application> {
|
||||
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<Window> m_window { nullptr };
|
||||
std::shared_ptr<Scene> m_scene { nullptr };
|
||||
std::unique_ptr<Window> m_window;
|
||||
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
|
||||
extern Application& getApplication();
|
||||
extern Application* createApplication();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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";
|
||||
}
|
||||
|
||||
|
||||
@@ -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