Moved world definition to Schema/Entities/Test.xml and removed HardcodedTestWorld
This commit is contained in:
+1
-1
Submodule assets updated: 4bd902b697...5a207bbb3e
@@ -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;
|
||||
|
||||
@@ -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<Game, Events::KeyUp> m_EKeyUp;
|
||||
bool testOnKeyUp(const Events::KeyUp& e);
|
||||
|
||||
void testIntialize();
|
||||
void testTick(double dt);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,47 +0,0 @@
|
||||
#include <list>
|
||||
#include <tuple>
|
||||
#include <boost/any.hpp>
|
||||
#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>("EntityXMLFile");
|
||||
ResourceManager::Load<EntityXMLFile>("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";
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -2,19 +2,43 @@
|
||||
|
||||
<Entity xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xi="http://www.w3.org/2001/XInclude" xsi:noNamespaceSchemaLocation="../Types/Entity.xsd" xmlns:c="components">
|
||||
<Components>
|
||||
<c:Transform>
|
||||
<Position X="0" Y="0" Z="0"/>
|
||||
<Scale X="3" Y="3" Z="3"/>
|
||||
</c:Transform>
|
||||
<c:Transform></c:Transform>
|
||||
<c:Model>
|
||||
<Resource>Models/Core/UnitSphere.obj</Resource>
|
||||
<Resource>Models/DummyScene.obj</Resource>
|
||||
</c:Model>
|
||||
<c:Test>
|
||||
<Integer>12</Integer>
|
||||
<Double>11.11</Double>
|
||||
<String>Hello World</String>
|
||||
</c:Test>
|
||||
</Components>
|
||||
<Children>
|
||||
<Entity>
|
||||
<Components>
|
||||
<c:Transform>
|
||||
<Position X="-1.5"/>
|
||||
<Scale X="1" Y="1" Z="1"/>
|
||||
</c:Transform>
|
||||
<c:Model>
|
||||
<Resource>Models/ScaleWidget.obj</Resource>
|
||||
</c:Model>
|
||||
</Components>
|
||||
</Entity>
|
||||
<Entity>
|
||||
<Components>
|
||||
<c:Transform>
|
||||
<Position X="1.5"/>
|
||||
</c:Transform>
|
||||
<c:Model>
|
||||
<Resource>Models/RotationWidget.obj</Resource>
|
||||
</c:Model>
|
||||
</Components>
|
||||
</Entity>
|
||||
<Entity>
|
||||
<Components>
|
||||
<c:Transform>
|
||||
<Position X="0" Y="-0"/>
|
||||
<Scale X="1" Y="1" Z="1"/>
|
||||
</c:Transform>
|
||||
<c:Model>
|
||||
<Resource>Models/Core/UnitRaptor.obj</Resource>
|
||||
</c:Model>
|
||||
</Components>
|
||||
</Entity>
|
||||
</Children>
|
||||
</Entity>
|
||||
@@ -7,7 +7,7 @@
|
||||
<xs:element name="Entity">
|
||||
<xs:complexType>
|
||||
<xs:all>
|
||||
<xs:element name="Components">
|
||||
<xs:element name="Components" minOccurs="0">
|
||||
<xs:complexType>
|
||||
<xs:all>
|
||||
<xs:element ref="c:Transform" minOccurs="0"/>
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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<Model>(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<Model>(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)
|
||||
|
||||
+29
-3
@@ -1,11 +1,11 @@
|
||||
#include "Game.h"
|
||||
#include "HardcodedTestWorld.h"
|
||||
|
||||
Game::Game(int argc, char* argv[])
|
||||
{
|
||||
ResourceManager::RegisterType<ConfigFile>("ConfigFile");
|
||||
ResourceManager::RegisterType<Model>("Model");
|
||||
ResourceManager::RegisterType<Texture>("Texture");
|
||||
ResourceManager::RegisterType<EntityXMLFile>("EntityXMLFile");
|
||||
|
||||
m_Config = ResourceManager::Load<ConfigFile>("Config.ini");
|
||||
LOG_LEVEL = static_cast<_LOG_LEVEL>(m_Config->Get<int>("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<EntityXMLFile>("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<Game>();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user