mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-18 01:59:19 +02:00
milek7/sim branch network code import
This commit is contained in:
16
Timer.h
16
Timer.h
@@ -16,11 +16,7 @@ double GetTime();
|
||||
double GetDeltaTime();
|
||||
double GetDeltaRenderTime();
|
||||
|
||||
void SetDeltaTime(double v);
|
||||
|
||||
bool GetSoundTimer();
|
||||
|
||||
double GetFPS();
|
||||
void set_delta_override(double v);
|
||||
|
||||
void ResetTimers();
|
||||
|
||||
@@ -35,17 +31,23 @@ public:
|
||||
void
|
||||
start() {
|
||||
m_start = std::chrono::steady_clock::now(); }
|
||||
void
|
||||
std::chrono::duration<float, std::milli>
|
||||
stop() {
|
||||
m_accumulator = 0.95f * m_accumulator + std::chrono::duration_cast<std::chrono::microseconds>( ( std::chrono::steady_clock::now() - m_start ) ).count() / 1000.f; }
|
||||
m_last = std::chrono::duration_cast<std::chrono::microseconds>( ( std::chrono::steady_clock::now() - m_start ) );
|
||||
m_accumulator = 0.95f * m_accumulator + 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 {
|
||||
|
||||
Reference in New Issue
Block a user