Minor - Start the Doxygen doc - V12.8.0
This commit is contained in:
@@ -3,6 +3,9 @@
|
||||
#include <typeindex>
|
||||
#include <typeinfo>
|
||||
|
||||
/**
|
||||
* namespace for the Entity-Component-System (ECS)
|
||||
*/
|
||||
namespace ecs {
|
||||
|
||||
// Classe de base pour tous les composants
|
||||
@@ -19,21 +22,34 @@ public:
|
||||
Component(Component&&) = default;
|
||||
Component& operator=(Component&&) = default;
|
||||
|
||||
// Fonction virtuelle pour initialiser le composant
|
||||
/**
|
||||
* Virtual function to initialize the component.
|
||||
*/
|
||||
virtual void Initialize() {}
|
||||
|
||||
// Fonction virtuelle pour la mise <20> jour du composant
|
||||
|
||||
/**
|
||||
* Virtual function to update the component.
|
||||
* @param deltaTime Time since the last update.
|
||||
*/
|
||||
virtual void Update(float deltaTime) {}
|
||||
|
||||
// virtual std::string Serialize() {}
|
||||
// virtual void Deserialize(const std::string& data) {}
|
||||
};
|
||||
|
||||
// Alias utiles
|
||||
/**
|
||||
* Type alias for a shared pointer to a Component.
|
||||
*/
|
||||
using ComponentPtr = std::shared_ptr<Component>;
|
||||
|
||||
/**
|
||||
* Type alias for a unique identifier for a component type.
|
||||
*/
|
||||
using ComponentTypeID = std::type_index;
|
||||
|
||||
// Fonction pour obtenir l'ID de type d'un composant
|
||||
/**
|
||||
* Function to get the unique type ID for a component type.
|
||||
*/
|
||||
template<typename T>
|
||||
ComponentTypeID GetComponentTypeID() {
|
||||
static_assert(std::is_base_of<Component, T>::value, "T must derive from Component");
|
||||
|
||||
@@ -3,36 +3,74 @@
|
||||
#include <string>
|
||||
|
||||
namespace ecs {
|
||||
|
||||
enum class ObjectType
|
||||
{
|
||||
Sphere,
|
||||
Cube,
|
||||
Terrain,
|
||||
Unknown
|
||||
};
|
||||
/**
|
||||
* Enum for different types of objects in the ECS.
|
||||
* The object types is used to specify the collision type of the object.
|
||||
*/
|
||||
enum class ObjectType
|
||||
{
|
||||
Sphere,
|
||||
Cube,
|
||||
Terrain,
|
||||
Unknown
|
||||
};
|
||||
|
||||
class IdentityComponent : public Component {
|
||||
public:
|
||||
/**
|
||||
* Builder for the IdentityComponent class.
|
||||
*/
|
||||
IdentityComponent() : m_id(0), m_type(ObjectType::Unknown) {}
|
||||
explicit IdentityComponent(int id) : m_id(id), m_type(ObjectType::Unknown) {}
|
||||
IdentityComponent(int id, const std::string& name) : m_id(id), m_name(name), m_type(ObjectType::Unknown) {}
|
||||
~IdentityComponent() = default;
|
||||
|
||||
/**
|
||||
* Initialize the component.
|
||||
* This method is called when the component is added to an entity.
|
||||
* It can be used to set up initial values or perform any necessary setup.
|
||||
*/
|
||||
void Initialize() override {}
|
||||
//void Update(float deltaTime) override {}
|
||||
|
||||
// Getters et setters
|
||||
|
||||
/**
|
||||
* Get the ID stored by the component.
|
||||
* @return The ID as an int.
|
||||
*/
|
||||
int GetId() const { return m_id; }
|
||||
/**
|
||||
* Set the ID for the component.
|
||||
* @param id The ID to set.
|
||||
*/
|
||||
void SetId(int id) { m_id = id; }
|
||||
|
||||
/**
|
||||
* Get the name of the object.
|
||||
* @return The name as a string.
|
||||
*/
|
||||
const std::string& GetName() const { return m_name; }
|
||||
/**
|
||||
* Set the name of the object.
|
||||
* @param name The name to set.
|
||||
*/
|
||||
void SetName(const std::string& name) { m_name = name; }
|
||||
|
||||
/**
|
||||
* Get the type of the object.
|
||||
* @return The type as an ObjectType enum.
|
||||
*/
|
||||
ObjectType GetType() const { return m_type; }
|
||||
/**
|
||||
* Set the type of the object.
|
||||
* @param type The type to set as an ObjectType enum.
|
||||
*/
|
||||
void SetType(ObjectType type) { m_type = type; }
|
||||
|
||||
// Conversions utiles
|
||||
/**
|
||||
* Convert an ObjectType to a string representation.
|
||||
* @param type The ObjectType to convert.
|
||||
* @return A string representation of the ObjectType.
|
||||
*/
|
||||
static std::string ObjectTypeToString(ObjectType type) {
|
||||
switch (type) {
|
||||
case ObjectType::Cube: return "Cube";
|
||||
@@ -42,6 +80,11 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a string representation to an ObjectType.
|
||||
* @param str The string to convert.
|
||||
* @return The corresponding ObjectType, or Unknown if the string does not match any type.
|
||||
*/
|
||||
static ObjectType StringToObjectType(const std::string& str) {
|
||||
if (str == "Cube") return ObjectType::Cube;
|
||||
if (str == "Sphere") return ObjectType::Sphere;
|
||||
@@ -50,9 +93,9 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
int m_id;
|
||||
std::string m_name;
|
||||
ObjectType m_type;
|
||||
int m_id; // ID unique de l'objet
|
||||
std::string m_name; // Nom de l'objet
|
||||
ObjectType m_type; // Type de l'objet (Cube, Sphere, Terrain, etc.)
|
||||
};
|
||||
|
||||
} // namespace ecs
|
||||
|
||||
@@ -13,8 +13,15 @@ public:
|
||||
void Initialize() override {}
|
||||
void Update(float deltaTime) override {}
|
||||
|
||||
// Getters et setters
|
||||
/**
|
||||
* Get the path of the model.
|
||||
* @return The path as a std::wstring.
|
||||
*/
|
||||
const std::wstring& GetPath() const { return m_path; }
|
||||
/**
|
||||
* Set the path of the model.
|
||||
* @param path The path to set as a std::wstring.
|
||||
*/
|
||||
void SetPath(const std::wstring& path) { m_path = path; }
|
||||
|
||||
private:
|
||||
|
||||
@@ -8,6 +8,10 @@ namespace ecs {
|
||||
|
||||
class PhysicsComponent : public Component {
|
||||
public:
|
||||
/**
|
||||
* Builder for the PhysicsComponent class.
|
||||
* Use default values for velocity, acceleration, mass, bounding radius, and grounded state.
|
||||
*/
|
||||
PhysicsComponent() {
|
||||
m_Velocity = XMVectorZero();
|
||||
m_Acceleration = XMVectorZero();
|
||||
@@ -21,10 +25,26 @@ public:
|
||||
|
||||
~PhysicsComponent() = default;
|
||||
|
||||
/**
|
||||
* Initialize the component.
|
||||
* This method is called when the component is added to an entity.
|
||||
* It can be used to set up initial values or perform any necessary setup.
|
||||
*/
|
||||
void Initialize() override {
|
||||
// Initialisation du composant physique
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the physics component.
|
||||
* This method is called every frame to update the physics state.
|
||||
*
|
||||
* This method is not the final update method
|
||||
* It will be called by the EntityManager's in the physics Thread.
|
||||
* This is due to the fact that the physics system is not updated every frame.
|
||||
* The physics thread is called at a fixed time step (50 FPS by default).
|
||||
*
|
||||
* @param deltaTime The time elapsed since the last frame.
|
||||
*/
|
||||
void Update(float deltaTime) override {
|
||||
if (!m_IsPhysicsEnabled) return;
|
||||
|
||||
@@ -37,7 +57,16 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
// Lancement d'un objet
|
||||
/**
|
||||
* Launch an object with a spring-like force.
|
||||
* This method calculates the initial velocity based on the angle, initial stretch, and spring constant.
|
||||
*
|
||||
* This method will be removed in the future
|
||||
*
|
||||
* @param alpha The launch angle in degrees.
|
||||
* @param initialStretch The initial stretch of the spring.
|
||||
* @param springConstant The spring constant.
|
||||
*/
|
||||
void LaunchObject(float alpha, float initialStretch, float springConstant) {
|
||||
// Constants
|
||||
const float gravity = -9.81f;
|
||||
@@ -72,26 +101,99 @@ public:
|
||||
SetGrounded(false);
|
||||
}
|
||||
|
||||
// Setters
|
||||
/**
|
||||
* Set the velocity of the object.
|
||||
* @param velocity
|
||||
*/
|
||||
void SetVelocity(XMVECTOR velocity) { m_Velocity = velocity; }
|
||||
/**
|
||||
* Set the acceleration of the object.
|
||||
* @param acceleration
|
||||
*/
|
||||
void SetAcceleration(XMVECTOR acceleration) { m_Acceleration = acceleration; }
|
||||
/**
|
||||
* Set the mass of the object.
|
||||
* @param mass The mass to set.
|
||||
*/
|
||||
void SetMass(float mass) { m_Mass = mass; }
|
||||
/**
|
||||
* Set the grounded state of the object.
|
||||
* @param isGrounded True if the object is grounded, false otherwise.
|
||||
*/
|
||||
void SetGrounded(bool isGrounded) { m_IsGrounded = isGrounded; }
|
||||
/**
|
||||
* Enable or disable physics for the object.
|
||||
* @param enabled True to enable physics, false to disable.
|
||||
*/
|
||||
void SetPhysicsEnabled(bool enabled) { m_IsPhysicsEnabled = enabled; }
|
||||
/**
|
||||
* Set the bounding radius of the object.
|
||||
* @param radius The bounding radius to set.
|
||||
*/
|
||||
void SetBoundingRadius(float radius) { m_BoundingRadius = radius; }
|
||||
/**
|
||||
* Set the previous position of the object.
|
||||
* @param position The previous position to set.
|
||||
*/
|
||||
void SetPreviousPosition(XMVECTOR position) { m_PreviousPosition = position; }
|
||||
/**
|
||||
* Enable or disable gravity for the object.
|
||||
* @param enabled True to enable gravity, false to disable.
|
||||
*/
|
||||
void SetGravityEnabled(bool enabled) { m_GravityEnabled = enabled; }
|
||||
/**
|
||||
* Set the callback to update the position of the object.
|
||||
* This callback will be connected to the TransformComponent to update the position.
|
||||
* @param callback The callback function that takes an XMVECTOR as a parameter.
|
||||
*/
|
||||
void SetUpdatePositionCallback(std::function<void(XMVECTOR)> callback) { m_UpdatePositionCallback = callback; }
|
||||
|
||||
// Getters
|
||||
/**
|
||||
* Get the current velocity of the object.
|
||||
* @return The velocity as an XMVECTOR.
|
||||
*/
|
||||
XMVECTOR GetVelocity() const { return m_Velocity; }
|
||||
/**
|
||||
* Get the current acceleration of the object.
|
||||
* @return The acceleration as an XMVECTOR.
|
||||
*/
|
||||
XMVECTOR GetAcceleration() const { return m_Acceleration; }
|
||||
/**
|
||||
* Get the mass of the object.
|
||||
* @return The mass as a float.
|
||||
*/
|
||||
float GetMass() const { return m_Mass; }
|
||||
/**
|
||||
* Get the grounded state of the object.
|
||||
* @return True if the object is grounded, false otherwise.
|
||||
*/
|
||||
bool IsGrounded() const { return m_IsGrounded; }
|
||||
/**
|
||||
* Check if physics is enabled for the object.
|
||||
* @return True if physics is enabled, false otherwise.
|
||||
*/
|
||||
bool IsPhysicsEnabled() const { return m_IsPhysicsEnabled; }
|
||||
/**
|
||||
* Get the bounding radius of the object.
|
||||
* @return The bounding radius as a float.
|
||||
*/
|
||||
float GetBoundingRadius() const { return m_BoundingRadius; }
|
||||
/**
|
||||
* Get the previous position of the object.
|
||||
* This is used to calculate the movement and collision detection.
|
||||
* @return The previous position as an XMVECTOR.
|
||||
*/
|
||||
XMVECTOR GetPreviousPosition() const { return m_PreviousPosition; }
|
||||
/**
|
||||
* Check if gravity is enabled for the object.
|
||||
* @return True if gravity is enabled, false otherwise.
|
||||
*/
|
||||
bool IsGravityEnabled() const { return m_GravityEnabled; }
|
||||
/**
|
||||
* Get the current position of the object.
|
||||
* This method should be connected to the TransformComponent to retrieve the current position.
|
||||
* @return The current position as an XMVECTOR.
|
||||
*/
|
||||
|
||||
private:
|
||||
XMVECTOR m_Velocity;
|
||||
|
||||
@@ -7,35 +7,57 @@
|
||||
#include <WICTextureLoader.h>
|
||||
|
||||
// D<>claration externe de la variable globale d<>finie dans application_class.h
|
||||
/**
|
||||
* Declaration of the global model cache externe variable from application_class.h .
|
||||
* This variable is used to cache models loaded from files to avoid reloading them multiple times.
|
||||
*/
|
||||
extern std::map<std::string, std::shared_ptr<model_class>> g_model_cache;
|
||||
|
||||
namespace ecs {
|
||||
|
||||
enum class TextureType
|
||||
{
|
||||
Diffuse,
|
||||
Normal,
|
||||
Specular,
|
||||
Alpha,
|
||||
Reflection
|
||||
};
|
||||
/**
|
||||
* Enum for different types of textures used in rendering.
|
||||
*/
|
||||
enum class TextureType
|
||||
{
|
||||
Diffuse,
|
||||
Normal,
|
||||
Specular,
|
||||
Alpha,
|
||||
Reflection
|
||||
};
|
||||
|
||||
class RenderComponent : public Component {
|
||||
public:
|
||||
/**
|
||||
* Builder for the RenderComponent class.
|
||||
*/
|
||||
RenderComponent() : m_model(nullptr), m_isVisible(true) {}
|
||||
~RenderComponent() = default;
|
||||
|
||||
void Initialize() override {}
|
||||
void Update(float deltaTime) override {}
|
||||
|
||||
// Initialisation avec un mod<6F>le existant
|
||||
/**
|
||||
* Initialize the RenderComponent with a model.
|
||||
* This method allows the component to be initialized with an existing model instance.
|
||||
* @param model A shared pointer to the model_class instance to use.
|
||||
* @return True if initialization was successful, false otherwise.
|
||||
*/
|
||||
bool InitializeWithModel(std::shared_ptr<model_class> model) {
|
||||
if (!model) return false;
|
||||
m_model = model;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Initialisation avec un chemin de fichier
|
||||
/**
|
||||
* Initialize the RenderComponent from a model file.
|
||||
* This method checks if the model is already cached; if not, it loads the model from the specified file.
|
||||
* @param device The Direct3D device used for rendering.
|
||||
* @param deviceContext The Direct3D device context used for rendering.
|
||||
* @param modelFilename The path to the model file to load.
|
||||
* @param textureContainer The container for textures used by the model.
|
||||
* @return True if initialization was successful, false otherwise.
|
||||
*/
|
||||
bool InitializeFromFile(ID3D11Device* device, ID3D11DeviceContext* deviceContext,
|
||||
const char* modelFilename, TextureContainer& textureContainer) {
|
||||
// V<>rifier si le mod<6F>le existe d<>j<EFBFBD> dans le cache
|
||||
@@ -57,7 +79,15 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
// Charger des textures depuis un chemin
|
||||
/**
|
||||
* Load textures from a list of file paths into the texture container.
|
||||
* This method uses DirectX's WIC texture loader to load textures from the specified paths.
|
||||
* @param texturePaths A vector of file paths to the textures to load.
|
||||
* @param texturesContainer The container where the loaded textures will be stored.
|
||||
* @param device The Direct3D device used for rendering.
|
||||
* @param deviceContext The Direct3D device context used for rendering.
|
||||
* @return True if all textures were loaded successfully, false otherwise.
|
||||
*/
|
||||
bool LoadTexturesFromPath(std::vector<std::wstring>& texturePaths, TextureContainer& texturesContainer,
|
||||
ID3D11Device* device, ID3D11DeviceContext* deviceContext) {
|
||||
HRESULT result;
|
||||
@@ -76,17 +106,49 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
// Getters et setters
|
||||
/**
|
||||
* Get the model associated with this RenderComponent.
|
||||
* @return A shared pointer to the model_class instance.
|
||||
*/
|
||||
std::shared_ptr<model_class> GetModel() const { return m_model; }
|
||||
/**
|
||||
* Set the model for this RenderComponent.
|
||||
* This method allows the component to be set with an existing model instance.
|
||||
* @param model A shared pointer to the model_class instance to set.
|
||||
*/
|
||||
void SetModel(std::shared_ptr<model_class> model) { m_model = model; }
|
||||
|
||||
/**
|
||||
* Get the file path of the model associated with this RenderComponent.
|
||||
* @return The file path as a string.
|
||||
*/
|
||||
const std::string& GetModelFilePath() const { return m_modelFilePath; }
|
||||
/**
|
||||
* Set the file path of the model for this RenderComponent.
|
||||
* This method allows the component to be set with a specific model file path.
|
||||
* @param path The file path to set as a string.
|
||||
*/
|
||||
void SetModelFilePath(const std::string& path) { m_modelFilePath = path; }
|
||||
|
||||
/**
|
||||
* Check if the model is currently visible.
|
||||
* @return True if the model is visible, false otherwise.
|
||||
*/
|
||||
bool IsVisible() const { return m_isVisible; }
|
||||
/**
|
||||
* Set the visibility of the model.
|
||||
* This method allows the component to control whether the model should be rendered or not.
|
||||
* @param visible True to make the model visible, false to hide it.
|
||||
*/
|
||||
void SetVisible(bool visible) { m_isVisible = visible; }
|
||||
|
||||
// Acc<63>s aux textures
|
||||
/**
|
||||
* Get a texture of a specific type by index.
|
||||
* This method retrieves the texture from the model based on the specified type and index.
|
||||
* @param type The type of texture to retrieve (Diffuse, Normal, Specular, Alpha).
|
||||
* @param index The index of the texture to retrieve (default is 0).
|
||||
* @return A pointer to the ID3D11ShaderResourceView of the texture, or nullptr if not found.
|
||||
*/
|
||||
ID3D11ShaderResourceView* GetTexture(TextureType type, int index = 0) {
|
||||
if (!m_model) return nullptr;
|
||||
|
||||
@@ -104,11 +166,20 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
// Pour le rendu
|
||||
/**
|
||||
* Get the number of vertices in the model.
|
||||
* This method retrieves the vertex count from the model.
|
||||
* @return The number of vertices as an integer.
|
||||
*/
|
||||
int GetIndexCount() const {
|
||||
return m_model ? m_model->GetIndexCount() : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the model using the provided device context.
|
||||
* This method calls the Render method of the model if it is initialized and visible.
|
||||
* @param deviceContext The Direct3D device context used for rendering.
|
||||
*/
|
||||
void Render(ID3D11DeviceContext* deviceContext) {
|
||||
if (m_model && m_isVisible) {
|
||||
m_model->Render(deviceContext);
|
||||
|
||||
@@ -3,6 +3,10 @@
|
||||
|
||||
namespace ecs {
|
||||
|
||||
/**
|
||||
* Enum for different shader types used in rendering.
|
||||
* This enum is used to specify the type of shader to be applied to a model.
|
||||
*/
|
||||
enum class ShaderType
|
||||
{
|
||||
CEL_SHADING,
|
||||
@@ -19,17 +23,35 @@ enum class ShaderType
|
||||
|
||||
class ShaderComponent : public Component {
|
||||
public:
|
||||
|
||||
/**
|
||||
* Builder for the ShaderComponent class.
|
||||
* Initializes the active shader to LIGHTING by default.
|
||||
*/
|
||||
ShaderComponent() : m_activeShader(ShaderType::LIGHTING) {}
|
||||
~ShaderComponent() = default;
|
||||
|
||||
void Initialize() override {}
|
||||
void Update(float deltaTime) override {}
|
||||
|
||||
// Getters et setters
|
||||
/**
|
||||
* Get the currently active shader type.
|
||||
* @return The active shader type as a ShaderType enum.
|
||||
*/
|
||||
ShaderType GetActiveShader() const { return m_activeShader; }
|
||||
/**
|
||||
* Set the active shader type.
|
||||
* This method allows changing the shader type used for rendering.
|
||||
* @param shader The shader type to set as a ShaderType enum.
|
||||
*/
|
||||
void SetActiveShader(ShaderType shader) { m_activeShader = shader; }
|
||||
|
||||
// Conversions utiles
|
||||
/**
|
||||
* Set the active shader type from a string.
|
||||
* This method converts a string representation of a shader type to the corresponding ShaderType enum.
|
||||
* @param shaderName The name of the shader type as a string.
|
||||
* @return The ShaderType enum corresponding to the provided string.
|
||||
*/
|
||||
static ShaderType StringToShaderType(const std::string& str) {
|
||||
if (str == "ALPHA_MAPPING") return ShaderType::ALPHA_MAPPING;
|
||||
if (str == "CEL_SHADING") return ShaderType::CEL_SHADING;
|
||||
@@ -44,6 +66,12 @@ public:
|
||||
return ShaderType::TEXTURE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a ShaderType enum to its string representation.
|
||||
* This method provides a string name for each shader type.
|
||||
* @param type The shader type as a ShaderType enum.
|
||||
* @return The name of the shader type as a string.
|
||||
*/
|
||||
static std::string ShaderTypeToString(ShaderType type) {
|
||||
switch (type) {
|
||||
case ShaderType::ALPHA_MAPPING: return "ALPHA_MAPPING";
|
||||
|
||||
@@ -8,6 +8,11 @@ namespace ecs {
|
||||
|
||||
class TransformComponent : public Component {
|
||||
public:
|
||||
|
||||
/**
|
||||
* Builder for the TransformComponent class.
|
||||
* Initializes the matrices to identity matrices.
|
||||
*/
|
||||
TransformComponent() {
|
||||
m_ScaleMatrix = XMMatrixIdentity();
|
||||
m_RotateMatrix = XMMatrixIdentity();
|
||||
@@ -17,7 +22,10 @@ public:
|
||||
|
||||
~TransformComponent() = default;
|
||||
|
||||
// M<>thodes pour les matrices
|
||||
/**
|
||||
* Set the position of the object in world space.
|
||||
* @param position
|
||||
*/
|
||||
void SetPosition(XMVECTOR position) {
|
||||
XMFLOAT4X4 matrix;
|
||||
XMStoreFloat4x4(&matrix, m_TranslateMatrix);
|
||||
@@ -28,11 +36,19 @@ public:
|
||||
UpdateWorldMatrix();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the rotation of the object in world space.
|
||||
* @param rotation The rotation as an XMVECTOR (roll, pitch, yaw).
|
||||
*/
|
||||
void SetRotation(XMVECTOR rotation) {
|
||||
m_RotateMatrix = XMMatrixRotationRollPitchYawFromVector(rotation);
|
||||
UpdateWorldMatrix();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the scale of the object in world space.
|
||||
* @param scale The scale as an XMVECTOR (x, y, z).
|
||||
*/
|
||||
void SetScale(XMVECTOR scale) {
|
||||
XMFLOAT4X4 matrix;
|
||||
XMStoreFloat4x4(&matrix, m_ScaleMatrix);
|
||||
@@ -43,12 +59,20 @@ public:
|
||||
UpdateWorldMatrix();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the position of the object in world space.
|
||||
* @return The position as an XMVECTOR (x, y, z, (w is O.0f)).
|
||||
*/
|
||||
XMVECTOR GetPosition() const {
|
||||
XMFLOAT4X4 matrix;
|
||||
XMStoreFloat4x4(&matrix, m_TranslateMatrix);
|
||||
return XMVectorSet(matrix._41, matrix._42, matrix._43, 0.0f);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the rotation of the object in world space.
|
||||
* @return The rotation as an XMVECTOR (roll, pitch, yaw, (w is O.0f)).
|
||||
*/
|
||||
XMVECTOR GetRotation() const {
|
||||
XMFLOAT4X4 matrix;
|
||||
XMStoreFloat4x4(&matrix, m_RotateMatrix);
|
||||
@@ -58,6 +82,10 @@ public:
|
||||
return XMVectorSet(rotationX, rotationY, rotationZ, 0.0f);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the scale of the object in world space.
|
||||
* @return The scale as an XMVECTOR (x, y, z, (w is O.0f)).
|
||||
*/
|
||||
XMVECTOR GetScale() const {
|
||||
XMFLOAT4X4 matrix;
|
||||
XMStoreFloat4x4(&matrix, m_ScaleMatrix);
|
||||
@@ -76,19 +104,53 @@ public:
|
||||
return scale;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the world matrix based on the current scale, rotation, and translation matrices.
|
||||
* This method is called whenever one of the matrices is modified.
|
||||
*/
|
||||
void UpdateWorldMatrix() {
|
||||
m_WorldMatrix = m_ScaleMatrix * m_RotateMatrix * m_TranslateMatrix;
|
||||
}
|
||||
|
||||
// Getters pour les matrices
|
||||
/**
|
||||
* Get the scale matrix.
|
||||
* @return The scale matrix as an XMMATRIX.
|
||||
*/
|
||||
XMMATRIX GetScaleMatrix() const { return m_ScaleMatrix; }
|
||||
/**
|
||||
* Get the rotation matrix.
|
||||
* @return The rotation matrix as an XMMATRIX.
|
||||
*/
|
||||
XMMATRIX GetRotateMatrix() const { return m_RotateMatrix; }
|
||||
/**
|
||||
* Get the translation matrix.
|
||||
* @return The translation matrix as an XMMATRIX.
|
||||
*/
|
||||
XMMATRIX GetTranslateMatrix() const { return m_TranslateMatrix; }
|
||||
/**
|
||||
* Get the world matrix.
|
||||
* This matrix combines scale, rotation, and translation to represent the object's position in world space.
|
||||
* @return The world matrix as an XMMATRIX.
|
||||
*/
|
||||
XMMATRIX GetWorldMatrix() const { return m_WorldMatrix; }
|
||||
|
||||
// Setters pour les matrices
|
||||
/**
|
||||
* Set the scale matrix directly.
|
||||
* This method allows setting the scale matrix without modifying the individual scale components.
|
||||
* @param matrix The scale matrix to set as an XMMATRIX.
|
||||
*/
|
||||
void SetScaleMatrix(XMMATRIX matrix) { m_ScaleMatrix = matrix; UpdateWorldMatrix(); }
|
||||
/**
|
||||
* Set the rotation matrix directly.
|
||||
* This method allows setting the rotation matrix without modifying the individual rotation components.
|
||||
* @param matrix The rotation matrix to set as an XMMATRIX.
|
||||
*/
|
||||
void SetRotateMatrix(XMMATRIX matrix) { m_RotateMatrix = matrix; UpdateWorldMatrix(); }
|
||||
/**
|
||||
* Set the translation matrix directly.
|
||||
* This method allows setting the translation matrix without modifying the individual translation components.
|
||||
* @param matrix The translation matrix to set as an XMMATRIX.
|
||||
*/
|
||||
void SetTranslateMatrix(XMMATRIX matrix) { m_TranslateMatrix = matrix; UpdateWorldMatrix(); }
|
||||
|
||||
private:
|
||||
|
||||
@@ -7,27 +7,44 @@
|
||||
#include <cassert>
|
||||
|
||||
namespace ecs {
|
||||
|
||||
// Identifiant unique pour les entit<EFBFBD>s
|
||||
using EntityID = uint32_t;
|
||||
/**
|
||||
* Type alias for a unique identifier for an entity.
|
||||
*/
|
||||
using EntityID = uint32_t;
|
||||
|
||||
class Entity {
|
||||
public:
|
||||
/**
|
||||
* Builder for an Entity with a unique ID.
|
||||
*/
|
||||
explicit Entity(EntityID id) : m_ID(id) {}
|
||||
~Entity() = default;
|
||||
|
||||
// Emp<6D>cher la copie
|
||||
/**
|
||||
* No copy constructor or assignment operator to prevent copying.
|
||||
*/
|
||||
Entity(const Entity&) = delete;
|
||||
Entity& operator=(const Entity&) = delete;
|
||||
|
||||
// Permettre le d<>placement
|
||||
/**
|
||||
* Move constructor and assignment operator to allow moving entities.
|
||||
*/
|
||||
Entity(Entity&&) = default;
|
||||
Entity& operator=(Entity&&) = default;
|
||||
|
||||
// Getter pour l'ID
|
||||
/**
|
||||
* Get the unique identifier for the entity.
|
||||
* @return The unique ID of the entity.
|
||||
*/
|
||||
EntityID GetID() const { return m_ID; }
|
||||
|
||||
// Ajouter un composant
|
||||
/**
|
||||
* Add a component of type T to the entity.
|
||||
* If the component already exists, it returns the existing component.
|
||||
* @tparam T
|
||||
* @param args Arguments to construct the component.
|
||||
* @return A shared pointer to the added or existing component.
|
||||
*/
|
||||
template<typename T, typename... Args>
|
||||
std::shared_ptr<T> AddComponent(Args&&... args) {
|
||||
static_assert(std::is_base_of<Component, T>::value, "T must derive from Component");
|
||||
@@ -49,7 +66,11 @@ public:
|
||||
return component;
|
||||
}
|
||||
|
||||
// R<>cup<75>rer un composant
|
||||
/**
|
||||
* Get a component of type T from the entity.
|
||||
* @tparam T
|
||||
* @return A shared pointer to the component if it exists, nullptr otherwise.
|
||||
*/
|
||||
template<typename T>
|
||||
std::shared_ptr<T> GetComponent() {
|
||||
static_assert(std::is_base_of<Component, T>::value, "T must derive from Component");
|
||||
@@ -64,7 +85,11 @@ public:
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// V<>rifier si l'entit<69> poss<73>de un composant
|
||||
/**
|
||||
* Check if the entity has a component of type T.
|
||||
* @tparam T
|
||||
* @return true if the entity has the component, false otherwise.
|
||||
*/
|
||||
template<typename T>
|
||||
bool HasComponent() const {
|
||||
static_assert(std::is_base_of<Component, T>::value, "T must derive from Component");
|
||||
@@ -73,7 +98,10 @@ public:
|
||||
return m_Components.find(typeID) != m_Components.end();
|
||||
}
|
||||
|
||||
// Supprimer un composant
|
||||
/**
|
||||
* Remove a component of type T from the entity.
|
||||
* @tparam T
|
||||
*/
|
||||
template<typename T>
|
||||
void RemoveComponent() {
|
||||
static_assert(std::is_base_of<Component, T>::value, "T must derive from Component");
|
||||
@@ -86,7 +114,10 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
// Mettre <20> jour tous les composants
|
||||
/**
|
||||
* Update all components of the entity.
|
||||
* @param deltaTime
|
||||
*/
|
||||
void UpdateComponents(float deltaTime) {
|
||||
for (auto& [typeID, component] : m_Components) {
|
||||
component->Update(deltaTime);
|
||||
@@ -94,7 +125,15 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* Unique identifier for the entity.
|
||||
*/
|
||||
EntityID m_ID;
|
||||
/**
|
||||
* Map to hold components associated with the entity.
|
||||
* The key is the type ID of the component, and the value is a shared pointer to the component.
|
||||
*/
|
||||
std::unordered_map<ComponentTypeID, ComponentPtr> m_Components;
|
||||
};
|
||||
|
||||
|
||||
@@ -8,10 +8,17 @@ namespace ecs {
|
||||
|
||||
class EntityManager {
|
||||
public:
|
||||
|
||||
/**
|
||||
* @brief Type pour l'ID d'une entit<69>
|
||||
*/
|
||||
EntityManager() : m_NextEntityID(0) {}
|
||||
~EntityManager() = default;
|
||||
|
||||
// Cr<43>er une nouvelle entit<69>
|
||||
/**
|
||||
* Create a new entity.
|
||||
* @return A shared pointer to the newly created entity.
|
||||
*/
|
||||
std::shared_ptr<Entity> CreateEntity() {
|
||||
EntityID id;
|
||||
|
||||
@@ -29,7 +36,10 @@ public:
|
||||
return entity;
|
||||
}
|
||||
|
||||
// Supprimer une entit<69>
|
||||
/**
|
||||
* Destroy an entity by its ID and recycle its ID for future use.
|
||||
* @param id The ID of the entity to destroy.
|
||||
*/
|
||||
void DestroyEntity(EntityID id) {
|
||||
auto it = m_Entities.find(id);
|
||||
if (it != m_Entities.end()) {
|
||||
@@ -38,7 +48,11 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
// Obtenir une entit<69> par son ID
|
||||
/**
|
||||
* Get an entity by its ID.
|
||||
* @param id The ID of the entity to retrieve.
|
||||
* @return A shared pointer to the entity, or nullptr if it does not exist.
|
||||
*/
|
||||
std::shared_ptr<Entity> GetEntity(EntityID id) {
|
||||
auto it = m_Entities.find(id);
|
||||
if (it != m_Entities.end()) {
|
||||
@@ -47,14 +61,20 @@ public:
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Mettre <20> jour toutes les entit<69>s
|
||||
/**
|
||||
* Update all entities by calling their UpdateComponents method.
|
||||
* @param deltaTime The time elapsed since the last update.
|
||||
*/
|
||||
void UpdateEntities(float deltaTime) {
|
||||
for (auto& [id, entity] : m_Entities) {
|
||||
entity->UpdateComponents(deltaTime);
|
||||
}
|
||||
}
|
||||
|
||||
// Obtenir toutes les entit<69>s
|
||||
/**
|
||||
* Get all entities managed by the EntityManager.
|
||||
* @return A vector of shared pointers to all entities.
|
||||
*/
|
||||
std::vector<std::shared_ptr<Entity>> GetAllEntities() {
|
||||
std::vector<std::shared_ptr<Entity>> result;
|
||||
result.reserve(m_Entities.size());
|
||||
@@ -66,7 +86,11 @@ public:
|
||||
return result;
|
||||
}
|
||||
|
||||
// Obtenir toutes les entit<69>s qui ont un composant sp<73>cifique
|
||||
/**
|
||||
* Get all entities that have a specific component type.
|
||||
* @tparam T The component type to filter entities by.
|
||||
* @return A vector of shared pointers to entities that have the specified component.
|
||||
*/
|
||||
template<typename T>
|
||||
std::vector<std::shared_ptr<Entity>> GetEntitiesWithComponent() {
|
||||
static_assert(std::is_base_of<Component, T>::value, "T must derive from Component");
|
||||
@@ -82,12 +106,18 @@ public:
|
||||
return result;
|
||||
}
|
||||
|
||||
// Obtenir le nombre d'entit<69>s
|
||||
/**
|
||||
* Get the total number of entities managed by the EntityManager.
|
||||
* @return The count of entities.
|
||||
*/
|
||||
size_t GetEntityCount() const {
|
||||
return m_Entities.size();
|
||||
}
|
||||
|
||||
// Vider toutes les entit<69>s
|
||||
/**
|
||||
* Clear all entities and reset the EntityManager.
|
||||
* This will remove all entities and free their IDs for future use.
|
||||
*/
|
||||
void Clear() {
|
||||
m_Entities.clear();
|
||||
|
||||
|
||||
@@ -10,10 +10,31 @@ namespace ecs {
|
||||
|
||||
class RenderSystem {
|
||||
public:
|
||||
/**
|
||||
* Builder for the RenderSystem class.
|
||||
* This class is responsible for rendering entities with the necessary components.
|
||||
* @param deviceContext
|
||||
* @param shaderManager
|
||||
*/
|
||||
RenderSystem(ID3D11DeviceContext* deviceContext, shader_manager_class* shaderManager)
|
||||
: m_deviceContext(deviceContext), m_shaderManager(shaderManager) {}
|
||||
|
||||
// Rendu d'une entit<69> sp<73>cifique
|
||||
/**
|
||||
* Render an entity with the necessary components.
|
||||
* This method checks if the entity has the required components and renders it using the appropriate shader.
|
||||
* @param entity The entity to render.
|
||||
* @param viewMatrix The view matrix for rendering.
|
||||
* @param projectionMatrix The projection matrix for rendering.
|
||||
* @param diffuseColors Array of diffuse colors for lighting.
|
||||
* @param lightPositions Array of light positions for lighting.
|
||||
* @param ambientColors Array of ambient colors for lighting.
|
||||
* @param cameraPosition The position of the camera in world space.
|
||||
* @param sunlightDiffuse The diffuse color of sunlight.
|
||||
* @param sunlightAmbient The ambient color of sunlight.
|
||||
* @param sunlightDirection The direction of sunlight in world space.
|
||||
* @param sunlightIntensity The intensity of sunlight.
|
||||
* @return True if rendering was successful, false otherwise.
|
||||
*/
|
||||
bool RenderEntity(std::shared_ptr<Entity> entity,
|
||||
const DirectX::XMMATRIX& viewMatrix,
|
||||
const DirectX::XMMATRIX& projectionMatrix,
|
||||
@@ -174,7 +195,22 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
// Rendu de toutes les entit<69>s avec les composants n<>cessaires
|
||||
/**
|
||||
* Render all entities in the EntityManager that have the necessary components.
|
||||
* This method iterates through all entities and renders them if they have the required components.
|
||||
* @param entityManager The EntityManager containing the entities to render.
|
||||
* @param viewMatrix The view matrix for rendering.
|
||||
* @param projectionMatrix The projection matrix for rendering.
|
||||
* @param diffuseColors Array of diffuse colors for lighting.
|
||||
* @param lightPositions Array of light positions for lighting.
|
||||
* @param ambientColors Array of ambient colors for lighting.
|
||||
* @param cameraPos The position of the camera in world space.
|
||||
* @param sunlightDiffuse The diffuse color of sunlight.
|
||||
* @param sunlightAmbient The ambient color of sunlight.
|
||||
* @param sunlightDirection The direction of sunlight in world space.
|
||||
* @param sunlightIntensity The intensity of sunlight.
|
||||
* @return The number of entities rendered successfully.
|
||||
*/
|
||||
int RenderAllEntities(EntityManager* entityManager,
|
||||
const DirectX::XMMATRIX& viewMatrix,
|
||||
const DirectX::XMMATRIX& projectionMatrix,
|
||||
|
||||
Reference in New Issue
Block a user