diff -ruN os-orig/src/core/audio.c os/src/core/audio.c --- os-orig/src/core/audio.c +++ os/src/core/audio.c @@ -127,7 +127,14 @@ m = mallocx(sizeof *m); m->is_paused = false; m->filepath = str_dup(path); - if(NULL == (m->stream = al_load_audio_stream(fullpath, 4, 1024))) +#if defined(__EMSCRIPTEN__) + /* no feeder threads in the browser: the streams are refilled from the audio + callback, so they get bigger buffers */ + m->stream = al_load_audio_stream(fullpath, 8, 4096); +#else + m->stream = al_load_audio_stream(fullpath, 4, 1024); +#endif + if(NULL == m->stream) fatal_error("Can't load music \"%s\"", path); /* configure the audio stream */ diff -ruN os-orig/src/scenes/gameover.c os/src/scenes/gameover.c --- os-orig/src/scenes/gameover.c +++ os/src/scenes/gameover.c @@ -101,7 +101,7 @@ mobilegamepad_fadeout(); /* fade out */ - if(gameover_timer >= GAMEOVER_APPEARTIME && !music_is_playing(music)) { + if(gameover_timer >= GAMEOVER_APPEARTIME && !music_is_playing()) { if(fadefx_is_over()) { quest_abort(); scenestack_pop(); diff -ruN os-orig/src/scripting/loaderthread.c os/src/scripting/loaderthread.c --- os-orig/src/scripting/loaderthread.c +++ os/src/scripting/loaderthread.c @@ -60,10 +60,16 @@ ctx->argv[i] = str_dup(argv[i]); } +#if defined(__EMSCRIPTEN__) + /* the browser build has no threads: load the scripts right now. The "thread" + handle is the context itself, which surgescriptloaderthread_destroy() returns */ + return (ALLEGRO_THREAD*)load_surgescript(NULL, ctx); +#else /* create & start thread */ ALLEGRO_THREAD* thread = al_create_thread(load_surgescript, ctx); al_start_thread(thread); return thread; +#endif } /* @@ -75,6 +81,11 @@ { ssthreadcontext_t* ctx = NULL; +#if defined(__EMSCRIPTEN__) + /* already loaded by surgescriptloaderthread_create() */ + ctx = (ssthreadcontext_t*)thread; + assertx(ctx != NULL); +#else /* wait for completion */ void* ret = NULL; al_join_thread(thread, &ret); @@ -83,6 +94,7 @@ /* release thread */ al_destroy_thread(thread); +#endif /* error checking */ if(ctx->error_message[0] != '\0') { diff -ruN os-orig/src/scripting/music.c os/src/scripting/music.c --- os-orig/src/scripting/music.c +++ os/src/scripting/music.c @@ -136,7 +136,7 @@ if(music != NULL) { if(music_current() == music && music_is_paused()) - music_resume(music); + music_resume(); else music_play(music, false); music_set_volume(volume); diff -ruN os-orig/src/core/video.c os/src/core/video.c --- os-orig/src/core/video.c +++ os/src/core/video.c @@ -381,10 +381,16 @@ /* clearing just after flipping may provide a slight performance increase in some drivers */ +#if defined(__EMSCRIPTEN__) + /* in the browser the flip does not present anything: the frame is shown when the + main loop gives control back to the page. Clearing the display now would wipe the + frame that is about to be shown (a black screen). The next frame covers it all. */ +#else if(_glClear != NULL) _glClear(GL_COLOR_BUFFER_BIT); else al_clear_to_color(al_map_rgba_f(0.0f, 0.0f, 0.0f, 0.0f)); +#endif #if USE_ROUNDROBIN_BACKBUFFER /* use a round-robin scheme for a (possible) performance improvement,