Minor - ECS use in stats - V12.5.0
This commit is contained in:
parent
7755150ae8
commit
9d0d2d1dfd
@ -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
|
||||
|
||||
|
@ -106,11 +106,11 @@ public:
|
||||
|
||||
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; };
|
||||
|
@ -2071,3 +2071,19 @@ void application_class::update_stats_after_modification()
|
||||
}
|
||||
}
|
||||
|
||||
int application_class::get_terrain_entity_count()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(objects_mutex_);
|
||||
int terrainCount = 0;
|
||||
|
||||
// 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) {
|
||||
terrainCount++;
|
||||
}
|
||||
}
|
||||
|
||||
return terrainCount;
|
||||
}
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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();
|
||||
// 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();
|
||||
|
||||
*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<ecs::RenderComponent>();
|
||||
|
||||
for (const auto& entity : entities)
|
||||
{
|
||||
auto renderComponent = entity->GetComponent<ecs::RenderComponent>();
|
||||
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<ecs::RenderComponent>();
|
||||
|
||||
for (const auto& entity : entities)
|
||||
{
|
||||
auto renderComponent = entity->GetComponent<ecs::RenderComponent>();
|
||||
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<ecs::RenderComponent>();
|
||||
|
||||
for (const auto& entity : entities)
|
||||
{
|
||||
auto renderComponent = entity->GetComponent<ecs::RenderComponent>();
|
||||
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;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user