Handles anything related to entities and components in the engine.
More...
#include <component_manager.hpp>
|
| ComponentManager () |
| Default constructor.
|
|
| ComponentManager (const ComponentManager &)=delete |
| Copy constructor (deleted).
|
|
ComponentManager & | operator= (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...
|
|
Handles anything related to entities and components in the engine.
◆ 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
-
- Parameters
-
t | Defines 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
-
...T | Types of components the entity will have; these components must have been registered with addComponentClass. |
- Parameters
-
parent | Entity from which the new entity will inherit the TransformCmp; can be nullptr if no parent is desired. |
editor_name | Name that will appear in the editor to reference this entity. |
...args | Values 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
-
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
-
T | Component type to retrieve. |
- Parameters
-
entity | Entity 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
-
T | Component 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
-
T | Component 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
-
T | Type of component to add. |
- Parameters
-
entity | Entity to which the component will be added. |
component | Component to add. |