From dd11b3af00799f1dcd34481281bb219216ac9a4b Mon Sep 17 00:00:00 2001 From: Holger Schemel Date: Wed, 29 Jan 2020 17:01:42 +0100 Subject: [PATCH] added separate playfield and buffer sizes for EM engine caves The cave playfield size (or just cave size) is the size of the visible playfield (potentially containing an additional steelwall border, if the level was converted from R'n'D format and does not contain a steelwall border). The cave buffer size is the size of the internal cave buffer (which also contains surrounding internal game engine elements) that is used by the EM game engine logic. Currently the native cave structure has the same size as the internal cave buffer; this should be changed. --- src/files.c | 8 ++++---- src/game_em/convert.c | 16 ++++++++-------- src/game_em/emerald.h | 28 +++++++++++++++++----------- src/game_em/export.h | 6 +++--- src/game_em/graphics.c | 8 ++++---- src/game_em/input.c | 24 ++++++++++++------------ src/game_em/logic.c | 16 ++++++++-------- 7 files changed, 56 insertions(+), 50 deletions(-) diff --git a/src/files.c b/src/files.c index 7224337d..0c0f2f9b 100644 --- a/src/files.c +++ b/src/files.c @@ -3519,8 +3519,8 @@ static void CopyNativeLevel_RND_to_EM(struct LevelInfo *level) struct PLAYER **ply = level_em->ply; int i, j, x, y; - lev->width = MIN(level->fieldx, EM_MAX_CAVE_WIDTH); - lev->height = MIN(level->fieldy, EM_MAX_CAVE_HEIGHT); + lev->width = MIN(level->fieldx, EM_MAX_CAVE_BUFFER_WIDTH); + lev->height = MIN(level->fieldy, EM_MAX_CAVE_BUFFER_HEIGHT); lev->time_seconds = level->time; lev->required_initial = level->gems_needed; @@ -3574,8 +3574,8 @@ static void CopyNativeLevel_RND_to_EM(struct LevelInfo *level) map_android_clone_elements_RND_to_EM(level); // first fill the complete playfield with the default border element - for (y = 0; y < EM_MAX_CAVE_HEIGHT; y++) - for (x = 0; x < EM_MAX_CAVE_WIDTH; x++) + for (y = 0; y < EM_MAX_CAVE_BUFFER_HEIGHT; y++) + for (x = 0; x < EM_MAX_CAVE_BUFFER_WIDTH; x++) level_em->cave[x][y] = Zborder; if (BorderElement == EL_STEELWALL) diff --git a/src/game_em/convert.c b/src/game_em/convert.c index dd220900..996f0d21 100644 --- a/src/game_em/convert.c +++ b/src/game_em/convert.c @@ -911,8 +911,8 @@ void convert_em_level(unsigned char *src, int file_version) } /* first fill the complete playfield with the default border element */ - for (y = 0; y < CAVE_HEIGHT; y++) - for (x = 0; x < CAVE_WIDTH; x++) + for (y = 0; y < CAVE_BUFFER_HEIGHT; y++) + for (x = 0; x < CAVE_BUFFER_WIDTH; x++) native_em_level.cave[x][y] = Zborder; /* then copy the real level contents from level file into the playfield */ @@ -938,16 +938,16 @@ void prepare_em_level(void) /* reset all runtime variables to their initial values */ - for (y = 0; y < CAVE_HEIGHT; y++) - for (x = 0; x < CAVE_WIDTH; x++) + for (y = 0; y < CAVE_BUFFER_HEIGHT; y++) + for (x = 0; x < CAVE_BUFFER_WIDTH; x++) lev.cave[x][y] = native_em_level.cave[x][y]; - for (y = 0; y < CAVE_HEIGHT; y++) - for (x = 0; x < CAVE_WIDTH; x++) + for (y = 0; y < CAVE_BUFFER_HEIGHT; y++) + for (x = 0; x < CAVE_BUFFER_WIDTH; x++) lev.next[x][y] = lev.cave[x][y]; - for (y = 0; y < CAVE_HEIGHT; y++) - for (x = 0; x < CAVE_WIDTH; x++) + for (y = 0; y < CAVE_BUFFER_HEIGHT; y++) + for (x = 0; x < CAVE_BUFFER_WIDTH; x++) lev.draw[x][y] = lev.cave[x][y]; lev.time_initial = lev.time_seconds; diff --git a/src/game_em/emerald.h b/src/game_em/emerald.h index 1cf3deff..26032ff4 100644 --- a/src/game_em/emerald.h +++ b/src/game_em/emerald.h @@ -51,9 +51,15 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. /* define these to use additional elements */ #define EM_ENGINE_USE_ADDITIONAL_ELEMENTS -/* one border for Zborder elements, one border for steelwall, if needed */ -#define CAVE_WIDTH (MAX_PLAYFIELD_WIDTH + 2 + 2) -#define CAVE_HEIGHT (MAX_PLAYFIELD_HEIGHT + 2 + 2) +/* with border for steelwall, if needed (when converted from R'n'D level) */ +#define CAVE_WIDTH (MAX_PLAYFIELD_WIDTH + 2) +#define CAVE_HEIGHT (MAX_PLAYFIELD_HEIGHT + 2) + +/* with border for Zborder elements (surrounding the visible playfield) */ +#define CAVE_BUFFER_XOFFSET 1 +#define CAVE_BUFFER_YOFFSET 1 +#define CAVE_BUFFER_WIDTH (CAVE_WIDTH + 2 * CAVE_BUFFER_XOFFSET) +#define CAVE_BUFFER_HEIGHT (CAVE_HEIGHT + 2 * CAVE_BUFFER_YOFFSET) /* ----------------------------------------------------------------------------- @@ -701,15 +707,15 @@ struct LEVEL int exit_x, exit_y; /* kludge for playing player exit sound */ - short cavebuf[CAVE_WIDTH][CAVE_HEIGHT]; - short nextbuf[CAVE_WIDTH][CAVE_HEIGHT]; - short drawbuf[CAVE_WIDTH][CAVE_HEIGHT]; - short boombuf[CAVE_WIDTH][CAVE_HEIGHT]; + short cavebuf[CAVE_BUFFER_WIDTH][CAVE_BUFFER_HEIGHT]; + short nextbuf[CAVE_BUFFER_WIDTH][CAVE_BUFFER_HEIGHT]; + short drawbuf[CAVE_BUFFER_WIDTH][CAVE_BUFFER_HEIGHT]; + short boombuf[CAVE_BUFFER_WIDTH][CAVE_BUFFER_HEIGHT]; - short *cavecol[CAVE_WIDTH]; - short *nextcol[CAVE_WIDTH]; - short *drawcol[CAVE_WIDTH]; - short *boomcol[CAVE_WIDTH]; + short *cavecol[CAVE_BUFFER_WIDTH]; + short *nextcol[CAVE_BUFFER_WIDTH]; + short *drawcol[CAVE_BUFFER_WIDTH]; + short *boomcol[CAVE_BUFFER_WIDTH]; short **cave; short **next; diff --git a/src/game_em/export.h b/src/game_em/export.h index 9c0ff052..5ba8c5ce 100644 --- a/src/game_em/export.h +++ b/src/game_em/export.h @@ -12,8 +12,8 @@ // constant definitions // ---------------------------------------------------------------------------- -#define EM_MAX_CAVE_WIDTH CAVE_WIDTH -#define EM_MAX_CAVE_HEIGHT CAVE_HEIGHT +#define EM_MAX_CAVE_BUFFER_WIDTH CAVE_BUFFER_WIDTH +#define EM_MAX_CAVE_BUFFER_HEIGHT CAVE_BUFFER_HEIGHT // ---------------------------------------------------------------------------- @@ -44,7 +44,7 @@ struct LevelInfo_EM { int file_version; - short cave[CAVE_WIDTH][CAVE_HEIGHT]; + short cave[CAVE_BUFFER_WIDTH][CAVE_BUFFER_HEIGHT]; struct LEVEL *lev; struct PLAYER *ply[MAX_PLAYERS]; diff --git a/src/game_em/graphics.c b/src/game_em/graphics.c index c6c1d542..548b24db 100644 --- a/src/game_em/graphics.c +++ b/src/game_em/graphics.c @@ -300,8 +300,8 @@ static void animscreen(void) }; if (!game.use_native_emc_graphics_engine) - for (y = 2; y < CAVE_HEIGHT - 2; y++) - for (x = 2; x < CAVE_WIDTH - 2; x++) + for (y = 2; y < CAVE_BUFFER_HEIGHT - 2; y++) + for (x = 2; x < CAVE_BUFFER_WIDTH - 2; x++) SetGfxAnimation_EM(&graphic_info_em_object[lev.draw[x][y]][frame], lev.draw[x][y], 7 - frame, x - 2, y - 2); @@ -326,8 +326,8 @@ static void animscreen(void) int yy = y + xy[i][1]; int tile_next; - if (xx < 0 || xx >= CAVE_WIDTH || - yy < 0 || yy >= CAVE_HEIGHT) + if (xx < 0 || xx >= CAVE_BUFFER_WIDTH || + yy < 0 || yy >= CAVE_BUFFER_HEIGHT) continue; tile_next = lev.draw[xx][yy]; diff --git a/src/game_em/input.c b/src/game_em/input.c index 3883bbda..70106b1d 100644 --- a/src/game_em/input.c +++ b/src/game_em/input.c @@ -22,26 +22,26 @@ void game_init_vars(void) RandomEM = 1684108901; - for (y = 0; y < CAVE_HEIGHT; y++) - for (x = 0; x < CAVE_WIDTH; x++) + for (y = 0; y < CAVE_BUFFER_HEIGHT; y++) + for (x = 0; x < CAVE_BUFFER_WIDTH; x++) lev.cavebuf[x][y] = Zborder; - for (y = 0; y < CAVE_HEIGHT; y++) - for (x = 0; x < CAVE_WIDTH; x++) + for (y = 0; y < CAVE_BUFFER_HEIGHT; y++) + for (x = 0; x < CAVE_BUFFER_WIDTH; x++) lev.nextbuf[x][y] = Zborder; - for (y = 0; y < CAVE_HEIGHT; y++) - for (x = 0; x < CAVE_WIDTH; x++) + for (y = 0; y < CAVE_BUFFER_HEIGHT; y++) + for (x = 0; x < CAVE_BUFFER_WIDTH; x++) lev.drawbuf[x][y] = Zborder; - for (y = 0; y < CAVE_HEIGHT; y++) - for (x = 0; x < CAVE_WIDTH; x++) + for (y = 0; y < CAVE_BUFFER_HEIGHT; y++) + for (x = 0; x < CAVE_BUFFER_WIDTH; x++) lev.boombuf[x][y] = Xblank; - for (x = 0; x < CAVE_WIDTH; x++) + for (x = 0; x < CAVE_BUFFER_WIDTH; x++) lev.cavecol[x] = lev.cavebuf[x]; - for (x = 0; x < CAVE_WIDTH; x++) + for (x = 0; x < CAVE_BUFFER_WIDTH; x++) lev.nextcol[x] = lev.nextbuf[x]; - for (x = 0; x < CAVE_WIDTH; x++) + for (x = 0; x < CAVE_BUFFER_WIDTH; x++) lev.drawcol[x] = lev.drawbuf[x]; - for (x = 0; x < CAVE_WIDTH; x++) + for (x = 0; x < CAVE_BUFFER_WIDTH; x++) lev.boomcol[x] = lev.boombuf[x]; lev.cave = lev.cavecol; diff --git a/src/game_em/logic.c b/src/game_em/logic.c index da397d56..df027b63 100644 --- a/src/game_em/logic.c +++ b/src/game_em/logic.c @@ -6273,8 +6273,8 @@ void logic_2(void) seed = RandomEM; score = 0; - for (y = 1; y < CAVE_HEIGHT - 1; y++) - for (x = 0; x < CAVE_WIDTH; x++) + for (y = 1; y < CAVE_BUFFER_HEIGHT - 1; y++) + for (x = 0; x < CAVE_BUFFER_WIDTH; x++) handle_tile(x, y); if (ply[0].alive || ply[1].alive || ply[2].alive || ply[3].alive) @@ -6334,8 +6334,8 @@ void logic_3(void) for (count = lev.amoeba_time; count--;) { - x = (random >> 10) % (CAVE_WIDTH - 2); - y = (random >> 20) % (CAVE_HEIGHT - 2); + x = (random >> 10) % (CAVE_BUFFER_WIDTH - 2); + y = (random >> 20) % (CAVE_BUFFER_HEIGHT - 2); Lamoeba(x, y); @@ -6346,13 +6346,13 @@ void logic_3(void) /* handle explosions */ - for (y = 1; y < CAVE_HEIGHT - 1; y++) - for (x = 1; x < CAVE_WIDTH - 1; x++) + for (y = 1; y < CAVE_BUFFER_HEIGHT - 1; y++) + for (x = 1; x < CAVE_BUFFER_WIDTH - 1; x++) Lexplode(x, y); /* triple buffering */ - for (y = 0; y < CAVE_HEIGHT; y++) - for (x = 0; x < CAVE_WIDTH; x++) + for (y = 0; y < CAVE_BUFFER_HEIGHT; y++) + for (x = 0; x < CAVE_BUFFER_WIDTH; x++) next[x][y] = cave[x][y]; } -- 2.34.1