blob: 82a24b547ed9be51cd368cb2dc9b4bc531452a41 (
plain)
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
|
#include "MainLoop.h"
#include <cstdio>
#include <cstdlib>
EM_BOOL loop(double time, void* loop) {
MainLoop* mainLoop = (MainLoop*) loop;
if (!mainLoop->isRunning) {
return false;
}
if (mainLoop->lastTime == 0) {
mainLoop->lastTime = time;
return true;
}
long deltaTime = time - mainLoop->lastTime;
mainLoop->lastTime = time;
mainLoop->elapsedTime += deltaTime;
mainLoop->numFrames++;
float deltaTimeSeconds = static_cast<float>(deltaTime) / 1000.f;
if (mainLoop->elapsedTime >= 1000.0) {
printf("FPS: %d\n", mainLoop->numFrames);
mainLoop->elapsedTime = 0.0;
mainLoop->numFrames = 0;
}
return mainLoop->updateFunc(deltaTimeSeconds, NULL);
}
|