From 9d0d2d1dfd11b6c2b01573832e309c9eff7b9c83 Mon Sep 17 00:00:00 2001 From: CatChow0 Date: Tue, 24 Jun 2025 17:15:58 +0200 Subject: [PATCH] Minor - ECS use in stats - V12.5.0 --- enginecustom/imgui.ini | 4 +- .../src/inc/system/application_class.h | 4 +- .../src/src/system/application_class.cpp | 16 +++ enginecustom/src/src/system/imguiManager.cpp | 4 +- enginecustom/src/src/system/stats.cpp | 109 +++++++++++++----- 5 files changed, 104 insertions(+), 33 deletions(-) diff --git a/enginecustom/imgui.ini b/enginecustom/imgui.ini index dac9d77..ab6c9d5 100644 --- a/enginecustom/imgui.ini +++ b/enginecustom/imgui.ini @@ -10,7 +10,7 @@ Collapsed=0 [Window][Khaotic Engine] Pos=1267,19 -Size=317,842 +Size=317,609 Collapsed=0 DockId=0x00000005,0 @@ -28,7 +28,7 @@ DockId=0x0000000B,0 [Window][Terrain] Pos=0,19 -Size=266,842 +Size=266,609 Collapsed=0 DockId=0x00000007,0 diff --git a/enginecustom/src/inc/system/application_class.h b/enginecustom/src/inc/system/application_class.h index 463d7ca..ac4d74c 100644 --- a/enginecustom/src/inc/system/application_class.h +++ b/enginecustom/src/inc/system/application_class.h @@ -103,14 +103,14 @@ public: float get_speed() const { return speed_; }; void set_speed(const float speed) { this->speed_ = speed; }; - + void add_cube(); void delete_entity_by_id(int entity_id); - void delete_kobject(int index); void add_kobject(std::wstring& filepath); void set_path(WCHAR* path) { path_ = path; }; void set_w_folder(const std::filesystem::path& w_folder) { w_folder_ = w_folder; }; std::filesystem::path get_w_folder() const { return w_folder_; }; + int get_terrain_entity_count(); int get_object_id() const { return object_id_; }; void set_object_id(int object_id) { object_id_ = object_id; }; diff --git a/enginecustom/src/src/system/application_class.cpp b/enginecustom/src/src/system/application_class.cpp index 289f982..6f4ecbd 100644 --- a/enginecustom/src/src/system/application_class.cpp +++ b/enginecustom/src/src/system/application_class.cpp @@ -2071,3 +2071,19 @@ void application_class::update_stats_after_modification() } } +int application_class::get_terrain_entity_count() +{ + std::lock_guard lock(objects_mutex_); + int terrainCount = 0; + + // Get all entities with the Terrain type + auto entities_with_terrain = entity_manager_->GetEntitiesWithComponent(); + for (auto& entity : entities_with_terrain) { + auto identity = entity->GetComponent(); + if (identity && identity->GetType() == ecs::ObjectType::Terrain) { + terrainCount++; + } + } + + return terrainCount; +} diff --git a/enginecustom/src/src/system/imguiManager.cpp b/enginecustom/src/src/system/imguiManager.cpp index b404564..c196632 100644 --- a/enginecustom/src/src/system/imguiManager.cpp +++ b/enginecustom/src/src/system/imguiManager.cpp @@ -386,7 +386,7 @@ void imguiManager::WidgetAddObject() } ImGui::SameLine(); - ImGui::Text("Number of cubes: %d", 1); //TODO: Replace with actual count of cubes + ImGui::Text("Number of cubes: %d", app_->get_entity_manager()->GetEntityCount()); } } @@ -702,7 +702,7 @@ void imguiManager::WidgetTerrainWindow() { ImGui::Begin("Terrain", &showTerrainWindow); - ImGui::Text("Number of terrain cubes: %d", 1); // TODO: Replace with actual count of terrain cubes + ImGui::Text("Number of terrain cubes: %d", app_->get_terrain_entity_count()); ImGui::Separator(); diff --git a/enginecustom/src/src/system/stats.cpp b/enginecustom/src/src/system/stats.cpp index 0debbd4..3fb453e 100644 --- a/enginecustom/src/src/system/stats.cpp +++ b/enginecustom/src/src/system/stats.cpp @@ -36,16 +36,16 @@ bool stats::initialize(application_class* app) void stats::update_geometric_stats() { - // TODO - // object_vec_ = app_->get_kobjects(); - // cubes_vec_ = app_->get_cubes(); - // terrain_chunk_vec_ = app_->get_terrain_cubes(); - - - *total_vertex_count_ = get_total_vertex_count(); - *total_triangle_count_ = get_total_triangle_count(); - - update_visible_count(); + // Utiliser le système ECS pour accéder aux entités avec des composants de rendu + if (app_ && app_->get_entity_manager()) + { + *total_vertex_count_ = get_total_vertex_count(); + *total_triangle_count_ = get_total_triangle_count(); + + update_visible_count(); + + Logger::Get().Log("Statistics updated: " + std::to_string(*total_vertex_count_) + " vertices, " + std::to_string(*total_triangle_count_) + " triangles", __FILE__, __LINE__, Logger::LogLevel::Debug); + } } void stats::update_visible_count() @@ -66,88 +66,143 @@ void stats::update_display_stats() int stats::get_total_vertex_count() const { int totalVertices = 0; + + // Utiliser le système ECS pour accéder aux entités avec des composants de rendu + if (app_ && app_->get_entity_manager()) + { + auto entities = app_->get_entity_manager()->GetEntitiesWithComponent(); + + for (const auto& entity : entities) + { + auto renderComponent = entity->GetComponent(); + if (renderComponent && renderComponent->GetModel()) + { + totalVertices += renderComponent->GetModel()->GetVertexCount(); + } + } + } + + // Ajouter également les éventuels objets restants de l'ancien système for (const auto& obj : object_vec_) { - if (obj) + if (obj && obj->get_model()) { totalVertices += obj->get_model()->GetVertexCount(); } } - // Ajoutez le nombre de sommets pour les cubes + for (const auto& cube : cubes_vec_) { - if (cube) + if (cube && cube->get_model()) { totalVertices += cube->get_model()->GetVertexCount(); } } - // Ajoutez le nombre de sommets pour le terrain + for (const auto& chunk : terrain_chunk_vec_) { - if (chunk) + if (chunk && chunk->get_model()) { totalVertices += chunk->get_model()->GetVertexCount(); } } + return totalVertices; } int stats::get_total_triangle_count() const { int totalTriangles = 0; + + // Utiliser le système ECS pour accéder aux entités avec des composants de rendu + if (app_ && app_->get_entity_manager()) + { + auto entities = app_->get_entity_manager()->GetEntitiesWithComponent(); + + for (const auto& entity : entities) + { + auto renderComponent = entity->GetComponent(); + if (renderComponent && renderComponent->GetModel()) + { + // Dans une topologie de liste de triangles, chaque triangle utilise 3 indices + totalTriangles += renderComponent->GetModel()->GetIndexCount() / 3; + } + } + } + + // Ajouter également les éventuels objets restants de l'ancien système for (const auto& obj : object_vec_) { - if (obj) + if (obj && obj->get_model()) { - // Dans une topologie de liste de triangles, chaque triangle utilise 3 indices totalTriangles += obj->get_model()->GetIndexCount() / 3; } } - // Ajoutez le nombre de triangles pour les cubes + for (const auto& cube : cubes_vec_) { - if (cube) + if (cube && cube->get_model()) { totalTriangles += cube->get_model()->GetIndexCount() / 3; } } - // Ajoutez le nombre de triangles pour le terrain + for (const auto& chunk : terrain_chunk_vec_) { - if (chunk) + if (chunk && chunk->get_model()) { totalTriangles += chunk->get_model()->GetIndexCount() / 3; } } + return totalTriangles; } int stats::get_visible_triangle_count() const { int visibleTriangles = 0; + + // Utiliser le système ECS pour accéder aux entités avec des composants de rendu + if (app_ && app_->get_entity_manager()) + { + auto entities = app_->get_entity_manager()->GetEntitiesWithComponent(); + + for (const auto& entity : entities) + { + auto renderComponent = entity->GetComponent(); + if (renderComponent && renderComponent->GetModel() && renderComponent->IsVisible()) + { + // Dans une topologie de liste de triangles, chaque triangle utilise 3 indices + visibleTriangles += renderComponent->GetModel()->GetIndexCount() / 3; + } + } + } + + // Ajouter également les éventuels objets restants de l'ancien système for (const auto& obj : object_vec_) { - if (obj && obj->IsVisible()) + if (obj && obj->get_model() && obj->IsVisible()) { visibleTriangles += obj->get_model()->GetIndexCount() / 3; } } - // Ajoutez le nombre de triangles visibles pour les cubes + for (const auto& cube : cubes_vec_) { - if (cube && cube->IsVisible()) + if (cube && cube->get_model() && cube->IsVisible()) { visibleTriangles += cube->get_model()->GetIndexCount() / 3; } } - // Ajoutez le nombre de triangles visibles pour le terrain + for (const auto& chunk : terrain_chunk_vec_) { - if (chunk && chunk->IsVisible()) + if (chunk && chunk->get_model() && chunk->IsVisible()) { visibleTriangles += chunk->get_model()->GetIndexCount() / 3; } } + return visibleTriangles; } @@ -224,4 +279,4 @@ std::string stats::get_gpu_driver_version(ID3D11Device* device) } return driverVersion; -} \ No newline at end of file +}