ECSTASY
All in the name
Loading...
Searching...
No Matches
Entities.hpp
Go to the documentation of this file.
1
11
12#ifndef ECSTASY_RESOURCE_ENTITY_ENTITIES_HPP_
13#define ECSTASY_RESOURCE_ENTITY_ENTITIES_HPP_
14
15#include <span>
16#include <vector>
17
18#include "Entity.hpp"
20#include "util/BitSet.hpp"
21
22namespace ecstasy
23{
30 class Entities : public IResource {
31 public:
38 class Builder {
39 public:
48 Builder(const Builder &other) = delete;
49
67 template <IsStorage S, typename... Args>
68 Builder &with(S &storage, Args &&...args)
69 {
71 _entity.add(storage, std::forward<Args>(args)...);
72 return *this;
73 }
74
91 template <IsContainerStorage S>
93 {
95 _entity.add(storage, list);
96 return *this;
97 }
98
111 Entity build();
112
124 [[nodiscard]] const Entity &getEntity() const noexcept
125 {
126 return _entity;
127 }
128
129 private:
135 bool _built;
136
146 Builder(Entities &parent, Entity entity) noexcept;
147
156 void assertNotBuilt() const;
157
158 friend Entities;
159 };
160
165
172 Entities();
173
184 Entity create(bool alive = true);
185
194 [[nodiscard]] Builder builder();
195
206 [[nodiscard]] Entity get(Entity::Index id) const noexcept;
207
220 bool erase(Entity entity);
221
234 size_t erase(std::span<Entity> entities);
235
247 bool kill(Entity entity);
248
259 [[nodiscard]] bool isAlive(Entity entity) const;
260
269 [[nodiscard]] constexpr const util::BitSet &getMask() const noexcept
270 {
271 return _alive;
272 }
273
284 [[nodiscard]] Entity getQueryData(Entity::Index index) const;
285
298
299 private:
306 };
307} // namespace ecstasy
308
309#endif /* !ECSTASY_RESOURCE_ENTITY_ENTITIES_HPP_ */
Encapsulate an index to an entity.
Base class of all registry resources.
Entities builder to add multiple component to an entity on creation.
Definition Entities.hpp:38
void assertNotBuilt() const
Verify if the builder has not already been consumed.
Definition Entities.cpp:21
Builder(const Builder &other)=delete
Cannot copy a builder.
Entity _entity
Entity being built.
Definition Entities.hpp:133
Builder & with(S &storage, Args &&...args)
Add a component to the builder target entity.
Definition Entities.hpp:68
Builder & with(S &storage, std::initializer_list< typename S::Component::value_type > list)
Add a component to the builder target entity.
Definition Entities.hpp:92
Entities & _parent
Reference to the parent Entities.
Definition Entities.hpp:131
bool _built
Whether the builder has been consumed.
Definition Entities.hpp:135
Entity build()
Finalize the entity, making it alive.
Definition Entities.cpp:28
const Entity & getEntity() const noexcept
Get a const reference to the entity being built.
Definition Entities.hpp:124
Resource holding all the Registry entities.
Definition Entities.hpp:30
Entity getQueryData(Entity::Index index) const
Get the entity from its index.
Definition Entities.cpp:113
Builder builder()
Create a new entity builder.
Definition Entities.cpp:65
constexpr const util::BitSet & getMask() const noexcept
Get the Alive entities mask.
Definition Entities.hpp:269
bool kill(Entity entity)
Mark en entity for deletion.
Definition Entities.cpp:96
Entity QueryData
QueryableObject constraint
Definition Entities.hpp:162
util::BitSet _alive
Mask of alive entities.
Definition Entities.hpp:303
Entities()
Construct a new Entities resource without any entity.
Definition Entities.cpp:36
bool erase(Entity entity)
Erase (delete) the entity when called.
Definition Entities.cpp:77
bool isAlive(Entity entity) const
Tests if an entity is alive.
Definition Entities.cpp:108
util::BitSet _killed
Mask of entities marked for deletion.
Definition Entities.hpp:305
Entity get(Entity::Index id) const noexcept
Retrieve an entity from its identifier.
Definition Entities.cpp:70
std::vector< Entity > maintain()
Effectively erase the entities marked for deletion (using kill()).
Definition Entities.cpp:118
std::vector< Entity::Generation > _generations
List of entity generations.
Definition Entities.hpp:301
Entity create(bool alive=true)
Create a new entity, alive or not.
Definition Entities.cpp:43
Encapsulate an index to an entity.
Definition Entity.hpp:35
S::Component & add(S &storage, Args &&...args)
Add a component to the entity.
Definition Entity.hpp:111
size_t Index
The entity identifier type.
Definition Entity.hpp:38
Base class of all registry resources.
Definition IResource.hpp:33
Mimics the API of std::bitset but with the dynamic properties of std::vector<bool>
Definition BitSet.hpp:35
Concept to check if a type is a storage.
Namespace containing all symbols specific to ecstasy.
Definition ecstasy.hpp:30