|
Engine
Raylib based game framework
|
Wraps entt::registry with a safer, callback-aware API. More...
#include <Registry.hpp>
Public Member Functions | |
| Entity | CreateEntity () |
| Creates a new entity. | |
| void | DestroyEntity (const Entity entity) |
| Destroys an entity if it is valid. | |
| bool | EntityValid (const Entity entity) |
| Checks whether an entity is alive in the registry. | |
| template<typename Component, typename... Args> | |
| const Component * | Emplace (const Entity entity, Args &&... args) |
| Adds a component to an entity. | |
| template<typename Component, typename... Args> | |
| const Component & | EmplaceOrReplace (const Entity entity, Args &&... args) |
| Adds or replaces a component on an entity. | |
| template<typename Component> | |
| bool | Patch (const Entity entity, const std::function< void(Component &)> &func) |
| Applies a function to an existing component in place. | |
| template<typename Component> | |
| const Component * | Get (const Entity entity) |
| Gets a pointer to a component on an entity. | |
| template<typename... Components> | |
| bool | HasAny (const Entity entity) |
| Checks whether an entity has at least one of the given components. | |
| template<typename... Components> | |
| bool | HasAll (const Entity entity) |
| Checks whether an entity has all of the given components. | |
| template<typename Component, typename... Args> | |
| const Component * | Replace (const Entity entity, Args &&... args) |
| Replaces an existing component on an entity. | |
| template<typename Component> | |
| void | Remove (const Entity entity) |
| Removes a component from an entity. | |
| template<typename Component> | |
| void | ClearComponents () |
| Removes all instances of a component type from every entity. | |
| template<typename... Components> | |
| auto | GetView () |
| Returns a view over all entities that have the given components. | |
| template<typename... Owned, typename... Get, typename... Exclude> | |
| auto | GetGroup (entt::get_t< Get... > get=entt::get_t{}, entt::exclude_t< Exclude... > exclude=entt::exclude_t{}) |
| Returns a group over entities with the specified owned and non-owned components. | |
| template<typename Component> | |
| void | Sort (const std::function< bool(const Component &a, const Component &b)> &comparitor) |
| Sorts a component pool using a comparator. | |
| template<typename... Owned, typename... Get, typename... Exclude> | |
| void | SortGroup (const std::function< bool(const Entity &a, const Entity &b)> &comparitor, entt::get_t< Get... > get=entt::get_t{}, entt::exclude_t< Exclude... > exclude=entt::exclude_t{}) |
| Sorts a group's entities using an entity comparator. | |
| template<typename Component> | |
| u32 | OnConstruct (const std::function< void(Component &component, const Entity entity)> &callback) |
| Registers a callback invoked when a component of the given type is constructed. | |
| template<typename Component> | |
| u32 | OnUpdate (const std::function< void(Component &component, const Entity entity)> &callback) |
| Registers a callback invoked when a component of the given type is updated. | |
| template<typename Component> | |
| u32 | OnDestroy (const std::function< void(Component &component, const Entity entity)> &callback) |
| Registers a callback invoked just before a component of the given type is destroyed. | |
| template<typename Component> | |
| void | RemoveConstructCallback (const u32 callbackId) |
| Removes a previously registered construction callback. | |
| template<typename Component> | |
| void | RemoveUpdateCallback (const u32 callbackId) |
| Removes a previously registered update callback. | |
| template<typename Component> | |
| void | RemoveDestroyCallback (const u32 callbackId) |
| Removes a previously registered destruction callback. | |
| entt::registry & | GetRegistry () |
| Returns a reference to the underlying entt registry. | |
Wraps entt::registry with a safer, callback-aware API.
Provides typed component operations and supports registering callbacks for component construction, update, and destruction events. All callbacks are identified by a u32 ID so they can be individually removed.
|
inline |
Removes all instances of a component type from every entity.
| Component | Component type to clear |
| Entity Registry::CreateEntity | ( | ) |
Creates a new entity.
| void Registry::DestroyEntity | ( | const Entity | entity | ) |
Destroys an entity if it is valid.
Does nothing if the entity is not valid.
| entity | Entity to destroy |
|
inline |
Adds a component to an entity.
Does nothing and returns nullptr if the entity already has this component.
| Component | Component type to add |
| Args | Component constructor argument types |
| entity | Target entity |
| args | Component constructor arguments |
|
inline |
Adds or replaces a component on an entity.
If the component already exists it is replaced in place; otherwise it is created.
| Component | Component type |
| Args | Component constructor argument types |
| entity | Target entity |
| args | Component constructor arguments |
| bool Registry::EntityValid | ( | const Entity | entity | ) |
Checks whether an entity is alive in the registry.
| entity | Entity to check |
|
inline |
Gets a pointer to a component on an entity.
| Component | Component type |
| entity | Target entity |
|
inline |
Returns a group over entities with the specified owned and non-owned components.
Owned components are stored contiguously for cache-friendly iteration. Non-owned components are fetched via Get. Excluded components filter entities out.
| Owned | Component types owned (and sorted) by the group |
| Get | Additional component types to fetch but not own |
| Exclude | Component types that disqualify an entity from the group |
| get | entt::get_t list of non-owned components to include |
| exclude | entt::exclude_t list of components to exclude |
| entt::registry & Registry::GetRegistry | ( | ) |
Returns a reference to the underlying entt registry.
Prefer the typed API above. This escape hatch exists for interop with entt APIs not yet wrapped by Registry.
|
inline |
Returns a view over all entities that have the given components.
Components are exposed as const references inside the view.
| Components | Component types to include in the view |
|
inline |
Checks whether an entity has all of the given components.
| Components | Component types to check |
| entity | Target entity |
|
inline |
Checks whether an entity has at least one of the given components.
| Components | Component types to check |
| entity | Target entity |
|
inline |
Registers a callback invoked when a component of the given type is constructed.
Multiple callbacks can be registered for the same component type. The returned ID can be used with RemoveConstructCallback to unregister.
| Component | Component type to observe |
| callback | Function receiving the new component and the owning entity |
|
inline |
Registers a callback invoked just before a component of the given type is destroyed.
Multiple callbacks can be registered for the same component type. The returned ID can be used with RemoveDestroyCallback.
| Component | Component type to observe |
| callback | Function receiving the component about to be destroyed and its entity |
|
inline |
Registers a callback invoked when a component of the given type is updated.
Triggered by Patch and Replace. Multiple callbacks can be registered for the same component type. The returned ID can be used with RemoveUpdateCallback.
| Component | Component type to observe |
| callback | Function receiving the updated component and the owning entity |
|
inline |
Applies a function to an existing component in place.
Triggers update callbacks. Does nothing and returns false if the entity does not have the component.
| Component | Component type |
| entity | Target entity |
| func | Function to apply to the component |
|
inline |
Removes a component from an entity.
Does nothing if the entity does not have the component.
| Component | Component type to remove |
| entity | Target entity |
|
inline |
Removes a previously registered construction callback.
Disconnects the underlying signal if no more callbacks remain for this type.
| Component | Component type the callback was registered for |
| callbackId | ID returned by OnConstruct |
|
inline |
Removes a previously registered destruction callback.
Disconnects the underlying signal if no more callbacks remain for this type.
| Component | Component type the callback was registered for |
| callbackId | ID returned by OnDestroy |
|
inline |
Removes a previously registered update callback.
Disconnects the underlying signal if no more callbacks remain for this type.
| Component | Component type the callback was registered for |
| callbackId | ID returned by OnUpdate |
|
inline |
Replaces an existing component on an entity.
Does nothing and returns nullptr if the entity does not have the component.
| Component | Component type |
| Args | Component constructor argument types |
| entity | Target entity |
| args | Component constructor arguments |
|
inline |
Sorts a component pool using a comparator.
The sort order affects the iteration order of views over this component.
| Component | Component type whose pool is sorted |
| comparitor | Comparator receiving two const component references |
|
inline |
Sorts a group's entities using an entity comparator.
Affects the iteration order of the group. The group is identified by the same owned/get/exclude template parameters used to create it.
| Owned | Owned component types of the group |
| Get | Non-owned component types of the group |
| Exclude | Excluded component types of the group |
| comparitor | Comparator receiving two entity references |
| get | entt::get_t matching the group's get list |
| exclude | entt::exclude_t matching the group's exclude list |