/
BasicEngine.cpp
57 lines (50 loc) · 990 Bytes
/
BasicEngine.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
43
44
45
46
47
48
49
50
51
52
53
54
55
#include "BasicEngine.h"
BasicEngine::BasicEngine(ITimerProvider* timerProvider)
: timerProvider(timerProvider),
MaxFPS(60),
LimitFPS(true),
running(true),
CurrentFPS(currentFPS),
frameCounter(0),
timeElapsed(0.0),
timeCount(0.0),
frameBegin(0.0),
lastTime(0.0)
{
}
BasicEngine::~BasicEngine(void)
{
}
void BasicEngine::Run()
{
Setup();
while (running)
{
frameBegin = timerProvider->GetTimeElapsed();
timeElapsed = frameBegin - lastTime;
++frameCounter;
timeCount += timeElapsed;
if (timeCount > 1.0)
{
currentFPS = frameCounter;
frameCounter = 0;
timeCount = 0.0;
}
t.dTimeElapsed = frameBegin;
t.dTimeSinceLastFrame = timeElapsed;
t.fTimeElapsed = (float)frameBegin;
t.fTimeSinceLastFrame = (float)timeElapsed;
Update(t);
Display();
if (LimitFPS)
{
timerProvider->Sleep(0.016 - timerProvider->GetTimeElapsed() + frameBegin);
}
EndFrame();
lastTime = frameBegin;
}
}
void BasicEngine::Exit()
{
running = false;
}