From 58d827f7d08431df982864dd1de8a92e998fae97 Mon Sep 17 00:00:00 2001 From: sippeangelo Date: Wed, 9 Dec 2015 14:25:41 +0100 Subject: [PATCH] Moved world definition to Schema/Entities/Test.xml and removed HardcodedTestWorld --- assets | 2 +- include/Engine/Core/World.h | 2 +- include/Game/Game.h | 8 ++++ include/Game/HardcodedTestWorld.h | 47 ------------------- resources/Schema/Entities/Test.xml | 44 ++++++++++++++---- resources/Schema/Types/Entity.xsd | 2 +- src/Engine/Core/World.cpp | 5 +- src/Engine/Rendering/RenderQueueFactory.cpp | 51 +++++++++++---------- src/Game/Game.cpp | 32 +++++++++++-- 9 files changed, 105 insertions(+), 88 deletions(-) delete mode 100644 include/Game/HardcodedTestWorld.h diff --git a/assets b/assets index 4bd902b6..5a207bbb 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit 4bd902b697b8eef063da800102e6e9c3b29353eb +Subproject commit 5a207bbb3ee4dcc620a9d2dfe8bfa0190db21a63 diff --git a/include/Engine/Core/World.h b/include/Engine/Core/World.h index 1ac10df1..932d2a17 100644 --- a/include/Engine/Core/World.h +++ b/include/Engine/Core/World.h @@ -22,7 +22,7 @@ public: // Get a component of an entity ComponentWrapper GetComponent(EntityID entity, std::string componentType); // Get all components of the specified type - const ComponentPool& GetComponents(std::string componentType); + const ComponentPool* GetComponents(std::string componentType); private: EntityID m_CurrentEntityID = 1; diff --git a/include/Game/Game.h b/include/Game/Game.h index cd16a3dd..b561119a 100644 --- a/include/Game/Game.h +++ b/include/Game/Game.h @@ -9,6 +9,8 @@ #include "GUI/Frame.h" #include "Core/World.h" #include "Rendering/RenderQueueFactory.h" +#include "Core/EKeyDown.h" +#include "Core/EntityXMLFile.h" class Game { @@ -28,6 +30,12 @@ private: GUI::Frame* m_FrameStack; World* m_World; RenderQueueFactory* m_RenderQueueFactory; + + EventRelay m_EKeyUp; + bool testOnKeyUp(const Events::KeyUp& e); + + void testIntialize(); + void testTick(double dt); }; #endif diff --git a/include/Game/HardcodedTestWorld.h b/include/Game/HardcodedTestWorld.h deleted file mode 100644 index ec7e3267..00000000 --- a/include/Game/HardcodedTestWorld.h +++ /dev/null @@ -1,47 +0,0 @@ -#include -#include -#include -#include "GLM.h" -#include "Core/World.h" -#include "Core/Util/Any.h" -#include "Core/EntityXMLFile.h" - -class HardcodedTestWorld : public World -{ -public: - HardcodedTestWorld() - : World() - { - ResourceManager::RegisterType("EntityXMLFile"); - ResourceManager::Load("Schema/Entities/Test.xml")->PopulateWorld(this); - - createTestEntities(); - } - -private: - void createTestEntities() - { - //Create some test widgets - { - EntityID entityScaleWidget = CreateEntity(); - ComponentWrapper transform = AttachComponent(entityScaleWidget, "Transform"); - transform["Position"] = glm::vec3(-1.5f, 0.f, 0.f); - ComponentWrapper model = AttachComponent(entityScaleWidget, "Model"); - model["Resource"] = "Models/ScaleWidget.obj"; - } - { - EntityID entityRotationWidget = CreateEntity(); - ComponentWrapper transform = AttachComponent(entityRotationWidget, "Transform"); - transform["Position"] = glm::vec3(1.5f, 0.f, 0.f); - ComponentWrapper model = AttachComponent(entityRotationWidget, "Model"); - model["Resource"] = "Models/RotationWidget.obj"; - } - { - EntityID entityDummyScene = CreateEntity(); - ComponentWrapper transform = AttachComponent(entityDummyScene, "Transform"); - transform["Position"] = glm::vec3(0, 0.f, 0.f); - ComponentWrapper model = AttachComponent(entityDummyScene, "Model"); - model["Resource"] = "Models/DummyScene.obj"; - } - } -}; \ No newline at end of file diff --git a/resources/Schema/Entities/Test.xml b/resources/Schema/Entities/Test.xml index 9b379495..2b003aea 100644 --- a/resources/Schema/Entities/Test.xml +++ b/resources/Schema/Entities/Test.xml @@ -2,19 +2,43 @@ - - - - + - Models/Core/UnitSphere.obj + Models/DummyScene.obj - - 12 - 11.11 - Hello World - + + + + + + + + Models/ScaleWidget.obj + + + + + + + + + + Models/RotationWidget.obj + + + + + + + + + + + Models/Core/UnitRaptor.obj + + + \ No newline at end of file diff --git a/resources/Schema/Types/Entity.xsd b/resources/Schema/Types/Entity.xsd index bd7de5a3..49d0f895 100644 --- a/resources/Schema/Types/Entity.xsd +++ b/resources/Schema/Types/Entity.xsd @@ -7,7 +7,7 @@ - + diff --git a/src/Engine/Core/World.cpp b/src/Engine/Core/World.cpp index 26d3f1e4..4ebf733e 100644 --- a/src/Engine/Core/World.cpp +++ b/src/Engine/Core/World.cpp @@ -41,9 +41,10 @@ ComponentWrapper World::GetComponent(EntityID entity, std::string componentType) return pool->GetByEntity(entity); } -const ComponentPool& World::GetComponents(std::string componentType) +const ComponentPool* World::GetComponents(std::string componentType) { - return *m_ComponentPools.at(componentType); + auto it = m_ComponentPools.find(componentType); + return (it != m_ComponentPools.end()) ? it->second : nullptr; } EntityID World::generateEntityID() diff --git a/src/Engine/Rendering/RenderQueueFactory.cpp b/src/Engine/Rendering/RenderQueueFactory.cpp index aec304ed..9d001b96 100644 --- a/src/Engine/Rendering/RenderQueueFactory.cpp +++ b/src/Engine/Rendering/RenderQueueFactory.cpp @@ -35,32 +35,37 @@ glm::vec3 GetAbsolutePosition(World* world, ComponentWrapper transformComponent) void RenderQueueFactory::FillModels(World* world, RenderQueue* renderQueue) { - for(auto& modelC : world->GetComponents("Model")) { - std::string resource = modelC["Resource"]; - if (resource.empty()) { - continue; - } - glm::vec4 color = modelC["Color"]; - Model* model = ResourceManager::Load(resource); + auto models = world->GetComponents("Model"); + if (models == nullptr) { + return; + } - for (auto texGroup : model->TextureGroups) { - ModelJob job; - job.TextureID = (texGroup.Texture) ? texGroup.Texture->ResourceID : 0; - job.DiffuseTexture = texGroup.Texture.get(); - job.NormalTexture = texGroup.NormalMap.get(); - job.SpecularTexture = texGroup.SpecularMap.get(); - job.Model = model; - job.StartIndex = texGroup.StartIndex; - job.EndIndex = texGroup.EndIndex; - job.ModelMatrix = model->m_Matrix * ModelMatrix(world, modelC.EntityID); - job.Color = color; + for (auto& modelC : *models) { + std::string resource = modelC["Resource"]; + if (resource.empty()) { + continue; + } + glm::vec4 color = modelC["Color"]; + Model* model = ResourceManager::Load(resource); - //TODO: RENDERER: Not sure if the best solution for pickingColor to entity link is this - job.Entity = modelC.EntityID; + for (auto texGroup : model->TextureGroups) { + ModelJob job; + job.TextureID = (texGroup.Texture) ? texGroup.Texture->ResourceID : 0; + job.DiffuseTexture = texGroup.Texture.get(); + job.NormalTexture = texGroup.NormalMap.get(); + job.SpecularTexture = texGroup.SpecularMap.get(); + job.Model = model; + job.StartIndex = texGroup.StartIndex; + job.EndIndex = texGroup.EndIndex; + job.ModelMatrix = model->m_Matrix * ModelMatrix(world, modelC.EntityID); + job.Color = color; - renderQueue->Add(job); - } - } + //TODO: RENDERER: Not sure if the best solution for pickingColor to entity link is this + job.Entity = modelC.EntityID; + + renderQueue->Add(job); + } + } } void RenderQueueFactory::FillLights(World* world, RenderQueue* renderQueue) diff --git a/src/Game/Game.cpp b/src/Game/Game.cpp index 416b054e..4dcf0416 100644 --- a/src/Game/Game.cpp +++ b/src/Game/Game.cpp @@ -1,11 +1,11 @@ #include "Game.h" -#include "HardcodedTestWorld.h" Game::Game(int argc, char* argv[]) { ResourceManager::RegisterType("ConfigFile"); ResourceManager::RegisterType("Model"); ResourceManager::RegisterType("Texture"); + ResourceManager::RegisterType("EntityXMLFile"); m_Config = ResourceManager::Load("Config.ini"); LOG_LEVEL = static_cast<_LOG_LEVEL>(m_Config->Get("Debug.LogLevel", 1)); @@ -35,10 +35,12 @@ Game::Game(int argc, char* argv[]) m_FrameStack->Width = m_Renderer->Resolution().Width; m_FrameStack->Height = m_Renderer->Resolution().Height; - // Create a TEST WORLD - m_World = new HardcodedTestWorld(); + // Create a world + m_World = new World(); m_LastTime = glfwGetTime(); + + testIntialize(); } Game::~Game() @@ -58,6 +60,7 @@ void Game::Tick() m_Renderer->Update(dt); m_EventBroker->Swap(); + testTick(dt); m_RenderQueueFactory->Update(m_World); m_Renderer->Draw(m_RenderQueueFactory->RenderQueues()); @@ -67,3 +70,26 @@ void Game::Tick() glfwPollEvents(); } + + +bool Game::testOnKeyUp(const Events::KeyUp& e) +{ + if (e.KeyCode == GLFW_KEY_R) { + delete m_World; + m_World = new World(); + ResourceManager::Release("EntityXMLFile", "Schema/Entities/Test.xml"); + ResourceManager::Load("Schema/Entities/Test.xml")->PopulateWorld(m_World); + } + + return false; +} + +void Game::testIntialize() +{ + EVENT_SUBSCRIBE_MEMBER(m_EKeyUp, &Game::testOnKeyUp); +} + +void Game::testTick(double dt) +{ + m_EventBroker->Process(); +}