Khaotic Engine Reborn
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.

4 : fps_(nullptr), drawcalls_(0)
5{
6 total_triangle_count_ = std::make_shared<int>(0);
7 total_vertex_count_ = std::make_shared<int>(0);
8}

◆ ~stats()

stats::~stats ( )

Definition at line 10 of file stats.cpp.

11{
12 fps_ = nullptr;
13}

Member Function Documentation

◆ get_cpu_name()

std::string stats::get_cpu_name ( )

Definition at line 209 of file stats.cpp.

210{
211 char CPUBrandString[0x40] = {0};
212 int CPUInfo[4] = {-1};
213
214 // Fonction CPUID pour récupérer le nom du CPU
215 __cpuid(CPUInfo, 0x80000000);
216 unsigned int nExIds = CPUInfo[0];
217
218 for (unsigned int i = 0x80000000; i <= nExIds; ++i)
219 {
220 __cpuid(CPUInfo, i);
221
222 if (i == 0x80000002)
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));
228 }
229
230 std::string result = CPUBrandString;
231
232 // Nettoyer les caractères non-ASCII ou problématiques
233 result.erase(std::remove_if(result.begin(), result.end(),
234 [](unsigned char c) { return c < 32 || c > 126; }),
235 result.end());
236
237 // Supprimer les espaces multiples consécutifs
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());
241
242 // Supprimer les espaces au début et à la fin
243 result.erase(0, result.find_first_not_of(' '));
244 result.erase(result.find_last_not_of(' ') + 1);
245
246 return result;
247}

◆ get_current_fps()

int stats::get_current_fps ( ) const
inline

Definition at line 28 of file stats.h.

28{ return current_fps_; };

◆ get_draw_calls()

int stats::get_draw_calls ( ) const
inline

Definition at line 32 of file stats.h.

32{ return drawcalls_; };

◆ get_frame_time()

float stats::get_frame_time ( ) const
inline

Definition at line 31 of file stats.h.

31{ 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.

250{
251 IDXGIDevice* dxgiDevice = nullptr;
252 IDXGIAdapter* adapter = nullptr;
253 std::string driverVersion = "Inconnu";
254
255 if (SUCCEEDED(device->QueryInterface(__uuidof(IDXGIDevice), (void**)&dxgiDevice)))
256 {
257 if (SUCCEEDED(dxgiDevice->GetAdapter(&adapter)))
258 {
259 DXGI_ADAPTER_DESC desc;
260 if (SUCCEEDED(adapter->GetDesc(&desc)))
261 {
262 // Conversion correcte de WCHAR (UTF-16) vers UTF-8
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();
269 }
270
271 char driverVersionStr[256];
272 sprintf_s(driverVersionStr, "%s (ID: %04X:%04X)", deviceName.c_str(), desc.VendorId, desc.DeviceId);
273
274 driverVersion = driverVersionStr;
275 }
276 adapter->Release();
277 }
278 dxgiDevice->Release();
279 }
280
281 return driverVersion;
282}

◆ get_max_fps()

int stats::get_max_fps ( ) const
inline

Definition at line 30 of file stats.h.

30{ return max_fps_; };

◆ get_min_fps()

int stats::get_min_fps ( ) const
inline

Definition at line 29 of file stats.h.

29{ return min_fps_; };

◆ get_total_triangle_count()

int stats::get_total_triangle_count ( ) const

Definition at line 113 of file stats.cpp.

114{
115 int totalTriangles = 0;
116
117 // Utiliser le système ECS pour accéder aux entités avec des composants de rendu
118 if (app_ && app_->get_entity_manager())
119 {
121
122 for (const auto& entity : entities)
123 {
124 auto renderComponent = entity->GetComponent<ecs::RenderComponent>();
125 if (renderComponent && renderComponent->GetModel())
126 {
127 // Dans une topologie de liste de triangles, chaque triangle utilise 3 indices
128 totalTriangles += renderComponent->GetModel()->GetIndexCount() / 3;
129 }
130 }
131 }
132
133 // Ajouter également les éventuels objets restants de l'ancien système
134 for (const auto& obj : object_vec_)
135 {
136 if (obj && obj->get_model())
137 {
138 totalTriangles += obj->get_model()->GetIndexCount() / 3;
139 }
140 }
141
142 for (const auto& cube : cubes_vec_)
143 {
144 if (cube && cube->get_model())
145 {
146 totalTriangles += cube->get_model()->GetIndexCount() / 3;
147 }
148 }
149
150 for (const auto& chunk : terrain_chunk_vec_)
151 {
152 if (chunk && chunk->get_model())
153 {
154 totalTriangles += chunk->get_model()->GetIndexCount() / 3;
155 }
156 }
157
158 return totalTriangles;
159}
ecs::EntityManager * get_entity_manager() const
std::vector< std::shared_ptr< Entity > > GetEntitiesWithComponent()

◆ get_total_vertex_count()

int stats::get_total_vertex_count ( ) const

Definition at line 66 of file stats.cpp.

67{
68 int totalVertices = 0;
69
70 // Utiliser le système ECS pour accéder aux entités avec des composants de rendu
71 if (app_ && app_->get_entity_manager())
72 {
74
75 for (const auto& entity : entities)
76 {
77 auto renderComponent = entity->GetComponent<ecs::RenderComponent>();
78 if (renderComponent && renderComponent->GetModel())
79 {
80 totalVertices += renderComponent->GetModel()->GetVertexCount();
81 }
82 }
83 }
84
85 // Ajouter également les éventuels objets restants de l'ancien système
86 for (const auto& obj : object_vec_)
87 {
88 if (obj && obj->get_model())
89 {
90 totalVertices += obj->get_model()->GetVertexCount();
91 }
92 }
93
94 for (const auto& cube : cubes_vec_)
95 {
96 if (cube && cube->get_model())
97 {
98 totalVertices += cube->get_model()->GetVertexCount();
99 }
100 }
101
102 for (const auto& chunk : terrain_chunk_vec_)
103 {
104 if (chunk && chunk->get_model())
105 {
106 totalVertices += chunk->get_model()->GetVertexCount();
107 }
108 }
109
110 return totalVertices;
111}

◆ get_triangle_count_ptr()

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

Definition at line 41 of file stats.h.

41{ 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.

40{ return total_vertex_count_; }

◆ get_visible_triangle_count()

int stats::get_visible_triangle_count ( ) const

Definition at line 161 of file stats.cpp.

162{
163 int visibleTriangles = 0;
164
165 // Utiliser le système ECS pour accéder aux entités avec des composants de rendu
166 if (app_ && app_->get_entity_manager())
167 {
169
170 for (const auto& entity : entities)
171 {
172 auto renderComponent = entity->GetComponent<ecs::RenderComponent>();
173 if (renderComponent && renderComponent->GetModel() && renderComponent->IsVisible())
174 {
175 // Dans une topologie de liste de triangles, chaque triangle utilise 3 indices
176 visibleTriangles += renderComponent->GetModel()->GetIndexCount() / 3;
177 }
178 }
179 }
180
181 // Ajouter également les éventuels objets restants de l'ancien système
182 for (const auto& obj : object_vec_)
183 {
184 if (obj && obj->get_model() && obj->IsVisible())
185 {
186 visibleTriangles += obj->get_model()->GetIndexCount() / 3;
187 }
188 }
189
190 for (const auto& cube : cubes_vec_)
191 {
192 if (cube && cube->get_model() && cube->IsVisible())
193 {
194 visibleTriangles += cube->get_model()->GetIndexCount() / 3;
195 }
196 }
197
198 for (const auto& chunk : terrain_chunk_vec_)
199 {
200 if (chunk && chunk->get_model() && chunk->IsVisible())
201 {
202 visibleTriangles += chunk->get_model()->GetIndexCount() / 3;
203 }
204 }
205
206 return visibleTriangles;
207}

◆ increment_draw_call_count()

void stats::increment_draw_call_count ( )
inline

Definition at line 34 of file stats.h.

34{ drawcalls_++; };

◆ initialize()

bool stats::initialize ( application_class * app)

Definition at line 15 of file stats.cpp.

16{
17 if (!app) {
18 Logger::Get().Log("Application pointer is null", __FILE__, __LINE__, Logger::LogLevel::Error);
19 return false;
20 }
21
22 drawcalls_ = 0;
23 app_ = app;
24
25 fps_ = app_->get_fps();
26
27 if (!fps_) {
28 Logger::Get().Log("FPS object is null", __FILE__, __LINE__, Logger::LogLevel::Error);
29 return false;
30 }
31
32 Logger::Get().Log("Stats initialized successfully", __FILE__, __LINE__, Logger::LogLevel::Initialize);
33
34 return true;
35}
static Logger & Get()
Definition Logger.h:20
void Log(const std::string &message, const std::string &fileName, int lineNumber, LogLevel level=LogLevel::Info)
Definition Logger.h:158
fps_class * get_fps() const

◆ reset_draw_call_count()

void stats::reset_draw_call_count ( )
inline

Definition at line 35 of file stats.h.

35{ drawcalls_ = 0; };

◆ update_display_stats()

void stats::update_display_stats ( )

Definition at line 56 of file stats.cpp.

57{
58
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();
64}

◆ update_geometric_stats()

void stats::update_geometric_stats ( )

Definition at line 37 of file stats.cpp.

38{
39 // Utiliser le système ECS pour accéder aux entités avec des composants de rendu
40 if (app_ && app_->get_entity_manager())
41 {
42 *total_vertex_count_ = get_total_vertex_count();
43 *total_triangle_count_ = get_total_triangle_count();
44
45 update_visible_count();
46
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);
48 }
49}

◆ update_visible_count()

void stats::update_visible_count ( )

Definition at line 51 of file stats.cpp.

52{
53 visible_triangle_count_ = get_visible_triangle_count();
54}

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