fixed saving game engine snapshots (save after game actions are finished)
authorHolger Schemel <info@artsoft.org>
Sat, 17 Sep 2016 14:37:12 +0000 (16:37 +0200)
committerHolger Schemel <info@artsoft.org>
Sat, 17 Sep 2016 14:37:12 +0000 (16:37 +0200)
src/game.c
src/game.h
src/tools.c

index e0e44eb4a1bb3e13c7396b283b20a604ea2c561c..09dc63fd73f158752a22eee66a69ac7ddeb717d1 100644 (file)
@@ -3049,6 +3049,7 @@ static void InitGameEngine()
      SNAPSHOT_MODE_EVERY_MOVE :
      strEqual(setup.engine_snapshot_mode, STR_SNAPSHOT_MODE_EVERY_COLLECT) ?
      SNAPSHOT_MODE_EVERY_COLLECT : SNAPSHOT_MODE_OFF);
+  game.snapshot.save_snapshot = FALSE;
 }
 
 int get_num_special_action(int element, int action_first, int action_last)
@@ -10698,7 +10699,7 @@ static void CheckSaveEngineSnapshot(struct PlayerInfo *player)
       (player->is_snapping && !player->was_snapping) ||
       (player->is_dropping && !player->was_dropping))
   {
-    if (!SaveEngineSnapshotToList())
+    if (!CheckSaveEngineSnapshotToList())
       return;
 
     player->was_moving = FALSE;
@@ -10959,7 +10960,7 @@ void StartGameActions(boolean init_network_game, boolean record_tape,
   InitGame();
 }
 
-void GameActions()
+void GameActionsExt()
 {
 #if 0
   static unsigned int game_frame_delay = 0;
@@ -11238,6 +11239,24 @@ void GameActions()
   }
 }
 
+static void GameActions_CheckSaveEngineSnapshot()
+{
+  if (!game.snapshot.save_snapshot)
+    return;
+
+  // clear flag for saving snapshot _before_ saving snapshot
+  game.snapshot.save_snapshot = FALSE;
+
+  SaveEngineSnapshotToList();
+}
+
+void GameActions()
+{
+  GameActionsExt();
+
+  GameActions_CheckSaveEngineSnapshot();
+}
+
 void GameActions_EM_Main()
 {
   byte effective_action[MAX_PLAYERS];
@@ -14770,11 +14789,10 @@ void SaveEngineSnapshotSingle()
   snapshot_level_nr = level_nr;
 }
 
-static boolean SaveEngineSnapshotToListExt(boolean initial_snapshot)
+boolean CheckSaveEngineSnapshotToList()
 {
   boolean save_snapshot =
-    (initial_snapshot ||
-     (game.snapshot.mode == SNAPSHOT_MODE_EVERY_STEP) ||
+    ((game.snapshot.mode == SNAPSHOT_MODE_EVERY_STEP) ||
      (game.snapshot.mode == SNAPSHOT_MODE_EVERY_MOVE &&
       game.snapshot.changed_action) ||
      (game.snapshot.mode == SNAPSHOT_MODE_EVERY_COLLECT &&
@@ -14782,30 +14800,28 @@ static boolean SaveEngineSnapshotToListExt(boolean initial_snapshot)
 
   game.snapshot.changed_action = FALSE;
   game.snapshot.collected_item = FALSE;
+  game.snapshot.save_snapshot = save_snapshot;
+
+  return save_snapshot;
+}
 
+void SaveEngineSnapshotToList()
+{
   if (game.snapshot.mode == SNAPSHOT_MODE_OFF ||
-      tape.quick_resume ||
-      !save_snapshot)
-    return FALSE;
+      tape.quick_resume)
+    return;
 
   ListNode *buffers = SaveEngineSnapshotBuffers();
 
   /* finally save all snapshot buffers to snapshot list */
   SaveSnapshotToList(buffers);
-
-  return TRUE;
-}
-
-boolean SaveEngineSnapshotToList()
-{
-  return SaveEngineSnapshotToListExt(FALSE);
 }
 
 void SaveEngineSnapshotToListInitial()
 {
   FreeEngineSnapshotList();
 
-  SaveEngineSnapshotToListExt(TRUE);
+  SaveEngineSnapshotToList();
 }
 
 void LoadEngineSnapshotValues()
index cd388da73abb3f792c094dfbb1a667359ee9cdfa..2f21455f8cfe65e2470a006ed6f26afd5c5a637d 100644 (file)
@@ -122,6 +122,8 @@ struct GameSnapshotInfo
   byte last_action[MAX_PLAYERS];
   boolean changed_action;
   boolean collected_item;
+
+  boolean save_snapshot;
 };
 
 struct GameInfo
@@ -386,7 +388,8 @@ void FreeEngineSnapshotSingle();
 void FreeEngineSnapshotList();
 void LoadEngineSnapshotSingle();
 void SaveEngineSnapshotSingle();
-boolean SaveEngineSnapshotToList();
+boolean CheckSaveEngineSnapshotToList();
+void SaveEngineSnapshotToList();
 void SaveEngineSnapshotToListInitial();
 boolean CheckEngineSnapshotSingle();
 boolean CheckEngineSnapshotList();
index fe14158f0c5904849b4bc9acf7b400cf728a046d..e534cc29c3e79c465cd50d0ee79420ed0bd5bc17 100644 (file)
@@ -8037,7 +8037,7 @@ void CheckSaveEngineSnapshot_EM(byte action[MAX_PLAYERS], int frame,
   {
     if (!local_player->was_waiting)
     {
-      if (!SaveEngineSnapshotToList())
+      if (!CheckSaveEngineSnapshotToList())
        return;
 
       local_player->was_waiting = TRUE;
@@ -8056,7 +8056,7 @@ void CheckSaveEngineSnapshot_SP(boolean murphy_is_waiting,
   {
     if (!local_player->was_waiting)
     {
-      if (!SaveEngineSnapshotToList())
+      if (!CheckSaveEngineSnapshotToList())
        return;
 
       local_player->was_waiting = TRUE;