-
Notifications
You must be signed in to change notification settings - Fork 0
/
Timing.cpp
42 lines (33 loc) · 843 Bytes
/
Timing.cpp
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
#include "stdafx.h"
#include "Timing.h"
Timing::Timing () {}
Timing::Timing (int steps_per_second)
{
target_steps_per_second = steps_per_second;
target_milliseconds_per_step = 1000 / target_steps_per_second;
last_step_tick = 0;
}
Timing::~Timing () {}
void Timing::Update ()
{
current_tick = GetTickCount ();
// mspf counter
milliseconds_per_frame = current_tick - last_frame_tick;
// fps counter
if (current_tick >= last_second_tick + 1000)
{
frames_per_second = frames_this_second;
frames_this_second = 0;
last_second_tick = current_tick;
}
frames_this_second += 1;
last_frame_tick = GetTickCount ();
}
bool Timing::is_step_ready ()
{
return current_tick - last_step_tick > target_milliseconds_per_step;
}
void Timing::update_step ()
{
last_step_tick = GetTickCount ();
}