Add Scene with systems

- Add Scene class which populates the engine with Systems which handles
  all logic in the game
- Add Systems to ecs
This commit is contained in:
Thraix
2023-05-20 19:45:15 +02:00
parent 05d2c2940b
commit 84b24457a0
20 changed files with 626 additions and 42 deletions
@@ -0,0 +1,59 @@
#include "copium/ecs/SystemPool.h"
namespace Copium
{
SystemPool::SystemPool(ECSManager* manager)
: manager{manager}
{}
SystemPool::~SystemPool()
{
for (auto& system : systemOrder)
{
delete system;
}
systemOrder.clear();
systems.clear();
}
SystemOrderer SystemPool::AddSystem(const std::type_index& systemId, SystemBase* system)
{
system->manager = manager;
systems.emplace(systemId, system);
systemOrder.emplace_back(system);
return SystemOrderer{systemId, this};
}
void SystemPool::Update()
{
for (auto& system : systemOrder)
{
system->Run();
}
}
void SystemPool::MoveSystemAfter(const std::type_index& systemId, const std::type_index& afterSystemId)
{
auto it1 = systems.find(systemId);
CP_ASSERT(it1 != systems.end(), "System does not exist in SystemPool");
auto it2 = systems.find(afterSystemId);
CP_ASSERT(it2 != systems.end(), "System does not exist in SystemPool");
auto itSystemId = std::find(systemOrder.rbegin(), systemOrder.rend(), it1->second);
auto itAfterSystemId = std::find(systemOrder.rbegin(), systemOrder.rend(), it2->second);
std::rotate(itSystemId, itSystemId + 1, itAfterSystemId);
}
void SystemPool::MoveSystemBefore(const std::type_index& systemId, const std::type_index& beforeSystemId)
{
auto it1 = systems.find(systemId);
CP_ASSERT(it1 != systems.end(), "System does not exist in SystemPool");
auto it2 = systems.find(beforeSystemId);
CP_ASSERT(it2 != systems.end(), "System does not exist in SystemPool");
auto itSystemId = std::find(systemOrder.rbegin(), systemOrder.rend(), it1->second);
auto itBeforeSystemId = std::find(systemOrder.rbegin(), systemOrder.rend(), it2->second);
std::rotate(itSystemId, itSystemId + 1, itBeforeSystemId + 1);
}
}