-
Notifications
You must be signed in to change notification settings - Fork 10
/
timing.h
37 lines (29 loc) · 948 Bytes
/
timing.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
/*
* timing.h
* XBolo
*
* Created by Michael Ash on 9/7/09.
*
*/
#ifndef __TIMING__
#define __TIMING__
#include <stdint.h>
struct frametimingstate {
uint64_t starttime;
uint64_t framecounter;
uint64_t timeperframe;
unsigned slop;
unsigned resetthreshold;
};
uint64_t getcurrenttime(void);
// initialize a timing state struct
// call this before doing any timing stuff
// times are in nanoseconds
// timeperframe is the amount of time desired for each frame
// slop is how much slop to accept when sleeping (helps avoid too many calls to sleep)
// resetthreshold is how far behind the target we can get before giving up on
// the target and resetting instead of trying to catch up
void timinginitializestate(struct frametimingstate *state, uint64_t timeperframe, unsigned slop, unsigned resetthreshold);
// sleep until the next frame
void timingwaitframe(struct frametimingstate *state);
#endif /* __TIMING__ */