aboutsummaryrefslogtreecommitdiff
path: root/sources/TZR_MainLoop.c
blob: 325a0ce15fbf16c75bfce5a9b17b4484bbdc6acf (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
30
31
32
33
34
35
36
37
#include "TZR.h"
#include "TZR_globals.h"

#ifdef __EMSCRIPTEN__

static int (*_main_loop)(void *udata);
static void *_udata;
static void
_em_loop(void)
{
	TZR_CycleEvents();
	_main_loop(_udata);
}

int
TZR_MainLoop(int (*main_loop)(void *udata), void *udata)
{
	_main_loop = main_loop;
	_udata = udata;
	emscripten_set_main_loop(_em_loop, 0, 1);
	return 0;
}

#else

int
TZR_MainLoop(int (*main_loop)(void *udata), void *udata)
{
	while (!TZR_ShouldQuit()) {
		TZR_CycleEvents();
		if (main_loop(udata))
			return 1;
	}
	return 0;
}

#endif