diff --git a/src/configfile.cc b/src/configfile.cc index aaf5613..95abbd7 100644 --- a/src/configfile.cc +++ b/src/configfile.cc @@ -417,6 +417,9 @@ configfile::save () break; } fprintf (config, ")\n"); + /* fredygames.com browser build: the file was never closed, so its contents stayed in the + * stdio buffer until the program exited, which a browser tab never does */ + fclose (config); } } diff --git a/src/handler_audio.cc b/src/handler_audio.cc index 78eed55..0279896 100644 --- a/src/handler_audio.cc +++ b/src/handler_audio.cc @@ -453,6 +453,11 @@ handler_audio::play_music (Uint32 music_id) "Mix_LoadMUS return " << SDL_GetError () << std::endl; return; } +#ifdef __EMSCRIPTEN__ + /* fredygames.com browser build: the music is played over libmodplug (tbzmusic.c), which keeps the + * MikMod-like position */ + song_module = tbz_music_module (current_music); +#else /* Ugly way to access sdl-mixer's internal structures */ union { @@ -461,6 +466,7 @@ handler_audio::play_music (Uint32 music_id) } dummy; memcpy (&song_module, (Uint8 *) current_music + sizeof (dummy), sizeof (void *)); +#endif /* start the music */ if (Mix_PlayMusic (current_music, -1) == -1) diff --git a/src/handler_display.cc b/src/handler_display.cc index 6dc8484..1fb6ab0 100644 --- a/src/handler_display.cc +++ b/src/handler_display.cc @@ -258,9 +258,12 @@ handler_display::get_info () vi->vfmt->Gshift, vi->vfmt->Bshift, vi->vfmt->Ashift); printf ("Rloss=%i Gloss=%i Bloss=%i Aloss=%i \n", vi->vfmt->Rloss, vi->vfmt->Gloss, vi->vfmt->Bloss, vi->vfmt->Aloss); +#ifndef __EMSCRIPTEN__ + /* fredygames.com browser build: SDL2's SDL_PixelFormat has no colorkey or alpha */ printf ("Pixel value of transparent pixels. colorkey=%i \n", vi->vfmt->colorkey); printf ("Overall surface alpha value. alpha=%i \n", vi->vfmt->alpha); +#endif printf ("Is it possible to create hardware surfaces? hw_available=%i \n", vi->hw_available); printf ("Is there a window manager available wm_available=%i \n", diff --git a/src/main.cc b/src/main.cc index 35f91ad..5003052 100644 --- a/src/main.cc +++ b/src/main.cc @@ -32,6 +32,17 @@ #include "../include/configfile.h" configfile configuration; +#ifdef __EMSCRIPTEN__ +#include +/* fredygames.com browser build: the page calls this when the tab is hidden or closed, because the + * game only writes its configuration when it quits (the high scores it writes at once) */ +extern "C" EMSCRIPTEN_KEEPALIVE void +fredygames_save (void) +{ + configuration.save (); +} +#endif + /** * Returns to the standard GP2X menu. */