summaryrefslogtreecommitdiff
path: root/frontend/shared_cpp/MainLoop.h
blob: 7300f6b1a7ed512ee957b5813bbf41e183c39612 (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
#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;
    }
};