Copperfield Engine 0.1
C++ Game Engine
Loading...
Searching...
No Matches
ComponentManager Class Reference

Handles anything related to entities and components in the engine. More...

#include <component_manager.hpp>

Public Member Functions

 ComponentManager ()
 Default constructor.
 
 ComponentManager (const ComponentManager &)=delete
 Copy constructor (deleted).
 
ComponentManageroperator= (const ComponentManager &)=delete
 Copy assignment operator (deleted).
 
template<typename... T>
Entity addEntity (Entity *parent, const std::string &editor_name, const T &... args)
 Creates an entity and assigns the specified components to it. More...
 
void deleteEntity (Entity &entity)
 Deletes an entity from the system and all its children. More...
 
template<typename T >
void addComponentClass (ComponentListType t=ComponentListType::kCompact)
 Defines a list for a custom component and makes it ready to use with the engine. More...
 
template<typename T >
void setComponent (const Entity &entity, const T &component)
 Adds a component to the specified entity. More...
 
template<typename T >
T * getComponent (Entity entity) const
 Retrieves a component for a specific entity. More...
 
template<typename T >
ComponentListCompact< T > & getComponentList () const
 Retrieves the list of all the components of the same type. More...
 
template<typename T >
ComponentListSparse< T > & getSparseList () const
 Retrieves the list of all the components of the same type. More...
 

Detailed Description

Handles anything related to entities and components in the engine.

Member Function Documentation

◆ addComponentClass()

template<typename T >
void ComponentManager::addComponentClass ( ComponentListType  t = ComponentListType::kCompact)
inline

Defines a list for a custom component and makes it ready to use with the engine.

Template Parameters
TComponent type to add.
Parameters
tDefines the type of storage to use for the component.

Most of the time, you'll want to use the default (compact), which is more efficient for components that won't be used by most entities in the scene. Sparse lists will be more efficient when the component is present in most entities in the scene. Detailed Information

◆ addEntity()

template<typename... T>
Entity ComponentManager::addEntity ( Entity parent,
const std::string &  editor_name,
const T &...  args 
)
inline

Creates an entity and assigns the specified components to it.

Template Parameters
...TTypes of components the entity will have; these components must have been registered with addComponentClass.
Parameters
parentEntity from which the new entity will inherit the TransformCmp; can be nullptr if no parent is desired.
editor_nameName that will appear in the editor to reference this entity.
...argsValues of the components to attach to the entity.
Returns
Created entity identifier. Most times, you won't need to store the value returned from addEntity, as most entities should be read and modified inside the systems.

An entity cannot have two components of the same type. If you need that, you can create another child entity with the desired component. Detailed Information

◆ deleteEntity()

void ComponentManager::deleteEntity ( Entity entity)

Deletes an entity from the system and all its children.

Parameters
entityEntity to delete.

Using the entity of a child after deletion will cause undefined behavior.

◆ getComponent()

template<typename T >
T * ComponentManager::getComponent ( Entity  entity) const
inline

Retrieves a component for a specific entity.

Template Parameters
TComponent type to retrieve.
Parameters
entityEntity for which to retrieve the component.
Returns
Specified component, nullptr if the entity does not have a component of the specified type.

◆ getComponentList()

template<typename T >
ComponentListCompact< T > & ComponentManager::getComponentList ( ) const
inline

Retrieves the list of all the components of the same type.

Template Parameters
TComponent type; the component type must use a CompactList.
Returns
List containing all the components of the specified type.

For components stored in a SparseList, use getSparseList. Detailed Information

◆ getSparseList()

template<typename T >
ComponentListSparse< T > & ComponentManager::getSparseList ( ) const
inline

Retrieves the list of all the components of the same type.

Template Parameters
TComponent type; the component type must use a SparseList.
Returns
List containing all the components of the specified type.

For components stored in a SparseList, use getSparseList. The only default components stored in Sparse list are:

◆ setComponent()

template<typename T >
void ComponentManager::setComponent ( const Entity entity,
const T &  component 
)
inline

Adds a component to the specified entity.

Template Parameters
TType of component to add.
Parameters
entityEntity to which the component will be added.
componentComponent to add.