17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-10-25 22:54:03 +01:00

perf(debug): cpu timers of the simulation and the main loop, cpu time of the frame parts next to the gpu, renderer data of the debug panel in folding sections

This commit is contained in:
2026-10-22 20:54:30 +02:00
parent 5d3f857c39
commit fc714d50ec
8 changed files with 346 additions and 99 deletions

View File

@@ -491,12 +491,14 @@ int eu07_application::run()
while (!glfwWindowShouldClose(m_windows.front()) && !m_modestack.empty())
{
Timer::subsystem.mainloop_total.start();
Timer::subsystem.loop_input.start();
glfwPollEvents();
if (m_headtrack)
m_headtrack->update();
begin_ui_frame();
Timer::subsystem.loop_input.stop();
// -------------------------------------------------------------------
// multiplayer command relaying logic can seem a bit complex
@@ -624,10 +626,14 @@ int eu07_application::run()
// keep streamed terrain loaded around the active camera in every mode (editor + driver),
// once the simulation is live (avoid streaming while the scenery is still loading)
Timer::subsystem.loop_terrain.start();
if (simulation::is_ready && EditorTerrain.active())
EditorTerrain.update(Global.pCamera.Pos);
Timer::subsystem.loop_terrain.stop();
Timer::subsystem.loop_tasks.start();
m_taskqueue.update();
Timer::subsystem.loop_tasks.stop();
opengl_texture::reset_unit_cache();
if (!GfxRenderer->Render())

View File

@@ -167,9 +167,13 @@ bool driver_mode::update()
double const deltatime = Timer::GetDeltaTime(); // 0.0 gdy pauza
Timer::subsystem.sim_scripting.start();
simulation::State.update_clocks();
simulation::State.update_scripting_interface();
Timer::subsystem.sim_scripting.stop();
Timer::subsystem.sim_environment.start();
simulation::Environment.update();
Timer::subsystem.sim_environment.stop();
if (deltatime != 0.0 || false == simulation::is_ready)
{
@@ -233,6 +237,7 @@ bool driver_mode::update()
Timer::subsystem.sim_dynamics.stop();
// secondary fixed step simulation time routines
Timer::subsystem.sim_secondary.start();
while (m_secondaryupdateaccumulator >= m_secondaryupdaterate)
{
@@ -252,6 +257,7 @@ bool driver_mode::update()
m_secondaryupdateaccumulator -= m_secondaryupdaterate; // these should be inexpensive enough we have no cap
}
Timer::subsystem.sim_secondary.stop();
// variable step simulation time routines
@@ -298,24 +304,33 @@ bool driver_mode::update()
else
TSubModel::iInstance = 0;
Timer::subsystem.sim_trains.start();
if (Global.trainThreads > 0)
simulation::Trains.updateAsync(deltatime);
else
simulation::Trains.update(deltatime);
Timer::subsystem.sim_trains.stop();
Timer::subsystem.sim_events.start();
simulation::Events.update();
simulation::Region->update_events();
Timer::subsystem.sim_events.stop();
Timer::subsystem.sim_lights.start();
simulation::Lights.update();
Timer::subsystem.sim_lights.stop();
}
// render time routines follow:
auto const deltarealtime = Timer::GetDeltaRenderTime(); // nie uwzględnia pauzowania ani mnożenia czasu
Timer::subsystem.sim_commands.start();
simulation::State.process_commands();
Timer::subsystem.sim_commands.stop();
// fixed step render time routines
fTime50Hz += deltarealtime; // w pauzie też trzeba zliczać czas, bo przy dużym FPS będzie problem z odczytem ramek
bool runonce{false};
Timer::subsystem.sim_ui.start();
while (fTime50Hz >= 1.0 / 50.0)
{
#ifdef _WIN32
@@ -406,22 +421,33 @@ bool driver_mode::update()
fTime50Hz -= 1.0 / 50.0;
}
Timer::subsystem.sim_ui.stop();
// variable step render time routines
Timer::subsystem.sim_camera.start();
update_camera(deltarealtime);
Timer::subsystem.sim_camera.stop();
Timer::subsystem.sim_precipitation.start();
simulation::Environment.update_precipitation(); // has to be launched after camera step to work properly
Timer::subsystem.sim_precipitation.stop();
Timer::subsystem.sim_total.stop();
Timer::subsystem.loop_audio.start();
simulation::Region->update_sounds();
audio::renderer.update(Global.iPause ? 0.0 : deltarealtime);
Timer::subsystem.loop_audio.stop();
// NOTE: particle system runs on simulation time, but needs actual camera position to determine how to update each particle source
Timer::subsystem.loop_particles.start();
simulation::Particles.update();
Timer::subsystem.loop_particles.stop();
Timer::subsystem.loop_renderer_update.start();
GfxRenderer->Update(deltarealtime);
Timer::subsystem.loop_renderer_update.stop();
simulation::is_ready = simulation::is_ready || (simulation::Train != nullptr && simulation::Train->is_cab_initialized) || Global.local_start_vehicle == "ghostview";

View File

@@ -600,7 +600,7 @@ debug_panel::render() {
ImGui::Checkbox( "Debug Traction", &DebugTractionFlag );
}
render_section( "Camera", m_cameralines );
render_section( "Gfx Renderer / Statistics", m_rendererlines );
render_section_renderer();
render_section_settings();
render_section_developer(); // Developer tools
#ifdef WITH_UART
@@ -1438,7 +1438,7 @@ debug_panel::update_section_camera( std::vector<text_line> &Output ) const {
}
void
debug_panel::update_section_renderer( std::vector<text_line> &Output ) const {
debug_panel::update_section_renderer( std::vector<text_line> &Output ) {
// gfx renderer data
auto textline =
@@ -1471,9 +1471,12 @@ debug_panel::update_section_renderer( std::vector<text_line> &Output ) const {
Output.emplace_back( textline, Global.UITextColor );
// renderer stats
Output.emplace_back( GfxRenderer->info_times(), Global.UITextColor );
Output.emplace_back( GfxRenderer->info_stats(), Global.UITextColor );
// renderer stats, in sections when the renderer has them (render_section_renderer())
m_renderersections = GfxRenderer->info_sections();
if( m_renderersections.empty() ) {
Output.emplace_back( GfxRenderer->info_times(), Global.UITextColor );
Output.emplace_back( GfxRenderer->info_stats(), Global.UITextColor );
}
// CPU related
Output.emplace_back("CPU:", Global.UITextColor);
@@ -1493,6 +1496,26 @@ debug_panel::render_section( std::string const &Header, std::vector<text_line> c
return render_section( Lines );
}
// the lines of the renderer, then its data in sections which fold, the long lines wrapped to the width of the panel
bool
debug_panel::render_section_renderer() {
if( false == render_section( "Gfx Renderer / Statistics", m_rendererlines ) ) { return false; }
ImGui::PushStyleColor( ImGuiCol_Text, { Global.UITextColor.r, Global.UITextColor.g, Global.UITextColor.b, Global.UITextColor.a } );
ImGui::PushTextWrapPos( 0.f );
for( auto const &section : m_renderersections ) {
ImGui::SetNextItemOpen( section.open, ImGuiCond_Once );
if( true == ImGui::TreeNode( section.title.c_str() ) ) {
ImGui::TextUnformatted( section.text.c_str() );
ImGui::TreePop();
}
}
ImGui::PopTextWrapPos();
ImGui::PopStyleColor();
return true;
}
bool
debug_panel::render_section( std::vector<text_line> const &Lines ) const {

View File

@@ -11,6 +11,7 @@ http://mozilla.org/MPL/2.0/.
#include "application/uilayer.h"
#include "utilities/Classes.h"
#include "rendering/renderer.h"
class drivingaid_panel : public ui_expandable_panel {
@@ -87,7 +88,7 @@ private:
void update_section_eventqueue( std::vector<text_line> &Output );
void update_section_powergrid( std::vector<text_line> &Output ) const;
void update_section_camera( std::vector<text_line> &Output ) const;
void update_section_renderer( std::vector<text_line> &Output ) const;
void update_section_renderer( std::vector<text_line> &Output );
#ifdef WITH_UART
void update_section_uart( std::vector<text_line> &Output ) const;
#endif
@@ -99,6 +100,7 @@ private:
bool render_section( std::vector<text_line> const &Lines ) const;
bool render_section_scenario();
bool render_section_eventqueue();
bool render_section_renderer();
bool render_section_settings() const;
bool render_section_developer() const;
// members
@@ -114,6 +116,7 @@ private:
std::vector<text_line> m_eventqueuelines;
std::vector<text_line> m_powergridlines;
std::vector<text_line> m_rendererlines;
std::vector<gfx_renderer::info_section> m_renderersections; // the data of the renderer, each part under a header of its own
std::vector<text_line> m_uartlines;
double last_time = std::numeric_limits<double>::quiet_NaN();