summaryrefslogtreecommitdiff
path: root/themes/src/MainLoop.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'themes/src/MainLoop.cpp')
-rw-r--r--themes/src/MainLoop.cpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/themes/src/MainLoop.cpp b/themes/src/MainLoop.cpp
new file mode 100644
index 0000000..09aa643
--- /dev/null
+++ b/themes/src/MainLoop.cpp
@@ -0,0 +1,31 @@
+#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;
+ }
+
+ mainLoop->updateFunc(deltaTimeSeconds, NULL);
+ return true;
+} \ No newline at end of file