From: Holger Schemel Date: Mon, 24 Jun 2024 22:28:09 +0000 (+0200) Subject: added playfield element buffer for drawing game graphics for BD engine X-Git-Tag: 4.4.0.0-test-3~27 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=f626b6a6b580cdb94483311945bef951da075bdc;p=rocksndiamonds.git added playfield element buffer for drawing game graphics for BD engine --- diff --git a/src/game_bd/bd_cave.c b/src/game_bd/bd_cave.c index a406afb7..40d20f15 100644 --- a/src/game_bd/bd_cave.c +++ b/src/game_bd/bd_cave.c @@ -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; diff --git a/src/game_bd/bd_cave.h b/src/game_bd/bd_cave.h index c551de65..03196b0f 100644 --- a/src/game_bd/bd_cave.h +++ b/src/game_bd/bd_cave.h @@ -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); diff --git a/src/game_bd/bd_gameplay.c b/src/game_bd/bd_gameplay.c index db10e62e..0baca4fd 100644 --- a/src/game_bd/bd_gameplay.c +++ b/src/game_bd/bd_gameplay.c @@ -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 diff --git a/src/game_bd/bd_gameplay.h b/src/game_bd/bd_gameplay.h index 1378f0ef..fbeeecfc 100644 --- a/src/game_bd/bd_gameplay.h +++ b/src/game_bd/bd_gameplay.h @@ -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; diff --git a/src/game_bd/export_bd.h b/src/game_bd/export_bd.h index ea288cd8..a50b9e9f 100644 --- a/src/game_bd/export_bd.h +++ b/src/game_bd/export_bd.h @@ -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]; diff --git a/src/game_bd/main_bd.c b/src/game_bd/main_bd.c index 4e0396fc..9f94b3b6 100644 --- a/src/game_bd/main_bd.c +++ b/src/game_bd/main_bd.c @@ -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];