-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTimer.h
62 lines (52 loc) · 1.92 KB
/
Timer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// VQEngine | DirectX11 Renderer
// Copyright(C) 2018 - Volkan Ilbeyli
//
// This program is free software : you can redistribute it and / or modify
// it under the terms of the GNU General Public License as published by
// VQE
// Copyright(C) 2020 - Volkan Ilbeyli
//
// This program is free software : you can redistribute it and / or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.If not, see <http://www.gnu.org/licenses/>.
//
// Contact: [email protected]
#pragma once
#include <chrono>
using TimeStamp = std::chrono::time_point<std::chrono::system_clock>; // TimeStamp != std::time_t
using Duration = std::chrono::duration<float>;
class Timer
{
public:
Timer();
// returns the time duration between Start() and Now, minus the paused duration.
float TotalTime() const;
// returns the last delta time measured between Start() and Stop()
float DeltaTime() const;
float GetPausedTime() const;
float GetStopDuration() const; // gets (Now - stopTime)
void Reset();
void Start();
void Stop();
inline float StopGetDeltaTimeAndReset() { Stop(); float dt = DeltaTime(); Reset(); return dt; }
// A Timer as to be updated by calling tick.
// Tick() will return the time duration since the last time Tick() is called.
// First call will return the duration between Start() and Tick().
float Tick();
private:
TimeStamp baseTime;
TimeStamp prevTime , currTime;
TimeStamp startTime, stopTime;
Duration pausedTime;
Duration dt;
bool bIsStopped;
};