diff --git a/source/build/include/compat.h b/source/build/include/compat.h index 53f00ab3e..4a2c9f489 100644 --- a/source/build/include/compat.h +++ b/source/build/include/compat.h @@ -1057,6 +1057,9 @@ CONSTEXPR size_t logbasenegative(T n) return n > static_cast(-(native_t)base) ? 1 : 1 + logbase(n / static_cast(-(native_t)base)); } +#define isPow2OrZero(v) (((v) & ((v) - 1)) == 0) +#define isPow2(v) (isPow2OrZero(v) && (v)) + #endif diff --git a/source/sw/src/game.h b/source/sw/src/game.h index 2dd48d7da..c0fb188b3 100644 --- a/source/sw/src/game.h +++ b/source/sw/src/game.h @@ -544,9 +544,13 @@ int StdRandomRange(int range); #define HIT_SECTOR BIT(14) #define HIT_PLAX_WALL BIT(13) -#define NORM_SPRITE(val) ((val) & (SIZ(sprite) - 1)) -#define NORM_WALL(val) ((val) & (SIZ(wall) - 1)) -#define NORM_SECTOR(val) ((val) & (SIZ(sector) - 1)) +#define NORM_SPRITE(val) ((val) & (MAXSPRITES - 1)) +#define NORM_WALL(val) ((val) & (MAXWALLS - 1)) +#define NORM_SECTOR(val) ((val) & (MAXSECTORS - 1)) + +EDUKE32_STATIC_ASSERT(isPow2(MAXSPRITES)); +EDUKE32_STATIC_ASSERT(isPow2(MAXWALLS)); +EDUKE32_STATIC_ASSERT(isPow2(MAXSECTORS)); // overwritesprite flags #define OVER_SPRITE_MIDDLE (BIT(0))