ECSTASY
All in the name
Loading...
Searching...
No Matches
RegistryEntity.hpp
Go to the documentation of this file.
1
11
12#ifndef ECSTASY_RESOURCE_ENTITY_REGISTRYENTITY_HPP_
13#define ECSTASY_RESOURCE_ENTITY_REGISTRYENTITY_HPP_
14
15#include "Entity.hpp"
17
18namespace ecstasy
19{
26 class RegistryEntity : public Entity {
27 public:
34 constexpr RegistryEntity(Entity entity, Registry &registry) noexcept
35 : Entity(entity.getIndex(), entity.getGeneration()), _registry(registry)
36 {
37 }
38
54 template <typename C, typename... Args>
55 C &add(Args &&...args)
56 {
57 return Entity::add(_registry.getStorageSafe<C>(), std::forward<Args>(args)...);
58 }
59
73 template <typename C>
74 [[nodiscard]] const C &get() const
75 {
76 return _registry.getStorage<C>()[_index];
77 }
78
92 template <typename C>
93 [[nodiscard]] C &get()
94 {
95 return _registry.getStorage<C>()[_index];
96 }
97
108 template <typename C>
109 [[nodiscard]] bool has() const
110 {
111 return _registry.getStorageSafe<C>().contains(_index);
112 }
113
122 [[nodiscard]] constexpr Registry &getRegistry() noexcept
123 {
124 return _registry;
125 }
126
127 private:
130 };
131} // namespace ecstasy
132
133#endif /* !ECSTASY_RESOURCE_ENTITY_REGISTRYENTITY_HPP_ */
Encapsulate an index to an entity.
Registry class definition.
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
Index _index
The entity identifier.
Definition Entity.hpp:223
Entity containing a reference to the registry.
constexpr Registry & getRegistry() noexcept
Get the entity owning registry.
const C & get() const
Try to fetch the instance of component C associated to the current entity.
C & add(Args &&...args)
Add a component to the entity.
constexpr RegistryEntity(Entity entity, Registry &registry) noexcept
Construct a new RegistryEntity by binding an Entity to a Registry reference.
bool has() const
Test if the entity has an associated component in the storage S.
C & get()
Try to fetch the instance of component C associated to the current entity.
Registry & _registry
Reference to the registry.
Base of an ECS architecture.
Definition Registry.hpp:82
getStorageType< C > & getStorageSafe() noexcept
Get the Storage of a component and create it if not found.
const getStorageType< C > & getStorage() const
Get the Storage for the component type C.
Definition Registry.hpp:973
Namespace containing all symbols specific to ecstasy.
Definition ecstasy.hpp:30