23#include "guillaume/ecs/system.hpp"
30 , _activeComponentRegistry(nullptr)
31 , _activeEntityRegistry(nullptr)
37 if (_activeEntityRegistry ==
nullptr) {
38 throw std::runtime_error(
39 "No active entity registry bound to system");
41 return *_activeEntityRegistry;
46 if (_activeEntityRegistry ==
nullptr) {
47 throw std::runtime_error(
48 "No active entity registry bound to system");
50 return *_activeEntityRegistry;
55 if (_activeComponentRegistry ==
nullptr) {
56 throw std::runtime_error(
57 "No active component registry bound to system");
59 return *_activeComponentRegistry;
64 if (_activeComponentRegistry ==
nullptr) {
65 throw std::runtime_error(
66 "No active component registry bound to system");
68 return *_activeComponentRegistry;
85 _activeComponentRegistry = &componentRegistry;
86 _activeEntityRegistry = &entityRegistry;
87 getLogger().debug() <<
"System routine started";
91 auto traversedEntities = traveler.
travel(entityRegistry);
93 for (
const auto &entity: traversedEntities) {
100 update(entity->getIdentifier());
105 getLogger().debug() <<
"System routine finished. Visited entities: "
106 << traversedEntities.size();
108 _activeComponentRegistry =
nullptr;
109 _activeEntityRegistry =
nullptr;
115 _activeComponentRegistry = &componentRegistry;
120 _activeComponentRegistry =
nullptr;
Stores every component of a scene, per component type and per entity identifier, and knows which ones...
Owns entities and gives the systems the list of entities to visit.
Decides in which order the entities of a scene are visited.
virtual std::vector< std::shared_ptr< Entity > > travel(EntityRegistry &entityRegistry) const =0
List every entity below a registry, in this traveler's order.
std::bitset< 128 > Signature
A set of component types, one bit per type (bit position given by ComponentTypeId,...
Phase getPhase(void) const noexcept
Get the phase of the frame in which the system runs.
virtual void cleanup(void)
Called once per pass, after the last update().
ecs::EntityRegistry & getEntityRegistry(void)
Get the entity registry of the scene being processed.
void unbindComponentRegistry(void)
Drop the binding made by bindComponentRegistry().
ecs::ComponentRegistry & getComponentRegistry(void)
Get the component registry of the scene being processed.
virtual void prepare(void)
Called once per pass, before the first update().
System(Phase phase)
Create a system that runs in a given phase, with an empty signature.
void routine(ecs::ComponentRegistry &componentRegistry, ecs::EntityRegistry &entityRegistry, const ecs::EntityTreeTraveler &traveler)
Run the system once over a scene: prepare(), update() on each matching entity, cleanup().
void bindComponentRegistry(ecs::ComponentRegistry &componentRegistry)
Bind a component registry so update() can be called directly, without routine().
Entity::Signature getSignature(void) const noexcept
Get the component types an entity must declare to be visited by this system.
virtual void update(const ecs::Entity::Identifier &entityIdentifier)=0
Apply the system's rule to one entity. Implemented by each system.
The entity-component-system core, independent of any widget.
Phase
The four steps of a frame. Every system belongs to one of them.