added playfield element buffer for drawing game graphics for BD engine
authorHolger Schemel <holger.schemel@virtion.de>
Mon, 24 Jun 2024 22:28:09 +0000 (00:28 +0200)
committerHolger Schemel <holger.schemel@virtion.de>
Mon, 24 Jun 2024 22:28:09 +0000 (00:28 +0200)
src/game_bd/bd_cave.c
src/game_bd/bd_cave.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 a406afb7c6d16ac16d14e1ec68327cd50a84a3a1..40d20f154c6ca240a0bb8d4ce47829f972d87ca9 100644 (file)
@@ -1317,6 +1317,7 @@ void gd_cave_count_diamonds(GdCave *cave)
   by the caller.
 */
 void gd_drawcave_game(const GdCave *cave,
+                     int **element_buffer, int **last_element_buffer,
                      int **drawing_buffer, int **last_drawing_buffer, int **gfx_buffer,
                      boolean bonus_life_flash, int animcycle, boolean hate_invisible_outbox)
 {
@@ -1581,6 +1582,9 @@ void gd_drawcave_game(const GdCave *cave,
        draw += GD_NUM_OF_CELLS;
 
       // set to buffer, with caching
+      if (element_buffer[y][x] != actual)
+       element_buffer[y][x] = actual;
+
       if (drawing_buffer[y][x] != map)
        drawing_buffer[y][x] = map;
 
index c551de659900e4a9c2c75662d5812ed944a8710e..03196b0fda543705e8aa8327232bb6cbb4893fe4 100644 (file)
@@ -704,6 +704,7 @@ GdScheduling gd_scheduling_from_string(const char *str);
 #define GD_REDRAW (1 << 10)
 
 void gd_drawcave_game(const GdCave *cave,
+                     int **element_buffer, int **last_element_buffer,
                      int **drawing_buffer, int **last_drawing_buffer, int **gfx_buffer,
                      boolean bonus_life_flash, int animcycle, boolean hate_invisible_outbox);
 
index db10e62e3bee18b851b869103a44aaa242594a04..0baca4fd130ad283edbf28bde0a51a0b7c33222b 100644 (file)
@@ -22,6 +22,10 @@ void gd_game_free(GdGame *game)
   // stop sounds
   gd_sound_off();
 
+  if (game->element_buffer)
+    gd_cave_map_free(game->element_buffer);
+  if (game->last_element_buffer)
+    gd_cave_map_free(game->last_element_buffer);
   if (game->drawing_buffer)
     gd_cave_map_free(game->drawing_buffer);
   if (game->last_drawing_buffer)
@@ -81,6 +85,16 @@ static void load_cave(GdGame *game)
 {
   int x, y;
 
+  // delete element buffer
+  if (game->element_buffer)
+    gd_cave_map_free(game->element_buffer);
+  game->element_buffer = NULL;
+
+  // delete last element buffer
+  if (game->last_element_buffer)
+    gd_cave_map_free(game->last_element_buffer);
+  game->last_element_buffer = NULL;
+
   // delete drawing buffer
   if (game->drawing_buffer)
     gd_cave_map_free(game->drawing_buffer);
@@ -131,6 +145,20 @@ static void load_cave(GdGame *game)
 
   game->cycle_counter = 0;
 
+  // create new element buffer
+  game->element_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->element_buffer[y][x] = O_NONE;
+
+  // create new last element buffer
+  game->last_element_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->last_element_buffer[y][x] = O_NONE;
+
   // create new drawing buffer
   game->drawing_buffer = gd_cave_map_new(game->cave, int);
 
@@ -406,6 +434,7 @@ static GdGameState gd_game_main_int(GdGame *game, boolean allow_iterate, boolean
       {
        for (x = 0; x < game->cave->w; x++)
        {
+         game->last_element_buffer[y][x] = game->element_buffer[y][x];
          game->last_drawing_buffer[y][x] = game->drawing_buffer[y][x];
          game->dir_buffer_from[y][x] = GD_MV_STILL;
          game->dir_buffer_to[y][x]   = GD_MV_STILL;
@@ -595,8 +624,9 @@ static GdGameState gd_game_main_int(GdGame *game, boolean allow_iterate, boolean
 
   // always render the cave to the gfx buffer;
   // however it may do nothing if animcycle was not changed.
-  if (game->drawing_buffer && game->gfx_buffer)
-    gd_drawcave_game(game->cave, game->drawing_buffer, game->last_drawing_buffer, game->gfx_buffer,
+  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->bonus_life_flash != 0, game->animcycle, setup.bd_show_invisible_outbox);
 
   game->state_counter = counter_next;
@@ -650,7 +680,7 @@ void play_game_func(GdGame *game, int action)
   // if drawcave was before scrolling, it would draw, scroll would invalidate,
   // and then it should be drawn again
   // only do the drawing if the cave already exists.
-  if (game->cave && game->drawing_buffer && game->gfx_buffer)
+  if (game->cave && game->element_buffer && game->drawing_buffer && game->gfx_buffer)
   {
     // if fine scrolling, scroll at 50hz. if not, only scroll at every second call, so 25hz.
     // do the scrolling. scroll exactly, if player is not yet alive
index 1378f0ef22388bde9a5b740d7d60d9e0d19bca50..fbeeecfcce94a54a3fd21df5792b08c3abffdcb8 100644 (file)
@@ -75,6 +75,8 @@ typedef struct _gd_game
   int bonus_life_flash;         // different kind of flashing, for bonus life
 
   int state_counter;            // counter used to control the game flow, rendering of caves
+  int **element_buffer;
+  int **last_element_buffer;
   int **drawing_buffer;
   int **last_drawing_buffer;
   int **dir_buffer_from;
index ea288cd840de62fe70b2fbc5312e774727718228..a50b9e9f5d817ba66f58e9c2c792e17d2a9f5d49 100644 (file)
@@ -81,6 +81,8 @@ 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 drawing_buffer[MAX_PLAYFIELD_WIDTH][MAX_PLAYFIELD_HEIGHT];
   int last_drawing_buffer[MAX_PLAYFIELD_WIDTH][MAX_PLAYFIELD_HEIGHT];
   int dir_buffer_from[MAX_PLAYFIELD_WIDTH][MAX_PLAYFIELD_HEIGHT];
index 4e0396fc80acdf0b361b50c23f8074d235a78559..9f94b3b68596799f92d87dd5fa1bd7b475c09ca4 100644 (file)
@@ -572,6 +572,8 @@ void SaveEngineSnapshotValues_BD(void)
   {
     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.drawing_buffer[x][y]      = game->drawing_buffer[y][x];
       engine_snapshot_bd.last_drawing_buffer[x][y] = game->last_drawing_buffer[y][x];
       engine_snapshot_bd.dir_buffer_from[x][y]     = game->dir_buffer_from[y][x];
@@ -604,6 +606,8 @@ void LoadEngineSnapshotValues_BD(void)
   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.drawing_buffer      = game->drawing_buffer;
   engine_snapshot_bd.game.last_drawing_buffer = game->last_drawing_buffer;
   engine_snapshot_bd.game.dir_buffer_from     = game->dir_buffer_from;
@@ -616,6 +620,8 @@ void LoadEngineSnapshotValues_BD(void)
   {
     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->drawing_buffer[y][x]      = engine_snapshot_bd.drawing_buffer[x][y];
       game->last_drawing_buffer[y][x] = engine_snapshot_bd.last_drawing_buffer[x][y];
       game->dir_buffer_from[y][x]     = engine_snapshot_bd.dir_buffer_from[x][y];