Shkyera Engine
Easy to use, game engine for Python
Loading...
Searching...
No Matches
shkyera::Registry Class Reference

#include <Registry.hpp>

Public Member Functions

 Registry ()=default
 
 ~Registry ()=default
 
 Registry (const Registry &other)
 
Registryoperator= (const Registry &other)
 
Entity addEntity ()
 
void removeEntity (Entity entity)
 
template<typename Component , typename... Args>
ComponentaddComponent (Entity entity, Args &&... args)
 
template<typename Component >
void clearComponents ()
 
template<typename Component , typename... Args>
ComponentassignComponent (Entity entity, Args &&... args)
 
template<typename Component >
void removeComponent (Entity entity)
 
template<typename Component >
bool hasComponent (Entity entity) const
 
template<typename... Components>
bool hasComponents (Entity entity) const
 
template<typename Component >
ComponentgetComponent (Entity entity)
 
template<typename Component >
const ComponentgetComponent (Entity entity) const
 
template<typename Component >
SparseSet< Component > & getComponentSet ()
 
template<typename Component >
const SparseSet< Component > & getComponentSet () const
 
template<typename Component >
std::vector< Component > & getComponents ()
 
template<typename Component >
const std::vector< Component > & getComponents () const
 
template<typename Component >
std::optional< EntitygetEntity () const
 
template<typename Component >
ComponentgetComponent ()
 
EntityHierarchygetHierarchy ()
 
const EntityHierarchygetHierarchy () const
 

Private Types

using ParentAndChild = std::pair< Entity, Entity >
 

Private Member Functions

template<typename Component >
SparseSet< Component > & getOrCreateComponentSet ()
 
template<typename Component >
const SparseSet< Component > & getOrCreateComponentSet () const
 

Private Attributes

std::unordered_map< size_t, std::unique_ptr< SparseSetBase > > _componentSets
 
EntityProvider _entityProvider
 
EntityHierarchy _entityHierarchy
 

Detailed Description

Manages a collection of entities and their components. Provides methods to add, remove, and query entities and components.

Member Typedef Documentation

◆ ParentAndChild

Constructor & Destructor Documentation

◆ Registry() [1/2]

shkyera::Registry::Registry ( )
default

Default constructor. Initializes the registry for managing entities and components.

◆ ~Registry()

shkyera::Registry::~Registry ( )
default

Default destructor.

◆ Registry() [2/2]

shkyera::Registry::Registry ( const Registry other)

Member Function Documentation

◆ addComponent()

template<typename Component , typename... Args>
Component & shkyera::Registry::addComponent ( Entity  entity,
Args &&...  args 
)
inline

Adds a component to the specified entity. Initializes the component with default values.

Template Parameters
ComponentType of the component to add.
Parameters
entityThe entity to which the component is added.
Returns
Refence to the constructed component

◆ addEntity()

Entity shkyera::Registry::addEntity ( )

Adds a new entity to the registry.

Returns
The newly created entity.

◆ assignComponent()

template<typename Component , typename... Args>
Component & shkyera::Registry::assignComponent ( Entity  entity,
Args &&...  args 
)
inline

◆ clearComponents()

template<typename Component >
void shkyera::Registry::clearComponents ( )
inline

◆ getComponent() [1/3]

template<typename Component >
Component * shkyera::Registry::getComponent ( )
inline

◆ getComponent() [2/3]

template<typename Component >
Component & shkyera::Registry::getComponent ( Entity  entity)
inline

Retrieves a reference to the component of the specified entity.

Template Parameters
ComponentType of the component to retrieve.
Parameters
entityThe entity whose component is retrieved.
Returns
Reference to the component.

◆ getComponent() [3/3]

template<typename Component >
const Component & shkyera::Registry::getComponent ( Entity  entity) const
inline

Retrieves a const reference to the component of the specified entity.

Template Parameters
ComponentType of the component to retrieve.
Parameters
entityThe entity whose component is retrieved.
Returns
Const reference to the component.

◆ getComponents() [1/2]

template<typename Component >
std::vector< Component > & shkyera::Registry::getComponents ( )
inline

◆ getComponents() [2/2]

template<typename Component >
const std::vector< Component > & shkyera::Registry::getComponents ( ) const
inline

◆ getComponentSet() [1/2]

template<typename Component >
SparseSet< Component > & shkyera::Registry::getComponentSet ( )
inline

Retrieves the component set for the specified component type.

Template Parameters
ComponentType of the component to retrieve the set for.
Returns
Reference to the component set.

◆ getComponentSet() [2/2]

template<typename Component >
const SparseSet< Component > & shkyera::Registry::getComponentSet ( ) const
inline

Retrieves the component set for the specified component type.

Template Parameters
ComponentType of the component to retrieve the set for.
Returns
Reference to the component set.

◆ getEntity()

template<typename Component >
std::optional< Entity > shkyera::Registry::getEntity ( ) const
inline

◆ getHierarchy() [1/2]

EntityHierarchy & shkyera::Registry::getHierarchy ( )

◆ getHierarchy() [2/2]

const EntityHierarchy & shkyera::Registry::getHierarchy ( ) const

◆ getOrCreateComponentSet() [1/2]

template<typename Component >
SparseSet< Component > & shkyera::Registry::getOrCreateComponentSet ( )
inlineprivate

Retrieves or creates the component set for the specified component type.

Template Parameters
ComponentType of the component to get or create the set for.
Returns
Reference to the component set.

◆ getOrCreateComponentSet() [2/2]

template<typename Component >
const SparseSet< Component > & shkyera::Registry::getOrCreateComponentSet ( ) const
inlineprivate

Retrieves or creates the component set for the specified component type.

Template Parameters
ComponentType of the component to get or create the set for.
Returns
Reference to the component set.

◆ hasComponent()

template<typename Component >
bool shkyera::Registry::hasComponent ( Entity  entity) const
inline

Checks if the specified entity has a specific component.

Template Parameters
ComponentType of the component to check for.
Parameters
entityThe entity to check.
Returns
True if the entity has the component, false otherwise.

◆ hasComponents()

template<typename... Components>
bool shkyera::Registry::hasComponents ( Entity  entity) const
inline

Checks if the specified entity has all of the specified components.

Template Parameters
ComponentsTypes of the components to check for.
Parameters
entityThe entity to check.
Returns
True if the entity has all the components, false otherwise.

◆ operator=()

Registry & shkyera::Registry::operator= ( const Registry other)

◆ removeComponent()

template<typename Component >
void shkyera::Registry::removeComponent ( Entity  entity)
inline

Removes a component from the specified entity.

Template Parameters
ComponentType of the component to remove.
Parameters
entityThe entity from which the component is removed.

◆ removeEntity()

void shkyera::Registry::removeEntity ( Entity  entity)

Removes an entity from the registry.

Parameters
entityThe entity to remove.

Member Data Documentation

◆ _componentSets

std::unordered_map<size_t, std::unique_ptr<SparseSetBase> > shkyera::Registry::_componentSets
mutableprivate

◆ _entityHierarchy

EntityHierarchy shkyera::Registry::_entityHierarchy
private

◆ _entityProvider

EntityProvider shkyera::Registry::_entityProvider
private

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