|
co_ecs 0.9.0
Cobalt ECS
|
Represents a reference to an entity within a registry. More...
#include <entity_ref.hpp>
Public Member Functions | |
| constexpr | entity_ref (base_registry ®istry, entity entity) noexcept |
| Constructs an entity reference for a specific entity in the given registry. | |
| constexpr auto | archetype () const noexcept -> const archetype & |
| Retrieves a constant reference to the archetype of the entity. | |
| constexpr auto | alive () const noexcept -> bool |
| Checks if the entity is currently active in the registry. | |
| template<component... C> | |
| constexpr auto | has () const noexcept -> bool |
| Determines if the entity has all specified components. | |
| template<component C> | |
| constexpr auto | get () -> C & |
| Retrieves a component of type C from the entity. | |
| template<component C> | |
| constexpr auto | get () const -> const C & |
| Retrieves a const-qualified component of type C from the entity in a read-only manner. | |
| template<component C, component O, component... Args> | |
| constexpr auto | get () -> decltype(auto) |
| Retrieves multiple components from the underlying registry for the current entity. | |
| template<component C, component O, component... Args> | |
| constexpr auto | get () const -> decltype(auto) |
| Retrieves multiple components from the underlying registry for the current entity (const version). | |
| template<component C> | |
| constexpr auto | get_or_insert (auto &&... args) -> C & |
| Get reference to component C, or insert it with provided arguments if not present. | |
| template<component C, typename... Args> | |
| constexpr auto | set (Args &&... args) -> entity_ref |
| Set component to an entity. It can either override a component value that is already assigned to an entity or it may construct a new once and assign to it. | |
| template<component C> | |
| constexpr auto | remove () -> entity_ref |
| Remove component C from an entity. In case entity does not have component attached nothing is done and this method returns. | |
| void | destroy () |
| Destroys the current entity. | |
| constexpr auto | visit (auto &&func) |
| Visit all components of an entity and apply a function to them. | |
| constexpr auto | visit (auto &&func) const |
| Visit all components of an entity and apply a function to them (const version). | |
| auto | clone () const -> entity_ref |
| Creates a duplicate of the current entity. | |
| auto | clone (placeholder_entity placeholder) |
| Clones the current entity to a placeholder entity. | |
| auto | copy (base_registry &destination) const -> entity_ref |
| Copies the current entity to another registry. | |
| auto | copy (base_registry &destination, placeholder_entity placeholder) const |
| Copies the current entity to another registry into a placeholder entity. | |
| auto | move (base_registry &destination) -> entity_ref |
| Moves the current entity to another registry. | |
| auto | move (base_registry &destination, placeholder_entity placeholder) |
| Moves the current entity to another registry into a placeholder entity. | |
| constexpr | operator entity () const noexcept |
Converts this entity_ref to its underlying entity. | |
| constexpr | operator bool () const noexcept |
| Checks if the underlying entity is valid. | |
Represents a reference to an entity within a registry.
This class provides an interface to interact with a specific entity managed by a given registry. It encapsulates the entity and the registry it belongs to, allowing for operations such as querying, modifying, or checking the status of the entity in a safe and convenient manner. This reference facilitates access to various functionalities provided by the registry concerning the specific entity.
|
inlineconstexprnoexcept |
Constructs an entity reference for a specific entity in the given registry.
This constructor initializes an entity_ref object that links an entity to its managing registry. It allows for subsequent operations on the entity through methods provided by this class.
| registry | Reference to the base_registry that manages the entity. |
| entity | The entity that this reference will encapsulate. |
|
inlineconstexprnoexcept |
Checks if the entity is currently active in the registry.
This method queries the registry to determine if the entity is still active and has not been destroyed. It is particularly useful for validity checks before performing operations on the entity.
|
inlineconstexprnoexcept |
Retrieves a constant reference to the archetype of the entity.
This method returns a reference to the archetype associated with the encapsulated entity. An archetype defines the configuration of components that an entity possesses in the entity-component system. Accessing the archetype can be useful for inspecting the structure and component makeup of the entity.
|
inline |
Creates a duplicate of the current entity.
This method is used to clone the current entity, creating an exact copy with the same components and states, but under a new entity identifier.
| std::invalid_argument | when copy constructor does not exist for one of components. Entity is left in an undefined state if this occurs. |
|
inline |
Clones the current entity to a placeholder entity.
This method clones the current entity, creating a copy in a new placeholder entity within the same registry.
| placeholder | The placeholder entity to clone into. |
|
inline |
Copies the current entity to another registry.
This method copies the current entity to a specified destination registry, creating a new entity in the destination registry.
| destination | The destination registry where the entity will be copied. |
|
inline |
Copies the current entity to another registry into a placeholder entity.
This method copies the current entity to a specified destination registry, creating a new entity in the destination registry and associating it with a placeholder entity.
| destination | The destination registry where the entity will be copied. |
| placeholder | The placeholder entity in the destination registry. |
|
inline |
Destroys the current entity.
This method is responsible for removing the entity from the registry.
|
inlineconstexpr |
Retrieves a component of type C from the entity.
This method template is designed to access a specific component from the entity managed by the registry. It provides direct access to a component, assuming that the entity contains it. If the entity does not have the requested component, it throws a component_not_found exception.
| C | The type of component to retrieve, specified as a non-const reference. |
| component_not_found | If the requested component C is not found in the entity. |
|
inlineconstexpr |
Retrieves multiple components from the underlying registry for the current entity.
This method allows accessing multiple components associated with the current entity from the underlying registry.
| C | The first component type to retrieve. |
| O | The second component type to retrieve. |
| Args | Additional component types to retrieve. |
|
inlineconstexpr |
Retrieves a const-qualified component of type C from the entity in a read-only manner.
This const method template is designed for read-only access to a specific component from the entity managed by the registry. It is used when the entity is expected to contain the component and modifications are not intended. If the requested component is not present, it throws a component_not_found exception.
| C | The type of the component to retrieve, specified as a const-qualified reference. |
| component_not_found | If the requested component C is not found in the entity. |
|
inlineconstexpr |
Retrieves multiple components from the underlying registry for the current entity (const version).
This method allows accessing multiple components associated with the current entity from the underlying registry in a const context.
| C | The first component type to retrieve. |
| O | The second component type to retrieve. |
| Args | Additional component types to retrieve. |
|
inlineconstexpr |
Get reference to component C, or insert it with provided arguments if not present.
This function tries to access a component of type C associated with the specified entity. If the component does not exist, it is inserted by forwarding the provided arguments to the constructor of C. This ensures that the component is initialized according to the arguments passed. After insertion, the entity's archetype is updated to include this new component type, and all related entity locations are adjusted accordingly to reflect changes in the archetype structure.
| C | Component type which must be constructible with the provided arguments. |
| args | Arguments to forward to the constructor of C if component C needs to be created. |
|
inlineconstexprnoexcept |
Determines if the entity has all specified components.
This template method checks whether the entity has each of the components listed in the template arguments. This can be useful for conditional logic where actions depend on the presence of specific components in an entity. For example, an operation that should only be performed if an entity has both a position and velocity component.
| C | The component types to check for. |
|
inline |
Moves the current entity to another registry.
This method moves the current entity to a specified destination registry, transferring ownership and creating a new entity in the destination registry.
| destination | The destination registry where the entity will be moved. |
|
inline |
Moves the current entity to another registry into a placeholder entity.
This method moves the current entity to a specified destination registry, transferring ownership and associating it with a placeholder entity in the destination registry.
| destination | The destination registry where the entity will be moved. |
| placeholder | The placeholder entity in the destination registry. |
|
inlineconstexprnoexcept |
Checks if the underlying entity is valid.
This conversion operator allows the entity_ref to be used in boolean contexts to check if the underlying entity is valid (i.e., has valid (id, generation) but may not be alive).
|
inlineconstexprnoexcept |
Converts this entity_ref to its underlying entity.
This conversion operator allows entity_ref to be treated as its underlying entity type directly. Useful in contexts where the entity's identifier is needed without explicit method calls.
entity_ref.
|
inlineconstexpr |
Remove component C from an entity. In case entity does not have component attached nothing is done and this method returns.
| C | Component type |
|
inlineconstexpr |
Set component to an entity. It can either override a component value that is already assigned to an entity or it may construct a new once and assign to it.
| C | Component type |
| Args | Parameter pack, argument types to construct C from |
| args | Arguments to construct C from |
|
inlineconstexpr |
Visit all components of an entity and apply a function to them.
This function visits all components associated with an entity in the registry and applies the provided function to each component.
| func | A callable object (function, lambda, etc.) that will be applied to each component. |
|
inlineconstexpr |
Visit all components of an entity and apply a function to them (const version).
This function visits all components associated with an entity in the registry and applies the provided function to each component. This version is const and can be used in const contexts.
| func | A callable object (function, lambda, etc.) that will be applied to each component. |