From: Holger Schemel Date: Mon, 10 Jun 2024 17:45:26 +0000 (+0200) Subject: added snapshot support for BD engine X-Git-Tag: 4.4.0.0-test-2~8 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=7e0902aa2014d4f2899972319f56fe9d5f24578d;p=rocksndiamonds.git added snapshot support for BD engine --- diff --git a/src/game.c b/src/game.c index 8b1bab36..a516155c 100644 --- a/src/game.c +++ b/src/game.c @@ -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) diff --git a/src/game_bd/export_bd.h b/src/game_bd/export_bd.h index 23809345..35f2e687 100644 --- a/src/game_bd/export_bd.h +++ b/src/game_bd/export_bd.h @@ -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 diff --git a/src/game_bd/main_bd.c b/src/game_bd/main_bd.c index 3376757f..dae512b6 100644 --- a/src/game_bd/main_bd.c +++ b/src/game_bd/main_bd.c @@ -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); +}