Merge branch 'master' of github.com:sippeangelo/Escape-the-Dawn
This commit is contained in:
@@ -11,7 +11,7 @@ struct Component;
|
|||||||
#define REGISTER_COMPONENT(NAME, TYPE) \
|
#define REGISTER_COMPONENT(NAME, TYPE) \
|
||||||
static ComponentRegistrar<TYPE> registrar(NAME);
|
static ComponentRegistrar<TYPE> registrar(NAME);
|
||||||
|
|
||||||
template<class T>
|
template <typename T>
|
||||||
class ComponentRegistrar
|
class ComponentRegistrar
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -92,6 +92,7 @@
|
|||||||
<ClCompile Include="Model.cpp" />
|
<ClCompile Include="Model.cpp" />
|
||||||
<ClCompile Include="Renderer\Renderer.cpp" />
|
<ClCompile Include="Renderer\Renderer.cpp" />
|
||||||
<ClCompile Include="Systems\CollisionSystem.cpp" />
|
<ClCompile Include="Systems\CollisionSystem.cpp" />
|
||||||
|
<ClCompile Include="World.cpp" />
|
||||||
<ClCompile Include="Systems\InputSystem.cpp" />
|
<ClCompile Include="Systems\InputSystem.cpp" />
|
||||||
<ClCompile Include="Systems\LevelGenerationSystem.cpp" />
|
<ClCompile Include="Systems\LevelGenerationSystem.cpp" />
|
||||||
<ClCompile Include="Systems\ParticleSystem.cpp" />
|
<ClCompile Include="Systems\ParticleSystem.cpp" />
|
||||||
@@ -108,8 +109,9 @@
|
|||||||
<ClInclude Include="glerror.h" />
|
<ClInclude Include="glerror.h" />
|
||||||
<ClInclude Include="Model.h" />
|
<ClInclude Include="Model.h" />
|
||||||
<ClInclude Include="Renderer\Renderer.h" />
|
<ClInclude Include="Renderer\Renderer.h" />
|
||||||
<ClInclude Include="Systems\CollisionSystem.h" />
|
|
||||||
<ClInclude Include="Systems\InputSystem.h" />
|
<ClInclude Include="Systems\InputSystem.h" />
|
||||||
|
<ClInclude Include="System.h" />
|
||||||
|
<ClInclude Include="Systems\CollisionSystem.h" />
|
||||||
<ClInclude Include="Systems\LevelGenerationSystem.h" />
|
<ClInclude Include="Systems\LevelGenerationSystem.h" />
|
||||||
<ClInclude Include="Systems\ParticleSystem.h" />
|
<ClInclude Include="Systems\ParticleSystem.h" />
|
||||||
<ClInclude Include="Systems\PlayerSystem.h" />
|
<ClInclude Include="Systems\PlayerSystem.h" />
|
||||||
|
|||||||
@@ -1,114 +1,66 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Filter Include="Source Files">
|
<ClCompile Include="main.cpp" />
|
||||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
<ClCompile Include="Renderer\Renderer.cpp" />
|
||||||
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
<ClCompile Include="World.cpp" />
|
||||||
</Filter>
|
|
||||||
<Filter Include="Header Files">
|
|
||||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
|
||||||
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
|
|
||||||
</Filter>
|
|
||||||
<Filter Include="Resource Files">
|
|
||||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
|
||||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
|
||||||
</Filter>
|
|
||||||
<Filter Include="Header Files\Components">
|
|
||||||
<UniqueIdentifier>{9af04489-86da-41b7-aaba-12d5b6653660}</UniqueIdentifier>
|
|
||||||
</Filter>
|
|
||||||
<Filter Include="Source Files\Renderer">
|
|
||||||
<UniqueIdentifier>{7abbf0e9-8bda-475e-bf00-a347f396b892}</UniqueIdentifier>
|
|
||||||
</Filter>
|
|
||||||
<Filter Include="Header Files\Renderer">
|
|
||||||
<UniqueIdentifier>{091f6f01-79ab-4a49-9639-c7185e89c84e}</UniqueIdentifier>
|
|
||||||
</Filter>
|
|
||||||
<Filter Include="Shaders">
|
|
||||||
<UniqueIdentifier>{26dccea6-3d9c-4d5f-9db2-98621e35ffcb}</UniqueIdentifier>
|
|
||||||
</Filter>
|
|
||||||
<Filter Include="Header Files\Systems">
|
|
||||||
<UniqueIdentifier>{e7de2e5a-0a73-437a-8d01-5f23770e5cba}</UniqueIdentifier>
|
|
||||||
</Filter>
|
|
||||||
<Filter Include="Source Files\Systems">
|
|
||||||
<UniqueIdentifier>{7673cacc-e435-4028-9354-b2c8b559c7b3}</UniqueIdentifier>
|
|
||||||
</Filter>
|
|
||||||
</ItemGroup>
|
|
||||||
<ItemGroup>
|
|
||||||
<ClCompile Include="main.cpp">
|
|
||||||
<Filter>Source Files</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="Systems\CollisionSystem.cpp">
|
<ClCompile Include="Systems\CollisionSystem.cpp">
|
||||||
<Filter>Source Files\Systems</Filter>
|
<Filter>Systems</Filter>
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="Systems\InputSystem.cpp">
|
|
||||||
<Filter>Source Files\Systems</Filter>
|
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="Systems\LevelGenerationSystem.cpp">
|
<ClCompile Include="Systems\LevelGenerationSystem.cpp">
|
||||||
<Filter>Source Files\Systems</Filter>
|
<Filter>Systems</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="Systems\InputSystem.cpp">
|
||||||
|
<Filter>Systems</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="Systems\ParticleSystem.cpp">
|
<ClCompile Include="Systems\ParticleSystem.cpp">
|
||||||
<Filter>Source Files\Systems</Filter>
|
<Filter>Systems</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="Systems\PlayerSystem.cpp">
|
<ClCompile Include="Systems\PlayerSystem.cpp">
|
||||||
<Filter>Source Files\Systems</Filter>
|
<Filter>Systems</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="Systems\RenderSystem.cpp">
|
<ClCompile Include="Systems\RenderSystem.cpp">
|
||||||
<Filter>Source Files\Systems</Filter>
|
<Filter>Systems</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="Systems\SoundsSystem.cpp">
|
<ClCompile Include="Systems\SoundsSystem.cpp">
|
||||||
<Filter>Source Files\Systems</Filter>
|
<Filter>Systems</Filter>
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="Renderer\Renderer.cpp">
|
|
||||||
<Filter>Source Files\Renderer</Filter>
|
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="Model.cpp">
|
<ClCompile Include="Model.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="glerror.h">
|
<ClInclude Include="Component.h" />
|
||||||
<Filter>Header Files</Filter>
|
<ClInclude Include="ComponentFactory.h" />
|
||||||
</ClInclude>
|
<ClInclude Include="Entity.h" />
|
||||||
<ClInclude Include="logging.h">
|
<ClInclude Include="logging.h" />
|
||||||
<Filter>Header Files</Filter>
|
<ClInclude Include="glerror.h" />
|
||||||
</ClInclude>
|
<ClInclude Include="Renderer\Renderer.h" />
|
||||||
<ClInclude Include="World.h">
|
<ClInclude Include="System.h" />
|
||||||
<Filter>Header Files</Filter>
|
<ClInclude Include="World.h" />
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="Component.h">
|
|
||||||
<Filter>Header Files</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="Entity.h">
|
|
||||||
<Filter>Header Files</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="Components\Transform.h">
|
|
||||||
<Filter>Header Files\Components</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="ComponentFactory.h">
|
|
||||||
<Filter>Header Files</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="Systems\CollisionSystem.h">
|
<ClInclude Include="Systems\CollisionSystem.h">
|
||||||
<Filter>Header Files\Systems</Filter>
|
<Filter>Systems</Filter>
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="Systems\InputSystem.h">
|
|
||||||
<Filter>Header Files\Systems</Filter>
|
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="Systems\LevelGenerationSystem.h">
|
<ClInclude Include="Systems\LevelGenerationSystem.h">
|
||||||
<Filter>Header Files\Systems</Filter>
|
<Filter>Systems</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="Systems\InputSystem.h">
|
||||||
|
<Filter>Systems</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="Systems\ParticleSystem.h">
|
<ClInclude Include="Systems\ParticleSystem.h">
|
||||||
<Filter>Header Files\Systems</Filter>
|
<Filter>Systems</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="Systems\PlayerSystem.h">
|
<ClInclude Include="Systems\PlayerSystem.h">
|
||||||
<Filter>Header Files\Systems</Filter>
|
<Filter>Systems</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="Systems\RenderSystem.h">
|
<ClInclude Include="Systems\RenderSystem.h">
|
||||||
<Filter>Header Files\Systems</Filter>
|
<Filter>Systems</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="Systems\SoundSystem.h">
|
<ClInclude Include="Systems\SoundSystem.h">
|
||||||
<Filter>Header Files\Systems</Filter>
|
<Filter>Systems</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="Renderer\Renderer.h">
|
<ClInclude Include="Components\Transform.h">
|
||||||
<Filter>Header Files\Renderer</Filter>
|
<Filter>Components</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="Model.h">
|
<ClInclude Include="Model.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
@@ -122,4 +74,15 @@
|
|||||||
<Filter>Shaders</Filter>
|
<Filter>Shaders</Filter>
|
||||||
</None>
|
</None>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Filter Include="Systems">
|
||||||
|
<UniqueIdentifier>{657e11f4-52e7-4336-b77f-80f00b85c33f}</UniqueIdentifier>
|
||||||
|
</Filter>
|
||||||
|
<Filter Include="Components">
|
||||||
|
<UniqueIdentifier>{59929465-a139-43b9-9c75-48121d156e78}</UniqueIdentifier>
|
||||||
|
</Filter>
|
||||||
|
<Filter Include="Shaders">
|
||||||
|
<UniqueIdentifier>{54f1eb6f-dc00-4e97-a3ef-ac255d755e2e}</UniqueIdentifier>
|
||||||
|
</Filter>
|
||||||
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
#ifndef System_h__
|
||||||
|
#define System_h__
|
||||||
|
|
||||||
|
#include "Entity.h"
|
||||||
|
|
||||||
|
class World;
|
||||||
|
|
||||||
|
class System
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
System(World* world) : m_World(world) { }
|
||||||
|
virtual ~System() { }
|
||||||
|
|
||||||
|
virtual void Update(double dt, EntityID entity, EntityID parent) = 0;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
World* m_World;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // System_h__
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
#include "CollisionSystem.h"
|
||||||
|
#include "World.h"
|
||||||
|
|
||||||
|
void Systems::Collision::Update(double dt, EntityID entity, EntityID parent)
|
||||||
|
{
|
||||||
|
if (parent != 0)
|
||||||
|
{
|
||||||
|
auto transform = m_World->GetComponent<Components::Transform>(entity, "Transform");
|
||||||
|
auto parentTransform = m_World->GetComponent<Components::Transform>(parent, "Transform");
|
||||||
|
|
||||||
|
transform->Position[0] += parentTransform->Position[0];
|
||||||
|
transform->Position[1] += parentTransform->Position[1];
|
||||||
|
transform->Position[2] += parentTransform->Position[2];
|
||||||
|
}
|
||||||
|
LOG_INFO("Updating entity %i with parent %i", entity, parent);
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
#ifndef CollisionSystem_h__
|
||||||
|
#define CollisionSystem_h__
|
||||||
|
|
||||||
|
#include "System.h"
|
||||||
|
#include "logging.h"
|
||||||
|
|
||||||
|
#include "Components/Transform.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace Systems
|
||||||
|
{
|
||||||
|
|
||||||
|
class Collision : public System
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Collision(World* world) : System(world) { }
|
||||||
|
|
||||||
|
void Update(double dt, EntityID entity, EntityID parent) override;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // CollisionSystem_h__
|
||||||
|
|||||||
@@ -0,0 +1,87 @@
|
|||||||
|
#include "World.h"
|
||||||
|
|
||||||
|
void World::RecycleEntityID(EntityID id)
|
||||||
|
{
|
||||||
|
m_RecycledEntityIDs.push(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
EntityID World::GenerateEntityID()
|
||||||
|
{
|
||||||
|
if (!m_RecycledEntityIDs.empty()) {
|
||||||
|
EntityID id = m_RecycledEntityIDs.top();
|
||||||
|
m_RecycledEntityIDs.pop();
|
||||||
|
return id;
|
||||||
|
} else {
|
||||||
|
return ++m_LastEntityID;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void World::RecursiveUpdate(std::shared_ptr<System> system, double dt, EntityID parentEntity)
|
||||||
|
{
|
||||||
|
for (auto pair : m_EntityParents) {
|
||||||
|
EntityID child = pair.first;
|
||||||
|
EntityID parent = pair.second;
|
||||||
|
|
||||||
|
if (parent == parentEntity) {
|
||||||
|
system->Update(dt, child, parent);
|
||||||
|
RecursiveUpdate(system, dt, child);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void World::Update(double dt)
|
||||||
|
{
|
||||||
|
for (auto system : m_Systems) {
|
||||||
|
RecursiveUpdate(system, dt, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void World::AddSystem(System* system)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//std::vector<EntityID> GetEntityChildren(EntityID entity);
|
||||||
|
//{
|
||||||
|
// std::vector<EntityID> children;
|
||||||
|
// auto range = m_SceneGraph.equal_range(entity);
|
||||||
|
// for (auto it = range.first; it != range.second; ++it)
|
||||||
|
// children.push_back(it->second);
|
||||||
|
// return children;
|
||||||
|
//}
|
||||||
|
|
||||||
|
EntityID World::GetEntityParent(EntityID entity)
|
||||||
|
{
|
||||||
|
auto it = m_EntityParents.find(entity);
|
||||||
|
return it == m_EntityParents.end() ? 0 : it->second;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool World::ValidEntity(EntityID entity)
|
||||||
|
{
|
||||||
|
return m_EntityParents.find(entity) != m_EntityParents.end();
|
||||||
|
}
|
||||||
|
|
||||||
|
void World::RemoveEntity(EntityID entity)
|
||||||
|
{
|
||||||
|
m_EntityParents.erase(entity);
|
||||||
|
RecycleEntityID(entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
EntityID World::CreateEntity(EntityID parent /*= 0*/)
|
||||||
|
{
|
||||||
|
EntityID newEntity = GenerateEntityID();
|
||||||
|
m_EntityParents.insert(std::pair<EntityID, EntityID>(newEntity, parent));
|
||||||
|
return newEntity;
|
||||||
|
}
|
||||||
|
|
||||||
|
World::~World()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
World::World()
|
||||||
|
{
|
||||||
|
m_LastEntityID = 0;
|
||||||
|
|
||||||
|
m_Systems.push_back(std::make_shared<Systems::Collision>(this));
|
||||||
|
}
|
||||||
+31
-50
@@ -9,79 +9,60 @@
|
|||||||
#include "Entity.h"
|
#include "Entity.h"
|
||||||
#include "Component.h"
|
#include "Component.h"
|
||||||
#include "ComponentFactory.h"
|
#include "ComponentFactory.h"
|
||||||
//#include "Components/Transform.h"
|
#include "System.h"
|
||||||
|
#include "Systems/CollisionSystem.h"
|
||||||
|
|
||||||
class World
|
class World
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
World()
|
World();
|
||||||
{
|
~World();
|
||||||
m_LastEntityID = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
EntityID CreateEntity(EntityID parent = 0)
|
EntityID CreateEntity(EntityID parent = 0);
|
||||||
{
|
|
||||||
EntityID newEntity = GenerateEntityID();
|
|
||||||
m_SceneGraph.insert(std::pair<EntityID, EntityID>(newEntity, parent));
|
|
||||||
return newEntity;
|
|
||||||
}
|
|
||||||
|
|
||||||
void RemoveEntity(EntityID entity)
|
void RemoveEntity(EntityID entity);
|
||||||
{
|
|
||||||
m_SceneGraph.erase(entity);
|
|
||||||
RecycleEntityID(entity);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ValidEntity(EntityID entity)
|
bool ValidEntity(EntityID entity);
|
||||||
{
|
|
||||||
return m_SceneGraph.find(entity) != m_SceneGraph.end();
|
|
||||||
}
|
|
||||||
|
|
||||||
EntityID GetEntityParent(EntityID entity)
|
EntityID GetEntityParent(EntityID entity);
|
||||||
{
|
|
||||||
auto it = m_SceneGraph.find(entity);
|
|
||||||
return it == m_SceneGraph.end() ? 0 : it->second;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::shared_ptr<Component> AddComponent(EntityID entity, std::string componentType)
|
template <class T>
|
||||||
|
std::shared_ptr<T> AddComponent(EntityID entity, std::string componentType)
|
||||||
{
|
{
|
||||||
std::shared_ptr<Component> component = ComponentFactory::Instance()->Create(componentType);
|
std::shared_ptr<T> component = std::static_pointer_cast<T>(ComponentFactory::Instance()->Create(componentType));
|
||||||
m_ComponentsOfType[componentType].push_back(component);
|
m_ComponentsOfType[componentType].push_back(component);
|
||||||
m_EntityComponents[entity][componentType] = component;
|
m_EntityComponents[entity][componentType] = component;
|
||||||
|
return component;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*std::vector<EntityID> GetEntityChildren(EntityID entity)
|
template <class T>
|
||||||
|
std::shared_ptr<T> GetComponent(EntityID entity, std::string componentType)
|
||||||
{
|
{
|
||||||
std::vector<EntityID> children;
|
return std::static_pointer_cast<T>(m_EntityComponents[entity][componentType]);
|
||||||
auto range = m_SceneGraph.equal_range(entity);
|
}
|
||||||
for (auto it = range.first; it != range.second; ++it)
|
|
||||||
children.push_back(it->second);
|
/*std::vector<EntityID> GetEntityChildren(EntityID entity);*/
|
||||||
return children;
|
|
||||||
}*/
|
void AddSystem(System* system);
|
||||||
|
|
||||||
|
// Recursively update through the scene graph
|
||||||
|
void Update(double dt);
|
||||||
|
|
||||||
|
void RecursiveUpdate(std::shared_ptr<System> system, double dt, EntityID parentEntity);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
EntityID m_LastEntityID;
|
EntityID m_LastEntityID;
|
||||||
std::stack<EntityID> m_RecycledEntityIDs;
|
std::stack<EntityID> m_RecycledEntityIDs;
|
||||||
// A map of child entities to parent entities
|
// A bottom to top tree. A map of child entities to parent entities.
|
||||||
std::unordered_map<EntityID, EntityID> m_SceneGraph;
|
std::unordered_map<EntityID, EntityID> m_EntityParents;
|
||||||
|
|
||||||
std::unordered_map<std::string, std::vector<std::shared_ptr<Component>>> m_ComponentsOfType;
|
std::unordered_map<std::string, std::vector<std::shared_ptr<Component>>> m_ComponentsOfType;
|
||||||
std::unordered_map<EntityID, std::map<std::string, std::shared_ptr<Component>>> m_EntityComponents;
|
std::unordered_map<EntityID, std::map<std::string, std::shared_ptr<Component>>> m_EntityComponents;
|
||||||
|
std::vector<std::shared_ptr<System>> m_Systems;
|
||||||
|
|
||||||
EntityID GenerateEntityID()
|
EntityID GenerateEntityID();
|
||||||
{
|
|
||||||
if (!m_RecycledEntityIDs.empty()) {
|
|
||||||
EntityID id = m_RecycledEntityIDs.top();
|
|
||||||
m_RecycledEntityIDs.pop();
|
|
||||||
return id;
|
|
||||||
} else {
|
|
||||||
return ++m_LastEntityID;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void RecycleEntityID(EntityID id)
|
void RecycleEntityID(EntityID id);
|
||||||
{
|
|
||||||
m_RecycledEntityIDs.push(id);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // World_h__
|
#endif // World_h__
|
||||||
@@ -49,7 +49,7 @@ static void _LOG(_LOG_LEVEL logLevel, char* file, char* func, unsigned int line,
|
|||||||
char message[512];
|
char message[512];
|
||||||
va_list args;
|
va_list args;
|
||||||
va_start(args, format);
|
va_start(args, format);
|
||||||
vsnprintf(message, 512, format, args);
|
vsnprintf_s(message, 512, format, args);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
|
|
||||||
if (logLevel == LOG_LEVEL_ERROR)
|
if (logLevel == LOG_LEVEL_ERROR)
|
||||||
|
|||||||
@@ -9,6 +9,8 @@
|
|||||||
#include "logging.h"
|
#include "logging.h"
|
||||||
#include "glerror.h"
|
#include "glerror.h"
|
||||||
|
|
||||||
|
#include "World.h"
|
||||||
|
|
||||||
GLFWwindow* window;
|
GLFWwindow* window;
|
||||||
GLint glVersion[2];
|
GLint glVersion[2];
|
||||||
GLchar* glVendor;
|
GLchar* glVendor;
|
||||||
|
|||||||
@@ -80,6 +80,16 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="main.cpp" />
|
<ClCompile Include="main.cpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\Escape-the-Dawn\Escape-the-Dawn.vcxproj">
|
||||||
|
<Project>{fe405cfa-8fce-4867-92cf-797e73b36482}</Project>
|
||||||
|
<Private>true</Private>
|
||||||
|
<ReferenceOutputAssembly>true</ReferenceOutputAssembly>
|
||||||
|
<CopyLocalSatelliteAssemblies>false</CopyLocalSatelliteAssemblies>
|
||||||
|
<LinkLibraryDependencies>true</LinkLibraryDependencies>
|
||||||
|
<UseLibraryDependencyInputs>false</UseLibraryDependencyInputs>
|
||||||
|
</ProjectReference>
|
||||||
|
</ItemGroup>
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
<ImportGroup Label="ExtensionTargets">
|
<ImportGroup Label="ExtensionTargets">
|
||||||
</ImportGroup>
|
</ImportGroup>
|
||||||
|
|||||||
@@ -20,6 +20,27 @@ BOOST_AUTO_TEST_CASE(Parenting)
|
|||||||
BOOST_CHECK(world.GetEntityParent(ent2) == ent1);
|
BOOST_CHECK(world.GetEntityParent(ent2) == ent1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(SceneGraphTraversal)
|
||||||
|
{
|
||||||
|
World world;
|
||||||
|
|
||||||
|
EntityID ent1 = world.CreateEntity();
|
||||||
|
auto t1 = world.AddComponent<Components::Transform>(ent1, "Transform");
|
||||||
|
t1->Position[0] = 1.0f;
|
||||||
|
t1->Position[1] = 1.0f;
|
||||||
|
t1->Position[2] = 1.0f;
|
||||||
|
EntityID ent2 = world.CreateEntity(ent1);
|
||||||
|
auto t2 = world.AddComponent<Components::Transform>(ent2, "Transform");
|
||||||
|
t2->Position[0] = 1.0f;
|
||||||
|
t2->Position[1] = 1.0f;
|
||||||
|
t2->Position[2] = 1.0f;
|
||||||
|
|
||||||
|
world.Update(0.0);
|
||||||
|
|
||||||
|
LOG_INFO("ent1: %f %f %f", t1->Position[0], t1->Position[1], t1->Position[2]);
|
||||||
|
LOG_INFO("ent2: %f %f %f", t2->Position[0], t2->Position[1], t2->Position[2]);
|
||||||
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(Recycling)
|
BOOST_AUTO_TEST_CASE(Recycling)
|
||||||
{
|
{
|
||||||
World world;
|
World world;
|
||||||
|
|||||||
Reference in New Issue
Block a user