-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathGameTime.cpp
42 lines (36 loc) · 906 Bytes
/
GameTime.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 "GameTime.h"
#include <Windows.h>
namespace VBA10
{
GameTime::GameTime(void)
{
this->frequency = Frequency();
this->startTime = Counter();
this->lastTime = this->startTime;
}
GameTime::~GameTime(void)
{ }
void GameTime::Update(void)
{
long long currentTime = Counter();
this->total = (currentTime - startTime) / (float)frequency;
this->elapsed = (currentTime - lastTime) / (float)frequency;
lastTime = currentTime;
}
void GameTime::SyncTime(void)
{
long long currentTime = Counter();
float newtimeTotal = (currentTime - startTime) / (float)frequency;
long long delta = (long long) ((newtimeTotal - this->total) * this->frequency);
startTime += delta;
lastTime += delta;
}
float GameTime::GetLastFrameElapsed(void)
{
return this->elapsed;
}
float GameTime::GetTotalElapsed(void)
{
return this->total;
}
}