Browse Source

Implement singleton class in all singletons

master
Riyyi 3 years ago
parent
commit
8f7665b8a3
  1. 39
      inferno/src/inferno/application.cpp
  2. 11
      inferno/src/inferno/render/font.cpp
  3. 11
      inferno/src/inferno/render/font.h
  4. 11
      inferno/src/inferno/render/gltf.h
  5. 24
      inferno/src/inferno/render/renderer.cpp
  6. 49
      inferno/src/inferno/render/renderer.h
  7. 11
      inferno/src/inferno/render/shader.cpp
  8. 14
      inferno/src/inferno/render/shader.h
  9. 11
      inferno/src/inferno/render/texture.cpp
  10. 16
      inferno/src/inferno/render/texture.h
  11. 20
      inferno/src/inferno/scene/scene.cpp
  12. 17
      inferno/src/inferno/system/camerasystem.cpp
  13. 12
      inferno/src/inferno/system/camerasystem.h
  14. 17
      inferno/src/inferno/system/rendersystem.cpp
  15. 12
      inferno/src/inferno/system/rendersystem.h
  16. 12
      inferno/src/inferno/system/scriptsystem.cpp
  17. 13
      inferno/src/inferno/system/scriptsystem.h
  18. 17
      inferno/src/inferno/system/transformsystem.cpp
  19. 12
      inferno/src/inferno/system/transformsystem.h

39
inferno/src/inferno/application.cpp

@ -34,27 +34,16 @@ namespace Inferno {
m_window->setEventCallback(NF_BIND_EVENT(Application::onEvent)); m_window->setEventCallback(NF_BIND_EVENT(Application::onEvent));
Input::initialize(); Input::initialize();
ShaderManager::initialize();
ShaderManager* shaderManager = new ShaderManager(); TextureManager::initialize();
shaderManager->initialize(); RenderCommand::initialize();
Renderer2D::initialize();
TextureManager* textureManager = new TextureManager(); RendererCharacter::initialize();
textureManager->initialize(); FontManager::initialize();
m_scene = std::make_shared<Scene>(); m_scene = std::make_shared<Scene>();
m_scene->initialize(); m_scene->initialize();
RenderCommand::initialize();
Renderer2D* renderer2D = new Renderer2D();
renderer2D->initialize();
RendererCharacter* rendererCharacter = new RendererCharacter();
rendererCharacter->initialize();
FontManager* fontManager = new FontManager();
fontManager->initialize();
// Load assets // Load assets
m_font = FontManager::the().load("assets/fnt/dejavu-sans"); m_font = FontManager::the().load("assets/fnt/dejavu-sans");
@ -62,14 +51,18 @@ namespace Inferno {
Application::~Application() Application::~Application()
{ {
FontManager::the().destroy();
RendererCharacter::the().destroy();
Renderer2D::the().destroy();
RenderCommand::destroy();
m_scene->destroy(); m_scene->destroy();
TextureManager::the().destroy();
ShaderManager::the().destroy(); FontManager::destroy();
RendererCharacter::destroy();
Renderer2D::destroy();
RenderCommand::destroy();
TextureManager::destroy();
ShaderManager::destroy();
// Input::destroy(); // Input::destroy();
m_window->destroy();
Settings::destroy(); Settings::destroy();
} }

11
inferno/src/inferno/render/font.cpp

@ -103,20 +103,13 @@ namespace Inferno {
// ----------------------------------------- // -----------------------------------------
FontManager* FontManager::s_instance = nullptr; FontManager::FontManager(s)
void FontManager::initialize()
{ {
ASSERT(!s_instance, "FontManager already exists!");
s_instance = this;
info() << "FontManager initialized"; info() << "FontManager initialized";
} }
void FontManager::destroy() FontManager::~FontManager()
{ {
delete s_instance;
s_instance = nullptr;
} }
void FontManager::add(const std::string& name, const std::shared_ptr<Font>& font) void FontManager::add(const std::string& name, const std::shared_ptr<Font>& font)

11
inferno/src/inferno/render/font.h

@ -11,6 +11,7 @@
#include "glm/ext/vector_int2.hpp" // glm::ivec2 #include "glm/ext/vector_int2.hpp" // glm::ivec2
#include "inferno/io/log.h" #include "inferno/io/log.h"
#include "inferno/singleton.h"
namespace Inferno { namespace Inferno {
@ -51,10 +52,10 @@ class Texture;
// ----------------------------------------- // -----------------------------------------
class FontManager { class FontManager final : public Singleton<FontManager> {
public: public:
void initialize(); FontManager(s);
void destroy(); virtual ~FontManager();
void add(const std::string& name, const std::shared_ptr<Font>& font); void add(const std::string& name, const std::shared_ptr<Font>& font);
std::shared_ptr<Font> load(const std::string& name); std::shared_ptr<Font> load(const std::string& name);
@ -64,12 +65,8 @@ class Texture;
void remove(const std::string& name); void remove(const std::string& name);
void remove(const std::shared_ptr<Font>& font); void remove(const std::shared_ptr<Font>& font);
static inline FontManager& the() { return *s_instance; }
private: private:
std::unordered_map<std::string, std::shared_ptr<Font>> m_fontList; std::unordered_map<std::string, std::shared_ptr<Font>> m_fontList;
static FontManager* s_instance;
}; };

11
inferno/src/inferno/render/gltf.h

@ -7,6 +7,7 @@
#include <unordered_map> // std::unordered_map #include <unordered_map> // std::unordered_map
#include <vector> // std::vector #include <vector> // std::vector
#include "inferno/singleton.h"
#include "inferno/util/json.h" #include "inferno/util/json.h"
namespace Inferno { namespace Inferno {
@ -128,10 +129,10 @@ namespace Inferno {
// ----------------------------------------- // -----------------------------------------
class GltfManager { class GltfManager final : Singleton<GltfManager> {
public: public:
void initialize(); GltfManager(s) {}
void destroy(); virtual ~GltfManager() {}
void add(const std::string& path, const std::shared_ptr<Gltf>& gltf); void add(const std::string& path, const std::shared_ptr<Gltf>& gltf);
std::shared_ptr<Gltf> load(const std::string& path); std::shared_ptr<Gltf> load(const std::string& path);
@ -141,12 +142,8 @@ namespace Inferno {
void remove(const std::string& path); void remove(const std::string& path);
void remove(const std::shared_ptr<Gltf>& gltf); void remove(const std::shared_ptr<Gltf>& gltf);
static inline GltfManager& the() { return *s_instance; }
private: private:
std::unordered_map<std::string, std::shared_ptr<Gltf>> m_gltfList; std::unordered_map<std::string, std::shared_ptr<Gltf>> m_gltfList;
static GltfManager* s_instance;
}; };
} // namespace Inferno } // namespace Inferno

24
inferno/src/inferno/render/renderer.cpp

@ -151,13 +151,8 @@ namespace Inferno {
// ----------------------------------------- // -----------------------------------------
Renderer2D* Renderer2D::s_instance = nullptr; Renderer2D::Renderer2D(s)
void Renderer2D::initialize()
{ {
ASSERT(!s_instance, "RendererCharacter already exists!");
s_instance = this;
Renderer::initialize(); Renderer::initialize();
// CPU // CPU
@ -210,10 +205,9 @@ namespace Inferno {
info() << "Renderer2D initialized"; info() << "Renderer2D initialized";
} }
void Renderer2D::destroy() Renderer2D::~Renderer2D()
{ {
delete s_instance; Renderer::destroy();
s_instance = nullptr;
} }
void Renderer2D::beginScene(glm::mat4 cameraProjectionView) void Renderer2D::beginScene(glm::mat4 cameraProjectionView)
@ -308,13 +302,8 @@ namespace Inferno {
// ----------------------------------------- // -----------------------------------------
RendererCharacter* RendererCharacter::s_instance = nullptr; RendererCharacter::RendererCharacter(s)
void RendererCharacter::initialize()
{ {
ASSERT(!s_instance, "RendererCharacter already exists!");
s_instance = this;
Renderer::initialize(); Renderer::initialize();
// CPU // CPU
@ -367,10 +356,9 @@ namespace Inferno {
info() << "RendererCharacter initialized"; info() << "RendererCharacter initialized";
} }
void RendererCharacter::destroy() RendererCharacter::~RendererCharacter()
{ {
delete s_instance; Renderer::destroy();
s_instance = nullptr;
} }
void RendererCharacter::beginScene() void RendererCharacter::beginScene()

49
inferno/src/inferno/render/renderer.h

@ -1,7 +1,7 @@
#ifndef RENDERER_H #ifndef RENDERER_H
#define RENDERER_H #define RENDERER_H
#include <cstdint> // std::int32_t, std::uint32_t #include <cstdint> // int32_t, uint32_t
#include <memory> // std::shared_ptr, std::unique_ptr, std::make_shared, std::make_unique #include <memory> // std::shared_ptr, std::unique_ptr, std::make_shared, std::make_unique
#include "glm/ext/matrix_float4x4.hpp" // glm::mat4 #include "glm/ext/matrix_float4x4.hpp" // glm::mat4
@ -10,6 +10,7 @@
#include "glm/ext/vector_float4.hpp" // glm::vec4 #include "glm/ext/vector_float4.hpp" // glm::vec4
#include "inferno/component/transformcomponent.h" #include "inferno/component/transformcomponent.h"
#include "inferno/singleton.h"
namespace Inferno { namespace Inferno {
@ -29,12 +30,14 @@ namespace Inferno {
struct CharacterVertex { struct CharacterVertex {
QuadVertex quad; QuadVertex quad;
// Font
float width = 0.44f; float width = 0.44f;
float edge = 0.15f; float edge = 0.15f;
// Outline
float borderWidth = 0.7f; float borderWidth = 0.7f;
float borderEdge = 0.1f; float borderEdge = 0.1f;
glm::vec4 borderColor { 1.0f, 1.0f, 1.0f, 1.0f }; glm::vec4 borderColor { 1.0f, 1.0f, 1.0f, 1.0f };
// Dropshadow
float offset = 0.0f; float offset = 0.0f;
}; };
@ -65,8 +68,10 @@ namespace Inferno {
static const uint32_t textureUnitPerBatch = 32; static const uint32_t textureUnitPerBatch = 32;
protected: protected:
virtual void initialize() = 0; Renderer() {}
virtual void destroy() = 0;
void initialize();
void destroy();
uint32_t addTextureUnit(std::shared_ptr<Texture> texture); uint32_t addTextureUnit(std::shared_ptr<Texture> texture);
@ -91,15 +96,20 @@ namespace Inferno {
// ----------------------------------------- // -----------------------------------------
class Renderer2D final : public Renderer { class Renderer2D final
: public Renderer
, public Singleton<Renderer2D> {
public: public:
Renderer2D(s);
virtual ~Renderer2D();
using Singleton<Renderer2D>::initialize;
using Singleton<Renderer2D>::destroy;
static const uint32_t quadCount = 1000; static const uint32_t quadCount = 1000;
static const uint32_t vertexCount = quadCount * vertexPerQuad; static const uint32_t vertexCount = quadCount * vertexPerQuad;
static const uint32_t indexCount = quadCount * indexPerQuad; static const uint32_t indexCount = quadCount * indexPerQuad;
void initialize() override;
void destroy() override;
void beginScene(glm::mat4 cameraProjectionView); void beginScene(glm::mat4 cameraProjectionView);
void endScene(); void endScene();
@ -107,9 +117,6 @@ namespace Inferno {
void drawQuad(const TransformComponent& transform, glm::mat4 color); void drawQuad(const TransformComponent& transform, glm::mat4 color);
void drawQuad(const TransformComponent& transform, glm::vec4 color, std::shared_ptr<Texture> texture); void drawQuad(const TransformComponent& transform, glm::vec4 color, std::shared_ptr<Texture> texture);
void drawQuad(const TransformComponent& transform, glm::mat4 color, std::shared_ptr<Texture> texture); void drawQuad(const TransformComponent& transform, glm::mat4 color, std::shared_ptr<Texture> texture);
static inline Renderer2D& the() { return *s_instance; }
private: private:
void loadShader() override; void loadShader() override;
void flush() override; void flush() override;
@ -122,28 +129,28 @@ namespace Inferno {
// Default quad vertex positions // Default quad vertex positions
glm::vec4 m_vertexPositions[vertexPerQuad]; glm::vec4 m_vertexPositions[vertexPerQuad];
static Renderer2D* s_instance;
}; };
// ----------------------------------------- // -----------------------------------------
class RendererCharacter final : public Renderer { class RendererCharacter final
: public Renderer
, public Singleton<RendererCharacter> {
public: public:
RendererCharacter(s);
virtual ~RendererCharacter();
using Singleton<RendererCharacter>::initialize;
using Singleton<RendererCharacter>::destroy;
static const uint32_t quadCount = 1000; static const uint32_t quadCount = 1000;
static const uint32_t vertexCount = quadCount * vertexPerQuad; static const uint32_t vertexCount = quadCount * vertexPerQuad;
static const uint32_t indexCount = quadCount * indexPerQuad; static const uint32_t indexCount = quadCount * indexPerQuad;
void initialize() override;
void destroy() override;
void beginScene(); void beginScene();
void endScene(); void endScene();
void drawCharacter(std::array<CharacterVertex, vertexPerQuad>& characterQuad, std::shared_ptr<Texture> texture); void drawCharacter(std::array<CharacterVertex, vertexPerQuad>& characterQuad, std::shared_ptr<Texture> texture);
static inline RendererCharacter& the() { return *s_instance; }
private: private:
void loadShader() override; void loadShader() override;
void flush() override; void flush() override;
@ -153,8 +160,6 @@ namespace Inferno {
// CPU quad vertices // CPU quad vertices
std::unique_ptr<CharacterVertex[]> m_vertexBufferBase = nullptr; std::unique_ptr<CharacterVertex[]> m_vertexBufferBase = nullptr;
CharacterVertex* m_vertexBufferPtr = nullptr; CharacterVertex* m_vertexBufferPtr = nullptr;
static RendererCharacter* s_instance;
}; };
} }

11
inferno/src/inferno/render/shader.cpp

@ -193,20 +193,13 @@ namespace Inferno {
// ----------------------------------------- // -----------------------------------------
ShaderManager* ShaderManager::s_instance = nullptr; ShaderManager::ShaderManager(s)
void ShaderManager::initialize()
{ {
ASSERT(!s_instance, "ShaderManager already exists!");
s_instance = this;
info() << "ShaderManager initialized"; info() << "ShaderManager initialized";
} }
void ShaderManager::destroy() ShaderManager::~ShaderManager()
{ {
delete s_instance;
s_instance = nullptr;
} }
void ShaderManager::add(const std::string& name, const std::shared_ptr<Shader>& shader) void ShaderManager::add(const std::string& name, const std::shared_ptr<Shader>& shader)

14
inferno/src/inferno/render/shader.h

@ -8,12 +8,14 @@
#include "glm/glm.hpp" #include "glm/glm.hpp"
#include "inferno/singleton.h"
namespace Inferno { namespace Inferno {
class Shader { class Shader {
public: public:
Shader(const std::string& name); Shader(const std::string& name);
~Shader(); virtual ~Shader();
int32_t findUniform(const std::string& name) const; int32_t findUniform(const std::string& name) const;
@ -45,10 +47,10 @@ namespace Inferno {
// ----------------------------------------- // -----------------------------------------
class ShaderManager { class ShaderManager final : public Singleton<ShaderManager> {
public: public:
void initialize(); ShaderManager(s);
void destroy(); virtual ~ShaderManager();
void add(const std::string& name, const std::shared_ptr<Shader>& shader); void add(const std::string& name, const std::shared_ptr<Shader>& shader);
std::shared_ptr<Shader> load(const std::string& name); std::shared_ptr<Shader> load(const std::string& name);
@ -60,16 +62,12 @@ namespace Inferno {
void remove(const std::string& name); void remove(const std::string& name);
void remove(const std::shared_ptr<Shader>& shader); void remove(const std::shared_ptr<Shader>& shader);
static inline ShaderManager& the() { return *s_instance; }
protected: protected:
std::string computeName(const std::string& vertexSource, std::string computeName(const std::string& vertexSource,
const std::string& fragmentSource); const std::string& fragmentSource);
private: private:
std::unordered_map<std::string, std::shared_ptr<Shader>> m_shaderList; std::unordered_map<std::string, std::shared_ptr<Shader>> m_shaderList;
static ShaderManager* s_instance;
}; };
} }

11
inferno/src/inferno/render/texture.cpp

@ -103,20 +103,13 @@ namespace Inferno {
// ----------------------------------------- // -----------------------------------------
TextureManager* TextureManager::s_instance = nullptr; TextureManager::TextureManager(s)
void TextureManager::initialize()
{ {
ASSERT(!s_instance, "TextureManager already exists!");
s_instance = this;
info() << "TextureManager initialized"; info() << "TextureManager initialized";
} }
void TextureManager::destroy() TextureManager::~TextureManager()
{ {
delete s_instance;
s_instance = nullptr;
} }
void TextureManager::add(const std::string& path, const std::shared_ptr<Texture>& texture) void TextureManager::add(const std::string& path, const std::shared_ptr<Texture>& texture)

16
inferno/src/inferno/render/texture.h

@ -1,11 +1,13 @@
#ifndef TEXTURE_H #ifndef TEXTURE_H
#define TEXTURE_H #define TEXTURE_H
#include <cstdint> // std::uint32_t #include <cstdint> // uint32_t
#include <memory> // std::shared_ptr #include <memory> // std::shared_ptr
#include <string> // std::string #include <string> // std::string
#include <unordered_map> // std::unordered_map #include <unordered_map> // std::unordered_map
#include "inferno/singleton.h"
namespace Inferno { namespace Inferno {
class Texture { class Texture {
@ -37,10 +39,10 @@ namespace Inferno {
// ----------------------------------------- // -----------------------------------------
class TextureManager { class TextureManager final : public Singleton<TextureManager> {
public: public:
void initialize(); TextureManager(s);
void destroy(); virtual ~TextureManager();
void add(const std::string& path, const std::shared_ptr<Texture>& texture); void add(const std::string& path, const std::shared_ptr<Texture>& texture);
std::shared_ptr<Texture> load(const std::string& path); std::shared_ptr<Texture> load(const std::string& path);
@ -50,12 +52,8 @@ namespace Inferno {
void remove(const std::string& path); void remove(const std::string& path);
void remove(const std::shared_ptr<Texture>& texture); void remove(const std::shared_ptr<Texture>& texture);
static inline TextureManager& the() { return *s_instance; }
private: private:
std::unordered_map<std::string, std::shared_ptr<Texture>> m_textureList; std::unordered_map<std::string, std::shared_ptr<Texture>> m_textureList;
static TextureManager* s_instance;
}; };
} }

20
inferno/src/inferno/scene/scene.cpp

@ -21,20 +21,16 @@ namespace Inferno {
m_registry = std::make_shared<entt::registry>(); m_registry = std::make_shared<entt::registry>();
TransformSystem* transformSystem = new TransformSystem(); TransformSystem::initialize();
transformSystem->initialize();
TransformSystem::the().setRegistry(m_registry); TransformSystem::the().setRegistry(m_registry);
CameraSystem* cameraSystem = new CameraSystem(); CameraSystem::initialize();
cameraSystem->initialize();
CameraSystem::the().setRegistry(m_registry); CameraSystem::the().setRegistry(m_registry);
RenderSystem* renderSystem = new RenderSystem(); RenderSystem::initialize();
renderSystem->initialize();
RenderSystem::the().setRegistry(m_registry); RenderSystem::the().setRegistry(m_registry);
ScriptSystem* scriptSystem = new ScriptSystem(); ScriptSystem::initialize();
scriptSystem->initialize();
ScriptSystem::the().setScene(this); ScriptSystem::the().setScene(this);
// Load assets // Load assets
@ -85,10 +81,10 @@ namespace Inferno {
void Scene::destroy() void Scene::destroy()
{ {
ScriptSystem::the().destroy(); ScriptSystem::destroy();
RenderSystem::the().destroy(); RenderSystem::destroy();
CameraSystem::the().destroy(); CameraSystem::destroy();
TransformSystem::the().destroy(); TransformSystem::destroy();
} }
uint32_t Scene::createEntity(const std::string& name) uint32_t Scene::createEntity(const std::string& name)

17
inferno/src/inferno/system/camerasystem.cpp

@ -10,16 +10,15 @@
namespace Inferno { namespace Inferno {
CameraSystem* CameraSystem::s_instance = nullptr; CameraSystem::CameraSystem(s)
void CameraSystem::initialize()
{ {
ASSERT(!s_instance, "CameraSystem already exists!");
s_instance = this;
info() << "CameraSystem initialized"; info() << "CameraSystem initialized";
} }
CameraSystem::~CameraSystem()
{
}
void CameraSystem::update() void CameraSystem::update()
{ {
auto view = m_registry->view<TransformComponent, CameraComponent>(); auto view = m_registry->view<TransformComponent, CameraComponent>();
@ -35,12 +34,6 @@ namespace Inferno {
} }
} }
void CameraSystem::destroy()
{
delete s_instance;
s_instance = nullptr;
}
glm::mat4 CameraSystem::projectionView() glm::mat4 CameraSystem::projectionView()
{ {
auto view = m_registry->view<TransformComponent, CameraComponent>(); auto view = m_registry->view<TransformComponent, CameraComponent>();

12
inferno/src/inferno/system/camerasystem.h

@ -7,31 +7,29 @@
#include "inferno/component/cameracomponent.h" #include "inferno/component/cameracomponent.h"
#include "inferno/component/transformcomponent.h" #include "inferno/component/transformcomponent.h"
#include "inferno/singleton.h"
#define NEAR_PLANE 0.1f #define NEAR_PLANE 0.1f
#define FAR_PLANE 100.0f #define FAR_PLANE 100.0f
namespace Inferno { namespace Inferno {
class CameraSystem { class CameraSystem final : public Singleton<CameraSystem> {
public: public:
void initialize(); CameraSystem(s);
virtual ~CameraSystem();
void update(); void update();
void destroy();
glm::mat4 projectionView(); glm::mat4 projectionView();
void setRegistry(const std::shared_ptr<entt::registry>& registry) { m_registry = registry; }; void setRegistry(const std::shared_ptr<entt::registry>& registry) { m_registry = registry; };
static inline CameraSystem& the() { return *s_instance; }
private: private:
void updateOrthographic(TransformComponent& transform, CameraComponent& camera); void updateOrthographic(TransformComponent& transform, CameraComponent& camera);
void updatePerspective(TransformComponent& transform, CameraComponent& camera); void updatePerspective(TransformComponent& transform, CameraComponent& camera);
std::shared_ptr<entt::registry> m_registry; std::shared_ptr<entt::registry> m_registry;
static CameraSystem* s_instance;
}; };
} }

17
inferno/src/inferno/system/rendersystem.cpp

@ -9,16 +9,15 @@
namespace Inferno { namespace Inferno {
RenderSystem* RenderSystem::s_instance = nullptr; RenderSystem::RenderSystem(s)
void RenderSystem::initialize()
{ {
ASSERT(!s_instance, "RenderSystem already exists!");
s_instance = this;
info() << "RenderSystem initialized"; info() << "RenderSystem initialized";
} }
RenderSystem::~RenderSystem()
{
}
void RenderSystem::render() void RenderSystem::render()
{ {
auto group = m_registry->group<TransformComponent, SpriteComponent>(); auto group = m_registry->group<TransformComponent, SpriteComponent>();
@ -28,10 +27,4 @@ namespace Inferno {
} }
} }
void RenderSystem::destroy()
{
delete s_instance;
s_instance = nullptr;
}
} }

12
inferno/src/inferno/system/rendersystem.h

@ -6,23 +6,21 @@
#include "entt/entity/registry.hpp" // entt::entity, entt::registry #include "entt/entity/registry.hpp" // entt::entity, entt::registry
#include "inferno/render/renderer.h" #include "inferno/render/renderer.h"
#include "inferno/singleton.h"
namespace Inferno { namespace Inferno {
class RenderSystem { class RenderSystem final : public Singleton<RenderSystem> {
public: public:
void initialize(); RenderSystem(s);
virtual ~RenderSystem();
void render(); void render();
void destroy();
void setRegistry(const std::shared_ptr<entt::registry>& registry) { m_registry = registry; }; void setRegistry(const std::shared_ptr<entt::registry>& registry) { m_registry = registry; };
static inline RenderSystem& the() { return *s_instance; }
private: private:
std::shared_ptr<entt::registry> m_registry; std::shared_ptr<entt::registry> m_registry;
static RenderSystem* s_instance;
}; };
} }

12
inferno/src/inferno/system/scriptsystem.cpp

@ -12,17 +12,12 @@
namespace Inferno { namespace Inferno {
ScriptSystem* ScriptSystem::s_instance = nullptr; ScriptSystem::ScriptSystem(s)
void ScriptSystem::initialize()
{ {
ASSERT(!s_instance, "ScriptSystem already exists!");
s_instance = this;
info() << "ScriptSystem initialized"; info() << "ScriptSystem initialized";
} }
void ScriptSystem::destroy() ScriptSystem::~ScriptSystem()
{ {
auto nativeScriptView = m_scene->registry()->view<NativeScriptComponent>(); auto nativeScriptView = m_scene->registry()->view<NativeScriptComponent>();
@ -35,9 +30,6 @@ namespace Inferno {
for (auto entity : luaScriptView) { for (auto entity : luaScriptView) {
cleanup(luaScriptView.get<LuaScriptComponent>(entity)); cleanup(luaScriptView.get<LuaScriptComponent>(entity));
} }
delete s_instance;
s_instance = nullptr;
} }
void ScriptSystem::update(float deltaTime) void ScriptSystem::update(float deltaTime)

13
inferno/src/inferno/system/scriptsystem.h

@ -3,6 +3,8 @@
#include <cstdint> // uint32_t #include <cstdint> // uint32_t
#include "inferno/singleton.h"
namespace Inferno { namespace Inferno {
struct NativeScriptComponent; struct NativeScriptComponent;
@ -10,10 +12,11 @@ namespace Inferno {
class Scene; class Scene;
class ScriptSystem { class ScriptSystem final : public Singleton<ScriptSystem> {
public: public:
void initialize(); ScriptSystem(s);
void destroy(); virtual ~ScriptSystem();
void update(float deltaTime); void update(float deltaTime);
void cleanup(uint32_t entity); void cleanup(uint32_t entity);
@ -22,12 +25,8 @@ namespace Inferno {
void setScene(Scene* scene) { m_scene = scene; } void setScene(Scene* scene) { m_scene = scene; }
static inline ScriptSystem& the() { return *s_instance; }
private: private:
Scene* m_scene; Scene* m_scene;
static ScriptSystem* s_instance;
}; };
} }

17
inferno/src/inferno/system/transformsystem.cpp

@ -7,16 +7,15 @@
namespace Inferno { namespace Inferno {
TransformSystem* TransformSystem::s_instance = nullptr; TransformSystem::TransformSystem(s)
void TransformSystem::initialize()
{ {
ASSERT(!s_instance, "TransformSystem already exists!");
s_instance = this;
info() << "TransformSystem initialized"; info() << "TransformSystem initialized";
} }
TransformSystem::~TransformSystem()
{
}
void TransformSystem::update() void TransformSystem::update()
{ {
auto view = m_registry->view<TransformComponent>(); auto view = m_registry->view<TransformComponent>();
@ -41,10 +40,4 @@ namespace Inferno {
} }
} }
void TransformSystem::destroy()
{
delete s_instance;
s_instance = nullptr;
}
} }

12
inferno/src/inferno/system/transformsystem.h

@ -4,23 +4,21 @@
#include <memory> //std::shared_ptr #include <memory> //std::shared_ptr
#include "entt/entity/registry.hpp" // entt::entity, entt::registry #include "entt/entity/registry.hpp" // entt::entity, entt::registry
#include "inferno/singleton.h"
namespace Inferno { namespace Inferno {
class TransformSystem { class TransformSystem final : public Singleton<TransformSystem> {
public: public:
void initialize(); TransformSystem(s);
virtual ~TransformSystem();
void update(); void update();
void destroy();
void setRegistry(const std::shared_ptr<entt::registry>& registry) { m_registry = registry; }; void setRegistry(const std::shared_ptr<entt::registry>& registry) { m_registry = registry; };
static inline TransformSystem& the() { return *s_instance; }
private: private:
std::shared_ptr<entt::registry> m_registry; std::shared_ptr<entt::registry> m_registry;
static TransformSystem* s_instance;
}; };
} }

Loading…
Cancel
Save