Add rendering debug infos

This commit is contained in:
JackCarterSmith 2025-01-05 23:10:41 +01:00
parent d6236a7857
commit ea712fae42
Signed by: JackCarterSmith
GPG Key ID: 832E52F4E23F8F24
5 changed files with 32 additions and 6 deletions

View File

@ -55,6 +55,12 @@ Graphic3DRenderer::Graphic3DRenderer() {
mRenderList.push_back(std::make_shared<Tank>()); mRenderList.push_back(std::make_shared<Tank>());
mRenderList.back()->SetPosition(0.f, 0.f, 0.f); mRenderList.back()->SetPosition(0.f, 0.f, 0.f);
mRenderList.back()->SetScale(5.0f); mRenderList.back()->SetScale(5.0f);
for (size_t i = 0; i < 40; i++) {
mRenderList.push_back(std::make_shared<Tank>());
mRenderList.back()->SetPosition(-100.f + (i * 5.f), 0.f, 8.f);
mRenderList.back()->SetScale(5.0f);
}
} }
Graphic3DRenderer::~Graphic3DRenderer() {} Graphic3DRenderer::~Graphic3DRenderer() {}
@ -97,6 +103,10 @@ void Graphic3DRenderer::Draw(sf::RenderTexture& context) {
sf::BlendMode sBM = sf::BlendNone; sf::BlendMode sBM = sf::BlendNone;
sf::RenderStates sRS(sBM); sf::RenderStates sRS(sBM);
#ifdef DEBUG
drawnTriCount = 0;
#endif
// Hardcoded debug movement, TODO: remove it // Hardcoded debug movement, TODO: remove it
UpdateInternalTestObjects(); UpdateInternalTestObjects();
@ -231,6 +241,9 @@ void Graphic3DRenderer::Draw(sf::RenderTexture& context) {
context.draw(v_tri, 4, sf::Triangles, sRS); context.draw(v_tri, 4, sf::Triangles, sRS);
#else #else
context.draw(v_tri, 4, sf::LineStrip, sRS); context.draw(v_tri, 4, sf::LineStrip, sRS);
#endif
#ifdef DEBUG
drawnTriCount++;
#endif #endif
} }
} }

View File

@ -32,6 +32,11 @@ public:
void UpdateCamera(CAMERA_MOVE type, const float value); void UpdateCamera(CAMERA_MOVE type, const float value);
void Draw(sf::RenderTexture& context); void Draw(sf::RenderTexture& context);
// Debug datas
#ifdef DEBUG
const unsigned int GetDrawTriCount() const noexcept { return drawnTriCount; }
#endif
private: private:
std::unique_ptr<Camera> mMainCamera; // Default player view std::unique_ptr<Camera> mMainCamera; // Default player view
sf::Vector2f mRTSize; sf::Vector2f mRTSize;
@ -40,5 +45,10 @@ private:
void UpdateInternalTestObjects(); void UpdateInternalTestObjects();
float ComputeSGRatio(); float ComputeSGRatio();
// Debug datas
#ifdef DEBUG
unsigned int drawnTriCount;
#endif
}; };

View File

@ -14,22 +14,23 @@ DebugUI::DebugUI() {
gDbgText.setFillColor(sf::Color::White); gDbgText.setFillColor(sf::Color::White);
} }
void DebugUI::UpdateDebugData(const double cpu_usage, const double cpu_time, const double cycle_time, const int fps, const std::size_t ram_virt_usage, const std::size_t ram_phys_usage) { void DebugUI::UpdateDebugData(const double cpu_usage, const double cpu_time, const double cycle_time, const int fps, const std::size_t ram_virt_usage, const std::size_t ram_phys_usage, const unsigned int drawnTriCount) {
gDbgStats.cpu_usage = cpu_usage; gDbgStats.cpu_usage = cpu_usage;
gDbgStats.cpu_time = cpu_time; gDbgStats.cpu_time = cpu_time;
gDbgStats.cycle_time = cycle_time; gDbgStats.cycle_time = cycle_time;
gDbgStats.fps = fps; gDbgStats.fps = fps;
gDbgStats.ram_virt_usage = ram_virt_usage; gDbgStats.ram_virt_usage = ram_virt_usage;
gDbgStats.ram_phys_usage = ram_phys_usage; gDbgStats.ram_phys_usage = ram_phys_usage;
gDbgStats.drawnTriCount = drawnTriCount;
} }
void DebugUI::DrawDebugData(std::shared_ptr<sf::RenderWindow> context) { void DebugUI::DrawDebugData(std::shared_ptr<sf::RenderWindow> context) {
std::ostringstream outStrStream; std::ostringstream outStrStream;
outStrStream << std::fixed; outStrStream << std::fixed;
outStrStream << std::setprecision(0) << "CPU: " << gDbgStats.cpu_usage << "% (cycle: " << std::setprecision(3) << gDbgStats.cpu_time << "/" << gDbgStats.cycle_time << "ms)" << std::endl; outStrStream << std::setprecision(0) << "CPU: " << gDbgStats.cpu_usage << "% (cycle: " << std::setprecision(3) << gDbgStats.cpu_time << "/" << gDbgStats.cycle_time << "ms) - Triangles: " << gDbgStats.drawnTriCount << '\n';
outStrStream << std::setprecision(1) << "RAM: " << gDbgStats.ram_virt_usage << "MB(V)/" << gDbgStats.ram_phys_usage << "MB(P)" << std::endl; outStrStream << std::setprecision(1) << "RAM: " << gDbgStats.ram_virt_usage << "MB(V)/" << gDbgStats.ram_phys_usage << "MB(P)\n";
outStrStream << std::setprecision(0) << "FPS: " << gDbgStats.fps; outStrStream << std::setprecision(0) << "FPS: " << gDbgStats.fps << std::flush;
gDbgText.setString(outStrStream.str()); gDbgText.setString(outStrStream.str());
context->draw(gDbgText); context->draw(gDbgText);

View File

@ -14,6 +14,7 @@ struct sDbgStats {
int fps; int fps;
std::size_t ram_virt_usage; std::size_t ram_virt_usage;
std::size_t ram_phys_usage; std::size_t ram_phys_usage;
unsigned int drawnTriCount;
}; };
class DebugUI { class DebugUI {
@ -21,7 +22,7 @@ public:
DebugUI(); DebugUI();
~DebugUI() {} ~DebugUI() {}
void UpdateDebugData(const double cpu_usage, const double cpu_time, const double cycle_time, const int fps, const std::size_t ram_virt_usage, const std::size_t ram_phys_usage); void UpdateDebugData(const double cpu_usage, const double cpu_time, const double cycle_time, const int fps, const std::size_t ram_virt_usage, const std::size_t ram_phys_usage, const unsigned int drawnTriCount);
void DrawDebugData(std::shared_ptr<sf::RenderWindow> context); void DrawDebugData(std::shared_ptr<sf::RenderWindow> context);
private: private:

View File

@ -68,7 +68,8 @@ GAME_STATUS Game::Tick() {
1000.f / TARGET_FPS, 1000.f / TARGET_FPS,
mFrameCnt, mFrameCnt,
PerfsGetVirtMem() / 1000, PerfsGetVirtMem() / 1000,
PerfsGetPhysMem() / 1000 PerfsGetPhysMem() / 1000,
mWorld3D->GetDrawTriCount()
); );
mFrameCnt = 0; mFrameCnt = 0;