mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-10-24 15:56:59 +02:00
91 lines
2.6 KiB
C++
91 lines
2.6 KiB
C++
/*
|
|
This Source Code Form is subject to the
|
|
terms of the Mozilla Public License, v.
|
|
2.0. If a copy of the MPL was not
|
|
distributed with this file, You can
|
|
obtain one at
|
|
http://mozilla.org/MPL/2.0/.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
namespace Timer {
|
|
|
|
double GetTime();
|
|
double GetRenderTime();
|
|
|
|
double GetDeltaTime();
|
|
double GetDeltaRenderTime();
|
|
|
|
void set_delta_override(double v);
|
|
|
|
void ResetTimers();
|
|
|
|
void UpdateTimers(bool pause);
|
|
|
|
class stopwatch {
|
|
|
|
public:
|
|
// constructors
|
|
stopwatch() = default;
|
|
// methods
|
|
void
|
|
start() {
|
|
m_start = std::chrono::steady_clock::now(); }
|
|
std::chrono::duration<float, std::milli>
|
|
stop() {
|
|
m_last = std::chrono::duration_cast<std::chrono::microseconds>( std::chrono::steady_clock::now() - m_start );
|
|
m_accumulator = 0.95f * m_accumulator + static_cast<float>(m_last.count()) / 1000.f;
|
|
return m_last; }
|
|
float
|
|
average() const {
|
|
return m_accumulator / 20.f;}
|
|
std::chrono::microseconds
|
|
last() const {
|
|
return m_last; }
|
|
|
|
private:
|
|
// members
|
|
std::chrono::time_point<std::chrono::steady_clock> m_start { std::chrono::steady_clock::now() };
|
|
float m_accumulator { 1000.f / 30.f * 20.f }; // 20 last samples, initial 'neutral' rate of 30 fps
|
|
std::chrono::microseconds m_last;
|
|
};
|
|
|
|
struct subsystem_stopwatches {
|
|
stopwatch gfx_total;
|
|
stopwatch gfx_color;
|
|
stopwatch gfx_shadows;
|
|
stopwatch gfx_reflections;
|
|
stopwatch gfx_swap;
|
|
stopwatch gfx_gui;
|
|
stopwatch gfx_animate;
|
|
stopwatch sim_total;
|
|
stopwatch sim_dynamics;
|
|
stopwatch sim_events;
|
|
stopwatch sim_ai;
|
|
// parts of sim_total for the debug panel, measured in driver_mode::update()
|
|
stopwatch sim_scripting; // clocks and the scripting interface
|
|
stopwatch sim_environment; // sky and weather
|
|
stopwatch sim_precipitation;
|
|
stopwatch sim_secondary; // secondary fixed step routines
|
|
stopwatch sim_trains; // cabs of the trains
|
|
stopwatch sim_lights;
|
|
stopwatch sim_commands;
|
|
stopwatch sim_ui; // 50 Hz routines: ui panels, tooltips
|
|
stopwatch sim_camera;
|
|
stopwatch mainloop_total;
|
|
// parts of the main loop outside the simulation and Render(), for the debug panel
|
|
stopwatch loop_input; // events, head tracking, start of the ui frame
|
|
stopwatch loop_audio; // sounds of the scenery and the audio renderer
|
|
stopwatch loop_particles; // cpu particles
|
|
stopwatch loop_renderer_update; // gfx_renderer::Update()
|
|
stopwatch loop_terrain; // terrain streaming
|
|
stopwatch loop_tasks; // task queue
|
|
};
|
|
|
|
extern subsystem_stopwatches subsystem;
|
|
|
|
};
|
|
|
|
//---------------------------------------------------------------------------
|