Minor - Stats Update - V11.2.0

This commit is contained in:
CatChow0 2025-06-03 18:35:51 +02:00
parent 2a1b474df0
commit 315d259acd
7 changed files with 205 additions and 50 deletions

View File

@ -5,15 +5,13 @@
</component>
<component name="ChangeListManager">
<list default="true" id="e81d6e08-efc7-40a0-909d-ec4943d948e9" name="Changes" comment="">
<change afterPath="$PROJECT_DIR$/enginecustom/src/inc/system/stats.h" afterDir="false" />
<change afterPath="$PROJECT_DIR$/enginecustom/src/src/system/stats.cpp" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/.idea.KhaoticEngineReborn/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/.idea.KhaoticEngineReborn/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/enginecustom/enginecustom.vcxproj" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/enginecustom.vcxproj" afterDir="false" />
<change beforePath="$PROJECT_DIR$/enginecustom/imgui.ini" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/imgui.ini" afterDir="false" />
<change beforePath="$PROJECT_DIR$/enginecustom/src/inc/system/application_class.h" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/src/inc/system/application_class.h" afterDir="false" />
<change beforePath="$PROJECT_DIR$/enginecustom/src/inc/system/imguiManager.h" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/src/inc/system/imguiManager.h" afterDir="false" />
<change beforePath="$PROJECT_DIR$/enginecustom/src/inc/system/stats.h" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/src/inc/system/stats.h" afterDir="false" />
<change beforePath="$PROJECT_DIR$/enginecustom/src/src/system/application_class.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/src/src/system/application_class.cpp" afterDir="false" />
<change beforePath="$PROJECT_DIR$/enginecustom/src/src/system/imguiManager.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/src/src/system/imguiManager.cpp" afterDir="false" />
<change beforePath="$PROJECT_DIR$/enginecustom/src/src/system/stats.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/src/src/system/stats.cpp" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -27,6 +25,11 @@
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component>
<component name="HighlightingSettingsPerFile">
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="cidr-memory-view://2" root0="FORCE_HIGHLIGHTING" />
<setting file="file://C:/Program Files (x86)/Windows Kits/10/Include/10.0.26100.0/um/d3d11.h" root0="SKIP_HIGHLIGHTING" />
<setting file="file://C:/Program Files (x86)/Windows Kits/10/Include/10.0.26100.0/um/dinput.h" root0="SKIP_HIGHLIGHTING" />
<setting file="file://$PROJECT_DIR$/enginecustom/include/Inc/VertexTypes.h" root0="SKIP_HIGHLIGHTING" />
@ -52,26 +55,26 @@
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent">{
&quot;keyToString&quot;: {
&quot;ASKED_SHARE_PROJECT_CONFIGURATION_FILES&quot;: &quot;true&quot;,
&quot;C++ Project.enginecustom.executor&quot;: &quot;Run&quot;,
&quot;C/C++ Project.KhaoticDemo.executor&quot;: &quot;Run&quot;,
&quot;C/C++ Project.enginecustom.executor&quot;: &quot;Run&quot;,
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
&quot;RunOnceActivity.git.unshallow&quot;: &quot;true&quot;,
&quot;SHARE_PROJECT_CONFIGURATION_FILES&quot;: &quot;true&quot;,
&quot;git-widget-placeholder&quot;: &quot;main&quot;,
&quot;ignore.virus.scanning.warn.message&quot;: &quot;true&quot;,
&quot;node.js.detected.package.eslint&quot;: &quot;true&quot;,
&quot;node.js.detected.package.tslint&quot;: &quot;true&quot;,
&quot;node.js.selected.package.eslint&quot;: &quot;(autodetect)&quot;,
&quot;node.js.selected.package.tslint&quot;: &quot;(autodetect)&quot;,
&quot;nodejs_package_manager_path&quot;: &quot;npm&quot;,
&quot;settings.editor.selected.configurable&quot;: &quot;preferences.pluginManager&quot;,
&quot;vue.rearranger.settings.migration&quot;: &quot;true&quot;
<component name="PropertiesComponent"><![CDATA[{
"keyToString": {
"ASKED_SHARE_PROJECT_CONFIGURATION_FILES": "true",
"C++ Project.enginecustom.executor": "Run",
"C/C++ Project.KhaoticDemo.executor": "Run",
"C/C++ Project.enginecustom.executor": "Debug",
"RunOnceActivity.ShowReadmeOnStart": "true",
"RunOnceActivity.git.unshallow": "true",
"SHARE_PROJECT_CONFIGURATION_FILES": "true",
"git-widget-placeholder": "main",
"ignore.virus.scanning.warn.message": "true",
"node.js.detected.package.eslint": "true",
"node.js.detected.package.tslint": "true",
"node.js.selected.package.eslint": "(autodetect)",
"node.js.selected.package.tslint": "(autodetect)",
"nodejs_package_manager_path": "npm",
"settings.editor.selected.configurable": "preferences.pluginManager",
"vue.rearranger.settings.migration": "true"
}
}</component>
}]]></component>
<component name="RunManager" selected="C/C++ Project.enginecustom">
<configuration name="KhaoticDemo" type="CppProject" factoryName="C++ Project">
<configuration_1 setup="1">
@ -210,7 +213,7 @@
<workItem from="1748861785837" duration="357000" />
<workItem from="1748865625274" duration="797000" />
<workItem from="1748869642637" duration="3049000" />
<workItem from="1748954607174" duration="8054000" />
<workItem from="1748954607174" duration="13379000" />
</task>
<task id="LOCAL-00001" summary="Minor update - viewport window tweak">
<option name="closed" value="true" />

View File

@ -160,6 +160,7 @@ public:
ID3D11ShaderResourceView* get_back_buffer_srv() const {return back_buffer_srv_;};
stats* get_stats() const { return stats_; };
fps_class* get_fps() const { return fps_; };
private:
bool render(float, float, float, float, float);

View File

@ -108,6 +108,14 @@ private:
int current_fps_, min_fps_, max_fps_, draw_calls_, total_vertex_count_, total_triangle_count_, visible_triangle_count_;
float current_frame_time_, min_frame_time_, max_frame_time_ ;
// gpu information
char card_name_[128];
int video_memory_ = 0;
// cpu information
std::string cpu_name_;
std::string version_driver_;
};
#endif

View File

@ -1,8 +1,12 @@
#pragma once
#include <thread>
#include <vector>
#include "fps_class.h"
#include "object.h"
#include <intrin.h> // Pour __cpuid
#include <dxgi.h> // Pour DXGI
#pragma comment(lib, "dxgi.lib")
class stats
{
@ -11,9 +15,9 @@ public:
stats();
~stats();
bool initialize(fps_class* fps, application_class* app);
void update_stats();
void update();
bool initialize(application_class* app);
void update_geometric_stats();
void update_display_stats();
int get_total_vertex_count() const;
int get_total_triangle_count() const;
@ -28,7 +32,13 @@ public:
void increment_draw_call_count() { drawcalls_++; };
void reset_draw_call_count() { drawcalls_ = 0; };
std::string get_cpu_name();
std::string get_gpu_driver_version(ID3D11Device* device);
private:
std::thread update_geometric_thread_;
std::thread update_display_thread_;
fps_class* fps_;
int drawcalls_;
application_class* app_;

View File

@ -492,7 +492,7 @@ bool application_class::initialize(int screenWidth, int screenHeight, HWND hwnd,
}
stats_ = new stats();
if (!stats_->initialize(fps_, this))
if (!stats_->initialize(this))
{
Logger::Get().Log("Could not initialize the stats object", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
@ -1529,6 +1529,8 @@ bool application_class::update_fps()
// Update the fps each frame.
fps_->Frame();
stats_->update_display_stats(); // Update the stats display with the latest information from fps class.
// Get the current fps.
fps = fps_->GetFps();

View File

@ -151,9 +151,10 @@ bool imguiManager::Initialize(HWND hwnd, ID3D11Device* device, ID3D11DeviceConte
fontConfig.OversampleV = 2; // Suréchantillonnage vertical
fontConfig.PixelSnapH = true; // Alignement sur la grille de pixels
fontConfig.RasterizerMultiply = 1.2f; // Légère augmentation de l'épaisseur
io->Fonts->AddFontDefault(&fontConfig);
io->Fonts->Build();
// OU charger une police personnalisée (décommenter si vous avez la police)
// io->Fonts->AddFontFromFileTTF("assets/fonts/roboto.ttf", 16.0f, &fontConfig);
@ -1044,5 +1045,51 @@ void imguiManager::WidgetRenderStats()
ImGui::SameLine();
ImGui::Text("Triangles visibles: %d", visible_triangle_count_);
app_->get_direct_3d()->get_video_card_info(card_name_, video_memory_);
cpu_name_ = stats_->get_cpu_name();
version_driver_ = stats_->get_gpu_driver_version(app_->get_direct_3d()->get_device());
ImGui::Columns(3, "GPUCPURAMColumns", false);
ImGui::SetColumnWidth(0, ImGui::GetWindowWidth() * 0.33f);
ImGui::SetColumnWidth(1, ImGui::GetWindowWidth() * 0.33f);
// Premier collapsing header pour les informations GPU
if (ImGui::CollapsingHeader("Informations GPU"))
{
ImGui::Text("Carte graphique: %s", card_name_);
ImGui::Text("Memoire video: %d Mo", video_memory_);
ImGui::Text("Pilote: %s", version_driver_.c_str());
}
ImGui::NextColumn();
// Second collapsing header pour les informations CPU
if (ImGui::CollapsingHeader("Informations CPU"))
{
SYSTEM_INFO sysInfo;
GetSystemInfo(&sysInfo);
ImGui::Text("Processeur: %s", cpu_name_.c_str());
ImGui::Text("Nombre de coeurs: %u", sysInfo.dwNumberOfProcessors);
ImGui::Text("Architecture: %s", (sysInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64) ? "x64" : "x86");
ImGui::Text("Taille de la page: %u octets", sysInfo.dwPageSize);
ImGui::Text("Taille du cache: %u octets", sysInfo.dwAllocationGranularity);
ImGui::Text("Type de processeur: %u", sysInfo.wProcessorLevel);
ImGui::Text("Version du processeur: %u", sysInfo.wProcessorRevision);
}
ImGui::NextColumn();
if (ImGui::CollapsingHeader("Informations RAM"))
{
MEMORYSTATUSEX mem_info;
mem_info.dwLength = sizeof(MEMORYSTATUSEX);
GlobalMemoryStatusEx(&mem_info);
ImGui::Text("Memoire totale: %llu Mo", mem_info.ullTotalPhys / (1024 * 1024));
ImGui::Text("Memoire disponible: %llu Mo", mem_info.ullAvailPhys / (1024 * 1024));
ImGui::Text("Memoire utilisee: %llu Mo", (mem_info.ullTotalPhys - mem_info.ullAvailPhys) / (1024 * 1024));
}
ImGui::Columns(1);
ImGui::End();
}

View File

@ -10,49 +10,58 @@ stats::~stats()
fps_ = nullptr;
}
bool stats::initialize(fps_class* fps, application_class* app)
bool stats::initialize(application_class* app)
{
if (!fps) {
Logger::Get().Log("FPS pointer is null", __FILE__, __LINE__, Logger::LogLevel::Error);
if (!app) {
Logger::Get().Log("Application pointer is null", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
fps_ = fps;
drawcalls_ = 0;
app_ = app;
fps_ = app_->get_fps();
if (!fps_) {
Logger::Get().Log("FPS object is null", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
// call update() in a separate thread
std::thread updateThread(&stats::update, this);
updateThread.detach(); // Detach the thread to run independently
std::thread update_geometric_thread(&stats::update_geometric_stats, this);
update_geometric_thread_ = std::move(update_geometric_thread); // Move the thread to the member variable
update_geometric_thread_.detach(); // Detach the thread to run independently
Logger::Get().Log("Stats initialized successfully", __FILE__, __LINE__, Logger::LogLevel::Initialize);
return true;
}
void stats::update()
void stats::update_geometric_stats()
{
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();
// call update_stats() every second
std::this_thread::sleep_for(std::chrono::seconds(1));
}
}
void stats::update_display_stats()
{
current_fps_ = fps_->GetFps();
min_fps_ = fps_->GetMinFps();
max_fps_ = fps_->GetMaxFps();
drawcalls_ = get_draw_calls();
current_frame_time_ = fps_->GetFrameTime();
}
int stats::get_total_vertex_count() const
@ -142,3 +151,78 @@ int stats::get_visible_triangle_count() const
}
return visibleTriangles;
}
std::string stats::get_cpu_name()
{
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;
}
std::string stats::get_gpu_driver_version(ID3D11Device* device)
{
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;
}