|
| | Registry ()=default |
| |
| | Registry (const Registry &)=delete |
| |
| Registry & | operator= (const Registry &)=delete |
| |
| | Registry (Registry &&) noexcept=default |
| |
| Registry & | operator= (Registry &&) noexcept=default |
| |
| | ~Registry ()=default |
| |
| Entity | create () |
| | Creates an entity without components.
|
| |
| bool | destroy (Entity entity) |
| | Destroys an entity and removes all its components.
|
| |
| bool | alive (Entity entity) const noexcept |
| | Tells whether a handle designates a living entity.
|
| |
| std::size_t | size () const noexcept |
| | Number of living entities.
|
| |
| void | clear () |
| | Destroys every entity and removes every component.
|
| |
| template<typename Component , typename... Args> |
| Component & | emplace (Entity entity, Args &&... args) |
| | Gives an entity a component built in place.
|
| |
| template<typename Component , typename... Args> |
| Component & | emplace_or_replace (Entity entity, Args &&... args) |
| | Gives an entity a component, or replaces the one it has.
|
| |
| template<typename Component > |
| bool | remove (Entity entity) |
| | Removes a component from an entity.
|
| |
template<typename... Components>
requires (sizeof...(Components) > 0) |
| bool | has (Entity entity) const |
| | Tells whether an entity has every listed component.
|
| |
| template<typename Component > |
| Component & | get (Entity entity) |
| | Component of an entity.
|
| |
| template<typename Component > |
| const Component & | get (Entity entity) const |
| | Component of an entity.
|
| |
| template<typename Component > |
| std::optional< std::reference_wrapper< Component > > | try_get (Entity entity) |
| | Component of an entity, if it has one.
|
| |
| template<typename Component > |
| std::optional< std::reference_wrapper< const Component > > | try_get (Entity entity) const |
| | Component of an entity, if it has one.
|
| |
| template<typename Component > |
| std::size_t | count () const |
| | Number of entities that have a component.
|
| |
| template<typename Component > |
| SparseSet< Component > & | pool () |
| | Pool of a component type, created empty on first use.
|
| |
| template<typename Component > |
| std::optional< std::reference_wrapper< SparseSet< Component > > > | find_pool () |
| | Pool of a component type, if it was ever used.
|
| |
| template<typename Component > |
| std::optional< std::reference_wrapper< const SparseSet< Component > > > | find_pool () const |
| | Pool of a component type, if it was ever used.
|
| |
| template<typename... Components> |
| View< Components... > | view () |
| | View on the entities that own all the listed components.
|
| |
Entry point of the ECS: creates entities and stores their components.
The registry owns an EntityAllocator and one SparseSet per component type, created the first time the type is used. Destroying an entity removes all its components, whatever their types, then recycles its index with a new generation: a handle kept after destroy() is stale, alive() rejects it and it reaches no component.
Any movable type with a noexcept move assignment can be a component, usually a plain struct: registry.emplace<Velocity>(player, Vec2{120.0F, 0.0F});.
References and spans returned by the registry or its pools are invalidated when a component of the same type is added or removed, as with std::vector. Not thread-safe: use the registry from the game thread only.
template<typename... Components>
| View< Components... > aegis2d::ecs::Registry::view |
( |
| ) |
|
|
inline |
View on the entities that own all the listed components.
Creates the pools that do not exist yet, so the view stays valid when the first components of a type are added later. Typical system: registry.view<Transform, Velocity>().each([dt](Transform& t, const Velocity& v) { t.position += v.value * dt; });
- Template Parameters
-
| Components | Component types, at least one, all different. |
- Returns
- A view that refers to the registry's pools; it must not outlive the registry.