Raftel Engine
 
Loading...
Searching...
No Matches
Raftel::EntityManager Class Reference

Manages entities in the ECS (Entity Component System). More...

#include <ecs.hpp>

Public Member Functions

 EntityManager ()
 Constructs an EntityManager.
 
Entity CreateEntity ()
 Creates a new entity and returns it.
 
const std::vector< Entity > & getActiveEntities () const
 Retrieves a constant reference to the list of active entities.
 
std::vector< Entity > & getActiveEntities ()
 Retrieves a mutable reference to the list of active entities.
 
void Update (float deltaTime)
 Updates the entity manager, processing entity behavior.
 
void setPosition (size_t ID, const glm::vec3 &pos)
 Sets the position of an entity.
 
glm::vec3 getPosition (size_t ID) const
 Gets the position of an entity.
 
void setRotation (size_t ID, const glm::vec3 &rot)
 Sets the rotation of an entity.
 
glm::vec3 getRotation (size_t ID) const
 Gets the rotation of an entity.
 
void setScale (size_t ID, const glm::vec3 &scale)
 Sets the scale of an entity.
 
glm::vec3 getScale (size_t ID) const
 Gets the scale of an entity.
 
void setMesh (size_t ID, const std::shared_ptr< Mesh > &mesh)
 Assigns a mesh to an entity.
 
std::optional< MeshComponentgetMesh (size_t ID) const
 Retrieves the mesh component of an entity.
 
void moveTo (size_t ID, const glm::vec3 &target, float speed)
 Moves an entity to a target position at a given speed.
 
void constantStraightMovement (size_t ID, float speed, bool isHorizontal)
 Moves an entity in a straight direction continuously.
 
void addMeshComp (size_t ID, const std::shared_ptr< Mesh > &mesh)
 Adds a mesh component to an entity.
 
std::optional< MeshComponentgetMeshComponent (size_t ID)
 Retrieves the mesh component of an entity.
 
bool hasMeshComponent (size_t ID) const
 Checks if an entity has a mesh component.
 
void removeMeshComponent (size_t ID)
 Removes the mesh component from an entity.
 
void addTransformComp (size_t ID, TransformComponent &&trans)
 Adds a transform component to an entity.
 
void addRenderComp (size_t ID, RenderComponent &&rend)
 Adds a render component to an entity.
 
void addScriptComp (size_t ID, ScriptComponent &&script)
 Adds a script component to an entity.
 
void addLightComp (size_t ID, LightComponent &&light)
 Adds a light component to an entity.
 
std::optional< Raftel::LightComponent > & getLightComponent (size_t ID)
 Retrieves the light component of an entity.
 
void removeEntity (size_t id)
 Removes an entity from the system.
 
void removeTransformComp (size_t ID)
 Removes the transform component from an entity.
 
void removeLightComp (size_t ID)
 Removes the light component from an entity.
 
void removeRenderComp (size_t ID)
 Removes the render component from an entity.
 
void removeScriptComp (size_t ID)
 Removes the script component from an entity.
 
std::optional< ScriptComponent > & getScriptComponent (size_t ID)
 Retrieves the script component of an entity.
 
std::optional< TransformComponent > & getTransformComponent (size_t ID)
 Retrieves the transform component of an entity.
 
std::optional< RenderComponent > & getRenderComponent (size_t ID)
 Retrieves the render component of an entity.
 

Friends

class RenderSystem
 
class Editor
 
void UpdateRenderSystem (EntityManager &em, Camera &cam, ShaderProgram &shader, glm::ivec2 screen, bool shadow)
 
void UpdateTransformSystem (EntityManager &em)
 
void UpdateScriptingSystem (EntityManager &em)
 
void UpdateLightSystem (EntityManager &em, ShaderProgram &lit_shader, Camera &cam)
 
bool Entity::hasLightComp () const
 

Detailed Description

Manages entities in the ECS (Entity Component System).

Definition at line 223 of file ecs.hpp.

Member Function Documentation

◆ addLightComp()

void Raftel::EntityManager::addLightComp ( size_t ID,
LightComponent && light )

Adds a light component to an entity.

Parameters
IDThe entity ID.
lightThe light component to add.

◆ addMeshComp()

void Raftel::EntityManager::addMeshComp ( size_t ID,
const std::shared_ptr< Mesh > & mesh )

Adds a mesh component to an entity.

Parameters
IDThe entity ID.
meshShared pointer to the mesh.

◆ addRenderComp()

void Raftel::EntityManager::addRenderComp ( size_t ID,
RenderComponent && rend )

Adds a render component to an entity.

Parameters
IDThe entity ID.
rendThe render component to add.

◆ addScriptComp()

void Raftel::EntityManager::addScriptComp ( size_t ID,
ScriptComponent && script )

Adds a script component to an entity.

Parameters
IDThe entity ID.
scriptThe script component to add.

◆ addTransformComp()

void Raftel::EntityManager::addTransformComp ( size_t ID,
TransformComponent && trans )

Adds a transform component to an entity.

Parameters
IDThe entity ID.
transThe transform component to add.

◆ constantStraightMovement()

void Raftel::EntityManager::constantStraightMovement ( size_t ID,
float speed,
bool isHorizontal )

Moves an entity in a straight direction continuously.

Parameters
IDThe entity ID.
speedThe movement speed.
isHorizontalTrue for horizontal movement, false for vertical.

◆ CreateEntity()

Entity Raftel::EntityManager::CreateEntity ( )

Creates a new entity and returns it.

Returns
The created entity.

◆ getActiveEntities() [1/2]

std::vector< Entity > & Raftel::EntityManager::getActiveEntities ( )

Retrieves a mutable reference to the list of active entities.

Returns
A vector containing the active entities.

◆ getActiveEntities() [2/2]

const std::vector< Entity > & Raftel::EntityManager::getActiveEntities ( ) const

Retrieves a constant reference to the list of active entities.

Returns
A vector containing the active entities.

◆ getLightComponent()

std::optional< Raftel::LightComponent > & Raftel::EntityManager::getLightComponent ( size_t ID)

Retrieves the light component of an entity.

Parameters
IDThe entity ID.
Returns
The light component if available.

◆ getMesh()

std::optional< MeshComponent > Raftel::EntityManager::getMesh ( size_t ID) const

Retrieves the mesh component of an entity.

Parameters
IDThe entity ID.
Returns
The mesh component if available.

◆ getMeshComponent()

std::optional< MeshComponent > Raftel::EntityManager::getMeshComponent ( size_t ID)

Retrieves the mesh component of an entity.

Parameters
IDThe entity ID.
Returns
The mesh component if available.

◆ getPosition()

glm::vec3 Raftel::EntityManager::getPosition ( size_t ID) const

Gets the position of an entity.

Parameters
IDThe entity ID.
Returns
The position of the entity.

◆ getRenderComponent()

std::optional< RenderComponent > & Raftel::EntityManager::getRenderComponent ( size_t ID)

Retrieves the render component of an entity.

Parameters
IDThe entity ID.
Returns
The render component if available.

◆ getRotation()

glm::vec3 Raftel::EntityManager::getRotation ( size_t ID) const

Gets the rotation of an entity.

Parameters
IDThe entity ID.
Returns
The rotation of the entity.

◆ getScale()

glm::vec3 Raftel::EntityManager::getScale ( size_t ID) const

Gets the scale of an entity.

Parameters
IDThe entity ID.
Returns
The scale of the entity.

◆ getScriptComponent()

std::optional< ScriptComponent > & Raftel::EntityManager::getScriptComponent ( size_t ID)

Retrieves the script component of an entity.

Parameters
IDThe entity ID.
Returns
The script component if available.

◆ getTransformComponent()

std::optional< TransformComponent > & Raftel::EntityManager::getTransformComponent ( size_t ID)

Retrieves the transform component of an entity.

Parameters
IDThe entity ID.
Returns
The transform component if available.

◆ hasMeshComponent()

bool Raftel::EntityManager::hasMeshComponent ( size_t ID) const

Checks if an entity has a mesh component.

Parameters
IDThe entity ID.
Returns
True if the entity has a mesh component, false otherwise.

◆ moveTo()

void Raftel::EntityManager::moveTo ( size_t ID,
const glm::vec3 & target,
float speed )

Moves an entity to a target position at a given speed.

Parameters
IDThe entity ID.
targetThe target position.
speedThe movement speed.

◆ removeEntity()

void Raftel::EntityManager::removeEntity ( size_t id)

Removes an entity from the system.

Parameters
IDThe entity ID.

◆ removeLightComp()

void Raftel::EntityManager::removeLightComp ( size_t ID)

Removes the light component from an entity.

Parameters
IDThe entity ID.

◆ removeMeshComponent()

void Raftel::EntityManager::removeMeshComponent ( size_t ID)

Removes the mesh component from an entity.

Parameters
IDThe entity ID.

◆ removeRenderComp()

void Raftel::EntityManager::removeRenderComp ( size_t ID)

Removes the render component from an entity.

Parameters
IDThe entity ID.

◆ removeScriptComp()

void Raftel::EntityManager::removeScriptComp ( size_t ID)

Removes the script component from an entity.

Parameters
IDThe entity ID.

◆ removeTransformComp()

void Raftel::EntityManager::removeTransformComp ( size_t ID)

Removes the transform component from an entity.

Parameters
IDThe entity ID.

◆ setMesh()

void Raftel::EntityManager::setMesh ( size_t ID,
const std::shared_ptr< Mesh > & mesh )

Assigns a mesh to an entity.

Parameters
IDThe entity ID.
meshShared pointer to the mesh.

◆ setPosition()

void Raftel::EntityManager::setPosition ( size_t ID,
const glm::vec3 & pos )

Sets the position of an entity.

Parameters
IDThe entity ID.
posThe new position.

◆ setRotation()

void Raftel::EntityManager::setRotation ( size_t ID,
const glm::vec3 & rot )

Sets the rotation of an entity.

Parameters
IDThe entity ID.
rotThe new rotation.

◆ setScale()

void Raftel::EntityManager::setScale ( size_t ID,
const glm::vec3 & scale )

Sets the scale of an entity.

Parameters
IDThe entity ID.
scaleThe new scale.

◆ Update()

void Raftel::EntityManager::Update ( float deltaTime)

Updates the entity manager, processing entity behavior.

Parameters
deltaTimeTime elapsed since the last update.

Friends And Related Symbol Documentation

◆ Editor

friend class Editor
friend

Definition at line 439 of file ecs.hpp.

◆ RenderSystem

friend class RenderSystem
friend

Definition at line 438 of file ecs.hpp.


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