X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Fnetwork.c;h=b7c753b45f9e429b56b07116e1b5323d9cfaa011;hb=1a07df371a8d0c7defad55b7c11f868b1bcbca56;hp=e21de8c5859c47b1f5e1dcae2cda6678f8704715;hpb=41165ff0a84cf7c0391f6b56520a1f7f97ccf496;p=rocksndiamonds.git diff --git a/src/network.c b/src/network.c index e21de8c5..b7c753b4 100644 --- a/src/network.c +++ b/src/network.c @@ -52,24 +52,45 @@ static boolean stop_network_game = FALSE; static void DrawNetworkTextExt(char *message, int font_nr, boolean initialize) { static int xpos = 0, ypos = 0; + static int max_line_width = 0; int font_width = getFontWidth(font_nr); int font_height = getFontHeight(font_nr); + int ypos_1 = 120; + int ypos_2 = 150; if (initialize) { - xpos = (WIN_XSIZE - getTextWidth(message, font_nr)) / 2; - ypos = 120; + if (game_status == GAME_MODE_LOADING) + { + max_line_width = WIN_XSIZE; + + xpos = (max_line_width - getTextWidth(message, font_nr)) / 2; + ypos = ypos_1; + + DrawText(xpos, ypos, message, font_nr); + + xpos = 0; + ypos = ypos_2; + } + else + { + max_line_width = SXSIZE; - DrawText(xpos, ypos, message, font_nr); + DrawTextSCentered(ypos_1, font_nr, message); - xpos = 0; - ypos = 150; + /* calculate offset to x position caused by rounding */ + int max_chars_per_line = max_line_width / font_width; + int xoffset = (max_line_width - max_chars_per_line * font_width) / 2; + + xpos = SX + xoffset; + ypos = SY + ypos_2; + } Error(ERR_DEBUG, "========== %s ==========", message); } else { - int max_chars_per_line = WIN_XSIZE / font_width; + int max_chars_per_line = max_line_width / font_width; int max_lines_per_text = 10; int num_lines_spacing = (font_nr == FC_YELLOW ? 1 : 3); int num_lines_printed = DrawTextBuffer(xpos, ypos, message, font_nr, @@ -219,25 +240,34 @@ boolean ConnectToServer(char *hostname, int port) DrawNetworkText("Looking for local network server ..."); - if (SDLNet_CheckSockets(udp_socket_set, 1000) == 1) + /* wait for any local network server to answer UDP broadcast */ + for (i = 0; i < 5; i++) { - int num_packets = SDLNet_UDP_Recv(udp, &packet); - - if (num_packets == 1) + if (SDLNet_CheckSockets(udp_socket_set, 0) == 1) { - DrawNetworkText_Success("Network server found!"); + int num_packets = SDLNet_UDP_Recv(udp, &packet); - server_host = SDLNet_Read32(&packet.address.host); + if (num_packets == 1) + { + DrawNetworkText_Success("Network server found!"); + + server_host = SDLNet_Read32(&packet.address.host); + } + else + { + DrawNetworkText_Failed("No answer from network server!"); + } + + break; } else { - DrawNetworkText_Failed("No answer from network server!"); + Delay_WithScreenUpdates(100); } } - else - { + + if (server_host == 0) DrawNetworkText_Failed("No network server found!"); - } } rfds = SDLNet_AllocSocketSet(1); @@ -297,10 +327,8 @@ boolean ConnectToServer(char *hostname, int port) StartNetworkServer(port); /* wait for server to start up and try connecting several times */ - for (i = 0; i < 6; i++) + for (i = 0; i < 30; i++) { - Delay(500); /* wait 500 ms == 0.5 seconds */ - if ((sfd = SDLNet_TCP_Open(&ip))) /* connected */ { DrawNetworkText_Success("Successfully connected!"); @@ -308,6 +336,8 @@ boolean ConnectToServer(char *hostname, int port) SDLNet_TCP_AddSocket(rfds, sfd); return TRUE; } + + Delay_WithScreenUpdates(100); } DrawNetworkText_Failed("Failed to connect to network server!"); @@ -820,5 +850,5 @@ void DisconnectFromNetworkServer() DrawNetworkText_Success("Successfully disconnected!"); /* short time to recognize result of network initialization */ - Delay(1000); + Delay_WithScreenUpdates(1000); }