Revert "Indentation style changed to Horstmann"
This reverts commit f2259f712d.
Conflicts:
src/GameWorld.cpp
src/Systems/PhysicsSystem.cpp
This commit is contained in:
+50
-25
@@ -2,35 +2,44 @@
|
||||
#include "World.h"
|
||||
|
||||
void World::RecycleEntityID(EntityID id)
|
||||
{ m_RecycledEntityIDs.push(id);
|
||||
{
|
||||
m_RecycledEntityIDs.push(id);
|
||||
}
|
||||
|
||||
EntityID World::GenerateEntityID()
|
||||
{ if (!m_RecycledEntityIDs.empty())
|
||||
{ EntityID id = m_RecycledEntityIDs.top();
|
||||
{
|
||||
if (!m_RecycledEntityIDs.empty())
|
||||
{
|
||||
EntityID id = m_RecycledEntityIDs.top();
|
||||
m_RecycledEntityIDs.pop();
|
||||
return id;
|
||||
}
|
||||
else
|
||||
{ return ++m_LastEntityID;
|
||||
{
|
||||
return ++m_LastEntityID;
|
||||
}
|
||||
}
|
||||
|
||||
void World::RecursiveUpdate(std::shared_ptr<System> system, double dt, EntityID parentEntity)
|
||||
{ for (auto pair : m_EntityParents)
|
||||
{ EntityID child = pair.first;
|
||||
{
|
||||
for (auto pair : m_EntityParents)
|
||||
{
|
||||
EntityID child = pair.first;
|
||||
EntityID parent = pair.second;
|
||||
|
||||
if (parent == parentEntity)
|
||||
{ system->UpdateEntity(dt, child, parent);
|
||||
{
|
||||
system->UpdateEntity(dt, child, parent);
|
||||
RecursiveUpdate(system, dt, child);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void World::Update(double dt)
|
||||
{ for (auto pair : m_Systems)
|
||||
{ auto system = pair.second;
|
||||
{
|
||||
for (auto pair : m_Systems)
|
||||
{
|
||||
auto system = pair.second;
|
||||
system->Update(dt);
|
||||
RecursiveUpdate(system, dt, 0);
|
||||
}
|
||||
@@ -48,12 +57,14 @@ void World::Update(double dt)
|
||||
//}
|
||||
|
||||
EntityID World::GetEntityParent(EntityID entity)
|
||||
{ auto it = m_EntityParents.find(entity);
|
||||
{
|
||||
auto it = m_EntityParents.find(entity);
|
||||
return it == m_EntityParents.end() ? 0 : it->second;
|
||||
}
|
||||
|
||||
EntityID World::GetEntityBaseParent(EntityID entity)
|
||||
{ EntityID parent = GetEntityParent(entity);
|
||||
{
|
||||
EntityID parent = GetEntityParent(entity);
|
||||
if (parent == 0)
|
||||
return entity;
|
||||
else
|
||||
@@ -61,28 +72,36 @@ EntityID World::GetEntityBaseParent(EntityID entity)
|
||||
}
|
||||
|
||||
bool World::ValidEntity(EntityID entity)
|
||||
{ return m_EntityParents.find(entity) != m_EntityParents.end();
|
||||
{
|
||||
return m_EntityParents.find(entity) != m_EntityParents.end();
|
||||
}
|
||||
|
||||
void World::RemoveEntity(EntityID entity)
|
||||
{ m_EntitiesToRemove.push_back(entity);
|
||||
{
|
||||
m_EntitiesToRemove.push_back(entity);
|
||||
for (auto pair : m_EntityParents)
|
||||
{ if (pair.second == entity)
|
||||
{ m_EntitiesToRemove.push_back(pair.first);
|
||||
{
|
||||
if (pair.second == entity)
|
||||
{
|
||||
m_EntitiesToRemove.push_back(pair.first);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void World::ProcessEntityRemovals()
|
||||
{ for (auto entity : m_EntitiesToRemove)
|
||||
{ m_EntityParents.erase(entity);
|
||||
{
|
||||
for (auto entity : m_EntitiesToRemove)
|
||||
{
|
||||
m_EntityParents.erase(entity);
|
||||
// Remove components
|
||||
for (auto pair : m_EntityComponents[entity])
|
||||
{ auto type = pair.first;
|
||||
{
|
||||
auto type = pair.first;
|
||||
auto component = pair.second;
|
||||
// Trigger events
|
||||
for (auto pair : m_Systems)
|
||||
{ auto system = pair.second;
|
||||
{
|
||||
auto system = pair.second;
|
||||
system->OnComponentRemoved(type, component.get());
|
||||
}
|
||||
m_ComponentsOfType[type].remove(component);
|
||||
@@ -95,7 +114,8 @@ void World::ProcessEntityRemovals()
|
||||
}
|
||||
|
||||
EntityID World::CreateEntity(EntityID parent /*= 0*/)
|
||||
{ EntityID newEntity = GenerateEntityID();
|
||||
{
|
||||
EntityID newEntity = GenerateEntityID();
|
||||
m_EntityParents.insert(std::pair<EntityID, EntityID>(newEntity, parent));
|
||||
return newEntity;
|
||||
}
|
||||
@@ -106,23 +126,28 @@ World::~World()
|
||||
}
|
||||
|
||||
World::World()
|
||||
{ m_LastEntityID = 0;
|
||||
{
|
||||
m_LastEntityID = 0;
|
||||
}
|
||||
|
||||
void World::Initialize()
|
||||
{ RegisterSystems();
|
||||
{
|
||||
RegisterSystems();
|
||||
AddSystems();
|
||||
for (auto system : m_Systems)
|
||||
{ system.second->Initialize();
|
||||
{
|
||||
system.second->Initialize();
|
||||
}
|
||||
|
||||
RegisterComponents();
|
||||
}
|
||||
|
||||
std::shared_ptr<Component> World::AddComponent(EntityID entity, std::string componentType)
|
||||
{ return AddComponent<Component>(entity, componentType);
|
||||
{
|
||||
return AddComponent<Component>(entity, componentType);
|
||||
}
|
||||
|
||||
void World::AddSystem(std::string systemType)
|
||||
{ m_Systems[systemType] = std::shared_ptr<System>(m_SystemFactory.Create(systemType));
|
||||
{
|
||||
m_Systems[systemType] = std::shared_ptr<System>(m_SystemFactory.Create(systemType));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user