From 0b2cc9f4111c88a546bc2ebd685ff86558ae6443 Mon Sep 17 00:00:00 2001 From: Riyyi Date: Thu, 14 Jan 2021 03:29:21 +0100 Subject: [PATCH] Move example entities to scene --- inferno/src/inferno/application.cpp | 22 +---------------- inferno/src/inferno/application.h | 2 -- inferno/src/inferno/scene/scene.cpp | 37 +++++++++++++++++++++-------- inferno/src/inferno/scene/scene.h | 7 +++--- 4 files changed, 32 insertions(+), 36 deletions(-) diff --git a/inferno/src/inferno/application.cpp b/inferno/src/inferno/application.cpp index 2bb2da4..600ac3d 100644 --- a/inferno/src/inferno/application.cpp +++ b/inferno/src/inferno/application.cpp @@ -46,6 +46,7 @@ namespace Inferno { textureManager->initialize(); m_scene = std::make_shared(); + m_scene->initialize(); Renderer2D* renderer2D = new Renderer2D(); renderer2D->initialize(); @@ -58,9 +59,6 @@ namespace Inferno { // Load assets - m_texture = TextureManager::the().load("assets/gfx/test.png"); - m_texture2 = TextureManager::the().load("assets/gfx/test-inverted.png"); - m_font = FontManager::the().load("assets/fnt/dejavu-sans"); } @@ -80,19 +78,6 @@ namespace Inferno { { dbg() << "Application startup"; - Entity quad = m_scene->createEntity("Quad"); - quad.add(glm::vec4 { 1.0f, 1.0f, 1.0f, 1.0f }, m_texture); - - Entity quad2 = m_scene->createEntity("Quad 2"); - auto& quad2Transform = quad2.get(); - quad2Transform.translate.x = 1.1f; - quad2.add(glm::vec4 { 0.5f, 0.6f, 0.8f, 1.0f }, m_texture); - - Entity quad3 = m_scene->createEntity("Quad 3"); - auto& quad3Transform = quad3.get(); - quad3Transform.translate.x = 2.2f; - quad3.add(glm::vec4 { 1.0f, 1.0f, 1.0f, 1.0f }, m_texture2); - std::array character; // character.at(0).quad.textureCoordinates = { 0.0f, 0.0f }; // bottom left @@ -131,11 +116,6 @@ namespace Inferno { character.at(2).quad.textureCoordinates = { x.y, y.y }; character.at(3).quad.textureCoordinates = { x.x, y.y }; - character.at(0).quad.textureIndex = 1.0f; - character.at(1).quad.textureIndex = 1.0f; - character.at(2).quad.textureIndex = 1.0f; - character.at(3).quad.textureIndex = 1.0f; - // pos // texcoords // diff --git a/inferno/src/inferno/application.h b/inferno/src/inferno/application.h index a316f37..73caa4b 100644 --- a/inferno/src/inferno/application.h +++ b/inferno/src/inferno/application.h @@ -47,8 +47,6 @@ namespace Inferno { float m_lastFrameTime = 0.0f; // - std::shared_ptr m_texture; - std::shared_ptr m_texture2; std::shared_ptr m_font; // diff --git a/inferno/src/inferno/scene/scene.cpp b/inferno/src/inferno/scene/scene.cpp index 3ffc3f6..ab68d5f 100644 --- a/inferno/src/inferno/scene/scene.cpp +++ b/inferno/src/inferno/scene/scene.cpp @@ -8,18 +8,11 @@ namespace Inferno { - Scene::Scene() - { - initialize(); - } - - Scene::~Scene() - { - destroy(); - } - void Scene::initialize() { + // Initialize + // --------------------------------- + m_registry = std::make_shared(); TransformSystem* transformSystem = new TransformSystem(); @@ -39,6 +32,30 @@ namespace Inferno { RenderSystem* renderSystem = new RenderSystem(); renderSystem->initialize(); RenderSystem::the().setRegistry(m_registry); + + // Load assets + // --------------------------------- + + m_texture = TextureManager::the().load("assets/gfx/test.png"); + m_texture2 = TextureManager::the().load("assets/gfx/test-inverted.png"); + + // Construct entities + // --------------------------------- + + Entity quad = createEntity("Quad"); + quad.add(glm::vec4 { 1.0f, 1.0f, 1.0f, 1.0f }, m_texture); + + Entity quad2 = createEntity("Quad 2"); + auto& quad2Transform = quad2.get(); + quad2Transform.translate.x = 1.1f; + quad2.add(glm::vec4 { 0.5f, 0.6f, 0.8f, 1.0f }, m_texture); + + Entity quad3 = createEntity("Quad 3"); + auto& quad3Transform = quad3.get(); + quad3Transform.translate.x = 2.2f; + quad3.add(glm::vec4 { 1.0f, 1.0f, 1.0f, 1.0f }, m_texture2); + + dbg(Log::Info) << "Scene initialized"; } void Scene::update(float deltaTime) diff --git a/inferno/src/inferno/scene/scene.h b/inferno/src/inferno/scene/scene.h index 9b53803..13746eb 100644 --- a/inferno/src/inferno/scene/scene.h +++ b/inferno/src/inferno/scene/scene.h @@ -11,12 +11,10 @@ namespace Inferno { class Camera; class Entity; + class Texture; class Scene { public: - Scene(); - virtual ~Scene(); - void initialize(); void update(float deltaTime); void render(); @@ -29,6 +27,9 @@ namespace Inferno { glm::mat4 cameraProjectionView(); private: + std::shared_ptr m_texture; + std::shared_ptr m_texture2; + std::shared_ptr m_registry; };