From: Holger Schemel Date: Tue, 24 Mar 2015 20:31:01 +0000 (+0100) Subject: added step-based engine snapshots to undo/redo game steps (continued) X-Git-Tag: 4.0.0.0-rc1~229 X-Git-Url: https://git.artsoft.org/?p=rocksndiamonds.git;a=commitdiff_plain;h=4b722be68436ced0b7bb3eff61ed14d6c66df949 added step-based engine snapshots to undo/redo game steps (continued) --- diff --git a/src/editor.c b/src/editor.c index 4a6e9dd4..c0d5ffd9 100644 --- a/src/editor.c +++ b/src/editor.c @@ -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); diff --git a/src/game.c b/src/game.c index c0153bdf..63eb9411 100644 --- a/src/game.c +++ b/src/game.c @@ -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) diff --git a/src/libgame/snapshot.c b/src/libgame/snapshot.c index f57cb5fa..1262ee88 100644 --- a/src/libgame/snapshot.c +++ b/src/libgame/snapshot.c @@ -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); diff --git a/src/libgame/system.h b/src/libgame/system.h index d3f518ed..617fc573 100644 --- a/src/libgame/system.h +++ b/src/libgame/system.h @@ -136,6 +136,10 @@ (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 diff --git a/src/tools.c b/src/tools.c index e98ac35b..7c063429 100644 --- a/src/tools.c +++ b/src/tools.c @@ -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)