diff --git a/data/berusky.ini b/data/berusky.ini index 6629d4e..2fdd892 100644 --- a/data/berusky.ini +++ b/data/berusky.ini @@ -11,6 +11,10 @@ graphics_data = /usr/share/berusky/Graphics fullscreen = 0 color_depth = 32 +# Start in the high resolution mode (1280x960) without asking; the page scales the picture +# to the player. Added for the browser build of fredygames.com. +startup_doublesize_question = 0 + # Logging log = 0 logfile = ~/.berusky/b1logfile.txt diff --git a/src/berusky_gui.cpp b/src/berusky_gui.cpp index c832b3b..0f6d40f 100644 --- a/src/berusky_gui.cpp +++ b/src/berusky_gui.cpp @@ -61,9 +61,26 @@ spr_handle menu_background_get(void) // Game UI // ------------------------------------------------------- +#ifdef __EMSCRIPTEN__ +#include + +/* The game writes the last used profile only when it quits; the page calls this when the tab is + * hidden or closed (the profile progress itself is written after each finished level). */ +static game_gui *fredygames_gui = NULL; + +extern "C" EMSCRIPTEN_KEEPALIVE void fredygames_save(void) +{ + if(fredygames_gui) + fredygames_gui->player_profile_save(); +} +#endif + game_gui::game_gui(ITEM_REPOSITORY *p_repo_, DIR_LIST *p_dir_) : gui_base(), p_repo(p_repo_), p_dir(p_dir_) { +#ifdef __EMSCRIPTEN__ + fredygames_gui = this; +#endif // Create game main class p_ber = new BERUSKY(p_repo_,p_dir); @@ -76,6 +93,9 @@ game_gui::game_gui(ITEM_REPOSITORY *p_repo_, DIR_LIST *p_dir_) game_gui::~game_gui(void) { +#ifdef __EMSCRIPTEN__ + fredygames_gui = NULL; +#endif player_profile_save(); if(p_ber) @@ -271,7 +291,10 @@ void game_gui::menu_main(MENU_STATE state, size_ptr data, size_ptr data1) menu_item_draw(profiles, MENU_LEFT, MENU_SAVE_BACK, LEVEL_EVENT(GC_MENU_PROFILES)); menu_item_draw(settings, MENU_LEFT, MENU_SAVE_BACK, LEVEL_EVENT(GC_MENU_SETTINGS)); menu_item_draw(help, MENU_LEFT, MENU_SAVE_BACK, LEVEL_EVENT(GC_MENU_HELP,FALSE)); +#ifndef __EMSCRIPTEN__ + /* The level editor runs as a separate program; there is none in the browser. */ menu_item_draw(editor, MENU_LEFT, MENU_SAVE_BACK, LEVEL_EVENT(GC_RUN_EDITOR)); +#endif menu_item_draw(quit, MENU_LEFT, MENU_SAVE_BACK, LEVEL_EVENT(GC_MENU_QUIT)); p_font->alignment_set(MENU_CENTER); diff --git a/src/editor.cpp b/src/editor.cpp index 04f77ee..9cf11c9 100644 --- a/src/editor.cpp +++ b/src/editor.cpp @@ -29,7 +29,9 @@ #include #include #include +#ifndef __EMSCRIPTEN__ #include +#endif #include #include diff --git a/src/input.cpp b/src/input.cpp index 23c6734..0d8b738 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -157,7 +157,11 @@ bool key_to_ascii(int key, char *p_char) bool input::key_status(int sdl_key) { Uint8 *keystate = SDL_GetKeyState(NULL); +#ifdef __EMSCRIPTEN__ + return(keystate[SDL12_KEY(sdl_key)]); +#else return(keystate[sdl_key]); +#endif } void input::keyset_set(EVENT_KEY_SET *p_keyset) @@ -260,8 +264,12 @@ void input::key_input(KEYTYPE key, KEYMOD modification, bool pressed) // Update all key events regard to current keyboard state for(i = 0; i < keynum; i++, p_key++) { +#ifdef __EMSCRIPTEN__ + if(keystate[SDL12_KEY(p_key->key)] && ctrl == p_key->ctrl && shift == p_key->shift) { +#else assert(p_key->key < numkeys); if(keystate[p_key->key] && ctrl == p_key->ctrl && shift == p_key->shift) { +#endif //bprintf("p_key = %p, activated, p_key->key = %d, keystate[p_key->key] = %d",p_key,p_key->key,keystate[p_key->key]); p_key->flag = p_key->flag|KEY_PRESSED; } @@ -304,7 +312,8 @@ void input::events_loop(LEVEL_EVENT_QUEUE *p_queue) bool pressed = FALSE; int i; for(i = 0; i < MOUSE_BUTTONS; i++) { - bool state = event.motion.state&SDL_BUTTON(i); + // SDL_BUTTON(0) shifts by -1, which is undefined; clang folds it into "pressed". + bool state = i > 0 && (event.motion.state&SDL_BUTTON(i)); if(state) { mouse_input(event.motion.x, event.motion.y, BUTTON_DOWN, i); pressed = TRUE; @@ -321,6 +330,7 @@ void input::events_loop(LEVEL_EVENT_QUEUE *p_queue) case SDL_MOUSEBUTTONUP: mouse_input(event.button.x, event.button.y, BUTTON_UP, event.button.button); break; +#ifndef __EMSCRIPTEN__ case SDL_ACTIVEEVENT: if(event.active.state&SDL_APPACTIVE) { if(event.active.gain) { @@ -330,6 +340,7 @@ void input::events_loop(LEVEL_EVENT_QUEUE *p_queue) } } break; +#endif case SDL_QUIT: p_queue->add(LEVEL_EVENT(GC_MENU_QUIT)); p_queue->commit(); @@ -398,7 +409,11 @@ void input::mouse_input(tpos mx, tpos my, MOUSE_BUTTON_STATE state, int button) } if(p_ev->flag&MEVENT_KEY) { +#ifdef __EMSCRIPTEN__ + cond_key = p_ev->mstate.key && p_keystate[SDL12_KEY(p_ev->mstate.key)]; +#else cond_key = p_ev->mstate.key && p_keystate[p_ev->mstate.key]; +#endif } if(cond_button && cond_key && cond_area) { diff --git a/src/main.cpp b/src/main.cpp index 3ea2281..51df268 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -25,7 +25,7 @@ * */ #include "portability.h" -#ifdef LINUX +#if defined(LINUX) && !defined(__EMSCRIPTEN__) #include #endif #include @@ -285,7 +285,7 @@ int main(int argc, char *argv[]) setbuf(stderr, NULL); srand(clock()); -#ifdef LINUX +#if defined(LINUX) && !defined(__EMSCRIPTEN__) gtk_parse_args(&argc, &argv); #endif diff --git a/src/utils.cpp b/src/utils.cpp index b2f1da4..0b0f7d2 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -29,7 +29,9 @@ Utility */ #include +#ifndef __EMSCRIPTEN__ #include +#endif #include #include #include