From 34359ec7bb0feff4e0e19d3c20a23af191eae268 Mon Sep 17 00:00:00 2001 From: "simon.kagstrom" Date: Sun, 1 Mar 2009 11:04:47 +0000 Subject: [PATCH] Implement the user interface for the network support. You can now connect from the menu as well and also abort connections. --- Src/C64_SDL.h | 36 +++++++++++++++++++----------------- Src/Network.cpp | 23 ++++++++++++++++++++++- 2 files changed, 41 insertions(+), 18 deletions(-) diff --git a/Src/C64_SDL.h b/Src/C64_SDL.h index a1fffec..4a68d4f 100644 --- a/Src/C64_SDL.h +++ b/Src/C64_SDL.h @@ -80,15 +80,10 @@ void C64::c64_ctor1(void) if (fixme_tmp_network_server) { int i; - this->peer = new Network("localhost", this->server_port, true); + this->peer = new Network(this->server_hostname, this->server_port, true); this->network_connection_type = MASTER; - for (i = 0; i < 20; i++) - { - printf("Waiting for connection, try %d of 20\n", i+1); - if (this->peer->Connect() == true) - break; - } - if (i == 20) + printf("Waiting for connection\n"); + if (this->peer->Connect() == false) { printf("No client connected. Bye\n"); delete this->peer; @@ -100,7 +95,12 @@ void C64::c64_ctor1(void) strcpy(this->server_hostname, fixme_tmp_network_client); this->peer = new Network(this->server_hostname, this->server_port, false); this->network_connection_type = CLIENT; - this->peer->Connect(); + if (this->peer->Connect() == false) + { + printf("Could not connect to server. Bye\n"); + delete this->peer; + this->peer = NULL; + } } } @@ -345,15 +345,17 @@ void C64::networking_menu(Prefs *np) this->server_port = atoi(m); } } - else if (opt == 0) { + else if (opt == 3 || opt == 4) { + bool master = (opt == 3); + this->peer = new Network(this->server_hostname, - this->server_port, true); - this->network_connection_type = MASTER; - } - else if (opt == 3) { - this->peer = new Network(this->server_hostname, - this->server_port, false); - this->network_connection_type = CLIENT; + this->server_port, master); + this->network_connection_type = master ? MASTER : CLIENT; + if (this->peer->Connect() == false) + { + delete this->peer; + this->peer = NULL; + } } } while (opt == 1 || opt == 2); diff --git a/Src/Network.cpp b/Src/Network.cpp index 05221df..1097ea2 100644 --- a/Src/Network.cpp +++ b/Src/Network.cpp @@ -970,8 +970,29 @@ bool Network::ConnectFSM() bool Network::Connect() { - for (int i = 0; i < this->is_master ? 120 : 10; i++ ) + while (1) { + SDL_FillRect(real_screen, 0, SDL_MapRGB(real_screen->format, + 0x00, 0x80, 0x80)); + menu_print_font(real_screen, 255,255,0, 20, 20, + "Connecting... Hold Esc or 1 to abort"); + SDL_Flip(real_screen); +#if defined(GEKKO) + WPADData *wpad, *wpad_other; + + WPAD_ScanPads(); + + wpad = WPAD_Data(WPAD_CHAN_0); + wpad_other = WPAD_Data(WPAD_CHAN_1); + remote_keys = wpad->btns_d | wpad_other->btns_d; + + if (remote_keys & WPAD_BUTTON_1) + return false; +#endif + SDL_PumpEvents(); + if (SDL_GetKeyState(NULL)[SDLK_ESCAPE]) + return false; + if (this->network_connection_state == CONN_CONNECTED) return true; /* Run the state machine */