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