fixed bug with player moving when releasing one of several pressed snap keys
authorHolger Schemel <info@artsoft.org>
Thu, 24 Jan 2019 18:26:01 +0000 (19:26 +0100)
committerHolger Schemel <info@artsoft.org>
Thu, 24 Jan 2019 18:26:04 +0000 (19:26 +0100)
When using TAS snap keys, pressing more than one snap key at the same
time and then releasing one of them caused the player to move.

src/events.c
src/game.c
src/game.h

index bc6e2eb083604889ca75802a0ab1c139df8bd418..0d1f6baf371a34982db7915ebd947e531bc96ca7 100644 (file)
@@ -2015,6 +2015,7 @@ void HandleKey(Key key, int key_status)
     for (pnr = 0; pnr < MAX_PLAYERS; pnr++)
     {
       byte key_action = 0;
+      byte key_snap_action = 0;
 
       if (setup.input[pnr].use_joystick)
        continue;
@@ -2030,15 +2031,33 @@ void HandleKey(Key key, int key_status)
       {
        ssi = setup.shortcut;
 
+       // also remember normal snap key when handling snap+direction keys
+       key_snap_action |= key_action & JOY_BUTTON_SNAP;
+
        for (i = 0; i < NUM_DIRECTIONS; i++)
+       {
          if (key == *key_info[i].key_snap)
-           key_action |= key_info[i].action | JOY_BUTTON_SNAP;
+         {
+           key_action      |= key_info[i].action | JOY_BUTTON_SNAP;
+           key_snap_action |= key_info[i].action;
+         }
+       }
       }
 
       if (key_status == KEY_PRESSED)
-       stored_player[pnr].action |= key_action;
+      {
+       stored_player[pnr].action      |= key_action;
+       stored_player[pnr].snap_action |= key_snap_action;
+      }
       else
-       stored_player[pnr].action &= ~key_action;
+      {
+       stored_player[pnr].action      &= ~key_action;
+       stored_player[pnr].snap_action &= ~key_snap_action;
+      }
+
+      // restore snap action if one of several pressed snap keys was released
+      if (stored_player[pnr].snap_action)
+       stored_player[pnr].action |= JOY_BUTTON_SNAP;
 
       if (tape.single_step && tape.recording && tape.pausing && !tape.use_mouse)
       {
index 20157c6d347482e2de7db3b0904b5c9916b10a2f..30ebdd17314ead1a30e8a90f51ba9e6125d02f94 100644 (file)
@@ -3402,6 +3402,7 @@ void InitGame(void)
     player->action = 0;
     player->effective_action = 0;
     player->programmed_action = 0;
+    player->snap_action = 0;
 
     player->mouse_action.lx = 0;
     player->mouse_action.ly = 0;
index 00131fb98a2babd7147389b47312daa93091c0c9..0319a8df9594e7c3aad85dec2ce7683730c1f74e 100644 (file)
@@ -281,6 +281,7 @@ struct PlayerInfo
                                   devices when in single player mode */
   byte programmed_action;      /* action forced by game itself (like moving
                                   through doors); overrides other actions */
+  byte snap_action;            // action from TAS snap keys
 
   struct MouseActionInfo mouse_action;          // (used by MM engine only)
   struct MouseActionInfo effective_mouse_action; // (used by MM engine only)