ECSTASY
All in the name
Loading...
Searching...
No Matches
ecstasy::Registry Class Reference

Base of an ECS architecture. More...

#include <Registry.hpp>

Collaboration diagram for ecstasy::Registry:

Classes

class  EntityBuilder
 Entity Builder using the registry storages. More...
 
struct  GetModifierProxy
 Proxy structure to extract the operand types using template partial specialization. More...
 
struct  GetModifierProxy< util::meta::Traits< Qs... > >
 Proxy structure to extract the operand types using template partial specialization. More...
 
class  RegistryStackQuery
 Registry query allocating everything on the stack (if allocation required). More...
 
class  RegistryStackQuery< util::meta::Traits< Selects... >, util::meta::Traits< Missings... >, Conditions, util::meta::Traits< Cs... >, AutoLock >
 Registry query allocating everything on the stack (if allocation required). More...
 
class  RegistryStackQuery< util::meta::Traits< Selects... >, util::meta::Traits<>, util::meta::Traits<>, util::meta::Traits< Selects... >, AutoLock >
 Registry query allocating everything on the stack (if allocation required). More...
 
class  RegistryStackQueryMemory
 Base class of RegistryStackQuery. More...
 
class  RegistryStackQueryMemory< util::meta::Traits< Selects... >, util::meta::Traits< Missings... >, util::meta::Traits< Conditions... >, AutoLock, Cs... >
 Base class of RegistryStackQuery. More...
 
class  Select
 Proxy class to use where method. More...
 

Public Types

template<bool AutoLock, typename... Selects>
using RegistrySelectStackQueryMemory = RegistryStackQueryMemory< util::meta::Traits< Selects... >, util::meta::Traits<>, util::meta::Traits<>, AutoLock, Selects... >
 
template<bool AutoLock, typename... Selects>
using RegistrySelectStackQuery = RegistryStackQuery< util::meta::Traits< Selects... >, util::meta::Traits<>, util::meta::Traits<>, util::meta::Traits< Selects... >, AutoLock >
 

Public Member Functions

template<typename C >
constexpr getStorageType< C > & getQueryable ()
 Get a queryable from a registry variable (component storage, resource, queryable storage...)
 
template<std::derived_from< IResource > R>
requires query::Queryable<R>
constexpr R & getQueryable ()
 Get a queryable from a registry variable (component storage, resource, queryable storage...)
 
template<IsStorage S>
requires query::Queryable<S>
S & getQueryable ()
 Get a queryable from a registry variable (component storage, resource, queryable storage...)
 
template<typename C >
constexpr getStorageType< C > & getFromType ()
 Get a registry object reference (storage, resource, system, or the registry itself) from its type.
 
template<IsStorage S>
S & getFromType ()
 Get a registry object reference (storage, resource, system, or the registry itself) from its type.
 
template<std::derived_from< IResource > R>
constexpr R & getFromType ()
 Get a registry object reference (storage, resource, system, or the registry itself) from its type.
 
template<std::derived_from< ISystem > S>
constexpr S & getFromType ()
 Get a registry object reference (storage, resource, system, or the registry itself) from its type.
 
template<std::derived_from< Registry > R>
constexpr R & getFromType () noexcept
 Get a registry object reference (storage, resource, system, or the registry itself) from its type.
 
template<query::Modifier M, typename ModifierAllocator >
constexpr M & getQueryable (ModifierAllocator &allocator)
 Get a queryable from a registry variable (component storage, resource, queryable storage...)
 
template<RegistryModifier M, typename ModifierAllocator >
constexpr M::Modifier & getQueryable (ModifierAllocator &allocator)
 Get a queryable from a registry variable (component storage, resource, queryable storage...)
 
 Registry (bool addEntities=true)
 Construct a new Registry.
 
 ~Registry ()=default
 Default destructor.
 
EntityBuilder entityBuilder () noexcept
 Create a new entity builder.
 
template<std::derived_from< ISystem > S, Pipeline::PhaseId Phase = static_cast<Pipeline::PhaseId>(Pipeline::PredefinedPhases::OnUpdate), typename... Args>
S & addSystem (Args &&...args)
 Add a new system in the registry.
 
template<std::derived_from< ISystem > S, util::meta::is_size_t_convertible T, typename... Args>
S & addSystemInPhase (T phaseId, Args &&...args)
 Add a new system in the registry in a specific phase.
 
template<std::derived_from< IResource > R, typename... Args>
R & addResource (Args &&...args)
 Add a new resource in the registry.
 
template<typename C >
getStorageType< C > & addStorage ()
 Add a new component storage in the registry.
 
template<std::derived_from< IResource > R>
bool hasResource () const
 Check whether the registry has the resource of type R.
 
template<std::derived_from< IResource > R, bool Locked = thread::AUTO_LOCK_RESOURCES_DEFAULT>
ResourceReference< const R, Locked > getResource () const
 Get the Resource of type R.
 
template<std::derived_from< IResource > R, bool Locked = thread::AUTO_LOCK_RESOURCES_DEFAULT>
ResourceReference< R, Locked > getResource ()
 Get the Resource of type R.
 
template<typename C >
const getStorageType< C > & getStorage () const
 Get the Storage for the component type C.
 
template<typename C >
getStorageType< C > & getStorage ()
 Get the Storage for the component type C.
 
template<typename C >
getStorageType< C > & getStorageSafe () noexcept
 Get the Storage of a component and create it if not found.
 
template<bool Locked = thread::AUTO_LOCK_RESOURCES_DEFAULT>
ResourceReference< const Entities, Locked > getEntities () const
 Get the Entities resource.
 
template<bool Locked = thread::AUTO_LOCK_RESOURCES_DEFAULT>
ResourceReference< Entities, Locked > getEntities ()
 Get the Entities resource.
 
Entity getEntity (Entity::Index index)
 Get the Entity at the index index.
 
std::vector< std::reference_wrapper< IStorage > > getEntityStorages (Entity entity)
 Get the Entity Storages.
 
template<std::derived_from< ISystem > S>
S & getSystem ()
 Get the System of type S.
 
template<typename C , typename... Cs>
RegistrySelectStackQuery< thread::AUTO_LOCK_DEFAULT, queryable_type_t< C >, queryable_type_t< Cs >... > query ()
 Construct a query for the given components.
 
template<bool AutoLock, typename C , typename... Cs>
RegistrySelectStackQuery< AutoLock, queryable_type_t< C >, queryable_type_t< Cs >... > queryEx ()
 Construct a query for the given components.
 
template<typename C , typename... Cs>
Select< queryable_type_t< C >, queryable_type_t< Cs >... > select ()
 Starts the creation of a complex query in the registry.
 
bool eraseEntity (Entity entity)
 Instantly erase an entity and its components from the registry.
 
size_t eraseEntities (std::span< Entity > entities)
 Instantly erase multiple entities and their components from the registry.
 
void clear ()
 Erase all resources, systems and storages.
 
template<std::derived_from< ISystem > S>
void runSystem ()
 Run a specific system from the registry.
 
void runSystem (const std::type_index &systemId)
 Run a specific system from the registry.
 
void runSystems ()
 Run all systems present in the registry.
 
void runSystemsPhase (Pipeline::PhaseId phase)
 Run all systems present in the registry for the given phase.
 
constexpr const Instances< IStorage > & getStorages () const noexcept
 Get a const reference to the storages instances.
 
constexpr Instances< IStorage > & getStorages () noexcept
 Get a reference to the storages instances.
 
constexpr PipelinegetPipeline () noexcept
 Get a reference to the registry pipeline.
 
constexpr const PipelinegetPipeline () const noexcept
 Get a const reference to the registry pipeline.
 

Private Member Functions

void eraseEntityComponents (Entity entity)
 
void eraseEntitiesComponents (std::span< Entity > entities)
 

Private Attributes

Instances< IResource_resources
 Registry resources.
 
Instances< IStorage_storages
 Registry storages.
 
Instances< ISystem_systems
 Registry systems.
 
Pipeline _pipeline
 System pipeline.
 

Detailed Description

Base of an ECS architecture.

It stores the entities, components and systems.

Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-11-18)

Definition at line 82 of file Registry.hpp.

Member Typedef Documentation

◆ RegistrySelectStackQuery

template<bool AutoLock, typename... Selects>
using ecstasy::Registry::RegistrySelectStackQuery = RegistryStackQuery< util::meta::Traits<Selects...>, util::meta::Traits<>, util::meta::Traits<>, util::meta::Traits<Selects...>, AutoLock >

Definition at line 402 of file Registry.hpp.

◆ RegistrySelectStackQueryMemory

template<bool AutoLock, typename... Selects>
using ecstasy::Registry::RegistrySelectStackQueryMemory = RegistryStackQueryMemory< util::meta::Traits<Selects...>, util::meta::Traits<>, util::meta::Traits<>, AutoLock, Selects... >

Definition at line 392 of file Registry.hpp.

Constructor & Destructor Documentation

◆ Registry()

ecstasy::Registry::Registry ( bool  addEntities = true)

Construct a new Registry.

Parameters
[in]addEntitiesWhether or not the Entities IResource should be declared or not in the registry.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-10-19)

Definition at line 27 of file Registry.cpp.

27 : _pipeline(*this)
28 {
29 if (addEntities)
30 addResource<Entities>();
31 }
Pipeline _pipeline
System pipeline.

◆ ~Registry()

ecstasy::Registry::~Registry ( )
default

Default destructor.

Member Function Documentation

◆ addResource()

template<std::derived_from< IResource > R, typename... Args>
R & ecstasy::Registry::addResource ( Args &&...  args)
inline

Add a new resource in the registry.

Template Parameters
RResource to add.
ArgsThe type of arguments to pass to the constructor of R.
Parameters
[in]argsThe arguments to pass to the constructor of R.
Returns
R& newly created Resource.
Exceptions
std::logic_errorIf the resource R was already present in the registry.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-10-18)

Definition at line 884 of file Registry.hpp.

885 {
886 return _resources.emplace<R>(std::forward<Args>(args)...);
887 }
Instances< IResource > _resources
Registry resources.

◆ addStorage()

template<typename C >
getStorageType< C > & ecstasy::Registry::addStorage ( )
inline

Add a new component storage in the registry.

Template Parameters
CComponent type to register.
Returns
& newly created Storage.
Exceptions
std::logic_errorIf a storage for component C was already present in the registry.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-10-18)

Definition at line 902 of file Registry.hpp.

903 {
904 return _storages.emplace<getStorageType<C>>();
905 }
Instances< IStorage > _storages
Registry storages.

◆ addSystem()

template<std::derived_from< ISystem > S, Pipeline::PhaseId Phase = static_cast<Pipeline::PhaseId>(Pipeline::PredefinedPhases::OnUpdate), typename... Args>
S & ecstasy::Registry::addSystem ( Args &&...  args)
inline

Add a new system in the registry.

Note
Call addSystemInPhase to add a system in a specific phase using runtime phase id or an Enum type for phase id.
Template Parameters
SSystem to add.
PhaseSystem phase. See Pipeline.
ArgsThe type of arguments to pass to the constructor of S.
Parameters
[in]argsThe arguments to pass to the constructor of S.
Returns
S& newly created System.
Exceptions
std::logic_errorIf the system S was already present in the registry.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-10-17)

Definition at line 839 of file Registry.hpp.

840 {
841 return addSystemInPhase<S>(Phase, std::forward<Args>(args)...);
842 }

◆ addSystemInPhase()

template<std::derived_from< ISystem > S, util::meta::is_size_t_convertible T, typename... Args>
S & ecstasy::Registry::addSystemInPhase ( phaseId,
Args &&...  args 
)
inline

Add a new system in the registry in a specific phase.

Template Parameters
SSystem to add.
TPhase id type. Usually an enum convertible to size_t, or a size_t directly.
ArgsThe type of arguments to pass to the constructor of S.
Parameters
[in]phaseIdPhase id where to add the system.
[in]argsThe arguments to pass to the constructor of S.
Returns
S& newly created System.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2024-11-21)

Definition at line 860 of file Registry.hpp.

861 {
862 S &system = _systems.emplace<S>(std::forward<Args>(args)...);
863
864 _pipeline.addSystem(typeid(S), static_cast<size_t>(phaseId));
865 return system;
866 }
void addSystem(std::type_index system, PhaseId phase=static_cast< std::size_t >(PredefinedPhases::OnUpdate))
Add a system to the pipeline.
Definition Pipeline.cpp:41
Instances< ISystem > _systems
Registry systems.
T system(T... args)

◆ clear()

void ecstasy::Registry::clear ( )

Erase all resources, systems and storages.

Note
Re creates the Entities resource.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2023-02-06)

Definition at line 102 of file Registry.cpp.

103 {
104 _resources.clear();
105 _storages.clear();
106 _systems.clear();
107 addResource<Entities>();
108 }

◆ entityBuilder()

Registry::EntityBuilder ecstasy::Registry::entityBuilder ( )
noexcept

Create a new entity builder.

Returns
EntityBuilder Newly created builder.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-10-19)

Definition at line 33 of file Registry.cpp.

34 {
35 return EntityBuilder(*this);
36 }

◆ eraseEntities()

size_t ecstasy::Registry::eraseEntities ( std::span< Entity entities)

Instantly erase multiple entities and their components from the registry.

Parameters
[in]entitiesentities to erase.
Returns
size_t number of erased entities.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-10-21)

Definition at line 62 of file Registry.cpp.

63 {
64 size_t erased = getResource<Entities>().get().erase(entities);
65
66 if (!erased)
67 return 0;
69 return erased;
70 }
void eraseEntitiesComponents(std::span< Entity > entities)
Definition Registry.cpp:78

◆ eraseEntitiesComponents()

void ecstasy::Registry::eraseEntitiesComponents ( std::span< Entity entities)
private

Definition at line 78 of file Registry.cpp.

79 {
80 for (auto &storage : _storages.getInner())
81 storage.second->erase(entities);
82 }

◆ eraseEntity()

bool ecstasy::Registry::eraseEntity ( Entity  entity)

Instantly erase an entity and its components from the registry.

Parameters
[in]entityEntity to erase.
Returns
bool Whether or not the entity was erased.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-10-21)

Definition at line 52 of file Registry.cpp.

53 {
54 bool erased = getResource<Entities>().get().erase(entity);
55
56 if (!erased)
57 return false;
59 return true;
60 }
void eraseEntityComponents(Entity entity)
Definition Registry.cpp:72

◆ eraseEntityComponents()

void ecstasy::Registry::eraseEntityComponents ( Entity  entity)
private

Definition at line 72 of file Registry.cpp.

73 {
74 for (auto &storage : _storages.getInner())
75 storage.second->erase(std::span{&entity, 1});
76 }

◆ getEntities() [1/2]

template<bool Locked = thread::AUTO_LOCK_RESOURCES_DEFAULT>
ResourceReference< Entities, Locked > ecstasy::Registry::getEntities ( )
inline

Get the Entities resource.

Returns
Entities& Reference to the Entities resource.
Exceptions
std::logic_errorIf the resource is not found.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-10-21)

Definition at line 1041 of file Registry.hpp.

1042 {
1043 return _resources.get<Entities>();
1044 }

◆ getEntities() [2/2]

template<bool Locked = thread::AUTO_LOCK_RESOURCES_DEFAULT>
ResourceReference< const Entities, Locked > ecstasy::Registry::getEntities ( ) const
inline

Get the Entities resource.

Returns
const Entities& Const reference to the Entities resource.
Exceptions
std::logic_errorIf the resource is not found.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-10-21)

Definition at line 1025 of file Registry.hpp.

1026 {
1027 return _resources.get<Entities>();
1028 }

◆ getEntity()

Entity ecstasy::Registry::getEntity ( Entity::Index  index)

Get the Entity at the index index.

Note
The entity returned may not exists.
Parameters
[in]indexEntity index.
Returns
Entity matching entity.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-10-21)

Definition at line 38 of file Registry.cpp.

39 {
40 return getResource<const Entities>().get().get(index);
41 }

◆ getEntityStorages()

std::vector< std::reference_wrapper< IStorage > > ecstasy::Registry::getEntityStorages ( Entity  entity)

Get the Entity Storages.

Note
This is the only way to return a list of components attached to an entity because components have no base class constraints and therefore cannot be stored in a container.
Parameters
[in]entityEntity to get the storages from.
Returns
std::vector<std::reference_wrapper<IStorage>> List of storages attached to the entity.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2024-06-11)

Definition at line 43 of file Registry.cpp.

44 {
46 for (auto &storage : _storages.getInner())
47 if (storage.second->contains(entity.getIndex()))
48 storages.push_back(*storage.second);
49 return storages;
50 }
constexpr bool contains
Checks if the type T exists in the types Ts.
Definition contains.hpp:29

◆ getFromType() [1/5]

template<typename C >
constexpr getStorageType< C > & ecstasy::Registry::getFromType ( )
inlineconstexpr

Get a registry object reference (storage, resource, system, or the registry itself) from its type.

Template Parameters
CType of the registry object to fetch.
Returns
constexpr getStorageType<C>& Associated registry object (if no specific case the storage for C is returned).
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2024-10-03)

Definition at line 131 of file Registry.hpp.

132 {
133 return getStorageSafe<C>();
134 }

◆ getFromType() [2/5]

template<IsStorage S>
S & ecstasy::Registry::getFromType ( )
inline

Get a registry object reference (storage, resource, system, or the registry itself) from its type.

Template Parameters
CType of the registry object to fetch.
Returns
constexpr getStorageType<C>& Associated registry object (if no specific case the storage for C is returned).
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2024-10-03)

Definition at line 138 of file Registry.hpp.

139 {
140 return _storages.get<std::remove_const_t<S>>();
141 }

◆ getFromType() [3/5]

template<std::derived_from< IResource > R>
constexpr R & ecstasy::Registry::getFromType ( )
inlineconstexpr

Get a registry object reference (storage, resource, system, or the registry itself) from its type.

Template Parameters
CType of the registry object to fetch.
Returns
constexpr getStorageType<C>& Associated registry object (if no specific case the storage for C is returned).
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2024-10-03)

Definition at line 145 of file Registry.hpp.

146 {
147 return getResource<R, false>();
148 }

◆ getFromType() [4/5]

template<std::derived_from< ISystem > S>
constexpr S & ecstasy::Registry::getFromType ( )
inlineconstexpr

Get a registry object reference (storage, resource, system, or the registry itself) from its type.

Template Parameters
CType of the registry object to fetch.
Returns
constexpr getStorageType<C>& Associated registry object (if no specific case the storage for C is returned).
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2024-10-03)

Definition at line 152 of file Registry.hpp.

153 {
154 return getSystem<S>();
155 }

◆ getFromType() [5/5]

template<std::derived_from< Registry > R>
constexpr R & ecstasy::Registry::getFromType ( )
inlineconstexprnoexcept

Get a registry object reference (storage, resource, system, or the registry itself) from its type.

Template Parameters
CType of the registry object to fetch.
Returns
constexpr getStorageType<C>& Associated registry object (if no specific case the storage for C is returned).
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2024-10-03)

Definition at line 159 of file Registry.hpp.

160 {
161 return *this;
162 }

◆ getPipeline() [1/2]

constexpr const Pipeline & ecstasy::Registry::getPipeline ( ) const
inlineconstexprnoexcept

Get a const reference to the registry pipeline.

Returns
const Pipeline& Const reference to the registry pipeline instance.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2024-11-21)

Definition at line 1282 of file Registry.hpp.

1283 {
1284 return _pipeline;
1285 }

◆ getPipeline() [2/2]

constexpr Pipeline & ecstasy::Registry::getPipeline ( )
inlineconstexprnoexcept

Get a reference to the registry pipeline.

Returns
Pipeline& Reference to the registry pipeline instance.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2024-11-21)

Definition at line 1269 of file Registry.hpp.

1270 {
1271 return _pipeline;
1272 }

◆ getQueryable() [1/5]

template<typename C >
constexpr getStorageType< C > & ecstasy::Registry::getQueryable ( )
inlineconstexpr

Get a queryable from a registry variable (component storage, resource, queryable storage...)

Template Parameters
CType of the variable to fetch.
Returns
& Associated queryable (if no specific case the storage for C is returned).
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-10-25)

Definition at line 96 of file Registry.hpp.

97 {
98 return getStorageSafe<C>();
99 }

◆ getQueryable() [2/5]

template<std::derived_from< IResource > R>
requires query::Queryable<R>
constexpr R & ecstasy::Registry::getQueryable ( )
inlineconstexpr

Get a queryable from a registry variable (component storage, resource, queryable storage...)

Template Parameters
CType of the variable to fetch.
Returns
& Associated queryable (if no specific case the storage for C is returned).
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-10-25)

Definition at line 104 of file Registry.hpp.

105 {
106 return getResource<R, false>();
107 }

◆ getQueryable() [3/5]

template<IsStorage S>
requires query::Queryable<S>
S & ecstasy::Registry::getQueryable ( )
inline

Get a queryable from a registry variable (component storage, resource, queryable storage...)

Template Parameters
CType of the variable to fetch.
Returns
& Associated queryable (if no specific case the storage for C is returned).
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-10-25)

Definition at line 112 of file Registry.hpp.

113 {
114 if (!_storages.contains<std::remove_const_t<S>>()) [[unlikely]]
115 return _storages.emplace<std::remove_const_t<S>>();
116 return _storages.get<std::remove_const_t<S>>();
117 }

◆ getQueryable() [4/5]

template<query::Modifier M, typename ModifierAllocator >
constexpr M & ecstasy::Registry::getQueryable ( ModifierAllocator &  allocator)
inlineconstexpr

Get a queryable from a registry variable (component storage, resource, queryable storage...)

Template Parameters
CType of the variable to fetch.
Returns
& Associated queryable (if no specific case the storage for C is returned).
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-10-25)

Definition at line 234 of file Registry.hpp.

235 {
236 return GetModifierProxy<typename M::Operands>::template get<M, ModifierAllocator>(*this, allocator);
237 }

◆ getQueryable() [5/5]

template<RegistryModifier M, typename ModifierAllocator >
constexpr M::Modifier & ecstasy::Registry::getQueryable ( ModifierAllocator &  allocator)
inlineconstexpr

Get a queryable from a registry variable (component storage, resource, queryable storage...)

Template Parameters
CType of the variable to fetch.
Returns
& Associated queryable (if no specific case the storage for C is returned).
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-10-25)

Definition at line 241 of file Registry.hpp.

242 {
243 return getQueryable<typename M::Modifier, ModifierAllocator>(allocator);
244 }

◆ getResource() [1/2]

template<std::derived_from< IResource > R, bool Locked = thread::AUTO_LOCK_RESOURCES_DEFAULT>
ResourceReference< R, Locked > ecstasy::Registry::getResource ( )
inline

Get the Resource of type R.

Template Parameters
RType of the resource to fetch.
Returns
R& Reference to an instance of type R.
Exceptions
std::logic_errorIf the resource R was not present in the registry.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-10-18)

Definition at line 955 of file Registry.hpp.

956 {
957 return _resources.get<R>();
958 }

◆ getResource() [2/2]

template<std::derived_from< IResource > R, bool Locked = thread::AUTO_LOCK_RESOURCES_DEFAULT>
ResourceReference< const R, Locked > ecstasy::Registry::getResource ( ) const
inline

Get the Resource of type R.

Template Parameters
RType of the resource to fetch.
LockedWhether or not the resource should be locked.
Returns
const R& Const reference to an instance of type R.
Exceptions
std::logic_errorIf the resource R was not present in the registry.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-10-18)

Definition at line 937 of file Registry.hpp.

938 {
939 return _resources.get<R>();
940 }

◆ getStorage() [1/2]

template<typename C >
getStorageType< C > & ecstasy::Registry::getStorage ( )
inline

Get the Storage for the component type C.

Template Parameters
CType of the component for which we want the storage.
Returns
& Reference to the storage of the component type C.
Exceptions
std::logic_errorIf no storage for component C was found in the registry.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-10-18)

Definition at line 991 of file Registry.hpp.

992 {
994 }

◆ getStorage() [2/2]

template<typename C >
const getStorageType< C > & ecstasy::Registry::getStorage ( ) const
inline

Get the Storage for the component type C.

Template Parameters
CType of the component for which we want the storage.
Returns
& Const reference to the storage of the component type C.
Exceptions
std::logic_errorIf no storage for component C was found in the registry.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-10-18)

Definition at line 973 of file Registry.hpp.

974 {
975 return _storages.get<getStorageType<C>>();
976 }

◆ getStorages() [1/2]

constexpr const Instances< IStorage > & ecstasy::Registry::getStorages ( ) const
inlineconstexprnoexcept

Get a const reference to the storages instances.

Returns
constexpr const Instances<IStorage>& Const reference to the storages instance.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2024-06-11)

Definition at line 1243 of file Registry.hpp.

1244 {
1245 return _storages;
1246 }

◆ getStorages() [2/2]

constexpr Instances< IStorage > & ecstasy::Registry::getStorages ( )
inlineconstexprnoexcept

Get a reference to the storages instances.

Returns
constexpr Instances<IStorage>& Reference to the storages instance.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2024-10-04)

Definition at line 1256 of file Registry.hpp.

1257 {
1258 return _storages;
1259 }

◆ getStorageSafe()

template<typename C >
getStorageType< C > & ecstasy::Registry::getStorageSafe ( )
inlinenoexcept

Get the Storage of a component and create it if not found.

Template Parameters
CType of the comonent for which we want the storage.
Returns
& Reference to the storage of the component type C.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-10-19)

Definition at line 1007 of file Registry.hpp.

1008 {
1009 if (!_storages.contains<std::remove_const_t<getStorageType<C>>>()) [[unlikely]]
1010 addStorage<std::remove_const_t<C>>();
1011 return _storages.get<getStorageType<std::remove_const_t<C>>>();
1012 }

◆ getSystem()

template<std::derived_from< ISystem > S>
S & ecstasy::Registry::getSystem ( )
inline

Get the System of type S.

Template Parameters
SType of the system to get.
Returns
S& Reference to the system of type S.
Exceptions
std::logic_errorIf the system S was not found in the registry.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2024-10-03)

Definition at line 1088 of file Registry.hpp.

1089 {
1090 return _systems.get<S>();
1091 }

◆ hasResource()

template<std::derived_from< IResource > R>
bool ecstasy::Registry::hasResource ( ) const
inline

Check whether the registry has the resource of type R.

Template Parameters
RType of the resource.
Returns
bool Whether the registry contains a resource instance of type R.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-11-06)

Definition at line 918 of file Registry.hpp.

919 {
920 return _resources.contains<R>();
921 }

◆ query()

template<typename C , typename... Cs>
RegistrySelectStackQuery< thread::AUTO_LOCK_DEFAULT, queryable_type_t< C >, queryable_type_t< Cs >... > ecstasy::Registry::query ( )
inline

Construct a query for the given components.

Template Parameters
CFirst component type.
CsOther component types.
Returns
query::Query<queryable_type_t<C>, queryable_type_t<Cs>...> New query which can be iterated.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-10-20)

Definition at line 1108 of file Registry.hpp.

1109 {
1110 return RegistrySelectStackQuery<thread::AUTO_LOCK_DEFAULT, queryable_type_t<C>, queryable_type_t<Cs>...>(*this);
1111 }

◆ queryEx()

template<bool AutoLock, typename C , typename... Cs>
RegistrySelectStackQuery< AutoLock, queryable_type_t< C >, queryable_type_t< Cs >... > ecstasy::Registry::queryEx ( )
inline

Construct a query for the given components.

This extented version allows to explicitly set the AutoLock value.

Template Parameters
AutoLockWhether or not the query should be auto locked.
CFirst component type.
CsOther component types.
Returns
RegistrySelectStackQuery<AutoLock, queryable_type_t<C>, queryable_type_t<Cs>...> New query which can be iterated.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2024-04-07)

Definition at line 1128 of file Registry.hpp.

1129 {
1130 return RegistrySelectStackQuery<AutoLock, queryable_type_t<C>, queryable_type_t<Cs>...>(*this);
1131 }

◆ runSystem() [1/2]

template<std::derived_from< ISystem > S>
void ecstasy::Registry::runSystem ( )
inline

Run a specific system from the registry.

Template Parameters
SSystem class to run.
Exceptions
std::logic_errorIf the system S is not present in the registry.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-10-17)

Definition at line 1199 of file Registry.hpp.

1200 {
1201 _systems.get<S>().run(*this);
1202 }

◆ runSystem() [2/2]

void ecstasy::Registry::runSystem ( const std::type_index systemId)

Run a specific system from the registry.

Parameters
[in]systemIdSystem type index to run.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2024-11-21)

Definition at line 84 of file Registry.cpp.

85 {
86 ISystem &system = _systems.get(systemId);
87
88 if (system.getTimer().trigger())
89 system.run(*this);
90 }

◆ runSystems()

void ecstasy::Registry::runSystems ( )

Run all systems present in the registry.

Note
Systems are run in ascending registration order. You can have further control using Phases.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-10-17)

Definition at line 92 of file Registry.cpp.

93 {
94 _pipeline.run();
95 }
void run()
Run a frame of the pipeline.
Definition Pipeline.cpp:59

◆ runSystemsPhase()

void ecstasy::Registry::runSystemsPhase ( Pipeline::PhaseId  phase)

Run all systems present in the registry for the given phase.

Parameters
[in]phasePhase to run the systems for.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2024-11-21)

Definition at line 97 of file Registry.cpp.

98 {
99 _pipeline.run(phase);
100 }

◆ select()

template<typename C , typename... Cs>
Select< queryable_type_t< C >, queryable_type_t< Cs >... > ecstasy::Registry::select ( )
inline

Starts the creation of a complex query in the registry.

Note
It does nothing until the Select::where() method is called.
Template Parameters
CFirst component to query.
CsOther components to query.
Returns
Select<queryable_type_t<C>, queryable_type_t<Cs>...> placeholder templated Select object.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-10-24)

Definition at line 1149 of file Registry.hpp.

1150 {
1151 return Select<queryable_type_t<C>, queryable_type_t<Cs>...>(*this);
1152 }

Member Data Documentation

◆ _pipeline

Pipeline ecstasy::Registry::_pipeline
private

System pipeline.

Definition at line 1295 of file Registry.hpp.

◆ _resources

Instances<IResource> ecstasy::Registry::_resources
private

Registry resources.

Definition at line 1289 of file Registry.hpp.

◆ _storages

Instances<IStorage> ecstasy::Registry::_storages
private

Registry storages.

Definition at line 1291 of file Registry.hpp.

◆ _systems

Instances<ISystem> ecstasy::Registry::_systems
private

Registry systems.

Definition at line 1293 of file Registry.hpp.


The documentation for this class was generated from the following files: