rnd-20060329-1-src
authorHolger Schemel <info@artsoft.org>
Wed, 29 Mar 2006 17:43:08 +0000 (19:43 +0200)
committerHolger Schemel <info@artsoft.org>
Sat, 30 Aug 2014 08:51:17 +0000 (10:51 +0200)
* 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

ChangeLog
src/conftime.h
src/game.c
src/game_em/graphics.c
src/libgame/gadgets.c
src/main.h
src/netserv.c
src/network.c
src/network.h
src/tools.c

index 5361acefd49d258232c1d0c02654876814c7b50d..b04a62339bcb55076d342f7aab62341e3918b643 100644 (file)
--- 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
 
index 2414d9152f8da6bcc84dfced7a59cddba84c78ab..050751399b400cd81a4edc8470400850af16c06c 100644 (file)
@@ -1 +1 @@
-#define COMPILE_DATE_STRING "[2006-03-23 10:55]"
+#define COMPILE_DATE_STRING "[2006-03-29 19:24]"
index 8f5a51fe4fb9d77af9a4ec40888aba90f454fed9..bbcb6604b16bdccee0f34e8393092cd1bca4a158 100644 (file)
@@ -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
     {
index 64b7129a81739d9984ecf232a4f3fca8ff9081ac..deee45a380a905e09b93cb2f02609659b33edfa2 100644 (file)
@@ -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);
index 1b368c569f703cb37f0245f1e09cf6d72b53bd12..9322fd84a84dd6e05ea92ae41be19f7aeef930e5 100644 (file)
@@ -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;
index b2a69ad38a745709d4696a1b926322075a625e1a..5e22d27a0d8ec82f62c73bd52335a436293d46fc 100644 (file)
 #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"
index 991fbba61ae2b94e999f4926c69958eeefc56342..f1f9a1a96528bb36198982d200f2f70474c3f7e7 100644 (file)
@@ -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++;
 }
 
index 104b83f9bb2df69b3e36c2f83107fe37d0bd6772..2f990f7f9911dad78be872df5e8c7cf67b920239 100644 (file)
@@ -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 */
index 6819bf27279a6dd823a15d65bea124b9005c0d58..72c58445d24e0509727e1e043e32f292dcbb6f9a 100644 (file)
@@ -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);
 
index 3bdf371f09e197e831f5e95ad620ddb7c7f3e937..130111dc2c8bd10c45826580cf84af5be549c7ed 100644 (file)
@@ -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)
   {