9#include <unordered_map>
11namespace acheron::ecs {
26 bool operator==(
const SystemStage& other)
const noexcept {
27 return id == other.id;
68 auto typeName =
typeid(T).name();
69 static_assert(std::is_base_of<System, T>::value,
"Trying to register system that doesnt inherit System");
71 assert(
systems.find(typeName) ==
systems.end() &&
"Duplicate system registration");
73 auto system = std::make_shared<T>();
75 stageSystems[
nameToID[stage]].push_back(system);
88 auto typeName =
typeid(T).name();
90 assert(
systems.find(typeName) !=
systems.end() &&
"System used before registration");
129 void StageBefore(std::string name, std::string after);
137 void StageAfter(std::string name, std::string before);
152 std::unordered_map<std::string, SystemStageID>
nameToID;
153 std::unordered_map<SystemStageID, std::vector<SystemStageID>>
edges;
157 std::unordered_map<SystemStageID, std::vector<std::shared_ptr<System>>> stageSystems;
158 std::unordered_map<std::string, std::shared_ptr<System>>
systems;
161 SystemStageID counter;
163 bool per_entity =
true;
Manages systems and the stages associated with them.
Definition system.hpp:53
void StageAfter(std::string name, std::string before)
Creates a stage before another.
Definition system.cpp:64
std::unordered_map< std::string, SystemStageID > nameToID
Maps a stage name to its respective ID.
Definition system.hpp:152
SystemStageID GetStageOrFail(const std::string &name)
Gets a StageID by name.
Definition system.cpp:36
std::vector< SystemStage > stages
A list of registered stages.
Definition system.hpp:154
std::vector< SystemStageID > orderedStages
Stages put in order by PopulateStages.
Definition system.hpp:155
SystemStageID GetOrCreateStage(const std::string &name)
Gets a StageID by name, or creates one if it doesnt exist.
Definition system.cpp:45
std::unordered_map< SystemStageID, std::vector< SystemStageID > > edges
How a stage is associated with one another.
Definition system.hpp:153
std::unordered_map< std::string, Signature > signatures
A map of systems name and the signature associated with them.
Definition system.hpp:159
std::shared_ptr< T > RegisterSystem(std::string stage)
Registers a system.
Definition system.hpp:67
void PopulateStages()
Clears and populates ordereredStages.
Definition system.cpp:70
std::unordered_map< std::string, std::shared_ptr< System > > systems
A map of systems and their name.
Definition system.hpp:158
void EntityDespawned(Entity entity)
Called when an entity is despawned.
Definition system.cpp:10
void StageBefore(std::string name, std::string after)
Creates a stage before another.
Definition system.cpp:57
void SetSignature(Signature signature)
Sets a systems signature.
Definition system.hpp:87
void EntitySignatureChanged(Entity entity, Signature signature)
Updates the system signature based on the entities new signature.
Definition system.cpp:16
Systems called every frame based on entities.
Definition system.hpp:34
virtual void Update(World &world, double dt)
This function is overriden with the functionality of the System.
Definition system.hpp:47
std::unordered_set< Entity > entities
List of entities a system is matched with.
Definition system.hpp:39
Central context for the ECS.
Definition world.hpp:20
Size for the stage ID.
Definition system.hpp:22