1
0
Fork 0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-12-23 01:59:43 +01:00

Use Emscripten's main loop

On Emscripten, SDL_Delay is implemented as a busy loop. In addition,
everything happens on a single thread. This effectively means that
you have to let Emscripten manage the main loop, since if you do it
yourself the browser will just be frozen.
This commit is contained in:
leo60228 2021-03-31 15:06:26 -04:00 committed by Misa Elizabeth Kai
parent 7baf143a6b
commit 0063e1c3bc

View file

@ -23,6 +23,11 @@
#include "SoundSystem.h"
#include "UtilityClass.h"
#ifdef __EMSCRIPTEN__
#include <emscripten.h>
#include <emscripten/html5.h>
#endif
scriptclass script;
#if !defined(NO_CUSTOM_LEVELS)
@ -54,8 +59,11 @@ static std::string playtestname;
static volatile Uint32 time_ = 0;
static volatile Uint32 timePrev = 0;
static volatile Uint32 accumulator = 0;
#ifndef __EMSCRIPTEN__
static volatile Uint32 f_time = 0;
static volatile Uint32 f_timePrev = 0;
#endif
enum FuncType
{
@ -339,6 +347,15 @@ static void inline deltaloop(void);
static void cleanup(void);
#ifdef __EMSCRIPTEN__
void emscriptenloop()
{
timePrev = time_;
time_ = SDL_GetTicks();
deltaloop();
}
#endif
int main(int argc, char *argv[])
{
char* baseDir = NULL;
@ -611,6 +628,9 @@ int main(int argc, char *argv[])
gamestate_funcs = get_gamestate_funcs(game.gamestate, &num_gamestate_funcs);
loop_assign_active_funcs();
#ifdef __EMSCRIPTEN__
emscripten_set_main_loop(emscriptenloop, 0, 0);
#else
while (true)
{
f_time = SDL_GetTicks();
@ -632,6 +652,8 @@ int main(int argc, char *argv[])
}
cleanup();
#endif
return 0;
}
@ -731,7 +753,9 @@ static void unfocused_run(void)
graphics.render();
gameScreen.FlipScreen();
//We are minimised, so lets put a bit of a delay to save CPU
#ifndef __EMSCRIPTEN__
SDL_Delay(100);
#endif
}
static void focused_begin(void)