mirror of
https://github.com/TerryCavanagh/VVVVVV.git
synced 2024-12-22 17:49: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:
parent
7baf143a6b
commit
0063e1c3bc
1 changed files with 24 additions and 0 deletions
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue