added separate buffer for playfield (un)covering in BD engine
authorHolger Schemel <holger.schemel@virtion.de>
Sun, 18 Aug 2024 11:25:56 +0000 (13:25 +0200)
committerHolger Schemel <holger.schemel@virtion.de>
Sun, 18 Aug 2024 11:25:58 +0000 (13:25 +0200)
src/game_bd/bd_cave.c
src/game_bd/bd_cave.h
src/game_bd/bd_elements.h
src/game_bd/bd_gameplay.c
src/game_bd/bd_gameplay.h
src/game_bd/export_bd.h
src/game_bd/main_bd.c

index 1a40351a519c42efe8a3d6c2c7f5d3d7cade1d82..d050c52069d7b30c0ffb75ef9301524279d2defa 100644 (file)
@@ -1317,6 +1317,7 @@ void gd_cave_count_diamonds(GdCave *cave)
 void gd_drawcave_game(const GdCave *cave,
                      int **element_buffer, int **last_element_buffer,
                      int **drawing_buffer, int **last_drawing_buffer, int **gfx_buffer,
+                     int **covered_buffer,
                      boolean bonus_life_flash, int animcycle, boolean hate_invisible_outbox)
 {
   static int player_blinking = 0;
@@ -1538,13 +1539,13 @@ void gd_drawcave_game(const GdCave *cave,
       GdElement actual = cave->map[y][x];
 
       // if covered, real element is not important
-      if (actual & COVERED)
+      if (covered_buffer[y][x])
        map = O_COVERED;
       else
        map = elemmapping[actual];
 
       // if covered, real element is not important
-      if (actual & COVERED)
+      if (covered_buffer[y][x])
        draw = gd_element_properties[O_COVERED].image_game;
       else
        draw = elemdrawing[actual];
index 3b8d28330f7fec5e83049c3e26bd9bb514f87011..190b23d294108a12a60d75b968455e82c8d358e3 100644 (file)
@@ -716,6 +716,7 @@ GdScheduling gd_scheduling_from_string(const char *str);
 void gd_drawcave_game(const GdCave *cave,
                      int **element_buffer, int **last_element_buffer,
                      int **drawing_buffer, int **last_drawing_buffer, int **gfx_buffer,
+                     int **covered_buffer,
                      boolean bonus_life_flash, int animcycle, boolean hate_invisible_outbox);
 
 // function to copy a GdString
index 2843b7958346752545b8988def8e6c61f45aade1..99bfa717675ed5e9f3c28b7e24e6f6618514f4b6 100644 (file)
@@ -408,10 +408,9 @@ typedef enum _element
   O_MAX_ALL,
 
   SCANNED = 0x400,
-  COVERED = 0x800,
 
   // binary AND this to elements to get rid of properties above.
-  O_MASK = ~(SCANNED | COVERED)
+  O_MASK = ~SCANNED
 } GdElement;
 
 typedef enum _sound
index b157bdf0640f04fcbfb726a4fca3bfb469e1c221..629e03620da17c6fcd295f93cdff9aecef01a3a2 100644 (file)
@@ -36,6 +36,8 @@ void gd_game_free(GdGame *game)
     gd_cave_map_free(game->dir_buffer_to);
   if (game->gfx_buffer)
     gd_cave_map_free(game->gfx_buffer);
+  if (game->covered_buffer)
+    gd_cave_map_free(game->covered_buffer);
 
   game->player_lives = 0;
 
@@ -120,6 +122,11 @@ static void load_cave(GdGame *game)
     gd_cave_map_free(game->gfx_buffer);
   game->gfx_buffer = NULL;
 
+  // delete covered buffer
+  if (game->covered_buffer)
+    gd_cave_map_free(game->covered_buffer);
+  game->covered_buffer = NULL;
+
   // load the cave
   game->cave_score = 0;
 
@@ -193,6 +200,13 @@ static void load_cave(GdGame *game)
   for (y = 0; y < game->cave->h; y++)
     for (x = 0; x < game->cave->w; x++)
       game->gfx_buffer[y][x] = -1;    // fill with "invalid"
+
+  // create new covered buffer
+  game->covered_buffer = gd_cave_map_new(game->cave, int);
+
+  for (y = 0; y < game->cave->h; y++)
+    for (x = 0; x < game->cave->w; x++)
+      game->covered_buffer[y][x] = FALSE;
 }
 
 GdCave *gd_create_snapshot(GdGame *game)
@@ -347,7 +361,7 @@ static GdGameState gd_game_main_int(GdGame *game, boolean allow_iterate, boolean
     // cover all cells of cave
     for (y = 0; y < game->cave->h; y++)
       for (x = 0; x < game->cave->w; x++)
-       game->cave->map[y][x] |= COVERED;
+        game->covered_buffer[y][x] = TRUE;
 
     counter_next = game->state_counter + 1;
 
@@ -378,7 +392,7 @@ static GdGameState gd_game_main_int(GdGame *game, boolean allow_iterate, boolean
        y = gd_random_int_range(0, game->cave->h);
        x = gd_random_int_range(0, game->cave->w);
 
-       game->cave->map[y][x] &= ~COVERED;
+        game->covered_buffer[y][x] = FALSE;
       }
 
       counter_next++;    // as we did something, advance the counter.
@@ -391,7 +405,7 @@ static GdGameState gd_game_main_int(GdGame *game, boolean allow_iterate, boolean
     // time to uncover the whole cave.
     for (y = 0; y < game->cave->h; y++)
       for (x = 0; x < game->cave->w; x++)
-       game->cave->map[y][x] &= ~COVERED;
+        game->covered_buffer[y][x] = FALSE;
 
     // to stop uncover sound.
     gd_cave_clear_sounds(game->cave);
@@ -587,7 +601,7 @@ static GdGameState gd_game_main_int(GdGame *game, boolean allow_iterate, boolean
 
       // covering eight times faster than uncovering.
       for (j = 0; j < game->cave->w * game->cave->h * 8 / 40; j++)
-       game->cave->map[gd_random_int_range(0, game->cave->h)][gd_random_int_range (0, game->cave->w)] |= COVERED;
+       game->covered_buffer[gd_random_int_range(0, game->cave->h)][gd_random_int_range(0, game->cave->w)] = TRUE;
     }
 
     return_state = GD_GAME_NOTHING;
@@ -597,7 +611,7 @@ static GdGameState gd_game_main_int(GdGame *game, boolean allow_iterate, boolean
     // cover all
     for (y = 0; y < game->cave->h; y++)
       for (x = 0; x < game->cave->w; x++)
-       game->cave->map[y][x] |= COVERED;
+        game->covered_buffer[y][x] = TRUE;
 
     counter_next = game->state_counter + 1;
     return_state = GD_GAME_NOTHING;
@@ -630,6 +644,7 @@ static GdGameState gd_game_main_int(GdGame *game, boolean allow_iterate, boolean
   if (game->element_buffer && game->drawing_buffer && game->gfx_buffer)
     gd_drawcave_game(game->cave, game->element_buffer, game->last_element_buffer,
                     game->drawing_buffer, game->last_drawing_buffer, game->gfx_buffer,
+                    game->covered_buffer,
                     game->bonus_life_flash != 0, game->animcycle, setup.bd_show_invisible_outbox);
 
   game->state_counter = counter_next;
index fbeeecfcce94a54a3fd21df5792b08c3abffdcb8..f54810bca97a6a4e42c1543070eb38b24b4733ca 100644 (file)
@@ -83,6 +83,7 @@ typedef struct _gd_game
   int **dir_buffer_to;
   int **gfx_buffer;             // contains the indexes to the cells;
                                 // created by *start_level, deleted by *stop_game
+  int **covered_buffer;
   int itercycle;
   int itermax;
   int itermax_last;
index a50b9e9f5d817ba66f58e9c2c792e17d2a9f5d49..db9a3e8b713dbb879c2f8ac5f00b9f87c9e2d93f 100644 (file)
@@ -88,6 +88,7 @@ struct EngineSnapshotInfo_BD
   int dir_buffer_from[MAX_PLAYFIELD_WIDTH][MAX_PLAYFIELD_HEIGHT];
   int dir_buffer_to[MAX_PLAYFIELD_WIDTH][MAX_PLAYFIELD_HEIGHT];
   int gfx_buffer[MAX_PLAYFIELD_WIDTH][MAX_PLAYFIELD_HEIGHT];
+  int covered_buffer[MAX_PLAYFIELD_WIDTH][MAX_PLAYFIELD_HEIGHT];
 
   GdCave cave;
 
index dc92297e33f8119209d11d77b994715cb1f466b3..99fdc18e8923abe3ee82671b8e03fc439937f7f1 100644 (file)
@@ -579,6 +579,7 @@ void SaveEngineSnapshotValues_BD(void)
       engine_snapshot_bd.dir_buffer_from[x][y]     = game->dir_buffer_from[y][x];
       engine_snapshot_bd.dir_buffer_to[x][y]       = game->dir_buffer_to[y][x];
       engine_snapshot_bd.gfx_buffer[x][y]          = game->gfx_buffer[y][x];
+      engine_snapshot_bd.covered_buffer[x][y]      = game->covered_buffer[y][x];
     }
   }
 
@@ -613,6 +614,7 @@ void LoadEngineSnapshotValues_BD(void)
   engine_snapshot_bd.game.dir_buffer_from     = game->dir_buffer_from;
   engine_snapshot_bd.game.dir_buffer_to       = game->dir_buffer_to;
   engine_snapshot_bd.game.gfx_buffer          = game->gfx_buffer;
+  engine_snapshot_bd.game.covered_buffer      = game->covered_buffer;
 
   *game = engine_snapshot_bd.game;
 
@@ -627,6 +629,7 @@ void LoadEngineSnapshotValues_BD(void)
       game->dir_buffer_from[y][x]     = engine_snapshot_bd.dir_buffer_from[x][y];
       game->dir_buffer_to[y][x]       = engine_snapshot_bd.dir_buffer_to[x][y];
       game->gfx_buffer[y][x]          = engine_snapshot_bd.gfx_buffer[x][y];
+      game->covered_buffer[y][x]      = engine_snapshot_bd.covered_buffer[x][y];
     }
   }