-
Notifications
You must be signed in to change notification settings - Fork 0
/
chess_timer.h
48 lines (39 loc) · 1.32 KB
/
chess_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
/*
* Wrapper for the high-resolution timer. Can't be used if the hi-res timer
* doesn't exist
*/
#ifndef __CHESS_TIMER_H__
#define __CHESS_TIMER_H__
#include <Windows.h>
class ChessHiResTimer {
public:
ChessHiResTimer() {};
~ChessHiResTimer() {};
/*
*
* If the hi-res timer is present, the tick rate is stored and the function
* returns true. Otherwise, the function returns false, and the timer should
* not be used.
*/
bool initialize();
float getElapsedSeconds(unsigned long elapsedFrames = 1);
/*
* Returns the average frames per second over elapsedFrames, which defaults to
* one. If this is not called every frame, the client should track the number
* of frames itself, and reset the value after this is called.
*/
float getFPS(unsigned long elapsedFrames = 1);
/*
* Used to lock the frame rate to a set amount. This will block until enough
* time has passed to ensure that the fps won't go over the requested amount.
* Note that this can only keep the fps from going above the specified level;
* it can still drop below it. It is assumed that if used, this function will
* be called every frame. The value returned is the instantaneous fps, which
* will be <= targetFPS.
*/
float lockFPS(unsigned char targetFPS);
private:
LARGE_INTEGER startTime;
LARGE_INTEGER ticksPerSecond;
};
#endif // __CHESS_TIMER_H__