From: Holger Schemel Date: Wed, 29 Mar 2006 17:43:08 +0000 (+0200) Subject: rnd-20060329-1-src X-Git-Tag: 3.2.0^2~43 X-Git-Url: https://git.artsoft.org/?p=rocksndiamonds.git;a=commitdiff_plain;h=113df1c4ad60b24a31ec6498f8cd3b2d4cd9dbfd rnd-20060329-1-src * changed behaviour of network games with internal errors (because of different client frame counters) from immediately terminating R'n'D to displaying an error message requester and stopping only the game (also to prevent impression of crashes under non command-line runs) * fixed playing network games with the EMC engine (did not work before) * fixed bug with not scrolling the screen in multi-player mode with the focus on player 1 when all players are moving in different directions * fixed bug with keeping pointer to gadget even after its deallocation * uploaded pre-release (test) version 3.2.0-7 binary and source code --- diff --git a/ChangeLog b/ChangeLog index 5361acef..b04a6233 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2006-03-29 + * changed behaviour of network games with internal errors (because of + different client frame counters) from immediately terminating R'n'D + to displaying an error message requester and stopping only the game + (also to prevent impression of crashes under non command-line runs) + * fixed playing network games with the EMC engine (did not work before) + * fixed bug with not scrolling the screen in multi-player mode with the + focus on player 1 when all players are moving in different directions + * fixed bug with keeping pointer to gadget even after its deallocation + +2006-03-22 + * uploaded pre-release (test) version 3.2.0-7 binary and source code + 2006-03-19 * code cleanup for game action control for R'n'D and EMC game engine diff --git a/src/conftime.h b/src/conftime.h index 2414d915..05075139 100644 --- a/src/conftime.h +++ b/src/conftime.h @@ -1 +1 @@ -#define COMPILE_DATE_STRING "[2006-03-23 10:55]" +#define COMPILE_DATE_STRING "[2006-03-29 19:24]" diff --git a/src/game.c b/src/game.c index 8f5a51fe..bbcb6604 100644 --- a/src/game.c +++ b/src/game.c @@ -9168,6 +9168,11 @@ void AdvanceFrameAndPlayerCounters(int player_nr) { int i; +#if 0 + Error(ERR_NETWORK_CLIENT, "advancing frame counter from %d to %d", + FrameCounter, FrameCounter + 1); +#endif + /* advance frame counters (global frame counter and time frame counter) */ FrameCounter++; TimeFrames++; @@ -9218,15 +9223,10 @@ void AdvanceFrameAndPlayerCounters(int player_nr) void StartGameActions(boolean init_network_game, boolean record_tape, long random_seed) { -#if 1 unsigned long new_random_seed = InitRND(random_seed); if (record_tape) TapeStartRecording(new_random_seed); -#else - if (record_tape) - TapeStartRecording(random_seed); -#endif #if defined(NETWORK_AVALIABLE) if (init_network_game) @@ -9241,10 +9241,6 @@ void StartGameActions(boolean init_network_game, boolean record_tape, game_status = GAME_MODE_PLAYING; -#if 0 - InitRND(random_seed); -#endif - InitGame(); } @@ -9311,11 +9307,19 @@ void GameActions() if (!network_player_action_received) return; /* failed to get network player actions in time */ + + /* do not yet reset "network_player_action_received" (for tape.pausing) */ } if (tape.pausing) return; + /* at this point we know that we really continue executing the game */ + +#if 1 + network_player_action_received = FALSE; +#endif + recorded_player_action = (tape.playing ? TapePlayAction() : NULL); if (tape.set_centered_player) @@ -9483,7 +9487,9 @@ void GameActions_RND() ScrollPlayer(&stored_player[i], SCROLL_GO_ON); } +#if 0 network_player_action_received = FALSE; +#endif ScrollScreen(NULL, SCROLL_GO_ON); @@ -12673,7 +12679,7 @@ void RequestQuitGame(boolean ask_if_really_quit) { #if defined(NETWORK_AVALIABLE) if (options.network) - SendToServer_StopPlaying(); + SendToServer_StopPlaying(NETWORK_STOP_BY_PLAYER); else #endif { diff --git a/src/game_em/graphics.c b/src/game_em/graphics.c index 64b7129a..deee45a3 100644 --- a/src/game_em/graphics.c +++ b/src/game_em/graphics.c @@ -690,7 +690,8 @@ void RedrawPlayfield_EM(boolean force_redraw) int game.centered_player_nr_next = getCenteredPlayerNr_EM(); #endif #if 1 - int player_nr = getMaxCenterDistancePlayerNr(screen_x, screen_y); + int max_center_distance_player_nr = + getMaxCenterDistancePlayerNr(screen_x, screen_y); #else int player_nr = game_em.last_moving_player; #endif @@ -757,8 +758,8 @@ void RedrawPlayfield_EM(boolean force_redraw) else { #if 1 - sx = PLAYER_SCREEN_X(player_nr); - sy = PLAYER_SCREEN_Y(player_nr); + sx = PLAYER_SCREEN_X(max_center_distance_player_nr); + sy = PLAYER_SCREEN_Y(max_center_distance_player_nr); #else sx = PLAYER_SCREEN_X(game_em.last_moving_player); sy = PLAYER_SCREEN_Y(game_em.last_moving_player); @@ -976,6 +977,8 @@ void RedrawPlayfield_EM(boolean force_redraw) #if 0 int player_nr = game_em.last_moving_player; #endif + int player_nr = (game.centered_player_nr == -1 ? + max_center_distance_player_nr : game.centered_player_nr); int player_move_dir = game_em.last_player_direction[player_nr]; int dx = SIGN(screen_x - screen_x_old); int dy = SIGN(screen_y - screen_y_old); diff --git a/src/libgame/gadgets.c b/src/libgame/gadgets.c index 1b368c56..9322fd84 100644 --- a/src/libgame/gadgets.c +++ b/src/libgame/gadgets.c @@ -28,6 +28,7 @@ static struct GadgetInfo *gadget_list_first_entry = NULL; static struct GadgetInfo *gadget_list_last_entry = NULL; +static struct GadgetInfo *last_info_gi = NULL; static int next_free_gadget_id = 1; static boolean gadget_id_wrapped = FALSE; @@ -1197,6 +1198,10 @@ void FreeGadget(struct GadgetInfo *gi) { struct GadgetInfo *gi_previous = gadget_list_first_entry; + /* prevent "last_info_gi" from pointing to memory that will be freed */ + if (last_info_gi == gi) + last_info_gi = NULL; + while (gi_previous != NULL && gi_previous->next != gi) gi_previous = gi_previous->next; @@ -1376,7 +1381,6 @@ void ClickOnGadget(struct GadgetInfo *gi, int button) boolean HandleGadgets(int mx, int my, int button) { - static struct GadgetInfo *last_info_gi = NULL; static unsigned long pressed_delay = 0; static int last_button = 0; static int last_mx = 0, last_my = 0; diff --git a/src/main.h b/src/main.h index b2a69ad3..5e22d27a 100644 --- a/src/main.h +++ b/src/main.h @@ -1674,7 +1674,7 @@ #define PROGRAM_VERSION_MAJOR 3 #define PROGRAM_VERSION_MINOR 2 #define PROGRAM_VERSION_PATCH 0 -#define PROGRAM_VERSION_BUILD 7 +#define PROGRAM_VERSION_BUILD 8 #define PROGRAM_TITLE_STRING "Rocks'n'Diamonds" #define PROGRAM_AUTHOR_STRING "Holger Schemel" diff --git a/src/netserv.c b/src/netserv.c index 991fbba6..f1f9a1a9 100644 --- a/src/netserv.c +++ b/src/netserv.c @@ -375,11 +375,11 @@ static void Handle_OP_START_PLAYING(struct NetworkServerPlayerInfo *player) if (options.verbose) Error(ERR_NETWORK_SERVER, - "client %d (%s) starts game [level %d from levedir %d (%s)]", + "client %d (%s) starts game [level %d from leveldir %d (%s)]", player->number, player->player_name, (buffer[2] << 8) + buffer[3], (buffer[4] << 8) + buffer[5], - &buffer[6]); + &buffer[10]); for (w = first_player; w; w = w->next) if (w->introduced) @@ -388,6 +388,8 @@ static void Handle_OP_START_PLAYING(struct NetworkServerPlayerInfo *player) /* reset frame counter */ ServerFrameCounter = 0; + Error(ERR_NETWORK_SERVER, "resetting ServerFrameCounter to 0"); + /* reset player actions */ for (v = first_player; v; v = v->next) { @@ -416,10 +418,12 @@ static void Handle_OP_CONTINUE_PLAYING(struct NetworkServerPlayerInfo *player) static void Handle_OP_STOP_PLAYING(struct NetworkServerPlayerInfo *player) { + int cause_for_stopping = buffer[2]; + if (options.verbose) - Error(ERR_NETWORK_SERVER, "client %d (%s) stops game", - player->number, player->player_name); - broadcast(NULL, 2, 0); + Error(ERR_NETWORK_SERVER, "client %d (%s) stops game [%d]", + player->number, player->player_name, cause_for_stopping); + broadcast(NULL, 3, 0); } static void Handle_OP_MOVE_PLAYER(struct NetworkServerPlayerInfo *player) @@ -467,6 +471,11 @@ static void Handle_OP_MOVE_PLAYER(struct NetworkServerPlayerInfo *player) broadcast(NULL, 6 + last_client_nr, 0); +#if 0 + Error(ERR_NETWORK_SERVER, "sending ServerFrameCounter value %d", + ServerFrameCounter); +#endif + ServerFrameCounter++; } diff --git a/src/network.c b/src/network.c index 104b83f9..2f990f7f 100644 --- a/src/network.c +++ b/src/network.c @@ -66,6 +66,7 @@ static byte realbuffer[512]; static byte readbuffer[MAX_BUFFER_SIZE], writbuffer[MAX_BUFFER_SIZE]; static byte *buffer = realbuffer + 4; static int nread = 0, nwrite = 0; +static boolean stop_network_game = FALSE; static void SendBufferToServer(int size) { @@ -342,11 +343,12 @@ void SendToServer_ContinuePlaying() SendBufferToServer(2); } -void SendToServer_StopPlaying() +void SendToServer_StopPlaying(int cause_for_stopping) { buffer[1] = OP_STOP_PLAYING; + buffer[2] = cause_for_stopping; - SendBufferToServer(2); + SendBufferToServer(3); } void SendToServer_MovePlayer(byte player_action) @@ -568,8 +570,18 @@ static void Handle_OP_CONTINUE_PLAYING() static void Handle_OP_STOP_PLAYING() { - printf("OP_STOP_PLAYING: %d\n", buffer[0]); - Error(ERR_NETWORK_CLIENT, "client %d stops game", buffer[0]); + printf("OP_STOP_PLAYING: %d [%d]\n", buffer[0], buffer[2]); + Error(ERR_NETWORK_CLIENT, "client %d stops game [%d]", buffer[0], buffer[2]); + + if (game_status == GAME_MODE_PLAYING) + { + if (buffer[2] == NETWORK_STOP_BY_PLAYER) + Request("Network game stopped by player!", REQ_CONFIRM); + else if (buffer[2] == NETWORK_STOP_BY_ERROR) + Request("Network game stopped due to internal error!", REQ_CONFIRM); + else + Request("Network game stopped !", REQ_CONFIRM); + } game_status = GAME_MODE_MAIN; DrawMainMenu(); @@ -586,12 +598,26 @@ static void Handle_OP_MOVE_PLAYER(unsigned int len) server_frame_counter = (buffer[2] << 24) | (buffer[3] << 16) | (buffer[4] << 8) | (buffer[5]); +#if 0 + Error(ERR_NETWORK_CLIENT, "receiving server frame counter value %d [%d]", + server_frame_counter, FrameCounter); +#endif + if (server_frame_counter != FrameCounter) { Error(ERR_RETURN, "client and servers frame counters out of sync"); Error(ERR_RETURN, "frame counter of client is %d", FrameCounter); Error(ERR_RETURN, "frame counter of server is %d", server_frame_counter); + +#if 1 + Error(ERR_RETURN, "this should not happen -- please debug"); + + stop_network_game = TRUE; + + return; +#else Error(ERR_EXIT, "this should not happen -- please debug"); +#endif } /* copy valid player actions */ @@ -606,6 +632,8 @@ static void HandleNetworkingMessages() { unsigned int message_length; + stop_network_game = FALSE; + while (nread >= 4 && nread >= 4 + readbuffer[3]) { message_length = readbuffer[3]; @@ -670,6 +698,10 @@ static void HandleNetworkingMessages() } fflush(stdout); + + /* in case of internal error, stop network game */ + if (stop_network_game) + SendToServer_StopPlaying(NETWORK_STOP_BY_ERROR); } /* TODO */ diff --git a/src/network.h b/src/network.h index 6819bf27..72c58445 100644 --- a/src/network.h +++ b/src/network.h @@ -16,6 +16,9 @@ #include "main.h" +#define NETWORK_STOP_BY_PLAYER 0 +#define NETWORK_STOP_BY_ERROR 1 + boolean ConnectToServer(char *, int); void SendToServer_PlayerName(char *); void SendToServer_ProtocolVersion(void); @@ -23,7 +26,7 @@ void SendToServer_NrWanted(int); void SendToServer_StartPlaying(void); void SendToServer_PausePlaying(void); void SendToServer_ContinuePlaying(void); -void SendToServer_StopPlaying(void); +void SendToServer_StopPlaying(int); void SendToServer_MovePlayer(byte); void HandleNetworking(void); diff --git a/src/tools.c b/src/tools.c index 3bdf371f..130111dc 100644 --- a/src/tools.c +++ b/src/tools.c @@ -133,11 +133,9 @@ void RedrawPlayfield(boolean force_redraw, int x, int y, int width, int height) if (game_status == GAME_MODE_PLAYING && level.game_engine_type == GAME_ENGINE_TYPE_EM) { -#if 1 - RedrawPlayfield_EM(force_redraw); -#else - BlitScreenToBitmap_EM(backbuffer); -#endif + /* currently there is no partial redraw -- always redraw whole playfield */ + + RedrawPlayfield_EM(TRUE); } else if (game_status == GAME_MODE_PLAYING && !game.envelope_active) {