--- a/src/font.c +++ b/src/font.c @@ -177,6 +177,6 @@ void clear_text(int length, int x, int y) dst_rect->w = length > -1 ? CHARWIDTH * length : XS - dst_rect->x; dst_rect->h = LINEHEIGHT; - SDL_FillRect(screen, dst_rect, 0x00000000); + SDL_FillRect(screen, dst_rect, SDL_MapRGB(screen->format, 0, 0, 0)); SDL_UpdateRect(screen, dst_rect->x, dst_rect->y, dst_rect->w, dst_rect->h); } --- /dev/null +++ b/src/fredy_stubs.c @@ -0,0 +1,33 @@ +/* + * fredygames.com: replaces net.c, netops.c and server.c (network games) and sound.c (the two sounds of the + * package are left out of this build) with functions that do nothing. The options screen hides the buttons + * that would lead here. GPL-2.0-or-later, like the rest of Biloba. + */ +#include +#include "net.h" +#include "sound.h" + +void net_init(void) {} +void net_stop(void) {} +int net_init_game(const char *gamename, int numplayers, InputSystemMethod methods[], char *names[]) { return -1; } +int net_wait_ready(int num_players, char **player_names) { return -1; } +LList *net_get_games(int numplayer) { return NULL; } +int net_get_info(Game *game) { return -1; } +int net_join(int id, int nump, const char *my_player_name) { return -1; } +void net_send_event(int player, int x, int y) {} +void net_get_event(int player, int *x, int *y) {} +void net_end_game(int player) {} +void net_close(void) {} +void net_set_server(const char *srv) {} +int net_get_servers(char ***distant_servers) { return 0; } +void net_stop_getting_servers(void) {} +void net_pull_recv_msg(void) {} +int net_is_typing_msg(void) { return 0; } +void net_set_typing_msg(int typing) {} +const char *net_get_pending_msg(void) { return NULL; } +void net_type_msg(unsigned char c) {} + +void sound_init(void) {} +void sound_stop(void) {} +void sound_play(SndId sound) {} +void sound_load_sounds(void) {} --- /dev/null +++ b/src/fredy_web.h @@ -0,0 +1,23 @@ +/* + * fredygames.com: included with -include in every file. The SDL 1.2 of Emscripten has no blocking + * SDL_WaitEvent and its SDL_Delay aborts in the browser's main loop, so both give way to the browser with + * emscripten_sleep (Asyncify). + */ +#ifndef FREDY_WEB_H +#define FREDY_WEB_H +#include + +/* not emscripten.h: its stdbool.h makes `bool` a macro, and the game uses `bool` as a parameter name */ +void emscripten_sleep(unsigned int ms); + +static inline int fredy_wait_event(SDL_Event *event) +{ + while (!SDL_PollEvent(event)) + emscripten_sleep(10); + return 1; +} + +#undef SDL_Delay +#define SDL_Delay(ms) emscripten_sleep(ms) +#define SDL_WaitEvent fredy_wait_event +#endif --- a/src/main.c +++ b/src/main.c @@ -65,7 +65,7 @@ int main(int argc, char *argv[]) printf("Couldn't chdir to %s\n", progpath); } - SDL_Init(SDL_INIT_EVERYTHING|SDL_INIT_NOPARACHUTE); + SDL_Init(SDL_INIT_VIDEO|SDL_INIT_NOPARACHUTE); SDL_EnableUNICODE(1); if ( (screen=SDL_SetVideoMode(XS, YS, BPP, FLAGS)) == NULL ) { fprintf(stderr, "Couldn't set %dx%dx%d video mode: %s\n", --- a/src/options.c +++ b/src/options.c @@ -678,6 +678,9 @@ static void build_gui(void) do_create_game, NULL); join_game = widget_create("join-game.png", JOINGAME_MIN_X, JOINGAME_MIN_Y, do_join_game, NULL); + /* fredygames.com: no network games in the browser build */ + widget_hide(create_game); + widget_hide(join_game); start = widget_create("start.png", START_MIN_X, START_MIN_Y, do_start, NULL); save_last = widget_create("save_last.png", SAVE_LAST_MIN_X, SAVE_LAST_MIN_Y, @@ -688,6 +691,9 @@ static void build_gui(void) lang = widget_create("en.png", LANG_MIN_X, LANG_MIN_Y, set_lang, NULL); + /* fredygames.com: only the English images are shipped, so the language button goes away */ + widget_hide(lang); + saved = widget_create("saved.png", SAVED_MIN_X, SAVED_MIN_Y, hide_saved, NULL); text_widget_init(saved, "", SAVED_LEN, 10, 0, NULL, NULL); text_widget_set_editable(saved, FALSE); @@ -750,10 +756,7 @@ int get_options(const char *replay_file) widget_hide(saved); - if (cur_game && cur_game->move_id > 1) - widget_show(save_last); - else - widget_hide(save_last); + widget_hide(save_last); /* fredygames.com: there is no desktop folder to save to in the browser */ reset_net_widgets(); use_net = FALSE; @@ -814,7 +817,7 @@ choose_again: if (use_net && (net_game_number < 0 || net_wait_ready(num_players, player_names) < 0)) { - SDL_FillRect(screen, NULL, 0x00000000); + SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0)); SDL_UpdateRect(screen, 0, 0, 0, 0); draw_message(get_msg(M_ENOCONN), 200, 284, -1, FALSE); @@ -839,7 +842,7 @@ choose_again: llist_free(network_games_list); network_games_list = NULL; - SDL_FillRect(screen, NULL, 0x00000000); + SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0)); SDL_UpdateRect(screen, 0, 0, 0, 0); return 0; --- a/src/utils.c +++ b/src/utils.c @@ -50,6 +50,7 @@ char *progpath = NULL; char *langpath = NULL; +SDL_Surface * screen; /** * Get an object's X coordinate as pixels @@ -270,7 +271,7 @@ int handle_generic_event(SDL_Event *event) if (event->type == SDL_KEYDOWN) { SDL_KeyboardEvent *kevent = &event->key; - if (kevent->keysym.sym && kevent->keysym.mod) { + if (kevent->keysym.sym) { key = kevent->keysym.sym; if (key == SDLK_a) key = SDLK_q; /* Ugly hack. */ --- a/src/utils.h +++ b/src/utils.h @@ -87,7 +87,7 @@ extern char *progpath; extern char *langpath; -SDL_Surface * screen; +extern SDL_Surface * screen; int get_x(int x); int get_y(int y); --- a/src/widget.c +++ b/src/widget.c @@ -339,7 +339,7 @@ static void list_widget_draw_list(Widget *widget) 0x7F, 0x7F, 0x7F)); rect.x++; rect.y++; rect.w -= 2; rect.h -= 2; - SDL_FillRect(screen, &rect, 0x00000000); + SDL_FillRect(screen, &rect, SDL_MapRGB(screen->format, 0, 0, 0)); widget->cur_list_start_x = start_x + 8; widget->cur_list_start_y = start_y + 8; @@ -423,7 +423,7 @@ void update_gui(void) { LList *rev, *cur; - SDL_FillRect(screen, NULL, 0x00000000); + SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0)); /* First added widget drawn first. */ rev = llist_reverse(widget_list);