added step-based engine snapshots to undo/redo game steps (continued)
authorHolger Schemel <info@artsoft.org>
Tue, 24 Mar 2015 20:31:01 +0000 (21:31 +0100)
committerHolger Schemel <info@artsoft.org>
Tue, 24 Mar 2015 20:31:01 +0000 (21:31 +0100)
src/editor.c
src/game.c
src/libgame/snapshot.c
src/libgame/system.h
src/tools.c

index 4a6e9dd40b89bcbac935369d246b00ac2324d766..c0d5ffd9a11e1cafe7742d872ba3f488fbdb1e8a 100644 (file)
@@ -3424,10 +3424,6 @@ static int new_element3 = EL_SAND;
 #define BUTTON_ELEMENT(button) ((button) == 1 ? new_element1 : \
                                (button) == 2 ? new_element2 : \
                                (button) == 3 ? new_element3 : EL_EMPTY)
-#define BUTTON_STEPSIZE(button) ((button) == 1 ?  1 : \
-                                (button) == 2 ?  5 : \
-                                (button) == 3 ? 10 : \
-                                (button))
 
 /* forward declaration for internal use */
 static void ModifyEditorCounterValue(int, int);
index c0153bdf452c0cdc55ada397285bbd9bd3681481..63eb94115bb5224ca532217187b45d973b69041a 100644 (file)
@@ -10681,9 +10681,6 @@ static void CheckSaveEngineSnapshot(struct PlayerInfo *player)
   static boolean player_was_snapping = FALSE;
   static boolean player_was_dropping = FALSE;
 
-  if (!tape.recording)
-    return;
-
   if ((!player->is_moving  && player_was_moving) ||
       (player->MovPos == 0 && player_was_moving) ||
       (player->is_snapping && !player_was_snapping) ||
@@ -14758,16 +14755,16 @@ void LoadEngineSnapshotSingle()
   LoadEngineSnapshotValues();
 }
 
-void LoadEngineSnapshot_Undo()
+void LoadEngineSnapshot_Undo(int steps)
 {
-  LoadSnapshotFromList_Older();
+  LoadSnapshotFromList_Older(steps);
 
   LoadEngineSnapshotValues();
 }
 
-void LoadEngineSnapshot_Redo()
+void LoadEngineSnapshot_Redo(int steps)
 {
-  LoadSnapshotFromList_Newer();
+  LoadSnapshotFromList_Newer(steps);
 
   LoadEngineSnapshotValues();
 }
@@ -14984,28 +14981,29 @@ void GameUndoRedoExt()
   BackToFront();
 }
 
-void GameUndo()
+void GameUndo(int steps)
 {
   if (!CheckEngineSnapshot())
     return;
 
-  LoadEngineSnapshot_Undo();
+  LoadEngineSnapshot_Undo(steps);
 
   GameUndoRedoExt();
 }
 
-void GameRedo()
+void GameRedo(int steps)
 {
   if (!CheckEngineSnapshot())
     return;
 
-  LoadEngineSnapshot_Redo();
+  LoadEngineSnapshot_Redo(steps);
 
   GameUndoRedoExt();
 }
 
-static void HandleGameButtonsExt(int id)
+static void HandleGameButtonsExt(int id, int button)
 {
+  int steps = BUTTON_STEPSIZE(button);
   boolean handle_game_buttons =
     (game_status == GAME_MODE_PLAYING ||
      (game_status == GAME_MODE_MAIN && tape.show_game_buttons));
@@ -15060,11 +15058,11 @@ static void HandleGameButtonsExt(int id)
       break;
 
     case GAME_CTRL_ID_UNDO:
-      GameUndo();
+      GameUndo(steps);
       break;
 
     case GAME_CTRL_ID_REDO:
-      GameRedo();
+      GameRedo(steps);
       break;
 
     case GAME_CTRL_ID_SAVE:
@@ -15121,7 +15119,7 @@ static void HandleGameButtonsExt(int id)
 
 static void HandleGameButtons(struct GadgetInfo *gi)
 {
-  HandleGameButtonsExt(gi->custom_id);
+  HandleGameButtonsExt(gi->custom_id, gi->event.button);
 }
 
 void HandleSoundButtonKeys(Key key)
index f57cb5fa6dd757f8de167541aecaaf77006d54be..1262ee88b2abda4f66173503e70240c2d0f42674 100644 (file)
@@ -133,11 +133,12 @@ boolean LoadSnapshotSingle()
   return FALSE;
 }
 
-boolean LoadSnapshotFromList_Older()
+boolean LoadSnapshotFromList_Older(int steps)
 {
   if (snapshot_current->next)
   {
-    snapshot_current = snapshot_current->next;
+    while (snapshot_current->next && steps--)
+      snapshot_current = snapshot_current->next;
 
     LoadSnapshotBuffers(snapshot_current->content);
 
@@ -151,11 +152,12 @@ boolean LoadSnapshotFromList_Older()
   return FALSE;
 }
 
-boolean LoadSnapshotFromList_Newer()
+boolean LoadSnapshotFromList_Newer(int steps)
 {
   if (snapshot_current->prev)
   {
-    snapshot_current = snapshot_current->prev;
+    while (snapshot_current->prev && steps--)
+      snapshot_current = snapshot_current->prev;
 
     LoadSnapshotBuffers(snapshot_current->content);
 
index d3f518ed3b17c2f1e31ef4293f6ae500a00775d8..617fc5730c1112525b9da861caf61b632d356fb3 100644 (file)
                                         (b) <= MB_WHEEL_DOWN)
 #define DEFAULT_WHEEL_STEPS            3
 
+#define BUTTON_STEPSIZE(b)             ((b) == MB_LEFTBUTTON   ?  1 :  \
+                                        (b) == MB_MIDDLEBUTTON ?  5 :  \
+                                        (b) == MB_RIGHTBUTTON  ? 10 : 1)
+
 /* values for move directions */
 #define MV_BIT_LEFT                    0
 #define MV_BIT_RIGHT                   1
index e98ac35b9476491b9b6192a282f16c8c447d99e0..7c0634294d1e78ebb2ea70822f2249858f29a0f5 100644 (file)
@@ -7801,9 +7801,6 @@ void CheckSaveEngineSnapshot_EM(byte action[MAX_PLAYERS], int frame,
 {
   static boolean player_was_waiting = TRUE;
 
-  if (!tape.recording)
-    return;
-
   if (frame == 0 && !any_player_dropping)
   {
     if (!player_was_waiting)
@@ -7824,9 +7821,6 @@ void CheckSaveEngineSnapshot_SP(boolean murphy_is_waiting,
 {
   static boolean player_was_waiting = FALSE;
 
-  if (!tape.recording)
-    return;
-
   if (murphy_is_waiting)
   {
     if (!player_was_waiting)