11#include "raftel/imguiRenderer.hpp"
12#include <raftel/global_macros.hpp>
13#include <glm/gtc/matrix_transform.hpp>
14#include <glm/gtx/quaternion.hpp>
15#include <raftel/components.hpp>
23 constexpr size_t MAX_ENTITIES = 200;
154 friend class EntityManager;
162 Entity(
size_t ID, EntityManager* em);
168 void setPosition(
const glm::vec3& pos);
174 glm::vec3 getPosition()
const;
180 void setRotation(
const glm::vec3& rot);
186 glm::vec3 getRotation()
const;
192 void setScale(
const glm::vec3& scale);
198 glm::vec3 getScale()
const;
204 void setMesh(
const std::shared_ptr<Mesh>& mesh);
210 std::optional<MeshComponent> getMesh()
const;
217 void moveTo(
const glm::vec3& target,
float speed);
300 void setMesh(
size_t ID,
const std::shared_ptr<Mesh>& mesh);
307 std::optional<MeshComponent>
getMesh(
size_t ID)
const;
315 void moveTo(
size_t ID,
const glm::vec3& target,
float speed);
438 friend class RenderSystem;
448 std::vector<std::optional<ScriptComponent>> scriptComps;
449 std::vector<std::optional<TransformComponent>> transformComps;
450 std::vector<std::optional<RenderComponent>> renderComps;
451 std::vector<std::optional<MeshComponent>> meshComps;
452 std::vector<std::optional<LightComponent>> lightComps;
453 std::vector<std::optional<BasicComponent>> basicComps;
455 std::vector<Entity> activeEntities;
456 size_t lastEntity = 0;
470 int pickEntity(
const std::unique_ptr<EntityManager>& ecs,
Camera& cam, glm::vec2 mousePos, glm::ivec2 screenSize);
481 bool intersectRaySphere(
const glm::vec3& rayOrigin,
const glm::vec3& rayDir,
const glm::vec3& sphereCenter,
float sphereRadius,
float& distance);
Camera class for handling movement and view transformations.
Represents an entity in the ECS (Entity Component System).
bool hasScriptComp() const
Checks if the entity has a script component.
void addTransformComp(TransformComponent &&trans)
Adds a TransformComponent to the entity.
void removeMeshComp()
Removes the mesh component from the entity.
Entity & operator=(Entity &&other) noexcept=default
Default move assignment operator.
bool hasRenderComp() const
Checks if the entity has a render component.
const std::optional< TransformComponent > & getTransformComp() const
Retrieves the TransformComponent of the entity (const version).
bool hasLightComp() const
Checks if the entity has a light component.
void addRenderComp(RenderComponent &&rend)
Adds a RenderComponent to the entity.
void addLightComp(LightComponent &&light)
Adds a LightComponent to the entity.
void addMeshComp(const std::shared_ptr< Mesh > &mesh)
Adds a MeshComponent to the entity.
Entity & operator=(const Entity &other)=default
Default copy assignment operator.
void addScriptComp(ScriptComponent &&script)
Adds a ScriptComponent to the entity.
bool hasMeshComp() const
Checks if the entity has a mesh component.
Entity(const Entity &other)=default
Default copy constructor.
std::optional< ScriptComponent > & getScriptComp()
Retrieves the ScriptComponent of the entity.
std::optional< LightComponent > & getLightComp()
Retrieves the LightComponent of the entity.
bool hasTransformComp() const
Checks if the entity has a transform component.
std::optional< TransformComponent > & getTransformComp()
Retrieves the TransformComponent of the entity.
std::optional< MeshComponent > getMeshComp() const
Retrieves the MeshComponent of the entity.
Entity(Entity &&other) noexcept=default
Default move constructor.
const std::optional< LightComponent > & getLightComp() const
Retrieves the LightComponent of the entity (const version).
Manages entities in the ECS (Entity Component System).
void setScale(size_t ID, const glm::vec3 &scale)
Sets the scale of an entity.
std::optional< Raftel::LightComponent > & getLightComponent(size_t ID)
Retrieves the light component of an entity.
std::optional< MeshComponent > getMesh(size_t ID) const
Retrieves the mesh component of an entity.
void addTransformComp(size_t ID, TransformComponent &&trans)
Adds a transform component to an entity.
void constantStraightMovement(size_t ID, float speed, bool isHorizontal)
Moves an entity in a straight direction continuously.
void setPosition(size_t ID, const glm::vec3 &pos)
Sets the position of an entity.
std::optional< MeshComponent > getMeshComponent(size_t ID)
Retrieves the mesh component of an entity.
Entity CreateEntity()
Creates a new entity and returns it.
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 removeMeshComponent(size_t ID)
Removes the mesh component from an entity.
glm::vec3 getPosition(size_t ID) const
Gets the position of an entity.
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 removeScriptComp(size_t ID)
Removes the script component from 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 addLightComp(size_t ID, LightComponent &&light)
Adds a light component to an entity.
glm::vec3 getRotation(size_t ID) const
Gets the rotation of an entity.
std::optional< RenderComponent > & getRenderComponent(size_t ID)
Retrieves the render component of an entity.
void setRotation(size_t ID, const glm::vec3 &rot)
Sets the rotation of an entity.
void setMesh(size_t ID, const std::shared_ptr< Mesh > &mesh)
Assigns a mesh to an entity.
std::optional< ScriptComponent > & getScriptComponent(size_t ID)
Retrieves the script component of an entity.
void removeEntity(size_t id)
Removes an entity from the system.
const std::vector< Entity > & getActiveEntities() const
Retrieves a constant reference to the list of active entities.
bool hasMeshComponent(size_t ID) const
Checks if an entity has a mesh component.
std::optional< TransformComponent > & getTransformComponent(size_t ID)
Retrieves the transform component of an entity.
void removeTransformComp(size_t ID)
Removes the transform component from an entity.
void addRenderComp(size_t ID, RenderComponent &&rend)
Adds a render component to an entity.
glm::vec3 getScale(size_t ID) const
Gets the scale of an entity.
void addMeshComp(size_t ID, const std::shared_ptr< Mesh > &mesh)
Adds a mesh component to an entity.
void addScriptComp(size_t ID, ScriptComponent &&script)
Adds a script component to an entity.
EntityManager()
Constructs an EntityManager.
Represents a 3D mesh, including vertex data, indices, and materials.
Component that handles Lua scripting.
A class to represent an OpenGL shader program, combining vertex and fragment shaders.
Represents a light component with different light types.
Render component that determines visibility.