Minor - ECS use in other method pt.1 - V12.2.0
This commit is contained in:
parent
3adfddf44f
commit
bf1b5d78e5
@ -7,7 +7,6 @@
|
|||||||
///////////////////////
|
///////////////////////
|
||||||
#include "d_3d_class.h"
|
#include "d_3d_class.h"
|
||||||
#include "camera_class.h"
|
#include "camera_class.h"
|
||||||
#include "object.h"
|
|
||||||
#include "light_class.h"
|
#include "light_class.h"
|
||||||
|
|
||||||
#include "bitmap_class.h"
|
#include "bitmap_class.h"
|
||||||
@ -106,13 +105,8 @@ public:
|
|||||||
void set_speed(const float speed) { this->speed_ = speed; };
|
void set_speed(const float speed) { this->speed_ = speed; };
|
||||||
|
|
||||||
void add_cube();
|
void add_cube();
|
||||||
|
void delete_entity_by_id(int entity_id);
|
||||||
void delete_kobject(int index);
|
void delete_kobject(int index);
|
||||||
size_t get_cube_count() const { return cubes_.size(); };
|
|
||||||
size_t get_terrain_cube_count() const { return terrain_chunk_.size(); };
|
|
||||||
std::vector<object*> get_cubes() const { return cubes_; };
|
|
||||||
std::vector<object*> get_terrain_cubes() const { return terrain_chunk_; };
|
|
||||||
std::vector<object*> get_kobjects() const { return object_; };
|
|
||||||
void set_kobjects(std::vector<object*> kobjects) { object_ = kobjects; };
|
|
||||||
void add_kobject(std::wstring& filepath);
|
void add_kobject(std::wstring& filepath);
|
||||||
void set_path(WCHAR* path) { path_ = path; };
|
void set_path(WCHAR* path) { path_ = path; };
|
||||||
void set_w_folder(const std::filesystem::path& w_folder) { w_folder_ = w_folder; };
|
void set_w_folder(const std::filesystem::path& w_folder) { w_folder_ = w_folder; };
|
||||||
@ -188,7 +182,7 @@ private:
|
|||||||
bool render_scene_to_texture(float);
|
bool render_scene_to_texture(float);
|
||||||
bool render_refraction_to_texture();
|
bool render_refraction_to_texture();
|
||||||
bool render_reflection_to_texture();
|
bool render_reflection_to_texture();
|
||||||
bool render_pass(const std::vector<std::reference_wrapper<std::vector<object*>>>& RenderQueues, XMFLOAT4* diffuse, XMFLOAT4* position, XMFLOAT4* ambient, XMMATRIX view, XMMATRIX projection);
|
bool render_pass(XMFLOAT4* diffuse, XMFLOAT4* position, XMFLOAT4* ambient, XMMATRIX view, XMMATRIX projection);
|
||||||
|
|
||||||
void update_skybox_position();
|
void update_skybox_position();
|
||||||
void culling_thread_function();
|
void culling_thread_function();
|
||||||
@ -246,14 +240,10 @@ private :
|
|||||||
std::unique_ptr<ecs::EntityManager> entity_manager_;
|
std::unique_ptr<ecs::EntityManager> entity_manager_;
|
||||||
|
|
||||||
object* selected_object_;
|
object* selected_object_;
|
||||||
std::vector<object*> cubes_;
|
|
||||||
std::vector<object*> terrain_chunk_;
|
|
||||||
std::vector<object*> object_;
|
|
||||||
|
|
||||||
float speed_ = 0.1f; // speed for the demo spinning object
|
float speed_ = 0.1f; // speed for the demo spinning object
|
||||||
std::vector<object*> imported_object_;
|
std::vector<object*> imported_object_;
|
||||||
int object_id_ = 0;
|
int object_id_ = 0;
|
||||||
std::vector<std::reference_wrapper<std::vector<object*>>> render_queues_;
|
|
||||||
std::vector<object*> skybox_;
|
std::vector<object*> skybox_;
|
||||||
|
|
||||||
// ----------------------------------- //
|
// ----------------------------------- //
|
||||||
|
@ -28,10 +28,6 @@ application_class::application_class() : should_quit_(false)
|
|||||||
reflection_texture_ = nullptr;
|
reflection_texture_ = nullptr;
|
||||||
scene_texture_ = nullptr;
|
scene_texture_ = nullptr;
|
||||||
physics_ = nullptr;
|
physics_ = nullptr;
|
||||||
cubes_.clear();
|
|
||||||
terrain_chunk_.clear();
|
|
||||||
object_.clear();
|
|
||||||
render_queues_.clear();
|
|
||||||
skybox_.clear();
|
skybox_.clear();
|
||||||
lights_.clear();
|
lights_.clear();
|
||||||
sun_light_ = nullptr;
|
sun_light_ = nullptr;
|
||||||
@ -86,11 +82,6 @@ bool application_class::initialize(int screenWidth, int screenHeight, HWND hwnd,
|
|||||||
bool result;
|
bool result;
|
||||||
HRESULT Hresult;
|
HRESULT Hresult;
|
||||||
|
|
||||||
render_queues_.push_back(std::ref(skybox_)); // Skybox doit être rendu en premier pour être derrière touts les autres objets
|
|
||||||
render_queues_.push_back(std::ref(object_));
|
|
||||||
render_queues_.push_back(std::ref(cubes_));
|
|
||||||
render_queues_.push_back(std::ref(terrain_chunk_));
|
|
||||||
|
|
||||||
// create entity manager
|
// create entity manager
|
||||||
entity_manager_ = std::make_unique<ecs::EntityManager>();
|
entity_manager_ = std::make_unique<ecs::EntityManager>();
|
||||||
|
|
||||||
@ -191,14 +182,14 @@ bool application_class::initialize(int screenWidth, int screenHeight, HWND hwnd,
|
|||||||
|
|
||||||
result = display_plane_->Initialize(direct_3d_->get_device(), 1.0f, 1.0f);
|
result = display_plane_->Initialize(direct_3d_->get_device(), 1.0f, 1.0f);
|
||||||
if (!result)
|
if (!result)
|
||||||
{
|
{
|
||||||
Logger::Get().Log("Could not initialize the display plane object", __FILE__, __LINE__, Logger::LogLevel::Error);
|
Logger::Get().Log("Could not initialize the display plane object", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Set the sprite info file we will be using.
|
// Set the sprite info file we will be using.
|
||||||
//
|
//
|
||||||
strcpy_s(spriteFilename, "sprite_data_01.txt");
|
strcpy_s(spriteFilename, "sprite_data_01.txt");
|
||||||
|
|
||||||
// Create and initialize the sprite object.
|
// Create and initialize the sprite object.
|
||||||
@ -252,7 +243,7 @@ bool application_class::initialize(int screenWidth, int screenHeight, HWND hwnd,
|
|||||||
};
|
};
|
||||||
|
|
||||||
TextureContainer CubeTextures;
|
TextureContainer CubeTextures;
|
||||||
|
|
||||||
for (const auto& textureFilename : textureFilenames)
|
for (const auto& textureFilename : textureFilenames)
|
||||||
{
|
{
|
||||||
ID3D11ShaderResourceView* texture = nullptr;
|
ID3D11ShaderResourceView* texture = nullptr;
|
||||||
@ -267,7 +258,7 @@ bool application_class::initialize(int screenWidth, int screenHeight, HWND hwnd,
|
|||||||
|
|
||||||
// Create and initialize the model object.
|
// Create and initialize the model object.
|
||||||
model_ = new model_class;
|
model_ = new model_class;
|
||||||
|
|
||||||
|
|
||||||
result = model_->Initialize(direct_3d_->get_device(), direct_3d_->get_device_context(), modelFilename, CubeTextures);
|
result = model_->Initialize(direct_3d_->get_device(), direct_3d_->get_device_context(), modelFilename, CubeTextures);
|
||||||
if (!result)
|
if (!result)
|
||||||
@ -370,7 +361,7 @@ bool application_class::initialize(int screenWidth, int screenHeight, HWND hwnd,
|
|||||||
};
|
};
|
||||||
|
|
||||||
TextureContainer BathTextures;
|
TextureContainer BathTextures;
|
||||||
|
|
||||||
textures.clear();
|
textures.clear();
|
||||||
for (const auto& textureFilename : bathTextures)
|
for (const auto& textureFilename : bathTextures)
|
||||||
{
|
{
|
||||||
@ -521,7 +512,7 @@ bool application_class::initialize(int screenWidth, int screenHeight, HWND hwnd,
|
|||||||
}
|
}
|
||||||
Logger::Get().Log("Application class initialized", __FILE__, __LINE__, Logger::LogLevel::Initialize);
|
Logger::Get().Log("Application class initialized", __FILE__, __LINE__, Logger::LogLevel::Initialize);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -529,7 +520,7 @@ bool application_class::initialize(int screenWidth, int screenHeight, HWND hwnd,
|
|||||||
void application_class::shutdown()
|
void application_class::shutdown()
|
||||||
{
|
{
|
||||||
Logger::Get().Log("Shutting down application class", __FILE__, __LINE__, Logger::LogLevel::Shutdown);
|
Logger::Get().Log("Shutting down application class", __FILE__, __LINE__, Logger::LogLevel::Shutdown);
|
||||||
|
|
||||||
// Release the shader manager object.
|
// Release the shader manager object.
|
||||||
if (shader_manager_)
|
if (shader_manager_)
|
||||||
{
|
{
|
||||||
@ -769,7 +760,7 @@ void application_class::shutdown()
|
|||||||
bool application_class::frame(input_class* Input)
|
bool application_class::frame(input_class* Input)
|
||||||
{
|
{
|
||||||
stats_->reset_draw_call_count();
|
stats_->reset_draw_call_count();
|
||||||
|
|
||||||
int mouseX, mouseY, currentMouseX, currentMouseY;
|
int mouseX, mouseY, currentMouseX, currentMouseY;
|
||||||
bool result, leftMouseDown, rightMouseDown, buttonQ, buttonD, buttonZ, buttonS, buttonA, buttonE, scrollUp, scrollDown;
|
bool result, leftMouseDown, rightMouseDown, buttonQ, buttonD, buttonZ, buttonS, buttonA, buttonE, scrollUp, scrollDown;
|
||||||
float rotationY, rotationX, positionX, positionY, positionZ;
|
float rotationY, rotationX, positionX, positionY, positionZ;
|
||||||
@ -834,12 +825,12 @@ bool application_class::frame(input_class* Input)
|
|||||||
buttonE = Input->IsEPressed();
|
buttonE = Input->IsEPressed();
|
||||||
position_->MoveCamera(buttonZ, buttonS, buttonQ, buttonD, buttonE, buttonA, scrollUp, scrollDown, rightMouseDown);
|
position_->MoveCamera(buttonZ, buttonS, buttonQ, buttonD, buttonE, buttonA, scrollUp, scrollDown, rightMouseDown);
|
||||||
position_->GetPosition(positionX, positionY, positionZ);
|
position_->GetPosition(positionX, positionY, positionZ);
|
||||||
|
|
||||||
XMFLOAT3 dir = sun_light_->GetDirection();
|
XMFLOAT3 dir = sun_light_->GetDirection();
|
||||||
float pitch = asinf(-dir.y) * (180.0f / XM_PI); // en degrés
|
float pitch = asinf(-dir.y) * (180.0f / XM_PI); // en degrés
|
||||||
float yaw = atan2f(dir.x, dir.z) * (180.0f / XM_PI); // en degrés
|
float yaw = atan2f(dir.x, dir.z) * (180.0f / XM_PI); // en degrés
|
||||||
float roll = 0.0f;
|
float roll = 0.0f;
|
||||||
|
|
||||||
if (Input->is_key_pressed(DIK_TAB)) {
|
if (Input->is_key_pressed(DIK_TAB)) {
|
||||||
if (!tab_was_pressed_) {
|
if (!tab_was_pressed_) {
|
||||||
// Alterner la caméra active
|
// Alterner la caméra active
|
||||||
@ -985,7 +976,7 @@ bool application_class::render_refraction_to_texture()
|
|||||||
// render the bath model using the refraction shader.
|
// render the bath model using the refraction shader.
|
||||||
bath_model_->Render(direct_3d_->get_device_context());
|
bath_model_->Render(direct_3d_->get_device_context());
|
||||||
|
|
||||||
result = shader_manager_->render_refraction_shader(direct_3d_->get_device_context(), bath_model_->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix,
|
result = shader_manager_->render_refraction_shader(direct_3d_->get_device_context(), bath_model_->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix,
|
||||||
bath_model_->GetTexture(TextureType::Diffuse,0), lights_[0]->GetDirection(), ambientColor, diffuseColor, lightPosition, clipPlane);
|
bath_model_->GetTexture(TextureType::Diffuse,0), lights_[0]->GetDirection(), ambientColor, diffuseColor, lightPosition, clipPlane);
|
||||||
if (!result)
|
if (!result)
|
||||||
{
|
{
|
||||||
@ -1002,7 +993,7 @@ bool application_class::render_refraction_to_texture()
|
|||||||
bool application_class::render_reflection_to_texture()
|
bool application_class::render_reflection_to_texture()
|
||||||
{
|
{
|
||||||
XMMATRIX reflectionViewMatrix;
|
XMMATRIX reflectionViewMatrix;
|
||||||
|
|
||||||
// Set the render target to be the reflection render to texture and clear it.
|
// Set the render target to be the reflection render to texture and clear it.
|
||||||
reflection_texture_->SetRenderTarget(direct_3d_->get_device_context());
|
reflection_texture_->SetRenderTarget(direct_3d_->get_device_context());
|
||||||
reflection_texture_->ClearRenderTarget(direct_3d_->get_device_context(), 0.0f, 0.0f, 0.0f, 1.0f);
|
reflection_texture_->ClearRenderTarget(direct_3d_->get_device_context(), 0.0f, 0.0f, 0.0f, 1.0f);
|
||||||
@ -1012,7 +1003,7 @@ bool application_class::render_reflection_to_texture()
|
|||||||
|
|
||||||
// Get the camera reflection view matrix instead of the normal view matrix.
|
// Get the camera reflection view matrix instead of the normal view matrix.
|
||||||
camera_->get_reflection_view_matrix(reflectionViewMatrix);
|
camera_->get_reflection_view_matrix(reflectionViewMatrix);
|
||||||
|
|
||||||
// Reset the render target back to the original back buffer and not the render to texture anymore. And reset the viewport back to the original.
|
// Reset the render target back to the original back buffer and not the render to texture anymore. And reset the viewport back to the original.
|
||||||
direct_3d_->set_back_buffer_render_target();
|
direct_3d_->set_back_buffer_render_target();
|
||||||
direct_3d_->reset_viewport();
|
direct_3d_->reset_viewport();
|
||||||
@ -1031,7 +1022,7 @@ bool application_class::render_scene_to_texture(float rotation)
|
|||||||
|
|
||||||
// Set the position of the camera for viewing the cube.
|
// Set the position of the camera for viewing the cube.
|
||||||
camera_->render();
|
camera_->render();
|
||||||
|
|
||||||
camera_->get_view_matrix(viewMatrix);
|
camera_->get_view_matrix(viewMatrix);
|
||||||
render_texture_->GetProjectionMatrix(projectionMatrix);
|
render_texture_->GetProjectionMatrix(projectionMatrix);
|
||||||
|
|
||||||
@ -1099,14 +1090,14 @@ bool application_class::render(float rotation, float x, float y, float z, float
|
|||||||
scene_texture_->Shutdown();
|
scene_texture_->Shutdown();
|
||||||
scene_texture_->Initialize(direct_3d_->get_device(), (int)window_size_.x, (int)window_size_.y, screen_depth, screen_near, 1);
|
scene_texture_->Initialize(direct_3d_->get_device(), (int)window_size_.x, (int)window_size_.y, screen_depth, screen_near, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
direct_3d_->set_back_buffer_render_target();
|
direct_3d_->set_back_buffer_render_target();
|
||||||
direct_3d_->reset_viewport();
|
direct_3d_->reset_viewport();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// CPT ALED C'EST ICI QUE CA SE PASSE ///
|
/// CPT ALED C'EST ICI QUE CA SE PASSE ///
|
||||||
|
|
||||||
|
|
||||||
//scene_texture_->SetRenderTarget(direct_3d_->get_device_context());
|
//scene_texture_->SetRenderTarget(direct_3d_->get_device_context());
|
||||||
//scene_texture_->ClearRenderTarget(direct_3d_->get_device_context(), 0.0f, 0.0f, 0.0f, 0.0f);
|
//scene_texture_->ClearRenderTarget(direct_3d_->get_device_context(), 0.0f, 0.0f, 0.0f, 0.0f);
|
||||||
|
|
||||||
@ -1126,7 +1117,7 @@ bool application_class::render(float rotation, float x, float y, float z, float
|
|||||||
diffuseColor, lightPosition, ambientColor);
|
diffuseColor, lightPosition, ambientColor);
|
||||||
|
|
||||||
update_skybox_position(); // Update the position of the skybox to match the camera position.
|
update_skybox_position(); // Update the position of the skybox to match the camera position.
|
||||||
|
|
||||||
direct_3d_->turn_z_buffer_on(); // Enable the Z buffer after rendering the skybox.
|
direct_3d_->turn_z_buffer_on(); // Enable the Z buffer after rendering the skybox.
|
||||||
|
|
||||||
// -------------------------------------------------------- //
|
// -------------------------------------------------------- //
|
||||||
@ -1138,7 +1129,7 @@ bool application_class::render(float rotation, float x, float y, float z, float
|
|||||||
// active_camera_->render();
|
// active_camera_->render();
|
||||||
// // Render the objects in the render queues. with depth only pass.
|
// // Render the objects in the render queues. with depth only pass.
|
||||||
// active_camera_->get_view_matrix(viewMatrix);
|
// active_camera_->get_view_matrix(viewMatrix);
|
||||||
result = render_pass(render_queues_, diffuseColor, lightPosition, ambientColor, viewMatrix, projectionMatrix);
|
result = render_pass(diffuseColor, lightPosition, ambientColor, viewMatrix, projectionMatrix);
|
||||||
if (!result)
|
if (!result)
|
||||||
{
|
{
|
||||||
Logger::Get().Log("Could not render the model using any shader", __FILE__, __LINE__, Logger::LogLevel::Error);
|
Logger::Get().Log("Could not render the model using any shader", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||||
@ -1159,7 +1150,7 @@ bool application_class::render(float rotation, float x, float y, float z, float
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
// stats_->update_geometric_stats();
|
// stats_->update_geometric_stats();
|
||||||
|
|
||||||
// Update the render count text.
|
// Update the render count text.
|
||||||
result = update_render_count_string(get_render_count());
|
result = update_render_count_string(get_render_count());
|
||||||
if (!result)
|
if (!result)
|
||||||
@ -1268,19 +1259,19 @@ bool application_class::render(float rotation, float x, float y, float z, float
|
|||||||
|
|
||||||
// turn on the Z buffer
|
// turn on the Z buffer
|
||||||
direct_3d_->turn_z_buffer_on();
|
direct_3d_->turn_z_buffer_on();
|
||||||
|
|
||||||
// Get the light properties.
|
// Get the light properties.
|
||||||
for (i = 0; i < num_lights_; i++)
|
for (i = 0; i < num_lights_; i++)
|
||||||
{
|
{
|
||||||
// Create the diffuse color array from the four light colors.
|
// Create the diffuse color array from the four light colors.
|
||||||
diffuseColor[i] = lights_[i]->GetDiffuseColor();
|
diffuseColor[i] = lights_[i]->GetDiffuseColor();
|
||||||
|
|
||||||
// Create the light position array from the four light positions.
|
// Create the light position array from the four light positions.
|
||||||
lightPosition[i] = lights_[i]->GetPosition();
|
lightPosition[i] = lights_[i]->GetPosition();
|
||||||
}
|
}
|
||||||
// Réinitialiser la cible de rendu au back buffer.
|
// Réinitialiser la cible de rendu au back buffer.
|
||||||
direct_3d_->set_back_buffer_render_target();
|
direct_3d_->set_back_buffer_render_target();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1301,10 +1292,11 @@ int application_class::get_screen_height() const
|
|||||||
|
|
||||||
void application_class::generate_terrain()
|
void application_class::generate_terrain()
|
||||||
{
|
{
|
||||||
Logger::Get().Log("Génération du terrain avec instanciation", __FILE__, __LINE__, Logger::LogLevel::Info);
|
Logger::Get().Log("Génération du terrain avec ECS", __FILE__, __LINE__, Logger::LogLevel::Info);
|
||||||
|
|
||||||
terrain_chunk_.clear();
|
|
||||||
|
|
||||||
|
// delete previous terrain if it exists
|
||||||
|
delete_terrain();
|
||||||
|
|
||||||
// Dimensions du terrain
|
// Dimensions du terrain
|
||||||
float scaleX = 10.0f;
|
float scaleX = 10.0f;
|
||||||
float scaleY = 1.0f;
|
float scaleY = 1.0f;
|
||||||
@ -1312,63 +1304,82 @@ void application_class::generate_terrain()
|
|||||||
int gridSizeX = 20;
|
int gridSizeX = 20;
|
||||||
int gridSizeZ = 20;
|
int gridSizeZ = 20;
|
||||||
|
|
||||||
// Créer un conteneur de textures_ partagé
|
// Vérifier si le modèle existe déjà dans le cache
|
||||||
TextureContainer textureContainer;
|
std::string modelName = "assets/Model/OBJ/plane.obj";
|
||||||
textureContainer.diffusePaths.push_back(L"assets/Texture/Bricks2K.png");
|
std::shared_ptr<model_class> sharedModel;
|
||||||
textureContainer.normalPaths.push_back(L"assets/Texture/BricksNRM2K.png");
|
|
||||||
textureContainer.specularPaths.push_back(L"assets/Texture/BricksGLOSS2K.png");
|
|
||||||
|
|
||||||
// Précharger les textures_ une seule fois
|
auto it = g_model_cache.find(modelName);
|
||||||
model_class* sharedModel = new model_class();
|
if (it != g_model_cache.end()) {
|
||||||
sharedModel->PreloadTextures(direct_3d_->get_device(), direct_3d_->get_device_context(), textureContainer);
|
// Utiliser le modèle existant du cache
|
||||||
|
Logger::Get().Log("Using cached model for terrain: " + modelName, __FILE__, __LINE__);
|
||||||
|
sharedModel = it->second;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// Créer un conteneur de textures partagé
|
||||||
|
TextureContainer textureContainer;
|
||||||
|
textureContainer.diffusePaths.push_back(L"assets/Texture/Bricks2K.png");
|
||||||
|
textureContainer.normalPaths.push_back(L"assets/Texture/BricksNRM2K.png");
|
||||||
|
textureContainer.specularPaths.push_back(L"assets/Texture/BricksGLOSS2K.png");
|
||||||
|
|
||||||
char modelFilename[128];
|
// Créer et initialiser le modèle si non trouvé
|
||||||
strcpy_s(modelFilename, "assets/Model/OBJ/plane.obj");
|
char modelFilename[128];
|
||||||
|
strcpy_s(modelFilename, modelName.c_str());
|
||||||
|
|
||||||
// Générer les tuiles de terrain
|
auto newModel = std::make_shared<model_class>();
|
||||||
for (int i = 0; i < gridSizeX; i++)
|
newModel->PreloadTextures(direct_3d_->get_device(), direct_3d_->get_device_context(), textureContainer);
|
||||||
{
|
|
||||||
for (int j = 0; j < gridSizeZ; j++)
|
|
||||||
{
|
|
||||||
// Créer un nouvel objet de terrain
|
|
||||||
object* terrain = new object(*this);
|
|
||||||
|
|
||||||
// Initialiser avec le modèle et les textures_ préchargées
|
if (!newModel->Initialize(direct_3d_->get_device(), direct_3d_->get_device_context(), modelFilename, textureContainer)) {
|
||||||
if (!terrain->Initialize(direct_3d_->get_device(), direct_3d_->get_device_context(), modelFilename, textureContainer))
|
Logger::Get().Log("Impossible d'initialiser le modèle du terrain", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||||
{
|
return;
|
||||||
Logger::Get().Log("Échec de l'initialisation d'une tuile de terrain", __FILE__, __LINE__, Logger::LogLevel::Error);
|
}
|
||||||
delete terrain;
|
|
||||||
continue;
|
// Ajouter le modèle au cache
|
||||||
|
g_model_cache[modelName] = newModel;
|
||||||
|
sharedModel = newModel;
|
||||||
|
Logger::Get().Log("Added terrain model to cache: " + modelName, __FILE__, __LINE__);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Vérifier si l'entity manager est disponible
|
||||||
|
if (entity_manager_) {
|
||||||
|
// Générer les tuiles de terrain avec le système ECS
|
||||||
|
for (int i = 0; i < gridSizeX; i++) {
|
||||||
|
for (int j = 0; j < gridSizeZ; j++) {
|
||||||
|
// Créer une entité
|
||||||
|
auto entity = entity_manager_->CreateEntity();
|
||||||
|
|
||||||
|
// Ajouter un composant d'identité
|
||||||
|
auto identity = entity->AddComponent<ecs::IdentityComponent>(object_id_++);
|
||||||
|
identity->SetName("TerrainTile_" + std::to_string(i) + "_" + std::to_string(j));
|
||||||
|
identity->SetType(ecs::ObjectType::Terrain);
|
||||||
|
|
||||||
|
// Ajouter un composant de transformation
|
||||||
|
auto transform = entity->AddComponent<ecs::TransformComponent>();
|
||||||
|
transform->SetPosition(XMVectorSet(i * scaleX, -12.0f, j * scaleZ, 0.0f));
|
||||||
|
transform->SetScale(XMVectorSet(scaleX, scaleY, scaleZ, 0.0f));
|
||||||
|
transform->UpdateWorldMatrix();
|
||||||
|
|
||||||
|
// Ajouter un composant de rendu
|
||||||
|
auto render = entity->AddComponent<ecs::RenderComponent>();
|
||||||
|
render->InitializeWithModel(sharedModel);
|
||||||
|
|
||||||
|
// Ajouter un composant de shader
|
||||||
|
auto shader = entity->AddComponent<ecs::ShaderComponent>();
|
||||||
|
shader->SetActiveShader(ecs::ShaderType::SUNLIGHT);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Définir la position dans la grille
|
|
||||||
XMFLOAT3 position(i * scaleX, -12.0f, j * scaleZ);
|
|
||||||
XMFLOAT3 scale(scaleX, scaleY, scaleZ);
|
|
||||||
|
|
||||||
terrain->SetPosition(XMLoadFloat3(&position));
|
|
||||||
terrain->SetScale(XMLoadFloat3(&scale));
|
|
||||||
|
|
||||||
// Configurer les propriétés
|
|
||||||
terrain->SetName("TerrainTile_" + std::to_string(i) + "_" + std::to_string(j));
|
|
||||||
terrain->SetType(ObjectType::Cube);
|
|
||||||
terrain->SetActiveShader(ShaderType::SUNLIGHT);
|
|
||||||
terrain->SetId(object_id_++);
|
|
||||||
|
|
||||||
// Ajouter à la liste des chunks de terrain
|
|
||||||
terrain_chunk_.push_back(terrain);
|
|
||||||
|
|
||||||
update_stats_after_modification();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger::Get().Log("Terrain généré avec " + std::to_string(terrain_chunk_.size()) + " tuiles", __FILE__, __LINE__, Logger::LogLevel::Info);
|
update_stats_after_modification();
|
||||||
|
|
||||||
|
int totalTiles = gridSizeX * gridSizeZ;
|
||||||
|
Logger::Get().Log("Terrain généré avec " + std::to_string(totalTiles) + " tuiles", __FILE__, __LINE__, Logger::LogLevel::Info);
|
||||||
}
|
}
|
||||||
|
|
||||||
void application_class::add_kobject(std::wstring& filepath)
|
void application_class::add_kobject(std::wstring& filepath)
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(objects_mutex_);
|
std::lock_guard<std::mutex> lock(objects_mutex_);
|
||||||
Logger::Get().Log("Adding object", __FILE__, __LINE__);
|
Logger::Get().Log("Adding object", __FILE__, __LINE__);
|
||||||
|
|
||||||
char modelFilename[128];
|
char modelFilename[128];
|
||||||
TextureContainer KobjectsTextures;
|
TextureContainer KobjectsTextures;
|
||||||
filesystem::path p(filepath);
|
filesystem::path p(filepath);
|
||||||
@ -1378,14 +1389,14 @@ void application_class::add_kobject(std::wstring& filepath)
|
|||||||
(void)wcstombs_s(&convertedChars, modelFilename, sizeof(modelFilename), filepath.c_str(), _TRUNCATE);
|
(void)wcstombs_s(&convertedChars, modelFilename, sizeof(modelFilename), filepath.c_str(), _TRUNCATE);
|
||||||
|
|
||||||
filesystem::current_path(w_folder_);
|
filesystem::current_path(w_folder_);
|
||||||
|
|
||||||
// Liste des fichiers de texture
|
// Liste des fichiers de texture
|
||||||
std::vector<std::wstring> kobjTexture = {
|
std::vector<std::wstring> kobjTexture = {
|
||||||
L"assets/Texture/Bricks2K.png",
|
L"assets/Texture/Bricks2K.png",
|
||||||
L"assets/Texture/BricksNRM2K.png",
|
L"assets/Texture/BricksNRM2K.png",
|
||||||
L"assets/Texture/BricksGLOSS2K.png"
|
L"assets/Texture/BricksGLOSS2K.png"
|
||||||
};
|
};
|
||||||
|
|
||||||
// Configurer les chemins des textures dans le conteneur
|
// Configurer les chemins des textures dans le conteneur
|
||||||
KobjectsTextures.diffusePaths.push_back(kobjTexture[0]);
|
KobjectsTextures.diffusePaths.push_back(kobjTexture[0]);
|
||||||
if (kobjTexture.size() > 1) KobjectsTextures.normalPaths.push_back(kobjTexture[1]);
|
if (kobjTexture.size() > 1) KobjectsTextures.normalPaths.push_back(kobjTexture[1]);
|
||||||
@ -1394,53 +1405,53 @@ void application_class::add_kobject(std::wstring& filepath)
|
|||||||
// Vérifier si le modèle existe déjà dans le cache
|
// Vérifier si le modèle existe déjà dans le cache
|
||||||
std::string modelKey = std::string(modelFilename);
|
std::string modelKey = std::string(modelFilename);
|
||||||
std::shared_ptr<model_class> sharedModel;
|
std::shared_ptr<model_class> sharedModel;
|
||||||
|
|
||||||
auto it = g_model_cache.find(modelKey);
|
auto it = g_model_cache.find(modelKey);
|
||||||
if (it != g_model_cache.end()) {
|
if (it != g_model_cache.end()) {
|
||||||
// Utiliser le modèle existant du cache
|
// Utiliser le modèle existant du cache
|
||||||
Logger::Get().Log("Using cached model for " + modelKey, __FILE__, __LINE__);
|
Logger::Get().Log("Using cached model for " + modelKey, __FILE__, __LINE__);
|
||||||
sharedModel = it->second;
|
sharedModel = it->second;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Créer un nouveau modèle
|
// Créer un nouveau modèle
|
||||||
sharedModel = std::make_shared<model_class>();
|
sharedModel = std::make_shared<model_class>();
|
||||||
|
|
||||||
// Précharger les textures
|
// Précharger les textures
|
||||||
sharedModel->PreloadTextures(direct_3d_->get_device(), direct_3d_->get_device_context(), KobjectsTextures);
|
sharedModel->PreloadTextures(direct_3d_->get_device(), direct_3d_->get_device_context(), KobjectsTextures);
|
||||||
|
|
||||||
// Initialiser le modèle
|
// Initialiser le modèle
|
||||||
if (!sharedModel->Initialize(direct_3d_->get_device(), direct_3d_->get_device_context(), modelFilename, KobjectsTextures)) {
|
if (!sharedModel->Initialize(direct_3d_->get_device(), direct_3d_->get_device_context(), modelFilename, KobjectsTextures)) {
|
||||||
Logger::Get().Log("Failed to initialize model for object: " + modelKey, __FILE__, __LINE__, Logger::LogLevel::Error);
|
Logger::Get().Log("Failed to initialize model for object: " + modelKey, __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ajouter le modèle au cache
|
// Ajouter le modèle au cache
|
||||||
g_model_cache[modelKey] = sharedModel;
|
g_model_cache[modelKey] = sharedModel;
|
||||||
Logger::Get().Log("Added model to cache: " + modelKey, __FILE__, __LINE__);
|
Logger::Get().Log("Added model to cache: " + modelKey, __FILE__, __LINE__);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Créer une nouvelle entité
|
// Créer une nouvelle entité
|
||||||
auto entity = entity_manager_->CreateEntity();
|
auto entity = entity_manager_->CreateEntity();
|
||||||
|
|
||||||
// Ajouter un composant d'identité
|
// Ajouter un composant d'identité
|
||||||
auto identity = entity->AddComponent<ecs::IdentityComponent>(object_id_++);
|
auto identity = entity->AddComponent<ecs::IdentityComponent>(object_id_++);
|
||||||
identity->SetName(filename);
|
identity->SetName(filename);
|
||||||
identity->SetType(ecs::ObjectType::Unknown);
|
identity->SetType(ecs::ObjectType::Unknown);
|
||||||
|
|
||||||
// Ajouter un composant de transformation
|
// Ajouter un composant de transformation
|
||||||
auto transform = entity->AddComponent<ecs::TransformComponent>();
|
auto transform = entity->AddComponent<ecs::TransformComponent>();
|
||||||
transform->SetPosition(XMVectorSet(0.0f, 50.0f, 0.0f, 0.0f));
|
transform->SetPosition(XMVectorSet(0.0f, 50.0f, 0.0f, 0.0f));
|
||||||
transform->SetScale(XMVectorSet(1.0f, 1.0f, 1.0f, 0.0f));
|
transform->SetScale(XMVectorSet(1.0f, 1.0f, 1.0f, 0.0f));
|
||||||
transform->UpdateWorldMatrix();
|
transform->UpdateWorldMatrix();
|
||||||
|
|
||||||
// Ajouter un composant de rendu avec le modèle partagé
|
// Ajouter un composant de rendu avec le modèle partagé
|
||||||
auto render = entity->AddComponent<ecs::RenderComponent>();
|
auto render = entity->AddComponent<ecs::RenderComponent>();
|
||||||
render->InitializeWithModel(sharedModel);
|
render->InitializeWithModel(sharedModel);
|
||||||
|
|
||||||
// Ajouter un composant de shader
|
// Ajouter un composant de shader
|
||||||
auto shader = entity->AddComponent<ecs::ShaderComponent>();
|
auto shader = entity->AddComponent<ecs::ShaderComponent>();
|
||||||
shader->SetActiveShader(ecs::ShaderType::LIGHTING);
|
shader->SetActiveShader(ecs::ShaderType::LIGHTING);
|
||||||
|
|
||||||
// Stocker le chemin du modèle
|
// Stocker le chemin du modèle
|
||||||
auto modelPath = entity->AddComponent<ecs::ModelPathComponent>();
|
auto modelPath = entity->AddComponent<ecs::ModelPathComponent>();
|
||||||
modelPath->SetPath(filepath);
|
modelPath->SetPath(filepath);
|
||||||
@ -1455,37 +1466,80 @@ void application_class::add_cube()
|
|||||||
std::lock_guard<std::mutex> lock(objects_mutex_);
|
std::lock_guard<std::mutex> lock(objects_mutex_);
|
||||||
Logger::Get().Log("Adding cube", __FILE__, __LINE__);
|
Logger::Get().Log("Adding cube", __FILE__, __LINE__);
|
||||||
|
|
||||||
char modelFilename[128];
|
std::string model_name = "assets/Model/TXT/cube.txt";
|
||||||
TextureContainer CubeTexture;
|
std::shared_ptr<model_class> sharedModel;
|
||||||
// Set the file name of the model.
|
|
||||||
strcpy_s(modelFilename, "assets/Model/TXT/cube.txt");
|
|
||||||
|
|
||||||
// Liste des fichiers de texture
|
auto it = g_model_cache.find(model_name);
|
||||||
std::vector<std::wstring> cubeTexture = {
|
if (it != g_model_cache.end())
|
||||||
L"assets/Texture/Bricks2K.png"
|
{
|
||||||
};
|
Logger::Get().Log("Using cached model: " + model_name, __FILE__, __LINE__);
|
||||||
|
sharedModel = it->second;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
TextureContainer cube_textures;
|
||||||
|
cube_textures.diffusePaths.push_back(L"assets/Texture/Bricks2K.png");
|
||||||
|
cube_textures.normalPaths.push_back(L"assets/Texture/BricksNRM2K.png");
|
||||||
|
cube_textures.specularPaths.push_back(L"assets/Texture/BricksGLOSS2K.png");
|
||||||
|
|
||||||
static int cubeCount = 0;
|
char model_filename[128];
|
||||||
float position = cubeCount * 2.0f;
|
strcpy_s(model_filename, model_name.c_str());
|
||||||
object* newCube = new object(*this);
|
|
||||||
newCube->LoadTexturesFromPath(cubeTexture, CubeTexture, direct_3d_); // Load textures_ from the path
|
|
||||||
newCube->Initialize(direct_3d_->get_device(), direct_3d_->get_device_context(), modelFilename, CubeTexture);
|
|
||||||
newCube->SetTranslateMatrix(XMMatrixTranslation(position, 0.0f, 0.0f));
|
|
||||||
|
|
||||||
cubes_.push_back(newCube);
|
auto newModel = std::make_shared<model_class>();
|
||||||
|
newModel->PreloadTextures(direct_3d_->get_device(), direct_3d_->get_device_context(), cube_textures);
|
||||||
|
if (!newModel->Initialize(direct_3d_->get_device(), direct_3d_->get_device_context(), model_filename, cube_textures)) {
|
||||||
|
Logger::Get().Log("Failed to initialize cube model", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
g_model_cache[model_name] = newModel;
|
||||||
|
sharedModel = newModel;
|
||||||
|
Logger::Get().Log("Added cube model to cache: " + model_name, __FILE__, __LINE__);
|
||||||
|
|
||||||
|
|
||||||
|
if (entity_manager_)
|
||||||
|
{
|
||||||
|
auto entity = entity_manager_->CreateEntity();
|
||||||
|
|
||||||
|
auto identity = entity->AddComponent<ecs::IdentityComponent>(object_id_++);
|
||||||
|
identity->SetName("Cube");
|
||||||
|
identity->SetType(ecs::ObjectType::Cube);
|
||||||
|
|
||||||
|
auto transform = entity->AddComponent<ecs::TransformComponent>();
|
||||||
|
transform->SetPosition(XMVectorSet(0.0f, 10.0f, 0.0f, 0.0f));
|
||||||
|
transform->SetScale(XMVectorSet(1.0f, 1.0f, 1.0f, 0.0f));
|
||||||
|
transform->UpdateWorldMatrix();
|
||||||
|
|
||||||
|
auto render = entity->AddComponent<ecs::RenderComponent>();
|
||||||
|
render->InitializeWithModel(sharedModel);
|
||||||
|
|
||||||
|
auto shader = entity->AddComponent<ecs::ShaderComponent>();
|
||||||
|
shader->SetActiveShader(ecs::ShaderType::TEXTURE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
update_stats_after_modification();
|
update_stats_after_modification();
|
||||||
|
Logger::Get().Log("Cube added successfully", __FILE__, __LINE__, Logger::LogLevel::Info);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void application_class::delete_kobject(int index)
|
void application_class::delete_entity_by_id(int entity_id)
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(objects_mutex_);
|
std::lock_guard<std::mutex> lock(objects_mutex_);
|
||||||
Logger::Get().Log("Deleting object", __FILE__, __LINE__);
|
Logger::Get().Log("Deleting entity with ID: " + std::to_string(entity_id), __FILE__, __LINE__, Logger::LogLevel::Info);
|
||||||
|
|
||||||
if (index < object_.size())
|
if (entity_manager_) {
|
||||||
{
|
// Rechercher l'entité avec l'ID spécifié via le composant IdentityComponent
|
||||||
object_.erase(object_.begin() + index);
|
auto entities_with_identity = entity_manager_->GetEntitiesWithComponent<ecs::IdentityComponent>();
|
||||||
|
for (auto& entity : entities_with_identity) {
|
||||||
|
auto identity = entity->GetComponent<ecs::IdentityComponent>();
|
||||||
|
if (identity && identity->GetId() == entity_id) {
|
||||||
|
// Supprimer l'entité
|
||||||
|
entity_manager_->DestroyEntity(entity->GetID());
|
||||||
|
Logger::Get().Log("Entity with ID " + std::to_string(entity_id) + " successfully deleted", __FILE__, __LINE__, Logger::LogLevel::Info);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
update_stats_after_modification();
|
update_stats_after_modification();
|
||||||
@ -1494,8 +1548,19 @@ void application_class::delete_kobject(int index)
|
|||||||
void application_class::delete_terrain()
|
void application_class::delete_terrain()
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(objects_mutex_);
|
std::lock_guard<std::mutex> lock(objects_mutex_);
|
||||||
Logger::Get().Log("Deleting terrain", __FILE__, __LINE__);
|
Logger::Get().Log("Deleting terrain", __FILE__, __LINE__, Logger::LogLevel::Info);
|
||||||
terrain_chunk_.clear();
|
|
||||||
|
// Get all entities with the Terrain type
|
||||||
|
auto entities_with_terrain = entity_manager_->GetEntitiesWithComponent<ecs::IdentityComponent>();
|
||||||
|
for (auto& entity : entities_with_terrain) {
|
||||||
|
auto identity = entity->GetComponent<ecs::IdentityComponent>();
|
||||||
|
if (identity && identity->GetType() == ecs::ObjectType::Terrain) {
|
||||||
|
// Destroy the entity
|
||||||
|
entity_manager_->DestroyEntity(entity->GetID());
|
||||||
|
Logger::Get().Log("Terrain entity with ID " + std::to_string(identity->GetId()) + " successfully deleted", __FILE__, __LINE__, Logger::LogLevel::Info);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
update_stats_after_modification();
|
update_stats_after_modification();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1569,7 +1634,7 @@ bool application_class::update_fps()
|
|||||||
fps_->Frame();
|
fps_->Frame();
|
||||||
|
|
||||||
stats_->update_display_stats(); // Update the stats display with the latest information from fps class.
|
stats_->update_display_stats(); // Update the stats display with the latest information from fps class.
|
||||||
|
|
||||||
// Get the current fps.
|
// Get the current fps.
|
||||||
fps = fps_->GetFps();
|
fps = fps_->GetFps();
|
||||||
|
|
||||||
@ -1733,9 +1798,9 @@ void application_class::culling_thread_function()
|
|||||||
for (auto& queueRef : queues)
|
for (auto& queueRef : queues)
|
||||||
{
|
{
|
||||||
std::vector<object*>& queue = queueRef.get();
|
std::vector<object*>& queue = queueRef.get();
|
||||||
|
|
||||||
std::lock_guard<std::mutex> lock(objects_mutex_);
|
std::lock_guard<std::mutex> lock(objects_mutex_);
|
||||||
|
|
||||||
for (auto* object : queue)
|
for (auto* object : queue)
|
||||||
{
|
{
|
||||||
if (!object) continue;
|
if (!object) continue;
|
||||||
@ -1753,10 +1818,10 @@ void application_class::culling_thread_function()
|
|||||||
// Vérification du frustum
|
// Vérification du frustum
|
||||||
bool visible = frustum_culling_.CheckCube(x, y, z, radius, get_frustum_tolerance());
|
bool visible = frustum_culling_.CheckCube(x, y, z, radius, get_frustum_tolerance());
|
||||||
object->SetVisible(visible);
|
object->SetVisible(visible);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pause pour éviter de surcharger le CPU
|
// Pause pour éviter de surcharger le CPU
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(16)); // ~60 Hz
|
std::this_thread::sleep_for(std::chrono::milliseconds(16)); // ~60 Hz
|
||||||
}
|
}
|
||||||
@ -1766,7 +1831,7 @@ void application_class::culling_thread_function()
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool application_class::render_pass(const std::vector<std::reference_wrapper<std::vector<object*>>>& RenderQueues, XMFLOAT4* diffuse, XMFLOAT4* position, XMFLOAT4* ambient, XMMATRIX view, XMMATRIX projection)
|
bool application_class::render_pass(XMFLOAT4* diffuse, XMFLOAT4* position, XMFLOAT4* ambient, XMMATRIX view, XMMATRIX projection)
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(objects_mutex_);
|
std::lock_guard<std::mutex> lock(objects_mutex_);
|
||||||
XMMATRIX scaleMatrix, rotateMatrix, translateMatrix;
|
XMMATRIX scaleMatrix, rotateMatrix, translateMatrix;
|
||||||
@ -1822,37 +1887,37 @@ bool application_class::render_pass(const std::vector<std::reference_wrapper<std
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
direct_3d_->turn_z_buffer_on(); // Réactiver le Z-buffer après le rendu de la skybox
|
direct_3d_->turn_z_buffer_on(); // Réactiver le Z-buffer après le rendu de la skybox
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rendu des entités du système ECS s'il est disponible
|
// Rendu des entités du système ECS s'il est disponible
|
||||||
if (entity_manager_) {
|
if (entity_manager_) {
|
||||||
// Créer le système de rendu pour les entités
|
// Créer le système de rendu pour les entités
|
||||||
ecs::RenderSystem renderSystem(direct_3d_->get_device_context(), shader_manager_);
|
ecs::RenderSystem renderSystem(direct_3d_->get_device_context(), shader_manager_);
|
||||||
|
|
||||||
// Données pour le système de rendu
|
// Données pour le système de rendu
|
||||||
XMFLOAT4 sunlightDiffuse = sun_light_->GetDiffuseColor();
|
XMFLOAT4 sunlightDiffuse = sun_light_->GetDiffuseColor();
|
||||||
XMFLOAT4 sunlightAmbient = sun_light_->GetAmbientColor();
|
XMFLOAT4 sunlightAmbient = sun_light_->GetAmbientColor();
|
||||||
XMFLOAT3 sunlightDirection = sun_light_->GetDirection();
|
XMFLOAT3 sunlightDirection = sun_light_->GetDirection();
|
||||||
float sunlightIntensity = sun_light_->GetIntensity();
|
float sunlightIntensity = sun_light_->GetIntensity();
|
||||||
|
|
||||||
// Effectuer le rendu de toutes les entités
|
// Effectuer le rendu de toutes les entités
|
||||||
int entitiesRendered = renderSystem.RenderAllEntities(
|
int entitiesRendered = renderSystem.RenderAllEntities(
|
||||||
entity_manager_.get(),
|
entity_manager_.get(),
|
||||||
view,
|
view,
|
||||||
projection,
|
projection,
|
||||||
diffuse,
|
diffuse,
|
||||||
position,
|
position,
|
||||||
ambient,
|
ambient,
|
||||||
camera_->get_position(),
|
camera_->get_position(),
|
||||||
sunlightDiffuse,
|
sunlightDiffuse,
|
||||||
sunlightAmbient,
|
sunlightAmbient,
|
||||||
sunlightDirection,
|
sunlightDirection,
|
||||||
sunlightIntensity
|
sunlightIntensity
|
||||||
);
|
);
|
||||||
|
|
||||||
renderCount += entitiesRendered;
|
renderCount += entitiesRendered;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1894,7 +1959,7 @@ void application_class::update_skybox_position()
|
|||||||
}
|
}
|
||||||
|
|
||||||
skybox_[0]->SetTranslateMatrix(XMMatrixTranslation(active_camera_->get_position().x, active_camera_->get_position().y, active_camera_->get_position().z));
|
skybox_[0]->SetTranslateMatrix(XMMatrixTranslation(active_camera_->get_position().x, active_camera_->get_position().y, active_camera_->get_position().z));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool application_class::render_physics(bool key_left, bool key_right, bool key_up, bool key_down, float delta_time) {
|
bool application_class::render_physics(bool key_left, bool key_right, bool key_up, bool key_down, float delta_time) {
|
||||||
@ -2018,7 +2083,7 @@ bool application_class::create_big_cube(int side_count)
|
|||||||
char model_file[128];
|
char model_file[128];
|
||||||
size_t convertedChars = 0;
|
size_t convertedChars = 0;
|
||||||
(void)wcstombs_s(&convertedChars, model_file, sizeof(model_file), std::wstring(modelName.begin(), modelName.end()).c_str(), _TRUNCATE);
|
(void)wcstombs_s(&convertedChars, model_file, sizeof(model_file), std::wstring(modelName.begin(), modelName.end()).c_str(), _TRUNCATE);
|
||||||
|
|
||||||
// Créer et initialiser le modèle si non trouvé
|
// Créer et initialiser le modèle si non trouvé
|
||||||
auto newModel = std::make_shared<model_class>();
|
auto newModel = std::make_shared<model_class>();
|
||||||
TextureContainer textures;
|
TextureContainer textures;
|
||||||
@ -2034,57 +2099,36 @@ bool application_class::create_big_cube(int side_count)
|
|||||||
sharedModel = newModel;
|
sharedModel = newModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Version ECS - Créer les entités pour le cube
|
for (int x = 0; x < side_count; x++) {
|
||||||
if (entity_manager_) {
|
for (int y = 0; y < side_count; y++) {
|
||||||
for (int x = 0; x < side_count; x++) {
|
for (int z = 0; z < side_count; z++) {
|
||||||
for (int y = 0; y < side_count; y++) {
|
// Créer une entité
|
||||||
for (int z = 0; z < side_count; z++) {
|
auto entity = entity_manager_->CreateEntity();
|
||||||
// Créer une entité
|
|
||||||
auto entity = entity_manager_->CreateEntity();
|
|
||||||
|
|
||||||
// Ajouter un composant d'identité
|
|
||||||
auto identity = entity->AddComponent<ecs::IdentityComponent>(object_id_++);
|
|
||||||
identity->SetName("CubePart_" + std::to_string(x) + "_" + std::to_string(y) + "_" + std::to_string(z));
|
|
||||||
identity->SetType(ecs::ObjectType::Cube);
|
|
||||||
|
|
||||||
// Ajouter un composant de transformation
|
|
||||||
auto transform = entity->AddComponent<ecs::TransformComponent>();
|
|
||||||
transform->SetPosition(XMVectorSet(static_cast<float>(x), static_cast<float>(y), static_cast<float>(z), 0.0f));
|
|
||||||
transform->SetScale(XMVectorSet(1.0f, 1.0f, 1.0f, 0.0f));
|
|
||||||
transform->UpdateWorldMatrix();
|
|
||||||
|
|
||||||
// Ajouter un composant de rendu
|
|
||||||
auto render = entity->AddComponent<ecs::RenderComponent>();
|
|
||||||
render->InitializeWithModel(sharedModel);
|
|
||||||
|
|
||||||
// Ajouter un composant de shader
|
|
||||||
auto shader = entity->AddComponent<ecs::ShaderComponent>();
|
|
||||||
shader->SetActiveShader(ecs::ShaderType::LIGHTING);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Ancien système - Créer temporairement les cubes dans un vecteur local
|
|
||||||
std::vector<object*> tempCubes;
|
|
||||||
tempCubes.reserve(side_count * side_count * side_count);
|
|
||||||
|
|
||||||
// Générer side_count³ cubes
|
// Ajouter un composant d'identité
|
||||||
for (int x = 0; x < side_count; x++) {
|
auto identity = entity->AddComponent<ecs::IdentityComponent>(object_id_++);
|
||||||
for (int y = 0; y < side_count; y++) {
|
identity->SetName("CubePart_" + std::to_string(x) + "_" + std::to_string(y) + "_" + std::to_string(z));
|
||||||
for (int z = 0; z < side_count; z++) {
|
identity->SetType(ecs::ObjectType::Terrain);
|
||||||
object* cubePart = new object(*this);
|
|
||||||
cubePart->SetModel(sharedModel);
|
// Ajouter un composant de transformation
|
||||||
cubePart->SetTranslateMatrix(XMMatrixTranslation(static_cast<float>(x), static_cast<float>(y), static_cast<float>(z)));
|
auto transform = entity->AddComponent<ecs::TransformComponent>();
|
||||||
tempCubes.push_back(cubePart);
|
transform->SetPosition(XMVectorSet(static_cast<float>(x), static_cast<float>(y), static_cast<float>(z), 0.0f));
|
||||||
}
|
transform->SetScale(XMVectorSet(1.0f, 1.0f, 1.0f, 0.0f));
|
||||||
}
|
transform->UpdateWorldMatrix();
|
||||||
}
|
|
||||||
// Transférer les cubes du vecteur temporaire au vecteur membre
|
// Ajouter un composant de rendu
|
||||||
cubes_ = std::move(tempCubes);
|
auto render = entity->AddComponent<ecs::RenderComponent>();
|
||||||
}
|
render->InitializeWithModel(sharedModel);
|
||||||
|
|
||||||
|
// Ajouter un composant de shader
|
||||||
|
auto shader = entity->AddComponent<ecs::ShaderComponent>();
|
||||||
|
shader->SetActiveShader(ecs::ShaderType::LIGHTING);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
update_stats_after_modification();
|
update_stats_after_modification();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2095,3 +2139,4 @@ void application_class::update_stats_after_modification()
|
|||||||
stats_ -> update_geometric_stats();
|
stats_ -> update_geometric_stats();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user