diff options
author | Matthew Kosarek <mattkae@protonmail.com> | 2021-05-16 19:50:15 -0400 |
---|---|---|
committer | Matthew Kosarek <mattkae@protonmail.com> | 2021-05-16 19:50:15 -0400 |
commit | a00c0aab1eb5a7a55bef8ca08115bdd722ab5699 (patch) | |
tree | 45b5c4cc8c380d0630a8e0185af7229f26dc754a /shared_cpp/MainLoop.cpp | |
parent | 4941a1874b6ca9d142d94df70b2aec5e0b35b94e (diff) |
Moved the frontend directory up so that it no longer exists
Diffstat (limited to 'shared_cpp/MainLoop.cpp')
-rw-r--r-- | shared_cpp/MainLoop.cpp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/shared_cpp/MainLoop.cpp b/shared_cpp/MainLoop.cpp new file mode 100644 index 0000000..09aa643 --- /dev/null +++ b/shared_cpp/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 |