-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStopwatch.h
43 lines (36 loc) · 898 Bytes
/
Stopwatch.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
#ifndef STOPWATCH_H_INCLUDED
#define STOPWATCH_H_INCLUDED
#include <SDL/SDL.h>
#include <time.h>
/**
* A stopwatch class to enable timing (for animation etc)
*/
class Stopwatch
{
Uint32 startTime, elapsed;
bool running;
public:
/**
* Creates a stopwatch
*/
Stopwatch():startTime(0), elapsed(0), running(false){}
/**
* Starts the watch (adds to current time if watch has not been reset
*/
void start(){if(running) return; startTime = SDL_GetTicks(); running = true;}
/**
* Stops the watch (does not reset the time)
* @return the time on the watch
*/
Uint32 stop();
/**
* Reads the watch (does not stop)
* @return the current time on the watch
*/
Uint32 read();
/**
* Resets time to zero
*/
void reset(){startTime = SDL_GetTicks(); elapsed = 0;}
};
#endif // STOPWATCH_H_INCLUDED