# Khaotic Engine Reborn: stats Class Reference

Loading...
Searching...
No Matches
stats Class Reference

## Public Member Functions

bool | initialize (application_class *app)
void | update_geometric_stats ()
void | update_visible_count ()
void | update_display_stats ()
int | get_total_vertex_count () const
int | get_total_triangle_count () const
int | get_visible_triangle_count () const
int | get_current_fps () const
int | get_min_fps () const
int | get_max_fps () const
float | get_frame_time () const
int | get_draw_calls () const
void | increment_draw_call_count ()
void | reset_draw_call_count ()
std::string | get_cpu_name ()
std::string | get_gpu_driver_version (ID3D11Device *device)
std::shared_ptr< int > & | get_vertex_count_ptr ()
std::shared_ptr< int > & | get_triangle_count_ptr ()

## Detailed Description

Definition at line 12 of file stats.h.

## Constructor & Destructor Documentation

## stats()

stats::stats | ( |  | ) |

Definition at line 4 of file stats.cpp.

: fps_(nullptr), drawcalls_(0)
{
total_triangle_count_ = std::make_shared<int>(0);
total_vertex_count_ = std::make_shared<int>(0);
}

## ~stats()

stats::~stats | ( |  | ) |

Definition at line 10 of file stats.cpp.

{
fps_ = nullptr;
}

## Member Function Documentation

## get_cpu_name()

std::string stats::get_cpu_name | ( |  | ) |

Definition at line 209 of file stats.cpp.

{
char CPUBrandString[0x40] = {0};
int CPUInfo[4] = {-1};
// Fonction CPUID pour récupérer le nom du CPU
__cpuid(CPUInfo, 0x80000000);
unsigned int nExIds = CPUInfo[0];
for (unsigned int i = 0x80000000; i <= nExIds; ++i)
{
__cpuid(CPUInfo, i);
if (i == 0x80000002)
memcpy(CPUBrandString, CPUInfo, sizeof(CPUInfo));
else if (i == 0x80000003)
memcpy(CPUBrandString + 16, CPUInfo, sizeof(CPUInfo));
else if (i == 0x80000004)
memcpy(CPUBrandString + 32, CPUInfo, sizeof(CPUInfo));
}
std::string result = CPUBrandString;
// Nettoyer les caractères non-ASCII ou problématiques
result.erase(std::remove_if(result.begin(), result.end(),
[](unsigned char c) { return c < 32 || c > 126; }),
result.end());
// Supprimer les espaces multiples consécutifs
std::string::iterator new_end = std::unique(result.begin(), result.end(),
[](char a, char b) { return a == ' ' && b == ' '; });
result.erase(new_end, result.end());
// Supprimer les espaces au début et à la fin
result.erase(0, result.find_first_not_of(' '));
result.erase(result.find_last_not_of(' ') + 1);
return result;
}

## get_current_fps()

int stats::get_current_fps | ( |  | ) | const

inline

Definition at line 28 of file stats.h.

{ return current_fps_; };

## get_draw_calls()

int stats::get_draw_calls | ( |  | ) | const

inline

Definition at line 32 of file stats.h.

{ return drawcalls_; };

## get_frame_time()

float stats::get_frame_time | ( |  | ) | const

inline

Definition at line 31 of file stats.h.

{ return current_frame_time_;};

## get_gpu_driver_version()

std::string stats::get_gpu_driver_version | ( | ID3D11Device * | device | ) |

Definition at line 249 of file stats.cpp.

{
IDXGIDevice* dxgiDevice = nullptr;
IDXGIAdapter* adapter = nullptr;
std::string driverVersion = "Inconnu";
if (SUCCEEDED(device->QueryInterface(__uuidof(IDXGIDevice), (void**)&dxgiDevice)))
{
if (SUCCEEDED(dxgiDevice->GetAdapter(&adapter)))
{
DXGI_ADAPTER_DESC desc;
if (SUCCEEDED(adapter->GetDesc(&desc)))
{
// Conversion correcte de WCHAR (UTF-16) vers UTF-8
int size_needed = WideCharToMultiByte(CP_UTF8, 0, desc.Description, -1, nullptr, 0, nullptr, nullptr);
std::string deviceName;
if (size_needed > 0) {
std::vector<char> buffer(size_needed);
WideCharToMultiByte(CP_UTF8, 0, desc.Description, -1, buffer.data(), size_needed, nullptr, nullptr);
deviceName = buffer.data();
}
char driverVersionStr[256];
sprintf_s(driverVersionStr, "%s (ID: %04X:%04X)", deviceName.c_str(), desc.VendorId, desc.DeviceId);
driverVersion = driverVersionStr;
}
adapter->Release();
}
dxgiDevice->Release();
}
return driverVersion;
}

## get_max_fps()

int stats::get_max_fps | ( |  | ) | const

inline

Definition at line 30 of file stats.h.

{ return max_fps_; };

## get_min_fps()

int stats::get_min_fps | ( |  | ) | const

inline

Definition at line 29 of file stats.h.

{ return min_fps_; };

## get_total_triangle_count()

int stats::get_total_triangle_count | ( |  | ) | const

Definition at line 113 of file stats.cpp.

{
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 && obj->get_model())
{
totalTriangles += obj->get_model()->GetIndexCount() / 3;
}
}
for (const auto& cube : cubes_vec_)
{
if (cube && cube->get_model())
{
totalTriangles += cube->get_model()->GetIndexCount() / 3;
}
}
for (const auto& chunk : terrain_chunk_vec_)
{
if (chunk && chunk->get_model())
{
totalTriangles += chunk->get_model()->GetIndexCount() / 3;
}
}
return totalTriangles;
}
application_class::get_entity_manager
ecs::EntityManager * get_entity_manager() const
Definition application_class.h:439
ecs::EntityManager::GetEntitiesWithComponent
std::vector< std::shared_ptr< Entity > > GetEntitiesWithComponent()
Definition entity_manager.h:95
ecs::RenderComponent
Definition render_component.h:29

## get_total_vertex_count()

int stats::get_total_vertex_count | ( |  | ) | const

Definition at line 66 of file stats.cpp.

{
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 && obj->get_model())
{
totalVertices += obj->get_model()->GetVertexCount();
}
}
for (const auto& cube : cubes_vec_)
{
if (cube && cube->get_model())
{
totalVertices += cube->get_model()->GetVertexCount();
}
}
for (const auto& chunk : terrain_chunk_vec_)
{
if (chunk && chunk->get_model())
{
totalVertices += chunk->get_model()->GetVertexCount();
}
}
return totalVertices;
}

## get_triangle_count_ptr()

std::shared_ptr< int > & stats::get_triangle_count_ptr | ( |  | ) |

inline

Definition at line 41 of file stats.h.

{ return total_triangle_count_; }

## get_vertex_count_ptr()

std::shared_ptr< int > & stats::get_vertex_count_ptr | ( |  | ) |

inline

Definition at line 40 of file stats.h.

{ return total_vertex_count_; }

## get_visible_triangle_count()

int stats::get_visible_triangle_count | ( |  | ) | const

Definition at line 161 of file stats.cpp.

{
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->get_model() && obj->IsVisible())
{
visibleTriangles += obj->get_model()->GetIndexCount() / 3;
}
}
for (const auto& cube : cubes_vec_)
{
if (cube && cube->get_model() && cube->IsVisible())
{
visibleTriangles += cube->get_model()->GetIndexCount() / 3;
}
}
for (const auto& chunk : terrain_chunk_vec_)
{
if (chunk && chunk->get_model() && chunk->IsVisible())
{
visibleTriangles += chunk->get_model()->GetIndexCount() / 3;
}
}
return visibleTriangles;
}

## increment_draw_call_count()

void stats::increment_draw_call_count | ( |  | ) |

inline

Definition at line 34 of file stats.h.

{ drawcalls_++; };

## initialize()

bool stats::initialize | ( | application_class * | app | ) |

Definition at line 15 of file stats.cpp.

{
if (!app) {
Logger::Get().Log("Application pointer is null", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
drawcalls_ = 0;
app_ = app;
fps_ = app_->get_fps();
if (!fps_) {
Logger::Get().Log("FPS object is null", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
Logger::Get().Log("Stats initialized successfully", __FILE__, __LINE__, Logger::LogLevel::Initialize);
return true;
}
application_class::get_fps
fps_class * get_fps() const
Definition application_class.h:433

## reset_draw_call_count()

void stats::reset_draw_call_count | ( |  | ) |

inline

Definition at line 35 of file stats.h.

{ drawcalls_ = 0; };

## update_display_stats()

void stats::update_display_stats | ( |  | ) |

Definition at line 56 of file stats.cpp.

{
current_fps_ = fps_->GetFps();
min_fps_ = fps_->GetMinFps();
max_fps_ = fps_->GetMaxFps();
drawcalls_ = get_draw_calls();
current_frame_time_ = fps_->GetFrameTime();
}

## update_geometric_stats()

void stats::update_geometric_stats | ( |  | ) |

Definition at line 37 of file stats.cpp.

{
// 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);
}
}

## update_visible_count()

void stats::update_visible_count | ( |  | ) |

Definition at line 51 of file stats.cpp.

{
visible_triangle_count_ = get_visible_triangle_count();
}

The documentation for this class was generated from the following files:

- enginecustom/src/inc/system/stats.h
- enginecustom/src/src/system/stats.cpp