An accessor class that implements high-level access to an entity that has the given component.
More...
|
| template<typename T > |
| auto | mutate (T C::*ptr) |
| | Accesses an element from an existing Component.
|
| |
template<typename MutatorFunc , typename T >
requires (CInvocable<MutatorFunc, T&>) |
| decltype(auto) | mutate (MutatorFunc &&func, T C::*ptr) |
| | Accesses an element from an existing Component.
|
| |
| template<typename T1 , typename T2 , typename... Ts> |
| Tuple< ComponentFieldMutator< T1, C >, ComponentFieldMutator< T2, C >, ComponentFieldMutator< Ts, C >... > | mutate (T1 C::*ptr1, T2 C::*ptr2, Ts C::*... ptrs) |
| | TODO Write docs.
|
| |
| template<typename MutatorFunc , typename T1 , typename T2 , typename... Ts> |
| Tuple< ComponentFieldMutator< T1, C >, ComponentFieldMutator< T2, C >, ComponentFieldMutator< Ts, C >... > | mutate (MutatorFunc &&func, T1 C::*ptr1, T2 C::*ptr2, Ts C::*... ptr) |
| |
| template<typename T > |
| auto | get (T C::*ptr) |
| | Accesses an element from an existing Component.
|
| |
| template<typename T1 , typename T2 , typename... Ts> |
| Tuple< ComponentFieldMutator< T1, C >, ComponentFieldMutator< T2, C >, ComponentFieldMutator< Ts, C >... > | get (T1 C::*ptr1, T2 C::*ptr2, Ts C::*... ptrs) |
| | Accesses an element from an existing Component.
|
| |
| template<typename T > |
| const T & | read (const T C::*ptr) const |
| | Accesses an element from an existing Component.
|
| |
| template<typename T1 , typename T2 , typename... Ts> |
| Tuple< const T1 &, const T2 &, const Ts &... > | read (const T1 C::*ptr1, const T2 C::*ptr2, const Ts C::*... ptrs) const |
| | TODO Write docs.
|
| |
| template<typename T > |
| const T & | get (const T C::*ptr) const |
| | Accesses an element from an existing Component.
|
| |
| template<typename T1 , typename T2 , typename... Ts> |
| Tuple< const T1 &, const T2 &, const Ts &... > | get (const T1 C::*ptr1, const T2 C::*ptr2, const Ts C::*... ptrs) const |
| | Accesses an element from an existing Component.
|
| |
template<
typename T>
struct CeresEngine::Component< T >::Accessor
An accessor class that implements high-level access to an entity that has the given component.
All components are encouraged to offer a TC::Accessor implementation that derives from this class that allows higher-level access to an entity.
Implementations can use the read() and mutate() methods to access data in the component. The C type is a type-alias to the component class the accessor is implemented for.
- Use
read() to access a value from a component. You can give it one or more pointers-to-member of the component type C. Data will be retrieved from the component and returned to you by const-reference.
- Use
mutate() to change a value from a component. You can give it one or more pointers-to-member of the component type C. Data will be retrieved from the component and returned to you by reference. mutate() automatically marks the entity as dirty.
- Alternatively, you can use
get() that will automatically deduce either read() if this is const or mutate() if it is non-const.
To use a custom Accessor you must use EntityObject or some of it's sub-classes.
};
struct MyComponent::Accessor :
Component<MyComponent>::Accessor {
using Component<MyComponent>::Accessor::Accessor;
const String& getFullyQualifiedName()
const {
return read(&C::name); }
void setName(
String newName) {
if(newName.empty()) throw std::invalid_argument("newName");
if(newName == read(&C::name)) return;
mutate(&C::name) = std::move(newName);
}
};
EntityManager& entityManager = ...;
object->setName("Testing");
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25
An accessor class that implements high-level access to an entity that has the given component.
Definition Component.hpp:175
Components serve as the base for data storage for an entity.
Definition Component.hpp:68
- Template Parameters
-
| TC | The component implementation type. |