added snapshot support for BD engine
authorHolger Schemel <holger.schemel@virtion.de>
Mon, 10 Jun 2024 17:45:26 +0000 (19:45 +0200)
committerHolger Schemel <holger.schemel@virtion.de>
Mon, 10 Jun 2024 17:45:26 +0000 (19:45 +0200)
src/game.c
src/game_bd/export_bd.h
src/game_bd/main_bd.c

index 8b1bab3629481fc52577754e013f64a87c7ad45d..a516155ce76b269b2704d5ecc3ffe2112899e4c1 100644 (file)
@@ -16612,6 +16612,8 @@ static ListNode *SaveEngineSnapshotBuffers(void)
 
   if (level.game_engine_type == GAME_ENGINE_TYPE_RND)
     SaveEngineSnapshotValues_RND();
+  if (level.game_engine_type == GAME_ENGINE_TYPE_BD)
+    SaveEngineSnapshotValues_BD();
   if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
     SaveEngineSnapshotValues_EM();
   if (level.game_engine_type == GAME_ENGINE_TYPE_SP)
@@ -16623,6 +16625,8 @@ static ListNode *SaveEngineSnapshotBuffers(void)
 
   if (level.game_engine_type == GAME_ENGINE_TYPE_RND)
     SaveSnapshotBuffer(&buffers, ARGS_ADDRESS_AND_SIZEOF(engine_snapshot_rnd));
+  if (level.game_engine_type == GAME_ENGINE_TYPE_BD)
+    SaveSnapshotBuffer(&buffers, ARGS_ADDRESS_AND_SIZEOF(engine_snapshot_bd));
   if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
     SaveSnapshotBuffer(&buffers, ARGS_ADDRESS_AND_SIZEOF(engine_snapshot_em));
   if (level.game_engine_type == GAME_ENGINE_TYPE_SP)
@@ -16762,6 +16766,8 @@ static void LoadEngineSnapshotValues(void)
 
   if (level.game_engine_type == GAME_ENGINE_TYPE_RND)
     LoadEngineSnapshotValues_RND();
+  if (level.game_engine_type == GAME_ENGINE_TYPE_BD)
+    LoadEngineSnapshotValues_BD();
   if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
     LoadEngineSnapshotValues_EM();
   if (level.game_engine_type == GAME_ENGINE_TYPE_SP)
index 23809345a82ead5a8e7b7f17ef2120e9bdcf9ad3..35f2e687fc2fa57daa740b7a5bf56c33437dca1e 100644 (file)
@@ -75,6 +75,19 @@ struct GraphicInfo_BD
 
 struct EngineSnapshotInfo_BD
 {
+  GdGame game;
+
+  // data from pointers in game structure
+  int element_buffer[MAX_PLAYFIELD_WIDTH][MAX_PLAYFIELD_HEIGHT];
+  int last_element_buffer[MAX_PLAYFIELD_WIDTH][MAX_PLAYFIELD_HEIGHT];
+  int dir_buffer[MAX_PLAYFIELD_WIDTH][MAX_PLAYFIELD_HEIGHT];
+  int gfx_buffer[MAX_PLAYFIELD_WIDTH][MAX_PLAYFIELD_HEIGHT];
+
+  GdCave cave;
+
+  // data from pointers in cave structure
+  short map[MAX_PLAYFIELD_WIDTH][MAX_PLAYFIELD_HEIGHT];
+  short hammered_reappear[MAX_PLAYFIELD_WIDTH][MAX_PLAYFIELD_HEIGHT];
 };
 
 
@@ -131,4 +144,7 @@ void CoverScreen_BD(void);
 void BlitScreenToBitmap_BD(Bitmap *);
 void RedrawPlayfield_BD(boolean);
 
+void SaveEngineSnapshotValues_BD(void);
+void LoadEngineSnapshotValues_BD(void);
+
 #endif // EXPORT_BD_H
index 3376757fb103fb256383886b6a821a5b8d5e6604..dae512b67ffc72ebbe5d58ea7b31435f50014744 100644 (file)
@@ -540,3 +540,96 @@ void RedrawPlayfield_BD(boolean force_redraw)
 {
   gd_drawcave(gd_screen_bitmap, game_bd.game, force_redraw);
 }
+
+
+// ============================================================================
+// snapshot functions
+// ============================================================================
+
+void SaveEngineSnapshotValues_BD(void)
+{
+  GdGame *game = game_bd.game;
+  GdCave *cave = game_bd.game->cave;
+  int x, y;
+
+  engine_snapshot_bd.game = *game;
+
+  for (y = 0; y < cave->h; y++)
+  {
+    for (x = 0; x < cave->w; x++)
+    {
+      engine_snapshot_bd.element_buffer[x][y]      = game->element_buffer[y][x];
+      engine_snapshot_bd.last_element_buffer[x][y] = game->last_element_buffer[y][x];
+      engine_snapshot_bd.dir_buffer[x][y]          = game->dir_buffer[y][x];
+      engine_snapshot_bd.gfx_buffer[x][y]          = game->gfx_buffer[y][x];
+    }
+  }
+
+  engine_snapshot_bd.cave = *cave;
+
+  for (y = 0; y < cave->h; y++)
+  {
+    for (x = 0; x < cave->w; x++)
+    {
+      engine_snapshot_bd.map[x][y] = cave->map[y][x];
+
+      if (cave->hammered_walls_reappear)
+        engine_snapshot_bd.hammered_reappear[x][y] = cave->hammered_reappear[y][x];
+    }
+  }
+}
+
+void LoadEngineSnapshotValues_BD(void)
+{
+  GdGame *game = game_bd.game;
+  GdCave *cave = game_bd.game->cave;
+  int x, y;
+
+  // copy pointers
+  engine_snapshot_bd.game.cave                = game->cave;
+  engine_snapshot_bd.game.original_cave       = game->original_cave;
+
+  engine_snapshot_bd.game.element_buffer      = game->element_buffer;
+  engine_snapshot_bd.game.last_element_buffer = game->last_element_buffer;
+  engine_snapshot_bd.game.dir_buffer          = game->dir_buffer;
+  engine_snapshot_bd.game.gfx_buffer          = game->gfx_buffer;
+
+  *game = engine_snapshot_bd.game;
+
+  for (y = 0; y < cave->h; y++)
+  {
+    for (x = 0; x < cave->w; x++)
+    {
+      game->element_buffer[y][x]      = engine_snapshot_bd.element_buffer[x][y];
+      game->last_element_buffer[y][x] = engine_snapshot_bd.last_element_buffer[x][y];
+      game->dir_buffer[y][x]          = engine_snapshot_bd.dir_buffer[x][y];
+      game->gfx_buffer[y][x]          = engine_snapshot_bd.gfx_buffer[x][y];
+    }
+  }
+
+  // copy pointers
+  engine_snapshot_bd.cave.story             = cave->story;
+  engine_snapshot_bd.cave.remark            = cave->remark;
+  engine_snapshot_bd.cave.tags              = cave->tags;
+  engine_snapshot_bd.cave.map               = cave->map;
+  engine_snapshot_bd.cave.objects           = cave->objects;
+  engine_snapshot_bd.cave.replays           = cave->replays;
+  engine_snapshot_bd.cave.random            = cave->random;
+  engine_snapshot_bd.cave.objects_order     = cave->objects_order;
+  engine_snapshot_bd.cave.hammered_reappear = cave->hammered_reappear;
+
+  *cave = engine_snapshot_bd.cave;
+
+  for (y = 0; y < cave->h; y++)
+  {
+    for (x = 0; x < cave->w; x++)
+    {
+      cave->map[y][x] = engine_snapshot_bd.map[x][y];
+
+      if (cave->hammered_walls_reappear)
+        cave->hammered_reappear[y][x] = engine_snapshot_bd.hammered_reappear[x][y];
+    }
+  }
+
+  gd_scroll(game_bd.game, TRUE, TRUE);
+}