summaryrefslogtreecommitdiff
path: root/shared_cpp/MainLoop.h
blob: 2573bb8324035758259f44778b7a3f650daf3173 (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;
	void (*updateFunc)(float dtSeconds, void *userData);

    void run(void (*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;
    }
};