2#include "application_class.h"
4stats::stats() : fps_(nullptr), drawcalls_(0)
6 total_triangle_count_ = std::make_shared<int>(0);
7 total_vertex_count_ = std::make_shared<int>(0);
18 Logger::Get().
Log(
"Application pointer is null", __FILE__, __LINE__, Logger::LogLevel::Error);
28 Logger::Get().
Log(
"FPS object is null", __FILE__, __LINE__, Logger::LogLevel::Error);
32 Logger::Get().
Log(
"Stats initialized successfully", __FILE__, __LINE__, Logger::LogLevel::Initialize);
37void stats::update_geometric_stats()
42 *total_vertex_count_ = get_total_vertex_count();
43 *total_triangle_count_ = get_total_triangle_count();
45 update_visible_count();
47 Logger::Get().
Log(
"Statistics updated: " + std::to_string(*total_vertex_count_) +
" vertices, " + std::to_string(*total_triangle_count_) +
" triangles", __FILE__, __LINE__, Logger::LogLevel::Debug);
51void stats::update_visible_count()
53 visible_triangle_count_ = get_visible_triangle_count();
56void stats::update_display_stats()
59 current_fps_ = fps_->GetFps();
60 min_fps_ = fps_->GetMinFps();
61 max_fps_ = fps_->GetMaxFps();
62 drawcalls_ = get_draw_calls();
63 current_frame_time_ = fps_->GetFrameTime();
66int stats::get_total_vertex_count()
const
68 int totalVertices = 0;
75 for (
const auto& entity : entities)
78 if (renderComponent && renderComponent->GetModel())
80 totalVertices += renderComponent->GetModel()->GetVertexCount();
86 for (
const auto& obj : object_vec_)
88 if (obj && obj->get_model())
90 totalVertices += obj->get_model()->GetVertexCount();
94 for (
const auto& cube : cubes_vec_)
96 if (cube && cube->get_model())
98 totalVertices += cube->get_model()->GetVertexCount();
102 for (
const auto& chunk : terrain_chunk_vec_)
104 if (chunk && chunk->get_model())
106 totalVertices += chunk->get_model()->GetVertexCount();
110 return totalVertices;
113int stats::get_total_triangle_count()
const
115 int totalTriangles = 0;
122 for (
const auto& entity : entities)
125 if (renderComponent && renderComponent->GetModel())
128 totalTriangles += renderComponent->GetModel()->GetIndexCount() / 3;
134 for (
const auto& obj : object_vec_)
136 if (obj && obj->get_model())
138 totalTriangles += obj->get_model()->GetIndexCount() / 3;
142 for (
const auto& cube : cubes_vec_)
144 if (cube && cube->get_model())
146 totalTriangles += cube->get_model()->GetIndexCount() / 3;
150 for (
const auto& chunk : terrain_chunk_vec_)
152 if (chunk && chunk->get_model())
154 totalTriangles += chunk->get_model()->GetIndexCount() / 3;
158 return totalTriangles;
161int stats::get_visible_triangle_count()
const
163 int visibleTriangles = 0;
170 for (
const auto& entity : entities)
173 if (renderComponent && renderComponent->GetModel() && renderComponent->IsVisible())
176 visibleTriangles += renderComponent->GetModel()->GetIndexCount() / 3;
182 for (
const auto& obj : object_vec_)
184 if (obj && obj->get_model() && obj->IsVisible())
186 visibleTriangles += obj->get_model()->GetIndexCount() / 3;
190 for (
const auto& cube : cubes_vec_)
192 if (cube && cube->get_model() && cube->IsVisible())
194 visibleTriangles += cube->get_model()->GetIndexCount() / 3;
198 for (
const auto& chunk : terrain_chunk_vec_)
200 if (chunk && chunk->get_model() && chunk->IsVisible())
202 visibleTriangles += chunk->get_model()->GetIndexCount() / 3;
206 return visibleTriangles;
209std::string stats::get_cpu_name()
211 char CPUBrandString[0x40] = {0};
212 int CPUInfo[4] = {-1};
215 __cpuid(CPUInfo, 0x80000000);
216 unsigned int nExIds = CPUInfo[0];
218 for (
unsigned int i = 0x80000000; i <= nExIds; ++i)
223 memcpy(CPUBrandString, CPUInfo,
sizeof(CPUInfo));
224 else if (i == 0x80000003)
225 memcpy(CPUBrandString + 16, CPUInfo,
sizeof(CPUInfo));
226 else if (i == 0x80000004)
227 memcpy(CPUBrandString + 32, CPUInfo,
sizeof(CPUInfo));
230 std::string result = CPUBrandString;
233 result.erase(std::remove_if(result.begin(), result.end(),
234 [](
unsigned char c) { return c < 32 || c > 126; }),
238 std::string::iterator new_end = std::unique(result.begin(), result.end(),
239 [](
char a,
char b) { return a ==
' ' && b ==
' '; });
240 result.erase(new_end, result.end());
243 result.erase(0, result.find_first_not_of(
' '));
244 result.erase(result.find_last_not_of(
' ') + 1);
249std::string stats::get_gpu_driver_version(ID3D11Device* device)
251 IDXGIDevice* dxgiDevice =
nullptr;
252 IDXGIAdapter* adapter =
nullptr;
253 std::string driverVersion =
"Inconnu";
255 if (SUCCEEDED(device->QueryInterface(__uuidof(IDXGIDevice), (
void**)&dxgiDevice)))
257 if (SUCCEEDED(dxgiDevice->GetAdapter(&adapter)))
259 DXGI_ADAPTER_DESC desc;
260 if (SUCCEEDED(adapter->GetDesc(&desc)))
263 int size_needed = WideCharToMultiByte(CP_UTF8, 0, desc.Description, -1,
nullptr, 0,
nullptr,
nullptr);
264 std::string deviceName;
265 if (size_needed > 0) {
266 std::vector<char> buffer(size_needed);
267 WideCharToMultiByte(CP_UTF8, 0, desc.Description, -1, buffer.data(), size_needed,
nullptr,
nullptr);
268 deviceName = buffer.data();
271 char driverVersionStr[256];
272 sprintf_s(driverVersionStr,
"%s (ID: %04X:%04X)", deviceName.c_str(), desc.VendorId, desc.DeviceId);
274 driverVersion = driverVersionStr;
278 dxgiDevice->Release();
281 return driverVersion;
void Log(const std::string &message, const std::string &fileName, int lineNumber, LogLevel level=LogLevel::Info)
fps_class * get_fps() const
ecs::EntityManager * get_entity_manager() const
std::vector< std::shared_ptr< Entity > > GetEntitiesWithComponent()