added support for tapes with both keyboard/joystick and mouse actions
authorHolger Schemel <info@artsoft.org>
Tue, 21 Apr 2020 20:13:13 +0000 (22:13 +0200)
committerHolger Schemel <info@artsoft.org>
Tue, 19 May 2020 16:21:19 +0000 (18:21 +0200)
src/events.c
src/files.c
src/game.c
src/tape.c
src/tape.h

index d48cf4801b239fb2a9dee795f67708c77487f089..45da8607964b7be19a441b0b194fb8b71ffe1352 100644 (file)
@@ -464,7 +464,7 @@ static void SetPlayerMouseAction(int mx, int my, int button)
   local_player->mouse_action.ly = ly;
   local_player->mouse_action.button = button;
 
-  if (tape.recording && tape.pausing && tape.event_mask == GAME_EVENTS_MOUSE)
+  if (tape.recording && tape.pausing && (tape.event_mask & GAME_EVENTS_MOUSE))
   {
     // un-pause a paused game only if mouse button was newly pressed down
     if (new_button)
@@ -1375,7 +1375,7 @@ static void HandleButtonOrFinger(int mx, int my, int button)
   {
     if (strEqual(setup.touch.control_type, TOUCH_CONTROL_FOLLOW_FINGER))
       HandleButtonOrFinger_FollowFinger(mx, my, button);
-    else if (game.event_mask == GAME_EVENTS_MOUSE && valid_mouse_event)
+    else if ((game.event_mask & GAME_EVENTS_MOUSE) && valid_mouse_event)
       SetPlayerMouseAction(mx, my, button);
   }
 }
@@ -2098,7 +2098,7 @@ void HandleKey(Key key, int key_status)
       if (stored_player[pnr].snap_action)
        stored_player[pnr].action |= JOY_BUTTON_SNAP;
 
-      if (tape.recording && tape.pausing && tape.event_mask == GAME_EVENTS_KEYS)
+      if (tape.recording && tape.pausing && (tape.event_mask & GAME_EVENTS_KEYS))
       {
        if (tape.single_step)
        {
@@ -2633,7 +2633,7 @@ void HandleJoystick(void)
        return;
       }
 
-      if (tape.recording && tape.pausing && tape.event_mask == GAME_EVENTS_KEYS)
+      if (tape.recording && tape.pausing && (tape.event_mask & GAME_EVENTS_KEYS))
       {
        if (tape.single_step)
        {
index d38858203b8fb2a5e527bedd43e22a28c9cbb18b..95256480249e9e672862aed626d16d9629e8358f 100644 (file)
@@ -7623,9 +7623,10 @@ static int getTapePosSize(struct TapeInfo *tape)
 {
   int tape_pos_size = 0;
 
-  if (tape->event_mask == GAME_EVENTS_KEYS)
+  if (tape->event_mask & GAME_EVENTS_KEYS)
     tape_pos_size += tape->num_participating_players;
-  else
+
+  if (tape->event_mask & GAME_EVENTS_MOUSE)
     tape_pos_size += 3;                // x and y position and mouse button mask
 
   tape_pos_size += 1;          // tape action delay value
@@ -7764,15 +7765,7 @@ static int LoadTape_BODY(File *file, int chunk_size, struct TapeInfo *tape)
       break;
     }
 
-    if (tape->event_mask == GAME_EVENTS_MOUSE)
-    {
-      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);
-
-      tape->pos[i].action[TAPE_ACTION_UNUSED] = 0;
-    }
-    else
+    if (tape->event_mask & GAME_EVENTS_KEYS)
     {
       for (j = 0; j < MAX_PLAYERS; j++)
       {
@@ -7783,6 +7776,13 @@ static int LoadTape_BODY(File *file, int chunk_size, struct TapeInfo *tape)
       }
     }
 
+    if (tape->event_mask & GAME_EVENTS_MOUSE)
+    {
+      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);
+    }
+
     tape->pos[i].delay = getFile8Bit(file);
 
     if (tape->file_version == FILE_VERSION_1_0)
@@ -8133,19 +8133,20 @@ static void SaveTape_BODY(FILE *file, struct TapeInfo *tape)
 
   for (i = 0; i < tape->length; i++)
   {
-    if (tape->event_mask == GAME_EVENTS_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
+    if (tape->event_mask & GAME_EVENTS_KEYS)
     {
       for (j = 0; j < MAX_PLAYERS; j++)
        if (tape->player_participates[j])
          putFile8Bit(file, tape->pos[i].action[j]);
     }
 
+    if (tape->event_mask & GAME_EVENTS_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]);
+    }
+
     putFile8Bit(file, tape->pos[i].delay);
   }
 }
index 36fc3b6835a4dd14edec4d2acc095f647b3dc7ae..9fe37cc551bb053b6536517d1809a297b6e6a1be 100644 (file)
@@ -3300,7 +3300,7 @@ static void InitGameEngine(void)
          HAS_CHANGE_EVENT(element, CE_PRESSED_BY_MOUSE) ||
          HAS_CHANGE_EVENT(element, CE_MOUSE_CLICKED_ON_X) ||
          HAS_CHANGE_EVENT(element, CE_MOUSE_PRESSED_ON_X))
-       game.event_mask = GAME_EVENTS_MOUSE;
+       game.event_mask = GAME_EVENTS_KEYS | GAME_EVENTS_MOUSE;
     }
   }
 }
@@ -11176,7 +11176,7 @@ static byte PlayerActions(struct PlayerInfo *player, byte player_action)
 static void SetMouseActionFromTapeAction(struct MouseActionInfo *mouse_action,
                                         byte *tape_action)
 {
-  if (tape.event_mask != GAME_EVENTS_MOUSE)
+  if (!(tape.event_mask & GAME_EVENTS_MOUSE))
     return;
 
   mouse_action->lx     = tape_action[TAPE_ACTION_LX];
@@ -11187,7 +11187,7 @@ static void SetMouseActionFromTapeAction(struct MouseActionInfo *mouse_action,
 static void SetTapeActionFromMouseAction(byte *tape_action,
                                         struct MouseActionInfo *mouse_action)
 {
-  if (tape.event_mask != GAME_EVENTS_MOUSE)
+  if (!(tape.event_mask & GAME_EVENTS_MOUSE))
     return;
 
   tape_action[TAPE_ACTION_LX]     = mouse_action->lx;
@@ -11910,8 +11910,8 @@ void GameActions_RND(void)
   {
     int new_button = (mouse_action.button && mouse_action_last.button == 0);
 
-    x = local_player->mouse_action.lx;
-    y = local_player->mouse_action.ly;
+    x = mouse_action.lx;
+    y = mouse_action.ly;
     element = Feld[x][y];
 
     if (new_button)
index 2464832c39452841db669daccf4243065330fb7d..0995976329d36c8ba5026037dfe5c8eea5c99e2c 100644 (file)
@@ -706,7 +706,7 @@ void TapeRecordAction(byte action_raw[MAX_TAPE_ACTIONS])
   for (i = 0; i < MAX_TAPE_ACTIONS; i++)
     action[i] = action_raw[i];
 
-  if (tape.event_mask == GAME_EVENTS_KEYS && tape.set_centered_player)
+  if ((tape.event_mask & GAME_EVENTS_KEYS) && tape.set_centered_player)
   {
     for (i = 0; i < MAX_PLAYERS; i++)
       if (tape.centered_player_nr_next == i ||
@@ -887,7 +887,7 @@ byte *TapePlayAction(void)
   tape.set_centered_player = FALSE;
   tape.centered_player_nr_next = -999;
 
-  if (tape.event_mask == GAME_EVENTS_KEYS)
+  if (tape.event_mask & GAME_EVENTS_KEYS)
   {
     for (i = 0; i < MAX_PLAYERS; i++)
     {
index eb0231b15b61a0becea078a19e34661e20e6e702..d2878581ed8942dba68c668cbf349083d2161557 100644 (file)
 #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
+#define TAPE_ACTION_LX         (MAX_PLAYERS + 0)
+#define TAPE_ACTION_LY         (MAX_PLAYERS + 1)
+#define TAPE_ACTION_BUTTON     (MAX_PLAYERS + 2)
 
-#define MAX_TAPE_ACTIONS       4
+#define MAX_TAPE_ACTIONS       (MAX_PLAYERS + 3)
 
 // values for tape action events stored in tape file
 #define TAPE_EVENTS_KEYS_ONLY          0