-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClock.cpp
More file actions
40 lines (32 loc) · 965 Bytes
/
Clock.cpp
File metadata and controls
40 lines (32 loc) · 965 Bytes
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
// system includes
#include <windows.h>
// game engine includes
#include "Clock.h"
// Sets previous_time to current time.
df::Clock::Clock(){
SYSTEMTIME time;
GetSystemTime(&time);
previous_time = (time.wSecond * 1000) + time.wMilliseconds;
}
// Return time elapsed since delta() was last called, -1 if error.
// Units are milliseconds.
long int df::Clock::delta(void){
// get time now
SYSTEMTIME time;
GetSystemTime(&time);
long int current_time = (time.wSecond * 1000) + time.wMilliseconds;
long int delta = current_time - previous_time;
// update previous time
previous_time = current_time;
return delta;
}
// Return time elapsed since delta() was last called.
// Units are milliseconds.
long int df::Clock::split(void) const{
// get time now
SYSTEMTIME time;
GetSystemTime(&time);
long int current_time = (time.wSecond * 1000) + time.wMilliseconds;
// return elapsed time since last delta() call
return (current_time - previous_time);
}