18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-27 23:57:09 +01:00
Files
maszyna/widgets/perfgraphs.cpp
jerrrrycho 4a52b5affc refactor: no fields shadowing the base class's (Sonar S2387) (#366)
TSt113 declared its own CP, which hid TH14K1::CP. TSt113 overrides
every TH14K1 method that touches CP (GetPF sets it from PP before
reading it, GetCP, Init), so the base field was never used in it; the
derived one is deleted and the St113 uses the inherited field. A new
test records the control chamber, brake pipe, cylinder and EP of the
EN57's St113 over an application and a release; it was written and
passed on the code before the change and passes unchanged after it.

perfgraph_panel::pos, the write index of the timings' ring buffer,
hid ui_panel::pos, the window position; it becomes history_pos.
2026-11-20 03:43:01 +01:00

62 lines
2.1 KiB
C++

#include "stdafx.h"
#include "widgets/perfgraphs.h"
#include "utilities/Timer.h"
#include "utilities/translation.h"
perfgraph_panel::perfgraph_panel() : ui_panel(STR("Performance"), false) {}
void perfgraph_panel::render_contents() {
if (ImGui::BeginCombo(STR_C("Timer"), timer_label[current_timer].c_str())) // The second parameter is the label previewed before opening the combo.
{
for (size_t i = 0; i < (size_t)TIMER_MAX; i++)
{
bool is_selected = (current_timer == (timers_e)i);
if (ImGui::Selectable(timer_label[i].c_str(), is_selected))
current_timer = (timers_e)i;
if (is_selected)
ImGui::SetItemDefaultFocus();
}
ImGui::EndCombo();
}
Timer::stopwatch const *stopwatch = nullptr;
if (current_timer == gfx_total)
stopwatch = &Timer::subsystem.gfx_total;
else if (current_timer == gfx_color)
stopwatch = &Timer::subsystem.gfx_color;
else if (current_timer == gfx_shadows)
stopwatch = &Timer::subsystem.gfx_shadows;
else if (current_timer == gfx_reflections)
stopwatch = &Timer::subsystem.gfx_reflections;
else if (current_timer == gfx_swap)
stopwatch = &Timer::subsystem.gfx_swap;
else if (current_timer == gfx_gui)
stopwatch = &Timer::subsystem.gfx_gui;
else if (current_timer == gfx_animate)
stopwatch = &Timer::subsystem.gfx_animate;
else if (current_timer == sim_total)
stopwatch = &Timer::subsystem.sim_total;
else if (current_timer == sim_dynamics)
stopwatch = &Timer::subsystem.sim_dynamics;
else if (current_timer == sim_events)
stopwatch = &Timer::subsystem.sim_events;
else if (current_timer == sim_ai)
stopwatch = &Timer::subsystem.sim_ai;
else if (current_timer == mainloop_total)
stopwatch = &Timer::subsystem.mainloop_total;
if (!stopwatch)
return;
history[history_pos] = static_cast<float>(static_cast<double>(stopwatch->last().count()) / 1000.0);
const std::string label = std::to_string(history[history_pos]) + "ms";
history_pos++;
if (history_pos >= history.size())
history_pos = 0;
ImGui::SliderFloat(STR_C("Range"), &max, 0.1f, 250.0f);
ImGui::PlotLines("##timer", &history[0], static_cast<int>(history.size()), static_cast<int>(history_pos), label.c_str(), 0.0f, max, ImVec2(500, 200));
}