mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-03 18:14:53 +01:00
2953bedafa
--snapshot-at <seconds> <file> writes a snapshot when the simulation has run that long, --load-snapshot <file> puts one over the scenery once it has loaded, before the first frame. This layer keeps the clock and the simulation timer, the weather with the wind, the random engine, the memory cells, the switches, the tracks an event can change and the ones made on the run, the traction power sources, the event queue, the timers of the launchers and the lamps of the signals. While a snapshot is put back the event manager is suspended, so nothing in the scenery reacts to it. Existing classes only get accessors for what was private (the fraction of the second, launcher timers, the speed limit of a track, the wind, the state of a power source, the event queue). Without the switches nothing changes.
81 lines
2.1 KiB
C++
81 lines
2.1 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);
|
|
|
|
// every frame advances the clocks by this many seconds, whatever the real time; 0 = real time (test mode)
|
|
void set_fixed_step(double v);
|
|
|
|
void ResetTimers();
|
|
|
|
// sets the time of the simulation GetTime() goes on from: the one a loaded simulation snapshot was taken at
|
|
void set_time(double v);
|
|
|
|
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;
|
|
stopwatch mainloop_total;
|
|
stopwatch mainloop_period; // start to start, the wait for fpslimit included
|
|
};
|
|
|
|
extern subsystem_stopwatches subsystem;
|
|
|
|
};
|
|
|
|
//---------------------------------------------------------------------------
|