-
Notifications
You must be signed in to change notification settings - Fork 0
/
clock.h
57 lines (47 loc) · 1.33 KB
/
clock.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
#include <SDL.h>
#include <string>
#include <deque>
class Manager;
class Clock {
public:
static Clock& getInstance();
unsigned int getTicks() const;
unsigned int getTotalTicks() const { return sumOfAllTicks; }
unsigned int getSeconds() const { return getTicks()/1000; }
unsigned int getFrameRate() const { return frameRate; }
private:
friend class Manager;
bool started;
bool paused;
bool sloMo;
const bool framesAreCapped;
const unsigned int frameCap;
unsigned int frames;
unsigned int tickSum;
unsigned int sumOfAllTicks;
unsigned int timeAtStart;
unsigned int timeAtPause;
unsigned int currTicks;
unsigned int prevTicks;
unsigned int ticks;
std::deque<unsigned int> timeEachFrame;
unsigned int frameRate;
unsigned int fpsAveragedOver;
unsigned int getElapsedTicks();
Clock& operator++();
void toggleSloMo();
bool isStarted() const { return started; }
bool isPaused() const { return paused; }
unsigned int getFrames() const { return frames; }
//unsigned int getFrameRate() const { return frameRate; }
//unsigned int getSeconds() const { return getTicks()/1000; }
unsigned int capFrameRate() const;
void computeFrameRate();
void start();
void pause();
void unpause();
void display() const;
Clock();
Clock(const Clock&);
Clock&operator=(const Clock&);
};