From: Holger Schemel Date: Sat, 17 Feb 2024 09:40:46 +0000 (+0100) Subject: added functions to get range corrected x/y cave position for BD engine X-Git-Tag: 4.4.0.0-test-1~359 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=c94cdac2a1cda58ac0e3640e14d3635b797c597a;p=rocksndiamonds.git added functions to get range corrected x/y cave position for BD engine --- diff --git a/src/game_bd/bd_cave.h b/src/game_bd/bd_cave.h index 189e2777..d97f280f 100644 --- a/src/game_bd/bd_cave.h +++ b/src/game_bd/bd_cave.h @@ -550,7 +550,13 @@ typedef struct _gd_cave boolean pneumatic_hammer_sound; /* internal variables, used during the game. private data :) */ - GdElement* (*getp) (const struct _gd_cave*, int x, int y); /* returns a pointer to the element at x, y. this points to a perfect border or a line shifting get function. */ + + /* returns range corrected x/y position (points to perfect or line shifting get function) */ + int (*getx) (const struct _gd_cave*, int x, int y); + int (*gety) (const struct _gd_cave*, int x, int y); + + /* returns pointer to element at x, y (points to perfect border or a line shifting get function) */ + GdElement* (*getp) (const struct _gd_cave*, int x, int y); boolean hatched; /* hatching has happened. (timers may run, ...) */ boolean gate_open; /* self-explaining */ diff --git a/src/game_bd/bd_caveengine.c b/src/game_bd/bd_caveengine.c index d33222e0..5f97940a 100644 --- a/src/game_bd/bd_caveengine.c +++ b/src/game_bd/bd_caveengine.c @@ -303,6 +303,38 @@ static void play_sound_of_element_pushing(GdCave *cave, GdElement element, int x } } +static inline int getx(const GdCave *cave, const int x, const int y) +{ + return cave->getx(cave, x, y); +} + +static inline int gety(const GdCave *cave, const int x, const int y) +{ + return cave->gety(cave, x, y); +} + +/* perfect (non-lineshifting) GET x/y functions; returns range corrected x/y position */ +static inline int getx_perfect(const GdCave *cave, const int x, const int y) +{ + return (x + cave->w) % cave->w; +} + +static inline int gety_perfect(const GdCave *cave, const int x, const int y) +{ + return (y + cave->h) % cave->h; +} + +/* line shifting GET x/y function; returns range corrected x/y position */ +static inline int getx_shift(const GdCave *cave, int x, int y) +{ + return (x + cave->w) % cave->w; +} + +static inline int gety_shift(const GdCave *cave, int x, int y) +{ + return ((x < 0 ? y - 1 : x >= cave->w ? y + 1 : y) + cave->h) % cave->h; +} + static inline GdElement *getp(const GdCave *cave, const int x, const int y) { return cave->getp(cave, x, y); @@ -1517,9 +1549,17 @@ void gd_cave_iterate(GdCave *cave, GdDirection player_move, boolean player_fire, /* set cave get function; to implement perfect or lineshifting borders */ if (cave->lineshift) + { cave->getp = getp_shift; + cave->getx = getx_shift; + cave->gety = gety_shift; + } else + { cave->getp = getp_perfect; + cave->getx = getx_perfect; + cave->gety = gety_perfect; + } /* increment this. if the scan routine comes across player, clears it (sets to zero). */ if (cave->player_seen_ago < 100)