From de850676e79da39aec6f1ce0400cfa94cecbd744 Mon Sep 17 00:00:00 2001 From: mattkae Date: Sun, 19 Sep 2021 16:32:15 -0400 Subject: First commit --- themes/MainLoop.cpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 themes/MainLoop.cpp (limited to 'themes/MainLoop.cpp') diff --git a/themes/MainLoop.cpp b/themes/MainLoop.cpp new file mode 100644 index 0000000..09aa643 --- /dev/null +++ b/themes/MainLoop.cpp @@ -0,0 +1,31 @@ +#include "MainLoop.h" +#include +#include + +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(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 -- cgit v1.2.1