Engine: Switch to ruc's singleton
This commit is contained in:
@@ -27,9 +27,6 @@ namespace Inferno {
|
||||
|
||||
Application::Application(s)
|
||||
{
|
||||
// Set singleton instance early
|
||||
s_instance = this;
|
||||
|
||||
// Initialize
|
||||
|
||||
Settings::initialize();
|
||||
@@ -38,12 +35,7 @@ namespace Inferno {
|
||||
m_window->setEventCallback(NF_BIND_EVENT(Application::onEvent));
|
||||
|
||||
Input::initialize();
|
||||
ShaderManager::initialize();
|
||||
TextureManager::initialize();
|
||||
RenderCommand::initialize();
|
||||
Renderer2D::initialize();
|
||||
RendererCharacter::initialize();
|
||||
FontManager::initialize();
|
||||
|
||||
m_scene = std::make_shared<Scene>();
|
||||
m_scene->initialize();
|
||||
@@ -162,7 +154,6 @@ namespace Inferno {
|
||||
RendererCharacter::the().endScene();
|
||||
|
||||
m_window->render();
|
||||
|
||||
}
|
||||
|
||||
dbg() << "Application shutdown";
|
||||
@@ -226,4 +217,4 @@ namespace Inferno {
|
||||
return Input::onMousePosition(e);
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace Inferno
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#include <memory> // std::unique_ptr, std::shared_ptr
|
||||
|
||||
#include "inferno/singleton.h"
|
||||
#include "ruc/singleton.h"
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace Inferno {
|
||||
class WindowCloseEvent;
|
||||
class WindowResizeEvent;
|
||||
|
||||
class Application : public Singleton<Application> {
|
||||
class Application : public ruc::Singleton<Application> {
|
||||
public:
|
||||
Application(s);
|
||||
virtual ~Application();
|
||||
@@ -48,7 +48,7 @@ namespace Inferno {
|
||||
// To be defined in the game
|
||||
extern Application& createApplication();
|
||||
|
||||
}
|
||||
} // namespace Inferno
|
||||
|
||||
#endif // APPLICATION_H
|
||||
|
||||
|
||||
@@ -7,15 +7,15 @@
|
||||
#include <unordered_map> // std::unordered_map
|
||||
#include <vector> // std::vector
|
||||
|
||||
#include "glm/ext/vector_uint2.hpp" // glm::uvec2
|
||||
#include "glm/ext/vector_int2.hpp" // glm::ivec2
|
||||
#include "glm/ext/vector_uint2.hpp" // glm::uvec2
|
||||
#include "ruc/singleton.h"
|
||||
|
||||
#include "inferno/io/log.h"
|
||||
#include "inferno/singleton.h"
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
class Texture;
|
||||
class Texture;
|
||||
|
||||
struct Character {
|
||||
glm::uvec2 position; // Position
|
||||
@@ -24,7 +24,7 @@ class Texture;
|
||||
uint32_t advance; // Amount to advance to next glyph
|
||||
};
|
||||
|
||||
// -----------------------------------------
|
||||
// -------------------------------------
|
||||
|
||||
class Font {
|
||||
public:
|
||||
@@ -50,9 +50,9 @@ class Texture;
|
||||
std::unordered_map<unsigned char, std::shared_ptr<Character>> m_characterList;
|
||||
};
|
||||
|
||||
// -----------------------------------------
|
||||
// -------------------------------------
|
||||
|
||||
class FontManager final : public Singleton<FontManager> {
|
||||
class FontManager final : public ruc::Singleton<FontManager> {
|
||||
public:
|
||||
FontManager(s);
|
||||
virtual ~FontManager();
|
||||
@@ -69,12 +69,11 @@ class Texture;
|
||||
std::unordered_map<std::string, std::shared_ptr<Font>> m_fontList;
|
||||
};
|
||||
|
||||
|
||||
// -----------------------------------------
|
||||
// -------------------------------------
|
||||
|
||||
const LogStream& operator<<(const LogStream& stream, const glm::ivec2& value);
|
||||
|
||||
}
|
||||
} // namespace Inferno
|
||||
|
||||
#endif // FONT_H
|
||||
|
||||
|
||||
@@ -8,7 +8,8 @@
|
||||
#include <unordered_map> // std::unordered_map
|
||||
#include <vector> // std::vector
|
||||
|
||||
#include "inferno/singleton.h"
|
||||
#include "ruc/singleton.h"
|
||||
|
||||
#include "inferno/util/json.h"
|
||||
|
||||
#define GLTF_TYPE_SCALAR 1
|
||||
@@ -149,7 +150,7 @@ namespace Inferno {
|
||||
|
||||
// -----------------------------------------
|
||||
|
||||
class GltfManager final : Singleton<GltfManager> {
|
||||
class GltfManager final : ruc::Singleton<GltfManager> {
|
||||
public:
|
||||
GltfManager(s) {}
|
||||
virtual ~GltfManager() {}
|
||||
|
||||
@@ -8,9 +8,9 @@
|
||||
#include "glm/ext/vector_float2.hpp" // glm::vec2
|
||||
#include "glm/ext/vector_float3.hpp" // glm::vec3
|
||||
#include "glm/ext/vector_float4.hpp" // glm::vec4
|
||||
#include "ruc/singleton.h"
|
||||
|
||||
#include "inferno/component/transformcomponent.h"
|
||||
#include "inferno/singleton.h"
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
@@ -39,7 +39,7 @@ namespace Inferno {
|
||||
float offset = 0.0f;
|
||||
};
|
||||
|
||||
// -----------------------------------------
|
||||
// -------------------------------------
|
||||
|
||||
class RenderCommand {
|
||||
public:
|
||||
@@ -57,7 +57,7 @@ namespace Inferno {
|
||||
static int32_t textureUnitAmount();
|
||||
};
|
||||
|
||||
// -----------------------------------------
|
||||
// -------------------------------------
|
||||
|
||||
class Renderer {
|
||||
public:
|
||||
@@ -92,16 +92,15 @@ namespace Inferno {
|
||||
std::shared_ptr<VertexArray> m_vertexArray;
|
||||
};
|
||||
|
||||
// -----------------------------------------
|
||||
// -------------------------------------
|
||||
|
||||
class Renderer2D final
|
||||
: public Renderer
|
||||
, public Singleton<Renderer2D> {
|
||||
, public ruc::Singleton<Renderer2D> {
|
||||
public:
|
||||
Renderer2D(s);
|
||||
virtual ~Renderer2D();
|
||||
|
||||
using Singleton<Renderer2D>::initialize;
|
||||
using Singleton<Renderer2D>::destroy;
|
||||
|
||||
static const uint32_t quadCount = 1000;
|
||||
@@ -115,6 +114,7 @@ namespace Inferno {
|
||||
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::mat4 color, std::shared_ptr<Texture> texture);
|
||||
|
||||
private:
|
||||
void loadShader() override;
|
||||
void flush() override;
|
||||
@@ -129,16 +129,15 @@ namespace Inferno {
|
||||
glm::vec4 m_vertexPositions[vertexPerQuad];
|
||||
};
|
||||
|
||||
// -----------------------------------------
|
||||
// -------------------------------------
|
||||
|
||||
class RendererCharacter final
|
||||
: public Renderer
|
||||
, public Singleton<RendererCharacter> {
|
||||
, public ruc::Singleton<RendererCharacter> {
|
||||
public:
|
||||
RendererCharacter(s);
|
||||
virtual ~RendererCharacter();
|
||||
|
||||
using Singleton<RendererCharacter>::initialize;
|
||||
using Singleton<RendererCharacter>::destroy;
|
||||
|
||||
static const uint32_t quadCount = 1000;
|
||||
@@ -149,6 +148,7 @@ namespace Inferno {
|
||||
void endScene();
|
||||
|
||||
void drawCharacter(std::array<CharacterVertex, vertexPerQuad>& characterQuad, std::shared_ptr<Texture> texture);
|
||||
|
||||
private:
|
||||
void loadShader() override;
|
||||
void flush() override;
|
||||
@@ -160,6 +160,6 @@ namespace Inferno {
|
||||
CharacterVertex* m_vertexBufferPtr { nullptr };
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace Inferno
|
||||
|
||||
#endif // RENDERER_H
|
||||
|
||||
@@ -7,8 +7,7 @@
|
||||
#include <unordered_map> // std::unordered_map
|
||||
|
||||
#include "glm/glm.hpp"
|
||||
|
||||
#include "inferno/singleton.h"
|
||||
#include "ruc/singleton.h"
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
@@ -45,9 +44,9 @@ namespace Inferno {
|
||||
uint32_t m_id;
|
||||
};
|
||||
|
||||
// -----------------------------------------
|
||||
// -------------------------------------
|
||||
|
||||
class ShaderManager final : public Singleton<ShaderManager> {
|
||||
class ShaderManager final : public ruc::Singleton<ShaderManager> {
|
||||
public:
|
||||
ShaderManager(s);
|
||||
virtual ~ShaderManager();
|
||||
@@ -70,7 +69,6 @@ namespace Inferno {
|
||||
std::unordered_map<std::string, std::shared_ptr<Shader>> m_shaderList;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
} // namespace Inferno
|
||||
|
||||
#endif // SHADER_H
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
#ifndef TEXTURE_H
|
||||
#define TEXTURE_H
|
||||
|
||||
#include <cstdint> // uint32_t
|
||||
#include <cstdint> // uint32_t
|
||||
#include <memory> // std::shared_ptr
|
||||
#include <string> // std::string
|
||||
#include <unordered_map> // std::unordered_map
|
||||
|
||||
#include "inferno/singleton.h"
|
||||
#include "ruc/singleton.h"
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
@@ -37,9 +37,9 @@ namespace Inferno {
|
||||
uint32_t m_dataFormat;
|
||||
};
|
||||
|
||||
// -----------------------------------------
|
||||
// -------------------------------------
|
||||
|
||||
class TextureManager final : public Singleton<TextureManager> {
|
||||
class TextureManager final : public ruc::Singleton<TextureManager> {
|
||||
public:
|
||||
TextureManager(s);
|
||||
virtual ~TextureManager();
|
||||
@@ -56,6 +56,6 @@ namespace Inferno {
|
||||
std::unordered_map<std::string, std::shared_ptr<Texture>> m_textureList;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace Inferno
|
||||
|
||||
#endif // TEXTURE_H
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#include "inferno/scene/scene.h"
|
||||
#include "inferno/assert.h"
|
||||
#include "inferno/component/cameracomponent.h"
|
||||
#include "inferno/component/luascriptcomponent.h"
|
||||
@@ -5,7 +6,6 @@
|
||||
#include "inferno/component/spritecomponent.h"
|
||||
#include "inferno/component/tagcomponent.h"
|
||||
#include "inferno/component/textareacomponent.h"
|
||||
#include "inferno/scene/scene.h"
|
||||
#include "inferno/script/cameracontroller.h"
|
||||
#include "inferno/script/nativescript.h"
|
||||
#include "inferno/system/camerasystem.h"
|
||||
@@ -23,19 +23,10 @@ namespace Inferno {
|
||||
|
||||
m_registry = std::make_shared<entt::registry>();
|
||||
|
||||
TransformSystem::initialize();
|
||||
TransformSystem::the().setRegistry(m_registry);
|
||||
|
||||
CameraSystem::initialize();
|
||||
CameraSystem::the().setRegistry(m_registry);
|
||||
|
||||
RenderSystem::initialize();
|
||||
RenderSystem::the().setRegistry(m_registry);
|
||||
|
||||
ScriptSystem::initialize();
|
||||
ScriptSystem::the().setScene(this);
|
||||
|
||||
TextAreaSystem::initialize();
|
||||
TextAreaSystem::the().setScene(this);
|
||||
|
||||
// Load assets
|
||||
@@ -122,14 +113,14 @@ namespace Inferno {
|
||||
|
||||
void Scene::validEntity(uint32_t entity) const
|
||||
{
|
||||
ASSERT(m_registry->valid(entt::entity {entity}), "Entity is not valid");
|
||||
ASSERT(m_registry->valid(entt::entity { entity }), "Entity is not valid");
|
||||
}
|
||||
|
||||
// ----------------------------------------
|
||||
// -------------------------------------
|
||||
|
||||
const LogStream& operator<<(const LogStream& stream, entt::entity entity)
|
||||
{
|
||||
return stream << static_cast<uint32_t>(entity);
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace Inferno
|
||||
|
||||
@@ -5,8 +5,7 @@
|
||||
|
||||
#include "entt/entity/registry.hpp" // entt::entity, entt::registry
|
||||
#include "glm/ext/matrix_float4x4.hpp" // glm::mat4
|
||||
|
||||
#include "inferno/singleton.h"
|
||||
#include "ruc/singleton.h"
|
||||
|
||||
#define NEAR_PLANE 0.1f
|
||||
#define FAR_PLANE 100.0f
|
||||
@@ -16,7 +15,7 @@ namespace Inferno {
|
||||
struct TransformComponent;
|
||||
struct CameraComponent;
|
||||
|
||||
class CameraSystem final : public Singleton<CameraSystem> {
|
||||
class CameraSystem final : public ruc::Singleton<CameraSystem> {
|
||||
public:
|
||||
CameraSystem(s);
|
||||
virtual ~CameraSystem();
|
||||
@@ -34,6 +33,6 @@ namespace Inferno {
|
||||
std::shared_ptr<entt::registry> m_registry;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace Inferno
|
||||
|
||||
#endif // CAMERA_SYSTEM_H
|
||||
|
||||
@@ -4,13 +4,13 @@
|
||||
#include <memory> //std::shared_ptr
|
||||
|
||||
#include "entt/entity/registry.hpp" // entt::entity, entt::registry
|
||||
#include "ruc/singleton.h"
|
||||
|
||||
#include "inferno/render/renderer.h"
|
||||
#include "inferno/singleton.h"
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
class RenderSystem final : public Singleton<RenderSystem> {
|
||||
class RenderSystem final : public ruc::Singleton<RenderSystem> {
|
||||
public:
|
||||
RenderSystem(s);
|
||||
virtual ~RenderSystem();
|
||||
@@ -23,6 +23,6 @@ namespace Inferno {
|
||||
std::shared_ptr<entt::registry> m_registry;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace Inferno
|
||||
|
||||
#endif // RENDER_SYSTEM_H
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#include <cstdint> // uint32_t
|
||||
|
||||
#include "inferno/singleton.h"
|
||||
#include "ruc/singleton.h"
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace Inferno {
|
||||
|
||||
class Scene;
|
||||
|
||||
class ScriptSystem final : public Singleton<ScriptSystem> {
|
||||
class ScriptSystem final : public ruc::Singleton<ScriptSystem> {
|
||||
public:
|
||||
ScriptSystem(s);
|
||||
virtual ~ScriptSystem();
|
||||
@@ -29,6 +29,6 @@ namespace Inferno {
|
||||
Scene* m_scene { nullptr };
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace Inferno
|
||||
|
||||
#endif // SCRIPT_SYSTEM_H
|
||||
|
||||
@@ -7,9 +7,9 @@
|
||||
#include <vector> // std::vector
|
||||
|
||||
#include "glm/ext/vector_float3.hpp" // glm::vec3
|
||||
#include "ruc/singleton.h"
|
||||
|
||||
#include "inferno/render/renderer.h"
|
||||
#include "inferno/singleton.h"
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace Inferno {
|
||||
class Font;
|
||||
class Scene;
|
||||
|
||||
class TextAreaSystem final : public Singleton<TextAreaSystem> {
|
||||
class TextAreaSystem final : public ruc::Singleton<TextAreaSystem> {
|
||||
public:
|
||||
TextAreaSystem(s);
|
||||
virtual ~TextAreaSystem();
|
||||
@@ -35,5 +35,4 @@ namespace Inferno {
|
||||
|
||||
} // namespace Inferno
|
||||
|
||||
|
||||
#endif // TEXTAREA_H
|
||||
|
||||
@@ -4,11 +4,11 @@
|
||||
#include <memory> //std::shared_ptr
|
||||
|
||||
#include "entt/entity/registry.hpp" // entt::entity, entt::registry
|
||||
#include "inferno/singleton.h"
|
||||
#include "ruc/singleton.h"
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
class TransformSystem final : public Singleton<TransformSystem> {
|
||||
class TransformSystem final : public ruc::Singleton<TransformSystem> {
|
||||
public:
|
||||
TransformSystem(s);
|
||||
virtual ~TransformSystem();
|
||||
@@ -21,6 +21,6 @@ namespace Inferno {
|
||||
std::shared_ptr<entt::registry> m_registry;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace Inferno
|
||||
|
||||
#endif // TRANSFORM_SYSTEM_H
|
||||
|
||||
Reference in New Issue
Block a user