From ad6538db661193b911d55fcc0ad81f5cbad5ac69 Mon Sep 17 00:00:00 2001 From: Antoine Bache Date: Thu, 17 Aug 2017 14:59:01 +0200 Subject: [PATCH] Porting menu to assembly --- include/menu.inc | 34 +++++ src/menu.asm | 364 ++++++++++++++++++++++++++++++++++++++++++++++- src/menu_c.c | 196 ++++++++++--------------- src/test.c | 11 ++ 4 files changed, 479 insertions(+), 126 deletions(-) create mode 100644 include/menu.inc diff --git a/include/menu.inc b/include/menu.inc new file mode 100644 index 0000000..2714759 --- /dev/null +++ b/include/menu.inc @@ -0,0 +1,34 @@ +;; Menu list +%define MENU_MAIN 0 +%define MENU_MULTIPLAYER 1 +%define MENU_SELECT_MAP_SOLO 2 +%define MENU_MULTIPLAYER_CONNECT 3 +%define MENU_MULTIPLAYER_HOST 4 +%define NB_MENUS 5 + +;; MENU_MAIN buttons +%define BUTTON_PLAY 0 +%define BUTTON_MULTIPLAYER 1 +%define BUTTON_EXIT 2 +%define NB_BUTTON_MAIN 3 + +;; MENU_MULTIPLAYER buttons +%define BUTTON_MP_HOST 0 +%define BUTTON_MP_CONNECT 1 +%define BUTTON_MP_BACK 2 +%define NB_BUTTON_MULTIPLAYER 3 + +;; MENU_SELECT_MAP_SOLO buttons +%define BUTTON_SM_SOLO_MAP 0 +%define BUTTON_SM_SOLO_BACK 1 +%define NB_BUTTON_SELECT_MAP_SOLO 2 + +;; MENU_MULTIPLAYER_CONNECT buttons +%define BUTTON_MP_CO_CONNECT 0 +%define BUTTON_MP_CO_BACK 1 +%define NB_BUTTON_MULTIPLAYER_CONNECT 2 + +;; MENU_MULTIPLAYER_HOST buttons +%define BUTTON_MP_HOST_MAP 0 +%define BUTTON_MP_HOST_BACK 1 +%define NB_BUTTON_MULTIPLAYER_HOST 2 diff --git a/src/menu.asm b/src/menu.asm index 6270919..876c637 100644 --- a/src/menu.asm +++ b/src/menu.asm @@ -1,13 +1,23 @@ [bits 64] %include "sdl.inc" + %include "menu.inc" global wolfasm_menu_render_button - extern gui_font, wolfasm_display_text, window_height + extern gui_font, wolfasm_display_text, window_height, \ + window_width, wolfasm, wolfasm_menu_play_music ;; SDL functions - extern _TTF_SetFontStyle + extern _TTF_SetFontStyle, _Mix_HaltMusic, \ + _SDL_StartTextInput + + ;; LibC functions + extern _strncpy, _strncat, _snprintf + + ;; TODO: rm + global selected_text_field_max_len, selected_text_field_len, selected_text_field, wolfasm_connect, wolfasm_connect_len, wolfasm_port, wolfasm_port_len, callbacks_main_menu, menu, selected_button, wolfasm_menu_nb_buttons, running, callback_sm_solo, wolfasm_selected_map, callbacks_multiplayer_menu + extern _wolfasm_load_maps section .text @@ -82,8 +92,356 @@ wolfasm_menu_render_button: pop rbp ret + ;; + ;; Main menu functions + ;; + +wolfasm_main_play: + push rbp + mov rbp, rsp + + mov dword [rel menu], MENU_SELECT_MAP_SOLO + mov dword [rel wolfasm_menu_nb_buttons], NB_BUTTON_SELECT_MAP_SOLO + mov dword [rel selected_button], 0 + call _wolfasm_load_maps + + mov rsp, rbp + pop rbp + ret + +wolfasm_main_multiplayer: + push rbp + mov rbp, rsp + + mov dword [rel menu], MENU_MULTIPLAYER + mov dword [rel wolfasm_menu_nb_buttons], NB_BUTTON_MULTIPLAYER + mov dword [rel selected_button], 0 + + mov rsp, rbp + pop rbp + ret + +wolfasm_main_exit: + push rbp + mov rbp, rsp + + mov byte [rel running], 0 + + mov rsp, rbp + pop rbp + ret + +wolfasm_main_buttons: + push rbp + mov rbp, rsp + + ;; Display "Play" button + lea rdi, [rel play_txt] + mov esi, [rel window_width] + shr esi, 1 + mov edx, [rel window_height] + shr edx, 1 + mov ecx, [rel window_width] + shr ecx, 4 + xor r8, r8 + mov r9, 1 + cmp dword [rel selected_button], BUTTON_PLAY + cmove r8w, r9w + call wolfasm_menu_render_button + + ;; Display "Multiplayer" button + lea rdi, [rel multiplayer_txt] + mov esi, [rel window_width] + shr esi, 1 + mov edx, [rel window_height] + shr edx, 1 ;; / 2 + mov r8d, [rel window_height] + shr r8d, 3 ;; /8 + add edx, r8d + mov ecx, [rel window_width] + shr ecx, 2 + xor r8, r8 + mov r9, 1 + cmp dword [rel selected_button], BUTTON_MULTIPLAYER + cmove r8w, r9w + call wolfasm_menu_render_button + + + ;; Display "Exit" button + lea rdi, [rel exit_txt] + mov esi, [rel window_width] + shr esi, 1 + mov edx, [rel window_height] + shr edx, 1 ;; / 2 + mov r8d, [rel window_height] + shr r8d, 3 ;; /8 + shl r8d, 1 ;; * 2 + add edx, r8d + mov ecx, [rel window_width] + shr ecx, 4 + xor r8, r8 + mov r9, 1 + cmp dword [rel selected_button], BUTTON_EXIT + cmove r8w, r9w + call wolfasm_menu_render_button + + mov rsp, rbp + pop rbp + ret + + ;; + ;; Select Map solo menu functions + ;; +wolfasm_sm_solo_map: + push rbp + mov rbp, rsp + + ;; Put path in buffer + lea rdi, [rel filename] + lea rsi, [rel filename_path] + mov edx, 512 - 1 + call _strncpy + + ;; Add filename to path + lea rdi, [rel filename] + mov rsi, [rel wolfasm_selected_map] + mov edx, 512 - 1 + call _strncat + + call _Mix_HaltMusic + lea rdi, [rel filename] + call wolfasm + call wolfasm_menu_play_music + + mov rsp, rbp + pop rbp + ret + +wolfasm_sm_solo_back: + push rbp + mov rbp, rsp + + mov dword [rel menu], MENU_MAIN + mov dword [rel wolfasm_menu_nb_buttons], NB_BUTTON_MAIN + mov dword [rel selected_button], 0 + + mov rsp, rbp + pop rbp + ret + +wolfasm_sm_solo_buttons: + push rbp + mov rbp, rsp + + lea rdi, [rel buff_file] + mov esi, 255 + 1 + 4 + lea rdx, [rel file_fmt] + mov rcx, [rel wolfasm_selected_map] + call _snprintf + + ;; Render file button + lea rdi, [rel buff_file] + mov esi, [rel window_width] + shr esi, 1 + mov edx, [rel window_height] + shr edx, 1 + mov ecx, [rel window_width] + shr ecx, 3 + xor r8, r8 + mov r9d, 1 + cmp dword [rel selected_button], BUTTON_SM_SOLO_MAP + cmove r8d, r9d + call wolfasm_menu_render_button + + ;; Render "Back" button + lea rdi, [rel back_txt] + mov esi, [rel window_width] + shr esi, 1 + mov edx, [rel window_height] + shr edx, 1 + mov r8d, [rel window_height] + shr r8d, 3 + add edx, r8d + mov ecx, [rel window_width] + shr ecx, 3 + xor r8, r8 + mov r9d, 1 + cmp dword [rel selected_button], BUTTON_SM_SOLO_BACK + cmove r8d, r9d + call wolfasm_menu_render_button + + mov rsp, rbp + pop rbp + ret + + ;; + ;; Multiplayer menu functions + ;; +wolfasm_multiplayer_host: + push rbp + mov rbp, rsp + + mov dword [rel menu], MENU_MULTIPLAYER_HOST + mov dword [rel wolfasm_menu_nb_buttons], NB_BUTTON_MULTIPLAYER_HOST + mov dword [rel selected_button], 0 + mov dword [rel wolfasm_port_len], 0 + lea rdi, [rel wolfasm_port_len] + mov qword [rel selected_text_field_len], rdi + mov dword [rel selected_text_field_max_len], 6 ;; sizeof("65535") + lea rdi, [rel wolfasm_port] + mov qword [rel selected_text_field], rdi + + ;; Load maps + call _wolfasm_load_maps + ;; Start handling text input + call _SDL_StartTextInput + + mov rsp, rbp + pop rbp + ret + +wolfasm_multiplayer_connect: + push rbp + mov rbp, rsp + + mov dword [rel menu], MENU_MULTIPLAYER_CONNECT + mov dword [rel wolfasm_menu_nb_buttons], NB_BUTTON_MULTIPLAYER_CONNECT + mov dword [rel selected_button], 0 + mov dword [rel wolfasm_connect_len], 0 + mov dword [rel wolfasm_port_len], 0 + lea rdi, [rel wolfasm_connect_len] + mov qword [rel selected_text_field_len], rdi + mov dword [rel selected_text_field_max_len], 255 + lea rdi, [rel wolfasm_connect] + mov qword [rel selected_text_field], rdi + + ;; Start handling text input + call _SDL_StartTextInput + + mov rsp, rbp + pop rbp + ret + +wolfasm_multiplayer_back: + push rbp + mov rbp, rsp + + mov dword [rel menu], MENU_MAIN + mov dword [rel wolfasm_menu_nb_buttons], NB_BUTTON_MAIN + mov dword [rel selected_button], 0 + + mov rsp, rbp + pop rbp + ret + +wolfasm_multiplayer_buttons: + push rbp + mov rbp, rsp + + ;; Render "Host" button + lea rdi, [rel host_txt] + mov esi, [rel window_width] + shr esi, 1 + mov edx, [rel window_height] + shr edx, 1 + mov ecx, [rel window_width] + shr ecx, 4 + xor r8, r8 + mov r9d, 1 + cmp dword [rel selected_button], BUTTON_MP_HOST + cmove r8d, r9d + call wolfasm_menu_render_button + + ;; Render "Connect" button + lea rdi, [rel connect_txt] + mov esi, [rel window_width] + shr esi, 1 + mov edx, [rel window_height] + shr edx, 1 + mov r8d, [rel window_height] + shr r8d, 3 + add edx, r8d + mov ecx, [rel window_width] + shr ecx, 3 + xor r8, r8 + mov r9d, 1 + cmp dword [rel selected_button], BUTTON_MP_CONNECT + cmove r8d, r9d + call wolfasm_menu_render_button + + ;; Render "Back" button + lea rdi, [rel back_txt] + mov esi, [rel window_width] + shr esi, 1 + mov edx, [rel window_height] + shr edx, 1 + mov r8d, [rel window_height] + shr r8d, 3 + shl r8d, 1 + add edx, r8d + mov ecx, [rel window_width] + shr ecx, 4 + xor r8, r8 + mov r9d, 1 + cmp dword [rel selected_button], BUTTON_MP_BACK + cmove r8d, r9d + call wolfasm_menu_render_button + + mov rsp, rbp + pop rbp + ret + + ;; + ;; Multiplayer Connect menu functions + ;; + + ;; + ;; Multiplayer Host menu functions + ;; + section .rodata -txt: db "Hello", 0x00 +;; Text strings +play_txt: db "Play", 0x00 +multiplayer_txt: db "Multiplayer", 0x00 +exit_txt: db "Exit", 0x00 +back_txt: db "Back", 0x00 +host_txt: db "Host", 0x00 +connect_txt: db "Connect", 0x00 +filename_path: db "./resources/map/", 0x00 +file_fmt: db "< %s >", 0x00 + +;; Callbacks +callbacks_main_menu: dq wolfasm_main_play, \ + wolfasm_main_multiplayer, \ + wolfasm_main_exit, \ + wolfasm_main_buttons +callback_sm_solo: dq wolfasm_sm_solo_map, \ + wolfasm_sm_solo_back, \ + wolfasm_sm_solo_buttons +callbacks_multiplayer_menu: \ + dq wolfasm_multiplayer_host, \ + wolfasm_multiplayer_connect, \ + wolfasm_multiplayer_back, \ + wolfasm_multiplayer_buttons + + section .data +selected_text_field: dq 0 +selected_text_field_len: dq 0 +selected_text_field_max_len: dd 0 +wolfasm_selected_text_field: dd 0 + +wolfasm_selected_map: dq 0 + +menu: dd MENU_MAIN +wolfasm_menu_nb_buttons: dd NB_BUTTON_MAIN +selected_button: dd BUTTON_PLAY +running: db 1 section .bss wolfasm_button_rect: resd 4 +wolfasm_connect: resb 255 +wolfasm_connect_len: resd 1 +wolfasm_port: resb 6 ;; sizeof("65535") +wolfasm_port_len: resd 1 +filename: resb 512 +buff_file: resb 255 + 1 + 4 diff --git a/src/menu_c.c b/src/menu_c.c index a122fcb..c616fb2 100644 --- a/src/menu_c.c +++ b/src/menu_c.c @@ -5,7 +5,6 @@ extern void render_sprite(wolfasm_sprite_t *sprite, int x, int y, SDL_Rect *clip) __asm__("wolfasm_render_sprite"); -extern void wolfasm(char const *map) __asm__("wolfasm"); extern void render_button(char const *text, int32_t const x, int32_t y, int32_t width, bool selected) __asm__("wolfasm_menu_render_button"); @@ -16,61 +15,55 @@ enum wolfasm_menus { MENU_MULTIPLAYER, MENU_SELECT_MAP_SOLO, MENU_MULTIPLAYER_CONNECT, + MENU_MULTIPLAYER_HOST, NB_MENUS }; -enum wolfasm_buttons_main { - BUTTON_PLAY = 0, - BUTTON_MULTIPLAYER, - BUTTON_EXIT, - NB_BUTTON_MAIN -}; - -enum wolfasm_buttons_mutliplayer { +enum wolfasm_buttons_multiplayer { BUTTON_MP_HOST = 0, BUTTON_MP_CONNECT, BUTTON_MP_BACK, NB_BUTTON_MULTIPLAYER }; -enum wolfasm_buttons_select_map_solo { - BUTTON_SM_SOLO_MAP = 0, - BUTTON_SM_SOLO_BACK, - NB_BUTTON_SELECT_MAP_SOLO -}; - -enum wolfasm_buttons_mutliplayer_connect { +enum wolfasm_buttons_multiplayer_connect { BUTTON_MP_CO_CONNECT = 0, BUTTON_MP_CO_BACK, NB_BUTTON_MULTIPLAYER_CONNECT }; +enum wolfasm_buttons_multiplayer_host { + BUTTON_MP_HOST_MAP = 0, + BUTTON_MP_HOST_BACK, + NB_BUTTON_MULTIPLAYER_HOST +}; + // // Menu // -static bool running = true; -static enum wolfasm_menus menu = MENU_MAIN; -static int32_t wolfasm_menu_nb_buttons = NB_BUTTON_MAIN; -static int32_t selected_button = BUTTON_PLAY; +extern bool running __asm__("running"); +extern enum wolfasm_menus menu __asm__("menu"); +extern int32_t wolfasm_menu_nb_buttons __asm__("wolfasm_menu_nb_buttons"); +extern int32_t selected_button __asm__("selected_button"); -static char const *wolfasm_selected_map = NULL; +extern char const *wolfasm_selected_map __asm__("wolfasm_selected_map"); static char const *wolfasm_maps[255] = {0}; static int32_t wolfasm_current_map = 0; static int32_t wolfasm_nb_maps = 0; -static char wolfasm_connect[255]; -static int32_t wolfasm_connect_len = 0; -static char wolfasm_port[sizeof("65535")]; -static int32_t wolfasm_port_len = 0; -static char *wolfasm_text_field[] = {wolfasm_connect, wolfasm_port}; -static int32_t wolfasm_selected_text_field = 0; +extern char wolfasm_connect[255] __asm__("wolfasm_connect"); +extern int32_t wolfasm_connect_len __asm__("wolfasm_connect_len"); -static int32_t selected_text_field_max_len = 0; -static int32_t *selected_text_field_len = NULL; -static char *selected_text_field = NULL; +extern char wolfasm_port[sizeof("65535")] __asm__("wolfasm_port"); +extern int32_t wolfasm_port_len __asm__("wolfasm_port_len"); + +extern int32_t + selected_text_field_max_len __asm__("selected_text_field_max_len"); +extern int32_t *selected_text_field_len __asm__("selected_text_field_len"); +extern char *selected_text_field __asm__("selected_text_field"); // Main Menu -static void wolfasm_load_maps() { +void wolfasm_load_maps() { DIR *d = opendir("./resources/map/"); struct dirent *dir = NULL; @@ -103,78 +96,21 @@ static void wolfasm_load_maps() { exit(1); } -// -// Main menu -// -static void wolfasm_main_play() { - menu = MENU_SELECT_MAP_SOLO; - wolfasm_menu_nb_buttons = NB_BUTTON_SELECT_MAP_SOLO; - selected_button = 0; - wolfasm_load_maps(); -} -static void wolfasm_main_multiplayer() { - menu = MENU_MULTIPLAYER; - wolfasm_menu_nb_buttons = NB_BUTTON_MULTIPLAYER; - selected_button = 0; -} -static void wolfasm_main_exit() { running = false; } -static void wolfasm_main_buttons() { - render_button("Play", window_width / 2, window_height / 2, window_width / 16, - selected_button == BUTTON_PLAY); - render_button("Multiplayer", window_width / 2, - window_height / 2 + window_height / 8, window_width / 4, - selected_button == BUTTON_MULTIPLAYER); - render_button("Exit", window_width / 2, - window_height / 2 + 2 * (window_height / 8), window_width / 16, - selected_button == BUTTON_EXIT); -} - -// -// Multiplayer -// -static void wolfasm_multiplayer_host() {} -static void wolfasm_multiplayer_connect() { - menu = MENU_MULTIPLAYER_CONNECT; - wolfasm_menu_nb_buttons = NB_BUTTON_MULTIPLAYER_CONNECT; - selected_button = 0; - wolfasm_selected_text_field = 0; - wolfasm_connect_len = 0; - wolfasm_port_len = 0; - selected_text_field_len = &wolfasm_connect_len; - selected_text_field_max_len = sizeof(wolfasm_connect); - selected_text_field = wolfasm_connect; - SDL_StartTextInput(); - SDL_SetTextInputRect((SDL_Rect[]){window_width / 2, window_height / 2, 100, - window_width / 16}); -} -static void wolfasm_multiplayer_back() { - menu = MENU_MAIN; - wolfasm_menu_nb_buttons = NB_BUTTON_MAIN; - selected_button = 0; -} -static void wolfasm_multiplayer_buttons() { - render_button("Host", window_width / 2, window_height / 2, window_width / 16, - selected_button == BUTTON_MP_HOST); - render_button("Connect", window_width / 2, - window_height / 2 + window_height / 8, window_width / 8, - selected_button == BUTTON_MP_CONNECT); - render_button("Back", window_width / 2, - window_height / 2 + 2 * (window_height / 8), window_width / 16, - selected_button == BUTTON_MP_BACK); -} - // // Multiplayer Connect // static void wolfasm_multiplayer_connect_connect() { - uint16_t port = strtol(wolfasm_port, NULL, 10); - printf("Going to connect to %s:%d\n", wolfasm_connect, port); + SDL_StopTextInput(); + Mix_HaltMusic(); + wolfasm_join_game(wolfasm_connect, strtol(wolfasm_port, NULL, 10)); + wolfasm_menu_play_music(); + SDL_StartTextInput(); } + static void wolfasm_multiplayer_connect_back() { menu = MENU_MULTIPLAYER; wolfasm_menu_nb_buttons = NB_BUTTON_MULTIPLAYER; selected_button = 0; - wolfasm_selected_text_field = 0; wolfasm_connect_len = 0; wolfasm_port_len = 0; selected_text_field_max_len = 0; @@ -184,6 +120,7 @@ static void wolfasm_multiplayer_connect_back() { memset(wolfasm_port, '\0', sizeof(wolfasm_port)); SDL_StopTextInput(); } + static void wolfasm_multiplayer_connect_buttons() { render_button("Host: ", window_width / 2, window_height / 2, window_width / 16, 0); @@ -200,59 +137,70 @@ static void wolfasm_multiplayer_connect_buttons() { } render_button("Connect", window_width / 2, window_height / 2 + 2 * (window_height / 8), window_width / 8, - selected_button == BUTTON_MP_CO_CONNECT); + selected_button == BUTTON_MP_HOST_MAP); render_button("Back", window_width / 2, window_height / 2 + 3 * (window_height / 8), window_width / 16, - selected_button == BUTTON_MP_CO_BACK); + selected_button == BUTTON_MP_HOST_BACK); } // // Multiplayer host // - -// -// Select Map Solo -// -static void wolfasm_sm_solo_map() { +static void wolfasm_multiplayer_host_map() { char filename[512]; strncpy(filename, "./resources/map/", sizeof(filename) - 1); strncat(filename, wolfasm_selected_map, sizeof(filename) - 1); Mix_HaltMusic(); - wolfasm(filename); + SDL_StopTextInput(); + wolfasm_host_game(filename, strtol(wolfasm_port, NULL, 10)); wolfasm_menu_play_music(); + SDL_StartTextInput(); } -static void wolfasm_sm_solo_back() { - menu = MENU_MAIN; - wolfasm_menu_nb_buttons = NB_BUTTON_MAIN; + +static void wolfasm_multiplayer_host_back() { + menu = MENU_MULTIPLAYER; + wolfasm_menu_nb_buttons = NB_BUTTON_MULTIPLAYER; selected_button = 0; + wolfasm_port_len = 0; + selected_text_field_max_len = 0; + selected_text_field_len = NULL; + selected_text_field = NULL; + memset(wolfasm_port, '\0', sizeof(wolfasm_port)); + SDL_StopTextInput(); } -static void wolfasm_sm_solo_buttons() { +static void wolfasm_multiplayer_host_buttons() { char buff[255 + 1 + 4]; snprintf(buff, sizeof(buff), "< %s >", wolfasm_selected_map); - render_button(buff, window_width / 2, window_height / 2, window_width / 8, - selected_button == BUTTON_SM_SOLO_MAP); + + render_button("Port: ", window_width / 2, window_height / 2, + window_width / 16, 0); + if (wolfasm_port[0]) { + render_button(wolfasm_port, window_width / 2 + window_width / 16, + window_height / 2, strlen(wolfasm_port) * 15, 0); + } + render_button(buff, window_width / 2, window_height / 2 + (window_height / 8), + window_width / 8, selected_button == BUTTON_MP_CO_CONNECT); render_button("Back", window_width / 2, - window_height / 2 + 1 * (window_height / 8), window_width / 8, - selected_button == BUTTON_SM_SOLO_BACK); + window_height / 2 + 2 * (window_height / 8), window_width / 16, + selected_button == BUTTON_MP_CO_BACK); } -static void (*callbacks_main_menu[])() = { - wolfasm_main_play, wolfasm_main_multiplayer, wolfasm_main_exit, - wolfasm_main_buttons}; -static void (*callbacks_multiplayer_menu[])() = { - wolfasm_multiplayer_host, wolfasm_multiplayer_connect, - wolfasm_multiplayer_back, wolfasm_multiplayer_buttons}; -static void (*callback_sm_solo[])() = { - wolfasm_sm_solo_map, wolfasm_sm_solo_back, wolfasm_sm_solo_buttons}; +extern void (*callbacks_main_menu[])() __asm__("callbacks_main_menu"); +extern void (*callbacks_multiplayer_menu[])() __asm__( + "callbacks_multiplayer_menu"); +extern void (*callback_sm_solo[])() __asm__("callback_sm_solo"); static void (*callback_mp_co[])() = {wolfasm_multiplayer_connect_connect, wolfasm_multiplayer_connect_back, wolfasm_multiplayer_connect_buttons}; +static void (*callback_mp_host[])() = {wolfasm_multiplayer_host_map, + wolfasm_multiplayer_host_back, + wolfasm_multiplayer_host_buttons}; static void (**callbacks[])() = {&callbacks_main_menu, &callbacks_multiplayer_menu, &callback_sm_solo, - &callback_mp_co}; + &callback_mp_co, &callback_mp_host}; int wolfasm_menu(void) { srand((unsigned int)time(NULL)); @@ -272,7 +220,7 @@ int wolfasm_menu(void) { // Menu controls case SDLK_LEFT: - if (menu == MENU_SELECT_MAP_SOLO) { + if (menu == MENU_SELECT_MAP_SOLO || menu == MENU_MULTIPLAYER_HOST) { --wolfasm_current_map; if (wolfasm_current_map < 0) { assert(wolfasm_nb_maps != 0); @@ -282,7 +230,7 @@ int wolfasm_menu(void) { } break; case SDLK_RIGHT: - if (menu == MENU_SELECT_MAP_SOLO) { + if (menu == MENU_SELECT_MAP_SOLO || menu == MENU_MULTIPLAYER_HOST) { ++wolfasm_current_map; if (wolfasm_current_map == wolfasm_nb_maps) { wolfasm_current_map = 0; @@ -307,7 +255,8 @@ int wolfasm_menu(void) { (callbacks[menu][selected_button])(); break; case SDLK_BACKSPACE: - if (menu == MENU_MULTIPLAYER_CONNECT) { + if (menu == MENU_MULTIPLAYER_CONNECT || + menu == MENU_MULTIPLAYER_HOST) { assert(selected_text_field_len); if (*selected_text_field_len > 0) { selected_text_field[*selected_text_field_len - 1] = '\0'; @@ -341,7 +290,8 @@ int wolfasm_menu(void) { case SDL_TEXTINPUT: assert(selected_text_field_len); assert(selected_text_field); - assert(menu == MENU_MULTIPLAYER_CONNECT); // TODO: Update for Host menu + assert(menu == MENU_MULTIPLAYER_CONNECT || + menu == MENU_MULTIPLAYER_HOST); { size_t const cur_len = strlen(event.text.text); size_t real_len = cur_len; diff --git a/src/test.c b/src/test.c index 3cf561d..3c145d2 100644 --- a/src/test.c +++ b/src/test.c @@ -291,3 +291,14 @@ void wolfasm_regulate_framerate(uint32_t fps) { } old_ticks = ticks; } + +// Network +void wolfasm_host_game(char const *map, uint16_t const port); +void wolfasm_host_game(char const *map, uint16_t const port) { + printf("Hosting %s on port %d\n", map, port); +} + +void wolfasm_join_game(char const *addr, uint16_t const port); +void wolfasm_join_game(char const *addr, uint16_t const port) { + printf("Joining game on %s:%d\n", addr, port); +}