diff options
| author | Matthew Kosarek <mattkae@protonmail.com> | 2021-03-27 11:49:56 -0400 |
|---|---|---|
| committer | Matthew Kosarek <mattkae@protonmail.com> | 2021-03-27 11:49:56 -0400 |
| commit | 58488f8eabcc61089e0ae4297f38f10cc28d78c7 (patch) | |
| tree | 81ac504e61c57c7228024ad40710f782a3d8c884 /frontend/shared_cpp/MainLoop.h | |
| parent | 26ea81c5893778a7fa4ecbb2e8f561c9edabd0b3 (diff) | |
Working reusable simulation loop
Diffstat (limited to 'frontend/shared_cpp/MainLoop.h')
| -rw-r--r-- | frontend/shared_cpp/MainLoop.h | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/frontend/shared_cpp/MainLoop.h b/frontend/shared_cpp/MainLoop.h new file mode 100644 index 0000000..7300f6b --- /dev/null +++ b/frontend/shared_cpp/MainLoop.h @@ -0,0 +1,29 @@ +#pragma once + +#include <emscripten.h> +#include <emscripten/html5.h> +#include <GLES2/gl2.h> +#include <EGL/egl.h> + +EM_BOOL loop(double time, void* loop); + +struct MainLoop { + bool isRunning = false; + double lastTime = 0, elapsedTime = 0; + int numFrames = 0; + EM_BOOL (*updateFunc)(float dtSeconds, void *userData); + + void run(EM_BOOL (*cb)(float dtSeconds, void *userData)) { + isRunning = true; + lastTime = 0; + elapsedTime = 0; + numFrames = 0; + updateFunc = cb; + + emscripten_request_animation_frame_loop(loop, this); + } + + void stop() { + isRunning = false; + } +};
\ No newline at end of file |
