16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-18 01:59:19 +02:00

continued refactoring: traction, events, event launchers, sounds; additional diagnostics timers, minor performance enhancements and bug fixes

This commit is contained in:
tmj-fstate
2017-10-14 03:53:13 +02:00
parent a12b84f50f
commit 09dbb3c639
23 changed files with 921 additions and 484 deletions

36
Timer.h
View File

@@ -9,8 +9,7 @@ http://mozilla.org/MPL/2.0/.
#pragma once
namespace Timer
{
namespace Timer {
double GetTime();
@@ -28,6 +27,39 @@ double GetFPS();
void ResetTimers();
void UpdateTimers(bool pause);
class stopwatch {
public:
void
start() {
m_start = std::chrono::steady_clock::now(); }
void
stop() {
m_accumulator = 0.95f * m_accumulator + std::chrono::duration_cast<std::chrono::microseconds>( ( std::chrono::steady_clock::now() - m_start ) ).count() / 1000.f; }
float
average() const {
return m_accumulator / 20.f;}
private:
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
};
struct subsystem_stopwatches {
stopwatch gfx_total;
stopwatch gfx_color;
stopwatch gfx_shadows;
stopwatch gfx_reflections;
stopwatch gfx_swap;
stopwatch sim_total;
stopwatch sim_dynamics;
stopwatch sim_events;
stopwatch sim_ai;
};
extern subsystem_stopwatches subsystem;
};
//---------------------------------------------------------------------------