added movement-based engine snapshot mode to step-based mode
authorHolger Schemel <info@artsoft.org>
Sun, 29 Mar 2015 19:30:11 +0000 (21:30 +0200)
committerHolger Schemel <info@artsoft.org>
Mon, 30 Mar 2015 10:32:56 +0000 (12:32 +0200)
src/game.c
src/game.h
src/tools.c

index f35e89db2dc428c5807c659b7f1613dfca125bf6..02861925e981cb2510b22c683f206a60cdef1afa 100644 (file)
@@ -3035,6 +3035,12 @@ static void InitGameEngine()
   game.scroll_delay_value =
     MIN(MAX(MIN_SCROLL_DELAY, game.scroll_delay_value), MAX_SCROLL_DELAY);
 
+  /* ---------- initialize game engine snapshots ---------------------------- */
+  for (i = 0; i < MAX_PLAYERS; i++)
+    game.snapshot.last_action[i] = 0;
+  game.snapshot.changed_action = FALSE;
+  game.snapshot.mode = SNAPSHOT_MODE_MOVE;
+
   FreeEngineSnapshotList();
 }
 
@@ -10686,7 +10692,8 @@ static void CheckSaveEngineSnapshot(struct PlayerInfo *player)
       (player->is_snapping && !player_was_snapping) ||
       (player->is_dropping && !player_was_dropping))
   {
-    SaveEngineSnapshotToList();
+    if (!SaveEngineSnapshotToList())
+      return;
 
     player_was_moving = FALSE;
     player_was_snapping = TRUE;
@@ -10955,6 +10962,23 @@ void GameActions()
   byte tape_action[MAX_PLAYERS];
   int i;
 
+  for (i = 0; i < MAX_PLAYERS; i++)
+  {
+    struct PlayerInfo *player = &stored_player[i];
+
+    // allow engine snapshot if movement attempt was stopped
+    if ((game.snapshot.last_action[i] & KEY_MOTION) != 0 &&
+       (player->action & KEY_MOTION) == 0)
+      game.snapshot.changed_action = TRUE;
+
+    // allow engine snapshot in case of snapping/dropping attempt
+    if ((game.snapshot.last_action[i] & KEY_BUTTON) == 0 &&
+       (player->action & KEY_BUTTON) != 0)
+      game.snapshot.changed_action = TRUE;
+
+    game.snapshot.last_action[i] = player->action;
+  }
+
   /* detect endless loops, caused by custom element programming */
   if (recursion_loop_detected && recursion_loop_depth == 0)
   {
@@ -14724,12 +14748,25 @@ void SaveEngineSnapshotSingle()
   SaveSnapshotSingle(buffers);
 }
 
-void SaveEngineSnapshotToList()
+boolean SaveEngineSnapshotToList()
 {
+  boolean save_snapshot =
+    (FrameCounter == 0 ||
+     (game.snapshot.mode == SNAPSHOT_MODE_STEP) ||
+     (game.snapshot.mode == SNAPSHOT_MODE_MOVE &&
+      game.snapshot.changed_action));
+
+  game.snapshot.changed_action = FALSE;
+
+  if (!save_snapshot)
+    return FALSE;
+
   ListNode *buffers = SaveEngineSnapshotBuffers();
 
   /* finally save all snapshot buffers to snapshot list */
   SaveSnapshotToList(buffers);
+
+  return TRUE;
 }
 
 void LoadEngineSnapshotValues()
index 3f04c02edfe87c8dba67f54c7b5f173101814469..ae0a1cc19ec93bfe4da257cec54d1ce30af1be61 100644 (file)
 #define NUM_PANEL_ELEMENTS     8
 #define NUM_PANEL_CE_SCORE     8
 
+#define SNAPSHOT_MODE_STEP     0
+#define SNAPSHOT_MODE_MOVE     1
+
+
 struct GamePanelInfo
 {
   struct TextPosInfo level_number;
@@ -101,6 +105,14 @@ struct GameButtonInfo
   struct XY sound_simple;
 };
 
+struct GameSnapshotInfo
+{
+  int mode;
+
+  byte last_action[MAX_PLAYERS];
+  boolean changed_action;
+};
+
 struct GameInfo
 {
   /* values for control panel */
@@ -175,6 +187,9 @@ struct GameInfo
 
   /* values for random number generator initialization after snapshot */
   unsigned int num_random_calls;
+
+  /* values for game engine snapshot control */
+  struct GameSnapshotInfo snapshot;
 };
 
 struct PlayerInfo
@@ -353,7 +368,7 @@ void FreeEngineSnapshotSingle();
 void FreeEngineSnapshotList();
 void LoadEngineSnapshotSingle();
 void SaveEngineSnapshotSingle();
-void SaveEngineSnapshotToList();
+boolean SaveEngineSnapshotToList();
 boolean CheckEngineSnapshot();
 
 void CreateGameButtons();
index 7c0634294d1e78ebb2ea70822f2249858f29a0f5..f9a2472c1fe45d5975bf9ee15f09b25ebcc402ca 100644 (file)
@@ -7805,7 +7805,8 @@ void CheckSaveEngineSnapshot_EM(byte action[MAX_PLAYERS], int frame,
   {
     if (!player_was_waiting)
     {
-      SaveEngineSnapshotToList();
+      if (!SaveEngineSnapshotToList())
+       return;
 
       player_was_waiting = TRUE;
     }
@@ -7819,13 +7820,14 @@ void CheckSaveEngineSnapshot_EM(byte action[MAX_PLAYERS], int frame,
 void CheckSaveEngineSnapshot_SP(boolean murphy_is_waiting,
                                boolean murphy_is_dropping)
 {
-  static boolean player_was_waiting = FALSE;
+  static boolean player_was_waiting = TRUE;
 
   if (murphy_is_waiting)
   {
     if (!player_was_waiting)
     {
-      SaveEngineSnapshotToList();
+      if (!SaveEngineSnapshotToList())
+       return;
 
       player_was_waiting = TRUE;
     }