Minor - architecture rework pt.2 - V11.1.0

This commit is contained in:
2025-06-03 17:01:18 +02:00
parent d364517633
commit 2a1b474df0
9 changed files with 254 additions and 1573 deletions

View File

@@ -44,6 +44,7 @@
#include <mutex>
#include "shadow_map.h"
#include "stats.h"
/////////////
@@ -77,10 +78,6 @@ public:
render_texture_class* get_refraction_texture() const { return refraction_texture_; };
render_texture_class* get_reflection_texture() const { return reflection_texture_; };
int get_total_vertex_count() const;
int get_total_triangle_count() const;
int get_visible_triangle_count() const;
void create_big_cube(int side_count);
void process_terrain_generation();
virtual bool initialize(int, int, HWND, bool is_vulkan);
@@ -144,18 +141,6 @@ public:
physics* get_physics() const { return physics_; };
// ------------------------------------- //
// --------------- Stats --------------- //
// ------------------------------------- //
int get_current_fps() const { return fps_ ? fps_->GetFps() : 0; };
int get_min_fps() const { return fps_ ? fps_->GetMinFps() : 0; };
int get_max_fps() const { return fps_ ? fps_->GetMaxFps() : 0; };
float get_frame_time() const { return fps_ ? fps_->GetFrameTime() : 0.0f; };
int get_draw_calls() const { return drawcalls_; };
void increment_draw_call_count() { drawcalls_++; };
void reset_draw_call_count() { drawcalls_ = 0; };
// ----------------------------------- //
// ------------- Culling ------------- //
// ----------------------------------- //
@@ -173,6 +158,8 @@ public:
void set_can_fixed_update(bool can_fixed_update) { can_fixed_update_ = can_fixed_update; };
ID3D11ShaderResourceView* get_back_buffer_srv() const {return back_buffer_srv_;};
stats* get_stats() const { return stats_; };
private:
bool render(float, float, float, float, float);
@@ -230,7 +217,6 @@ private :
camera_class* sun_camera_;
camera_class* active_camera_;
position_class* position_;
int drawcalls_;
shadow_map* shadow_map_;
ID3D11ShaderResourceView* shadow_map_srv_;
@@ -306,6 +292,8 @@ private :
ID3D11Texture2D* back_buffer_texture_;
ID3D11ShaderResourceView* back_buffer_srv_;
stats* stats_;
// ------------------------------------------------- //
// ------------------- Culling --------------------- //
// ------------------------------------------------- //

View File

@@ -17,6 +17,7 @@
#include "scene_manager.h"
class application_class;
class stats;
struct widget_entry
{
@@ -76,6 +77,7 @@ private:
application_class* app_;
scene_manager* scene_manager_;
stats* stats_;
bool showObjectWindow;
bool showTerrainWindow;

View File

@@ -0,0 +1,48 @@
#pragma once
#include <vector>
#include "fps_class.h"
#include "object.h"
class stats
{
public:
stats();
~stats();
bool initialize(fps_class* fps, application_class* app);
void update_stats();
void update();
int get_total_vertex_count() const;
int get_total_triangle_count() const;
int get_visible_triangle_count() const;
int get_current_fps() const { return current_fps_; };
int get_min_fps() const { return min_fps_; };
int get_max_fps() const { return max_fps_; };
float get_frame_time() const { return current_frame_time_;};
int get_draw_calls() const { return drawcalls_; };
void increment_draw_call_count() { drawcalls_++; };
void reset_draw_call_count() { drawcalls_ = 0; };
private:
fps_class* fps_;
int drawcalls_;
application_class* app_;
std::vector<object*> object_vec_;
std::vector<object*> cubes_vec_;
std::vector<object*> terrain_chunk_vec_;
int total_vertex_count_;
int total_triangle_count_;
int visible_triangle_count_ = 0;
int current_fps_ = 0;
int min_fps_ = 0;
int max_fps_ = 0;
float current_frame_time_ = 0.0f;
};

View File

@@ -49,7 +49,6 @@ application_class::application_class() : should_quit_(false)
true_light_position_ = XMFLOAT3(0.0f, 0.0f, 0.0f);
light_model_ = nullptr;
render_count_ = 0;
drawcalls_ = 0;
tab_was_pressed_ = false;
}
@@ -492,6 +491,13 @@ bool application_class::initialize(int screenWidth, int screenHeight, HWND hwnd,
return false;
}
stats_ = new stats();
if (!stats_->initialize(fps_, this))
{
Logger::Get().Log("Could not initialize the stats object", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
physics_ = new physics;
physics_thread_ = std::thread(&application_class::physics_thread_function, this);
@@ -761,7 +767,7 @@ bool application_class::frame(input_class* Input)
{
process_terrain_generation();
reset_draw_call_count();
stats_->reset_draw_call_count();
int mouseX, mouseY, currentMouseX, currentMouseY;
bool result, leftMouseDown, rightMouseDown, buttonQ, buttonD, buttonZ, buttonS, buttonA, buttonE, scrollUp, scrollDown;
@@ -2010,7 +2016,7 @@ bool application_class::render_pass(const std::vector<std::reference_wrapper<std
break;
}
increment_draw_call_count();
stats_->increment_draw_call_count();
}
if (isSkybox)
@@ -2160,94 +2166,6 @@ void application_class::physics_thread_function()
}
}
int application_class::get_total_vertex_count() const
{
int totalVertices = 0;
for (const auto& obj : object_)
{
if (obj)
{
totalVertices += obj->GetVertexCount();
}
}
// Ajoutez le nombre de sommets pour les cubes
for (const auto& cube : cubes_)
{
if (cube)
{
totalVertices += cube->GetVertexCount();
}
}
// Ajoutez le nombre de sommets pour le terrain
for (const auto& chunk : terrain_chunk_)
{
if (chunk)
{
totalVertices += chunk->GetVertexCount();
}
}
return totalVertices;
}
int application_class::get_total_triangle_count() const
{
int totalTriangles = 0;
for (const auto& obj : object_)
{
if (obj)
{
// Dans une topologie de liste de triangles, chaque triangle utilise 3 indices
totalTriangles += obj->GetIndexCount() / 3;
}
}
// Ajoutez le nombre de triangles pour les cubes
for (const auto& cube : cubes_)
{
if (cube)
{
totalTriangles += cube->GetIndexCount() / 3;
}
}
// Ajoutez le nombre de triangles pour le terrain
for (const auto& chunk : terrain_chunk_)
{
if (chunk)
{
totalTriangles += chunk->GetIndexCount() / 3;
}
}
return totalTriangles;
}
int application_class::get_visible_triangle_count() const
{
int visibleTriangles = 0;
for (const auto& obj : object_)
{
if (obj && obj->IsVisible())
{
visibleTriangles += obj->GetIndexCount() / 3;
}
}
// Ajoutez le nombre de triangles visibles pour les cubes
for (const auto& cube : cubes_)
{
if (cube && cube->IsVisible())
{
visibleTriangles += cube->GetIndexCount() / 3;
}
}
// Ajoutez le nombre de triangles visibles pour le terrain
for (const auto& chunk : terrain_chunk_)
{
if (chunk && chunk->IsVisible())
{
visibleTriangles += chunk->GetIndexCount() / 3;
}
}
return visibleTriangles;
}
void application_class::create_big_cube(int side_count)
{
Logger::Get().Log("Lancement de la g<>n<EFBFBD>ration du terrain dans un thread s<>par<61>", __FILE__, __LINE__, Logger::LogLevel::Info);

View File

@@ -1,5 +1,6 @@
#include "imguiManager.h"
#include "application_class.h"
#include "stats.h"
static fps_limiter fpsLimiter(60.0f);
@@ -167,6 +168,8 @@ bool imguiManager::Initialize(HWND hwnd, ID3D11Device* device, ID3D11DeviceConte
Logger::Get().Log("Failed to initialize scene manager", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
stats_ = app_->get_stats();
Logger::Get().Log("imgui initialized", __FILE__, __LINE__, Logger::LogLevel::Initialize);
@@ -981,15 +984,14 @@ void imguiManager::WidgetRenderStats()
{
ImGui::Begin("render Stats");
current_fps_ = app_->get_current_fps();
min_fps_ = app_->get_min_fps();
max_fps_ = app_->get_max_fps();
draw_calls_ = app_->get_draw_calls();
total_vertex_count_ = app_->get_total_vertex_count();
total_triangle_count_ = app_->get_total_triangle_count();
visible_triangle_count_ = app_->get_visible_triangle_count();
current_frame_time_ = app_->get_frame_time();
current_fps_ = stats_->get_current_fps();
min_fps_ = stats_->get_min_fps();
max_fps_ = stats_->get_max_fps();
draw_calls_ = stats_->get_draw_calls();
total_vertex_count_ = stats_->get_total_vertex_count();
total_triangle_count_ = stats_->get_total_triangle_count();
visible_triangle_count_ = stats_->get_visible_triangle_count();
current_frame_time_ = stats_->get_frame_time();
m_frameTimeHistory[m_frameTimeHistoryIndex] = current_frame_time_;
m_frameTimeHistoryIndex = (m_frameTimeHistoryIndex + 1) % FRAME_HISTORY_COUNT;

View File

@@ -0,0 +1,144 @@
#include "stats.h"
#include "application_class.h"
stats::stats() : fps_(nullptr), drawcalls_(0)
{
}
stats::~stats()
{
fps_ = nullptr;
}
bool stats::initialize(fps_class* fps, application_class* app)
{
if (!fps) {
Logger::Get().Log("FPS pointer is null", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
fps_ = fps;
drawcalls_ = 0;
app_ = app;
// call update() in a separate thread
std::thread updateThread(&stats::update, this);
updateThread.detach(); // Detach the thread to run independently
Logger::Get().Log("Stats initialized successfully", __FILE__, __LINE__, Logger::LogLevel::Initialize);
return true;
}
void stats::update()
{
while (true)
{
// call update_stats() every second
std::this_thread::sleep_for(std::chrono::seconds(1));
update_stats();
}
}
void stats::update_stats()
{
object_vec_ = app_->get_kobjects();
cubes_vec_ = app_->get_cubes();
terrain_chunk_vec_ = app_->get_terrain_cubes();
current_fps_ = get_current_fps();
min_fps_ = get_min_fps();
max_fps_ = get_max_fps();
drawcalls_ = get_draw_calls();
total_vertex_count_ = get_total_vertex_count();
total_triangle_count_ = get_total_triangle_count();
visible_triangle_count_ = get_visible_triangle_count();
current_frame_time_ = get_frame_time();
}
int stats::get_total_vertex_count() const
{
int totalVertices = 0;
for (const auto& obj : object_vec_)
{
if (obj)
{
totalVertices += obj->GetVertexCount();
}
}
// Ajoutez le nombre de sommets pour les cubes
for (const auto& cube : cubes_vec_)
{
if (cube)
{
totalVertices += cube->GetVertexCount();
}
}
// Ajoutez le nombre de sommets pour le terrain
for (const auto& chunk : terrain_chunk_vec_)
{
if (chunk)
{
totalVertices += chunk->GetVertexCount();
}
}
return totalVertices;
}
int stats::get_total_triangle_count() const
{
int totalTriangles = 0;
for (const auto& obj : object_vec_)
{
if (obj)
{
// Dans une topologie de liste de triangles, chaque triangle utilise 3 indices
totalTriangles += obj->GetIndexCount() / 3;
}
}
// Ajoutez le nombre de triangles pour les cubes
for (const auto& cube : cubes_vec_)
{
if (cube)
{
totalTriangles += cube->GetIndexCount() / 3;
}
}
// Ajoutez le nombre de triangles pour le terrain
for (const auto& chunk : terrain_chunk_vec_)
{
if (chunk)
{
totalTriangles += chunk->GetIndexCount() / 3;
}
}
return totalTriangles;
}
int stats::get_visible_triangle_count() const
{
int visibleTriangles = 0;
for (const auto& obj : object_vec_)
{
if (obj && obj->IsVisible())
{
visibleTriangles += obj->GetIndexCount() / 3;
}
}
// Ajoutez le nombre de triangles visibles pour les cubes
for (const auto& cube : cubes_vec_)
{
if (cube && cube->IsVisible())
{
visibleTriangles += cube->GetIndexCount() / 3;
}
}
// Ajoutez le nombre de triangles visibles pour le terrain
for (const auto& chunk : terrain_chunk_vec_)
{
if (chunk && chunk->IsVisible())
{
visibleTriangles += chunk->GetIndexCount() / 3;
}
}
return visibleTriangles;
}