mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-21 18:19:19 +02:00
perf window
This commit is contained in:
62
widgets/perfgraphs.cpp
Normal file
62
widgets/perfgraphs.cpp
Normal file
@@ -0,0 +1,62 @@
|
||||
#include "stdafx.h"
|
||||
#include "widgets/perfgraphs.h"
|
||||
#include "Timer.h"
|
||||
|
||||
perfgraph_panel::perfgraph_panel()
|
||||
: ui_panel("Perf", false)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void perfgraph_panel::render_contents() {
|
||||
if (ImGui::BeginCombo("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 *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 == 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[pos] = stopwatch->last().count() / 1000.0;
|
||||
const std::string label = std::to_string(history[pos]) + "ms";
|
||||
|
||||
pos++;
|
||||
if (pos >= history.size())
|
||||
pos = 0;
|
||||
|
||||
ImGui::SliderFloat("Range", &max, 0.1f, 250.0f);
|
||||
ImGui::PlotLines("##timer", &history[0], history.size(), pos, label.c_str(), 0.0f, max, ImVec2(500, 200));
|
||||
}
|
||||
45
widgets/perfgraphs.h
Normal file
45
widgets/perfgraphs.h
Normal file
@@ -0,0 +1,45 @@
|
||||
#include "uilayer.h"
|
||||
|
||||
class perfgraph_panel : public ui_panel
|
||||
{
|
||||
std::array<float, 400> history;
|
||||
size_t pos = 0;
|
||||
|
||||
enum timers_e {
|
||||
gfx_total = 0,
|
||||
gfx_color,
|
||||
gfx_shadows,
|
||||
gfx_reflections,
|
||||
gfx_swap,
|
||||
gfx_gui,
|
||||
sim_total,
|
||||
sim_dynamics,
|
||||
sim_events,
|
||||
sim_ai,
|
||||
mainloop_total,
|
||||
TIMER_MAX
|
||||
};
|
||||
|
||||
float max = 50.0f;
|
||||
timers_e current_timer = mainloop_total;
|
||||
|
||||
std::vector<std::string> timer_label =
|
||||
{
|
||||
"gfx_total",
|
||||
"gfx_color",
|
||||
"gfx_shadows",
|
||||
"gfx_reflections",
|
||||
"gfx_swap",
|
||||
"gfx_gui",
|
||||
"sim_total",
|
||||
"sim_dynamics",
|
||||
"sim_events",
|
||||
"sim_ai",
|
||||
"mainloop_total"
|
||||
};
|
||||
|
||||
public:
|
||||
perfgraph_panel();
|
||||
|
||||
void render_contents() override;
|
||||
};
|
||||
Reference in New Issue
Block a user