NcEngine
nc::ecs::ComponentRegistry Class Reference

Core collection of data pools and registration information game types. More...

#include <ComponentRegistry.h>

Inheritance diagram for nc::ecs::ComponentRegistry:
nc::StableAddress

Public Member Functions

 ComponentRegistry (size_t entityCapacity)
 Construct a ComponentRegistry. More...
 
template<PooledComponent T>
void RegisterType (size_t capacity, ComponentHandler< T > handler={})
 Register a component type. More...
 
template<PooledComponent T>
auto IsTypeRegistered () const noexcept -> bool
 Check if a type is registered.
 
auto IsTypeRegistered (size_t id) const noexcept -> bool
 Check if a type is registered using a component id.
 
template<PooledComponent T>
auto GetPool () -> ComponentPool< T > &
 Get the pool for a registered component type.
 
template<PooledComponent T>
auto GetPool () const -> const ComponentPool< T > &
 Get the pool for a registered component type.
 
auto GetPool (size_t id) -> ComponentPoolBase &
 Get the pool base for a registered type by component id.
 
auto GetPool (size_t id) const -> ComponentPoolBase &
 Get the pool base for a registered type by component id.
 
auto GetFreeComponentPool () -> FreeComponentPool &
 Get the pool for all FreeComponents.
 
template<std::same_as< Entity > T>
auto GetPool () -> EntityPool &
 Get the entity pool.
 
template<std::same_as< Entity > T>
auto GetPool () const -> const EntityPool &
 Get the entity pool.
 
auto GetComponentPools ()
 Get a view of all registered component pools as ComponentPoolBase*.
 
auto GetMaxEntities () const noexcept
 Get the maximum number of concurrent entities supported.
 
void CommitPendingChanges ()
 Merge staged components into their pools and finalize any entity removals.
 
void ClearSceneData ()
 Destroy all non-persistent entities and components.
 
void Clear ()
 Destroy all entities and components.
 
- Public Member Functions inherited from nc::StableAddress
 StableAddress (const StableAddress &)=delete
 
 StableAddress (StableAddress &&)=delete
 
StableAddressoperator= (const StableAddress &)=delete
 
StableAddressoperator= (StableAddress &&)=delete
 

Detailed Description

Core collection of data pools and registration information game types.

The ComponentRegistry houses all entity and component data and provides a low-level interface over game state. An instance is created and bootstrapped with engine types during NcEngine initialization. This instance remains valid and pointer stable until the engine is destroyed. Capacity parameters are taken from the config::Config object used to initialize the engine.

Custom component types may be registered at any time to create pools for managing component instances. For types satisfying PooledComponent, registration is required prior to working with that type through any ecs operation. Registration is not necessary for any types deriving from FreeComponent.

Constructor & Destructor Documentation

◆ ComponentRegistry()

nc::ecs::ComponentRegistry::ComponentRegistry ( size_t  entityCapacity)
inlineexplicit

Construct a ComponentRegistry.

Parameters
entityCapacityMax concurrent entity instances.
Note
Only one ComponentRegistry instance can exist at a time. An instance is created automatically during initialization of the NcEngine instance.

Member Function Documentation

◆ RegisterType()

template<PooledComponent T>
void nc::ecs::ComponentRegistry::RegisterType ( size_t  capacity,
ComponentHandler< T >  handler = {} 
)
inline

Register a component type.

Parameters
capacityMax concurrent instances - must be <= the registry's entity capacity.
handlerOptional callbacks for handling generic component operations.

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