ECSTASY
All in the name
Loading...
Searching...
No Matches
Registry.cpp
Go to the documentation of this file.
1
11
12#include "Registry.hpp"
14
15namespace ecstasy
16{
18 : _registry(registry), _builder(registry.getResource<Entities>().get().builder())
19 {
20 }
21
23 {
24 return _builder.build();
25 }
26
27 Registry::Registry(bool addEntities) : _pipeline(*this)
28 {
29 if (addEntities)
30 addResource<Entities>();
31 }
32
34 {
35 return EntityBuilder(*this);
36 }
37
39 {
40 return getResource<const Entities>().get().get(index);
41 }
42
44 {
46 for (auto &storage : _storages.getInner())
47 if (storage.second->contains(entity.getIndex()))
48 storages.push_back(*storage.second);
49 return storages;
50 }
51
53 {
54 bool erased = getResource<Entities>().get().erase(entity);
55
56 if (!erased)
57 return false;
59 return true;
60 }
61
63 {
64 size_t erased = getResource<Entities>().get().erase(entities);
65
66 if (!erased)
67 return 0;
69 return erased;
70 }
71
73 {
74 for (auto &storage : _storages.getInner())
75 storage.second->erase(std::span{&entity, 1});
76 }
77
78 void Registry::eraseEntitiesComponents(std::span<Entity> entities)
79 {
80 for (auto &storage : _storages.getInner())
81 storage.second->erase(entities);
82 }
83
84 void Registry::runSystem(const std::type_index &systemId)
85 {
86 ISystem &system = _systems.get(systemId);
87
88 if (system.getTimer().trigger())
89 system.run(*this);
90 }
91
92 void Registry::runSystems()
93 {
94 _pipeline.run();
95 }
96
97 void Registry::runSystemsPhase(Pipeline::PhaseId phase)
98 {
99 _pipeline.run(phase);
100 }
101
102 void Registry::clear()
103 {
104 _resources.clear();
105 _storages.clear();
106 _systems.clear();
107 addResource<Entities>();
108 }
109
110} // namespace ecstasy
Definition of the Entities class.
Registry class definition.
Entity build()
Finalize the entity, making it alive.
Definition Entities.cpp:28
Resource holding all the Registry entities.
Definition Entities.hpp:30
Entity get(Entity::Index id) const noexcept
Retrieve an entity from its identifier.
Definition Entities.cpp:70
Encapsulate an index to an entity.
Definition Entity.hpp:35
constexpr Index getIndex() const noexcept
Get the entity identifier,.
Definition Entity.hpp:50
size_t Index
The entity identifier type.
Definition Entity.hpp:38
const S::Component & get(S &storage) const
Try to fetch the instance of component C associated to the current entity.
Definition Entity.hpp:178
System interface, base class of all systems.
Definition ISystem.hpp:28
Entity Builder using the registry storages.
Definition Registry.hpp:537
Entities::Builder _builder
Entities builder.
Definition Registry.hpp:643
EntityBuilder(const EntityBuilder &other)=delete
Copy constructor is deleted.
Entity build()
Finalize the entity, making it alive.
Definition Registry.cpp:22
Base of an ECS architecture.
Definition Registry.hpp:82
Instances< IStorage > _storages
Registry storages.
Entity getEntity(Entity::Index index)
Get the Entity at the index index.
Definition Registry.cpp:38
Registry(bool addEntities=true)
Construct a new Registry.
Definition Registry.cpp:27
EntityBuilder entityBuilder() noexcept
Create a new entity builder.
Definition Registry.cpp:33
std::vector< std::reference_wrapper< IStorage > > getEntityStorages(Entity entity)
Get the Entity Storages.
Definition Registry.cpp:43
void eraseEntitiesComponents(std::span< Entity > entities)
Definition Registry.cpp:78
void eraseEntityComponents(Entity entity)
Definition Registry.cpp:72
size_t eraseEntities(std::span< Entity > entities)
Instantly erase multiple entities and their components from the registry.
Definition Registry.cpp:62
bool eraseEntity(Entity entity)
Instantly erase an entity and its components from the registry.
Definition Registry.cpp:52
Pipeline _pipeline
System pipeline.
Namespace containing all symbols specific to ecstasy.
Definition ecstasy.hpp:30
T push_back(T... args)