-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTimer.cpp
71 lines (52 loc) · 1.54 KB
/
Timer.cpp
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
62
63
64
65
66
67
68
69
70
71
//----------------------------------------------------//
// Timer.cpp //
// Singleton //
// Used to keep track of the time between each reset //
// A reset is usually called after each frame //
// //
// By: Ather Omar //
//----------------------------------------------------//
#include "Timer.h"
//--------------------------------------------------------
// QuickSDL
//--------------------------------------------------------
namespace QuickSDL {
//Initializing sInstance to NULL
Timer* Timer::sInstance = NULL;
Timer* Timer::Instance() {
//Create a new instance of Timer if no instance was created before
if(sInstance == NULL)
sInstance = new Timer();
return sInstance;
}
void Timer::Release() {
delete sInstance;
sInstance = NULL;
}
Timer::Timer() {
//Using Reset to initialize all the values beside mTimeScale
Reset();
mTimeScale = 1.0f;
}
Timer::~Timer() {
}
void Timer::Reset() {
mStartTicks = SDL_GetTicks();
mElapsedTicks = 0;
mDelataTime = 0.0f;
}
float Timer::DeltaTime() {
return mDelataTime;
}
void Timer::TimeScale(float t) {
mTimeScale = t;
}
float Timer::TimeScale() {
return mTimeScale;
}
void Timer::Update() {
mElapsedTicks = SDL_GetTicks() - mStartTicks;
//Converting milliseconds to seconds
mDelataTime = mElapsedTicks * 0.001f;
}
}