Minor - Start the Doxygen doc - V12.8.0
This commit is contained in:
@@ -31,7 +31,7 @@ public:
|
||||
alpha_map_shader_class();
|
||||
alpha_map_shader_class(const alpha_map_shader_class&);
|
||||
~alpha_map_shader_class();
|
||||
|
||||
|
||||
bool initialize(ID3D11Device*, HWND);
|
||||
void shutdown();
|
||||
bool render(ID3D11DeviceContext*, int, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*, ID3D11ShaderResourceView*, ID3D11ShaderResourceView*);
|
||||
|
@@ -78,58 +78,228 @@ struct input
|
||||
class application_class
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Constructor for the application class.
|
||||
* Initializes member variables and sets up the application.
|
||||
*/
|
||||
application_class();
|
||||
~application_class();
|
||||
virtual d_3d_class* get_direct_3d();
|
||||
void set_direct_3d(d_3d_class* direct_3d) { direct_3d_ = direct_3d; };
|
||||
|
||||
|
||||
/**
|
||||
* Get the scene texture, which is used for rendering the scene.
|
||||
* @return Pointer to the scene texture.
|
||||
*/
|
||||
render_texture_class* get_scene_texture() const { return scene_texture_; };
|
||||
/**
|
||||
* Get the display plane used for rendering.
|
||||
* @return Pointer to the display plane.
|
||||
*/
|
||||
render_texture_class* get_render_texture() const { return render_texture_; };
|
||||
/**
|
||||
* Get the refraction texture used for rendering water effects.
|
||||
* @return Pointer to the refraction texture.
|
||||
*/
|
||||
render_texture_class* get_refraction_texture() const { return refraction_texture_; };
|
||||
/**
|
||||
* Get the reflection texture used for rendering reflections.
|
||||
* @return Pointer to the reflection texture.
|
||||
*/
|
||||
render_texture_class* get_reflection_texture() const { return reflection_texture_; };
|
||||
|
||||
/**
|
||||
* @brief Create a big cube with a specified number of little cube per sides.
|
||||
* @param side_count The number of cubes per sides for the big cube.
|
||||
* @return True if the cube was created successfully, false otherwise.
|
||||
*/
|
||||
bool create_big_cube(int side_count);
|
||||
virtual bool initialize(int, int, HWND, bool is_vulkan);
|
||||
/**
|
||||
* initialize the application with the given parameters.
|
||||
*
|
||||
* @param screen_width The width of the screen.
|
||||
* @param screen_height The height of the screen.
|
||||
* @param hwdn The handle to the window.
|
||||
* @param is_vulkan Whether to use Vulkan for rendering.
|
||||
* @return True if the initialization was successful, false otherwise.
|
||||
*/
|
||||
virtual bool initialize(int screen_width, int screen_height, HWND hwdn, bool is_vulkan);
|
||||
/**
|
||||
* Shutdown the application and release resources.
|
||||
*/
|
||||
void shutdown();
|
||||
/**
|
||||
* @brief Run the main loop of the application.
|
||||
* This function will handle the main loop, including rendering and updating the application.
|
||||
* @return True if the application should continue running, false if it should quit.
|
||||
*/
|
||||
virtual bool frame(input_class*);
|
||||
/**
|
||||
* @brief Thread function for handling physics updates.
|
||||
* this function will run in a separate thread to handle physics updates at a fixed rate (50 fps by default).
|
||||
*/
|
||||
void physics_thread_function();
|
||||
/**
|
||||
* Get the physics tick rate.
|
||||
* @return The physics tick rate in frames per second as an integer.
|
||||
*/
|
||||
int get_physics_tick_rate() const { return physics_tick_rate_; };
|
||||
/**
|
||||
* Set the physics tick rate.
|
||||
* @param physics_tick_rate The new physics tick rate in frames per second.
|
||||
*/
|
||||
void set_physics_tick_rate(int physics_tick_rate) { physics_tick_rate_ = physics_tick_rate; };
|
||||
|
||||
/**
|
||||
* Get the screen width.
|
||||
* @return The width of the screen in pixels as an integer.
|
||||
*/
|
||||
int get_screen_width() const;
|
||||
/**
|
||||
* Set the screen width.
|
||||
* @param screen_width The new width of the screen in pixels as an integer.
|
||||
*/
|
||||
void set_screen_width(int screen_width);
|
||||
/**
|
||||
* Get the screen height.
|
||||
* @return The height of the screen in pixels as an integer.
|
||||
*/
|
||||
int get_screen_height() const;
|
||||
/**
|
||||
* Set the screen height.
|
||||
* @param screen_height The new height of the screen in pixels as an integer.
|
||||
*/
|
||||
void set_screen_height(int screen_height);
|
||||
|
||||
/**
|
||||
* Get the speed value.
|
||||
* An old value used for the demo spinning object.
|
||||
* This value is not used in the current implementation.
|
||||
* @return The speed value as a float.
|
||||
*/
|
||||
float get_speed() const { return speed_; };
|
||||
/**
|
||||
* Set the speed value.
|
||||
* An old value used for the demo spinning object.
|
||||
* This value is not used in the current implementation.
|
||||
* @param speed The new speed value as a float.
|
||||
*/
|
||||
void set_speed(const float speed) { this->speed_ = speed; };
|
||||
|
||||
|
||||
/**
|
||||
* Add a basic cube to the scene.
|
||||
*/
|
||||
void add_cube();
|
||||
/**
|
||||
* Delete an entity by its ID.
|
||||
* @param entity_id The ID of the entity to delete.
|
||||
*/
|
||||
void delete_entity_by_id(int entity_id);
|
||||
/**
|
||||
* Create a new entity with the specified model path.
|
||||
* @param filepath
|
||||
*/
|
||||
void add_kobject(std::wstring& filepath);
|
||||
/**
|
||||
* Set the executable path of the engine.
|
||||
* @param path
|
||||
*/
|
||||
void set_path(WCHAR* path) { path_ = path; };
|
||||
/**
|
||||
* Set the working folder of the engine.
|
||||
*/
|
||||
void set_w_folder(const std::filesystem::path& w_folder) { w_folder_ = w_folder; };
|
||||
/**
|
||||
* Get the working folder of the engine.
|
||||
* @return The working folder as a std::filesystem::path.
|
||||
*/
|
||||
std::filesystem::path get_w_folder() const { return w_folder_; };
|
||||
/**
|
||||
* Get the number of entities with the ObjectType set as Terrain in the scene.
|
||||
* @return The count of terrain entities as an integer.
|
||||
*/
|
||||
int get_terrain_entity_count();
|
||||
|
||||
/**
|
||||
* Get the object ID.
|
||||
* @return The object ID as an integer.
|
||||
*/
|
||||
int get_object_id() const { return object_id_; };
|
||||
/**
|
||||
* Set the object ID.
|
||||
* @param object_id The new object ID as an integer.
|
||||
*/
|
||||
void set_object_id(int object_id) { object_id_ = object_id; };
|
||||
|
||||
/**
|
||||
* Generate a flat terrain for test purposes using plane entities.
|
||||
*/
|
||||
void generate_terrain();
|
||||
/**
|
||||
* Delete the flat terrain/Big Cubes from the scene.
|
||||
*/
|
||||
void delete_terrain();
|
||||
|
||||
/**
|
||||
* Get the position for a specific light index.
|
||||
* @param index
|
||||
* @return The position of the light as an XMVECTOR.
|
||||
*/
|
||||
XMVECTOR get_light_position(int index);
|
||||
/**
|
||||
* Get the color for a specific light index.
|
||||
* @param index
|
||||
* @return The color of the light as an XMVECTOR.
|
||||
*/
|
||||
XMVECTOR get_light_color(int index);
|
||||
/**
|
||||
* Set the position for a specific light index.
|
||||
* @param index The index of the light to set the position for.
|
||||
* @param position The new position as an XMVECTOR.
|
||||
*/
|
||||
void set_light_position(int index, XMVECTOR position);
|
||||
/**
|
||||
* Set the color for a specific light index.
|
||||
* @param index The index of the light to set the color for.
|
||||
* @param color The new color as an XMVECTOR.
|
||||
*/
|
||||
void set_light_color(int index, XMVECTOR color);
|
||||
/**
|
||||
* Get all the lights in the scene.
|
||||
* @return A vector of pointers to light_class objects representing the lights in the scene.
|
||||
*/
|
||||
std::vector<light_class*> get_lights() const { return lights_; };
|
||||
/**
|
||||
* Get the sun light in the scene.
|
||||
* @return The sun light as a pointer to a light_class object.
|
||||
*/
|
||||
light_class* get_sun_light() const { return sun_light_; };
|
||||
|
||||
/**
|
||||
* Get the should_quit flag.
|
||||
* This flag indicates whether the application should quit.
|
||||
* @return The should_quit flag as a boolean.
|
||||
*/
|
||||
bool get_should_quit() const { return should_quit_; };
|
||||
/**
|
||||
* Set the should_quit flag.
|
||||
* This flag indicates whether the application should quit.
|
||||
* @param should_quit The new value for the should_quit flag as a boolean.
|
||||
*/
|
||||
void set_should_quit(const bool should_quit) { should_quit_ = should_quit; };
|
||||
|
||||
/**
|
||||
* Set the cel shading mode.
|
||||
* This function isn't used in the current implementation.
|
||||
* It's an old function that was used for cel shading effects before the complete implementation of the cel shading shader.
|
||||
* @param enable
|
||||
*/
|
||||
void set_cel_shading(const bool enable) { enable_cel_shading_ = enable; };
|
||||
|
||||
/**
|
||||
* Set the V-sync state.
|
||||
* @param vsync
|
||||
*/
|
||||
void set_vsync(bool vsync) {
|
||||
vsync_enabled_ = vsync;
|
||||
if (direct_3d_) {
|
||||
@@ -137,58 +307,226 @@ public:
|
||||
Logger::Get().Log("Setting Vsync to " + std::to_string(vsync), __FILE__, __LINE__);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the V-sync state.
|
||||
* @return The V-sync state as a boolean.
|
||||
*/
|
||||
bool get_vsync() const { return vsync_enabled_; };
|
||||
|
||||
/**
|
||||
* Get the handle to the window.
|
||||
* @return The handle to the window as an HWND.
|
||||
*/
|
||||
HWND get_hwnd() const { return hwnd_; };
|
||||
/**
|
||||
* Set the handle to the window.
|
||||
* @param hwnd The new handle to the window as an HWND.
|
||||
*/
|
||||
void set_hwnd(HWND hwnd) { hwnd_ = hwnd; };
|
||||
|
||||
/**
|
||||
* Check if the application is running in windowed mode.
|
||||
* @return True if the application is in windowed mode, false otherwise.
|
||||
*/
|
||||
bool is_windowed() const { return windowed_; };
|
||||
/**
|
||||
* Set the windowed mode state.
|
||||
* @param windowed True to set the application in windowed mode, false for full screen.
|
||||
*/
|
||||
void set_windowed(bool windowed) { windowed_ = windowed; };
|
||||
|
||||
/**
|
||||
* Set the window size for an ImGui window.
|
||||
* This isn't used in the current implementation.
|
||||
* @param size
|
||||
*/
|
||||
void set_window_size(const ImVec2 size) { window_size_ = size; };
|
||||
/**
|
||||
* Get the window size for an ImGui window.
|
||||
* This isn't used in the current implementation.
|
||||
* @return The window size as an ImVec2.
|
||||
*/
|
||||
ImVec2 get_window_size() const { return window_size_; };
|
||||
/**
|
||||
* Get the aspect ratio of the screen.
|
||||
* @return The aspect ratio as a float.
|
||||
*/
|
||||
float get_aspect_ratio() const { return static_cast<float>(screen_width_) / static_cast<float>(screen_height_); };
|
||||
|
||||
/**
|
||||
* Get the physics engine instance.
|
||||
* @return Pointer to the physics engine instance.
|
||||
*/
|
||||
physics* get_physics() const { return physics_; };
|
||||
|
||||
// ----------------------------------- //
|
||||
// ------------- Culling ------------- //
|
||||
// ----------------------------------- //
|
||||
|
||||
/**
|
||||
* Get the frustum used for culling.
|
||||
* @return The frustum used for culling as a frustum object.
|
||||
*/
|
||||
frustum get_frustum() const { return frustum_culling_; };
|
||||
/**
|
||||
* Set the frustum used for culling.
|
||||
* @param frustum The new frustum to set for culling.
|
||||
*/
|
||||
void set_frustum(const frustum& frustum) { frustum_culling_ = frustum; };
|
||||
|
||||
/**
|
||||
* Construct the frustum for culling.
|
||||
* This function will calculate the frustum based on the current camera view and projection matrices.
|
||||
*/
|
||||
void construct_frustum();
|
||||
|
||||
|
||||
/**
|
||||
* Get the number of objects rendered in the current frame.
|
||||
* @return
|
||||
*/
|
||||
int get_render_count() const { return render_count_; };
|
||||
/**
|
||||
* Set the number of objects rendered in the current frame.
|
||||
* @param render_count The new render count as an integer.
|
||||
*/
|
||||
void set_render_count(const int render_count) { render_count_ = render_count; };
|
||||
/**
|
||||
* Get the frustum culling tolerance.
|
||||
* This value is used to determine how much an object must be outside the frustum to be culled.
|
||||
* @return The frustum culling tolerance as a float.
|
||||
*/
|
||||
float get_frustum_tolerance() const { return frustum_culling_tolerance_; };
|
||||
/**
|
||||
* Set the frustum culling tolerance.
|
||||
* This value is used to determine how much an object must be outside the frustum to be culled.
|
||||
* @param frustum_tolerance The new frustum culling tolerance as a float.
|
||||
*/
|
||||
void set_frustum_tolerance(const float frustum_tolerance) { frustum_culling_tolerance_ = frustum_tolerance; };
|
||||
|
||||
/**
|
||||
* Get the flag indicating whether the application can perform fixed updates.
|
||||
* @return True if fixed updates are allowed, false otherwise.
|
||||
*/
|
||||
bool get_can_fixed_update() const { return can_fixed_update_; };
|
||||
/**
|
||||
* Set the flag indicating whether the application can perform fixed updates.
|
||||
* @param can_fixed_update True to allow fixed updates, false to disallow them.
|
||||
*/
|
||||
void set_can_fixed_update(bool can_fixed_update) { can_fixed_update_ = can_fixed_update; };
|
||||
|
||||
/**
|
||||
* Get the Direct3D back buffer texture.
|
||||
* @return Pointer to the Direct3D back buffer texture.
|
||||
*/
|
||||
ID3D11ShaderResourceView* get_back_buffer_srv() const {return back_buffer_srv_;};
|
||||
|
||||
/**
|
||||
* Get the Stats manager instance.
|
||||
* @return Pointer to the Stats manager instance.
|
||||
*/
|
||||
stats* get_stats() const { return stats_; };
|
||||
/**
|
||||
* Get the FPS manager instance.
|
||||
* @return Pointer to the FPS manager instance.
|
||||
*/
|
||||
fps_class* get_fps() const { return fps_; };
|
||||
|
||||
|
||||
/**
|
||||
* Get the entity manager instance.
|
||||
* @return Pointer to the entity manager instance.
|
||||
*/
|
||||
ecs::EntityManager* get_entity_manager() const { return entity_manager_.get(); };
|
||||
/**
|
||||
* Update the stats after an update in the scene.
|
||||
*/
|
||||
void update_stats_after_modification();
|
||||
/**
|
||||
* Get the global model cache.
|
||||
* The model cache is a static map that stores shared pointers to model_class objects.
|
||||
* This cache is used to avoid loading the same model multiple times.
|
||||
* @return A reference to the global model cache as a map of strings to shared pointers of model_class.
|
||||
*/
|
||||
std::map<std::string, std::shared_ptr<model_class>>& get_model_cache() { return g_model_cache; }
|
||||
|
||||
private:
|
||||
/**
|
||||
* Do the rendering of the scene by calling the appropriate rendering functions.
|
||||
* @param rotation The rotation angle in radians use for the demo spinning object.
|
||||
* @param x The x position of the demo spinning object.
|
||||
* @param y The y position of the demo spinning object.
|
||||
* @param z The z position of the demo spinning object.
|
||||
* @param textureTranslation This isn't used in the current implementation.
|
||||
* @return True if the rendering was successful, false otherwise.
|
||||
*/
|
||||
bool render(float, float, float, float, float);
|
||||
/**
|
||||
* Update the physics engine with the delta time.
|
||||
* @param delta_time
|
||||
* @return True if the physics update was successful, false otherwise.
|
||||
*/
|
||||
bool render_physics(float delta_time);
|
||||
/**
|
||||
* Update the mouse strings displayed on the screen.
|
||||
* @param mouseX The x position of the mouse cursor.
|
||||
* @param mouseY The y position of the mouse cursor.
|
||||
* @param mouseDown Whether the left mouse button is pressed or not.
|
||||
* @return True if the mouse strings were updated successfully, false otherwise.
|
||||
*/
|
||||
bool update_mouse_strings(int, int, bool);
|
||||
/**
|
||||
* Update the frames per second (FPS) counter.
|
||||
* @return True if the FPS was updated successfully, false otherwise.
|
||||
*/
|
||||
bool update_fps();
|
||||
/**
|
||||
* Update the render count string displayed on the screen.
|
||||
* @param render_count The number of objects rendered in the current frame.
|
||||
* @return True if the render count string was updated successfully, false otherwise.
|
||||
*/
|
||||
bool update_render_count_string(int);
|
||||
/**
|
||||
* Render the scene to a texture.
|
||||
* This function will render the scene to a texture for further processing, such as reflections or refractions.
|
||||
* @param rotation The rotation angle in radians used for the demo spinning object.
|
||||
* @return True if the scene was rendered to the texture successfully, false otherwise.
|
||||
*/
|
||||
bool render_scene_to_texture(float);
|
||||
/**
|
||||
* Render the refraction of the scene to a texture.
|
||||
* This function will render the refraction effects, such as water or glass, to a texture.
|
||||
* @return True if the refraction was rendered to the texture successfully, false otherwise.
|
||||
*/
|
||||
bool render_refraction_to_texture();
|
||||
/**
|
||||
* Render the reflection of the scene to a texture.
|
||||
* This function will render the reflection effects, such as water or mirrors, to a texture.
|
||||
* @return True if the reflection was rendered to the texture successfully, false otherwise.
|
||||
*/
|
||||
bool render_reflection_to_texture();
|
||||
/**
|
||||
* Render All the Objects in the scene.
|
||||
* The Skysphere is rendered first, then the objects in the scene.
|
||||
* The Skysphere isn't a entity, but a static object that is always rendered in the background.
|
||||
* The other objects are render using the entity manager.
|
||||
* @param diffuse
|
||||
* @param position
|
||||
* @param ambient
|
||||
* @param view
|
||||
* @param projection
|
||||
* @return True if the rendering was successful, false otherwise.
|
||||
*/
|
||||
bool render_pass(XMFLOAT4* diffuse, XMFLOAT4* position, XMFLOAT4* ambient, XMMATRIX view, XMMATRIX projection);
|
||||
|
||||
/**
|
||||
* Update the position of the skysphere based on the camera position.
|
||||
* The skyphere is a sphere rendered first without depth to be the background of the scene.
|
||||
* This function will update the position of the skysphere to match the camera position.
|
||||
*/
|
||||
void update_skybox_position();
|
||||
/**
|
||||
* The thread function for culling objects in the scene.
|
||||
*/
|
||||
void culling_thread_function();
|
||||
|
||||
public :
|
||||
|
@@ -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