added loading/saving mouse actions from/to tape (for MM engine)
authorHolger Schemel <info@artsoft.org>
Tue, 28 Mar 2017 22:39:22 +0000 (00:39 +0200)
committerHolger Schemel <info@artsoft.org>
Fri, 23 Mar 2018 22:21:11 +0000 (23:21 +0100)
src/files.c
src/game.c
src/tape.c
src/tape.h

index 30e10f5a5f60c7e50acd1af37109a68d62d12808..d18122f270c1d03efadea0dd71fd0a6603ce2159 100644 (file)
@@ -57,7 +57,7 @@
 
 #define TAPE_CHUNK_VERS_SIZE   8       /* size of file version chunk */
 #define TAPE_CHUNK_HEAD_SIZE   20      /* size of tape file header   */
-#define TAPE_CHUNK_HEAD_UNUSED 3       /* unused tape header bytes   */
+#define TAPE_CHUNK_HEAD_UNUSED 2       /* unused tape header bytes   */
 
 #define LEVEL_CHUNK_CNT3_SIZE(x)        (LEVEL_CHUNK_CNT3_HEADER + (x))
 #define LEVEL_CHUNK_CUS3_SIZE(x)        (2 + (x) * LEVEL_CPART_CUS3_SIZE)
@@ -7564,6 +7564,8 @@ static int LoadTape_HEAD(File *file, int chunk_size, struct TapeInfo *tape)
       }
     }
 
+    tape->use_mouse = (getFile8Bit(file) == 1 ? TRUE : FALSE);
+
     ReadUnusedBytesFromFile(file, TAPE_CHUNK_HEAD_UNUSED);
 
     engine_version = getFileVersion(file);
@@ -7599,8 +7601,9 @@ static int LoadTape_INFO(File *file, int chunk_size, struct TapeInfo *tape)
 static int LoadTape_BODY(File *file, int chunk_size, struct TapeInfo *tape)
 {
   int i, j;
-  int chunk_size_expected =
-    (tape->num_participating_players + 1) * tape->length;
+  int tape_pos_size =
+    (tape->use_mouse ? 3 : tape->num_participating_players) + 1;
+  int chunk_size_expected = tape_pos_size * tape->length;
 
   if (chunk_size_expected != chunk_size)
   {
@@ -7622,12 +7625,23 @@ static int LoadTape_BODY(File *file, int chunk_size, struct TapeInfo *tape)
       break;
     }
 
-    for (j = 0; j < MAX_PLAYERS; j++)
+    if (tape->use_mouse)
     {
-      tape->pos[i].action[j] = MV_NONE;
+      tape->pos[i].action[TAPE_ACTION_LX]     = getFile8Bit(file);
+      tape->pos[i].action[TAPE_ACTION_LY]     = getFile8Bit(file);
+      tape->pos[i].action[TAPE_ACTION_BUTTON] = getFile8Bit(file);
 
-      if (tape->player_participates[j])
-       tape->pos[i].action[j] = getFile8Bit(file);
+      tape->pos[i].action[TAPE_ACTION_UNUSED] = 0;
+    }
+    else
+    {
+      for (j = 0; j < MAX_PLAYERS; j++)
+      {
+       tape->pos[i].action[j] = MV_NONE;
+
+       if (tape->player_participates[j])
+         tape->pos[i].action[j] = getFile8Bit(file);
+      }
     }
 
     tape->pos[i].delay = getFile8Bit(file);
@@ -7684,7 +7698,7 @@ static int LoadTape_BODY(File *file, int chunk_size, struct TapeInfo *tape)
   }
 
   if (i != tape->length)
-    chunk_size = (tape->num_participating_players + 1) * i;
+    chunk_size = tape_pos_size * i;
 
   return chunk_size;
 }
@@ -7953,6 +7967,8 @@ static void SaveTape_HEAD(FILE *file, struct TapeInfo *tape)
 
   putFile8Bit(file, store_participating_players);
 
+  putFile8Bit(file, (tape->use_mouse ? 1 : 0));
+
   /* unused bytes not at the end here for 4-byte alignment of engine_version */
   WriteUnusedBytesToFile(file, TAPE_CHUNK_HEAD_UNUSED);
 
@@ -7978,9 +7994,18 @@ static void SaveTape_BODY(FILE *file, struct TapeInfo *tape)
 
   for (i = 0; i < tape->length; i++)
   {
-    for (j = 0; j < MAX_PLAYERS; j++)
-      if (tape->player_participates[j])
-       putFile8Bit(file, tape->pos[i].action[j]);
+    if (tape->use_mouse)
+    {
+      putFile8Bit(file, tape->pos[i].action[TAPE_ACTION_LX]);
+      putFile8Bit(file, tape->pos[i].action[TAPE_ACTION_LY]);
+      putFile8Bit(file, tape->pos[i].action[TAPE_ACTION_BUTTON]);
+    }
+    else
+    {
+      for (j = 0; j < MAX_PLAYERS; j++)
+       if (tape->player_participates[j])
+         putFile8Bit(file, tape->pos[i].action[j]);
+    }
 
     putFile8Bit(file, tape->pos[i].delay);
   }
@@ -7991,6 +8016,7 @@ void SaveTape(int nr)
   char *filename = getTapeFilename(nr);
   FILE *file;
   int num_participating_players = 0;
+  int tape_pos_size;
   int info_chunk_size;
   int body_chunk_size;
   int i;
@@ -8011,8 +8037,10 @@ void SaveTape(int nr)
     if (tape.player_participates[i])
       num_participating_players++;
 
+  tape_pos_size = (tape.use_mouse ? 3 : num_participating_players) + 1;
+
   info_chunk_size = 2 + (strlen(tape.level_identifier) + 1) + 2;
-  body_chunk_size = (num_participating_players + 1) * tape.length;
+  body_chunk_size = tape_pos_size * tape.length;
 
   putFileChunkBE(file, "RND1", CHUNK_SIZE_UNDEFINED);
   putFileChunkBE(file, "TAPE", CHUNK_SIZE_NONE);
index 1bfe0100d1084c4214ad9cbaff4026f1456bf450..cc6f27d69459e037abb378f3082755cd6564607e 100644 (file)
@@ -10974,6 +10974,22 @@ static byte PlayerActions(struct PlayerInfo *player, byte player_action)
   }
 }
 
+static void SetMouseActionFromTapeAction(struct MouseActionInfo *mouse_action,
+                                        byte *tape_action)
+{
+  mouse_action->lx     = tape_action[TAPE_ACTION_LX];
+  mouse_action->ly     = tape_action[TAPE_ACTION_LY];
+  mouse_action->button = tape_action[TAPE_ACTION_BUTTON];
+}
+
+static void SetTapeActionFromMouseAction(byte *tape_action,
+                                        struct MouseActionInfo *mouse_action)
+{
+  tape_action[TAPE_ACTION_LX]     = mouse_action->lx;
+  tape_action[TAPE_ACTION_LY]     = mouse_action->ly;
+  tape_action[TAPE_ACTION_BUTTON] = mouse_action->button;
+}
+
 static void CheckLevelTime()
 {
   int i;
@@ -11301,6 +11317,10 @@ void GameActionsExt()
   /* when playing tape, read previously recorded player input from tape data */
   recorded_player_action = (tape.playing ? TapePlayAction() : NULL);
 
+  if (recorded_player_action != NULL)
+    SetMouseActionFromTapeAction(&local_player->mouse_action,
+                                recorded_player_action);
+
   /* TapePlayAction() may return NULL when toggling to "pause before death" */
   if (tape.pausing)
     return;
@@ -11357,6 +11377,8 @@ void GameActionsExt()
       tape.player_participates[i] = TRUE;
   }
 
+  SetTapeActionFromMouseAction(tape_action, &local_player->mouse_action);
+
   /* only record actions from input devices, but not programmed actions */
   if (tape.recording)
     TapeRecordAction(tape_action);
index abec7013f7b809c05a1eb6d29798b02a999e1c74..55c414fd1b0233982caae45c2600d0489208762b 100644 (file)
@@ -544,6 +544,8 @@ void TapeErase()
 
   tape.centered_player_nr_next = -1;
   tape.set_centered_player = FALSE;
+
+  tape.use_mouse = (level.game_engine_type == GAME_ENGINE_TYPE_MM);
 }
 
 static void TapeRewind()
@@ -709,7 +711,7 @@ void TapeRecordAction(byte action_raw[MAX_PLAYERS])
   for (i = 0; i < MAX_PLAYERS; i++)
     action[i] = action_raw[i];
 
-  if (tape.set_centered_player)
+  if (!tape.use_mouse && tape.set_centered_player)
   {
     for (i = 0; i < MAX_PLAYERS; i++)
       if (tape.centered_player_nr_next == i ||
@@ -887,16 +889,19 @@ byte *TapePlayAction()
   tape.set_centered_player = FALSE;
   tape.centered_player_nr_next = -999;
 
-  for (i = 0; i < MAX_PLAYERS; i++)
+  if (!tape.use_mouse)
   {
-    if (action[i] & KEY_SET_FOCUS)
+    for (i = 0; i < MAX_PLAYERS; i++)
     {
-      tape.set_centered_player = TRUE;
-      tape.centered_player_nr_next =
-       (tape.centered_player_nr_next == -999 ? i : -1);
-    }
+      if (action[i] & KEY_SET_FOCUS)
+      {
+       tape.set_centered_player = TRUE;
+       tape.centered_player_nr_next =
+         (tape.centered_player_nr_next == -999 ? i : -1);
+      }
 
-    action[i] &= ~KEY_SET_FOCUS;
+      action[i] &= ~KEY_SET_FOCUS;
+    }
   }
 
   tape.delay_played++;
index f4d19043409cf0c85c518be6e47f7488b8581411..ab3fd55cea32dc09e1f781f212e84b6080e53280 100644 (file)
 /* values for tape properties */
 #define MAX_TAPE_LEN           (1000 * FRAMES_PER_SECOND) /* max.time x fps */
 
+/* values for tape mouse actions */
+#define TAPE_ACTION_LX         0
+#define TAPE_ACTION_LY         1
+#define TAPE_ACTION_BUTTON     2
+#define TAPE_ACTION_UNUSED     3
+
 /* some positions in the video tape control window */
 #define VIDEO_DISPLAY1_XPOS    5
 #define VIDEO_DISPLAY1_YPOS    5
@@ -182,6 +188,8 @@ struct TapeInfo
   int centered_player_nr_next;
   boolean set_centered_player;
 
+  boolean use_mouse;
+
   struct
   {
     byte action[MAX_PLAYERS];