diff --git a/src/simulation/ElementDefs.h b/src/simulation/ElementDefs.h index 10c2413f0..6b9ac045d 100644 --- a/src/simulation/ElementDefs.h +++ b/src/simulation/ElementDefs.h @@ -68,13 +68,6 @@ #define PT_NUM (1< 16 -#error PMAPBITS is too large -#endif -#if ((XRES*YRES)< 0x100000000L -#error not enough space in pmap -#endif - struct playerst; diff --git a/src/simulation/Simulation.cpp b/src/simulation/Simulation.cpp index dc0d6be02..d32f66728 100644 --- a/src/simulation/Simulation.cpp +++ b/src/simulation/Simulation.cpp @@ -5267,3 +5267,14 @@ float Simulation::remainder_p(float x, float y) { return std::fmod(x, y) + (x>=0 ? 0 : y); } + +constexpr size_t ce_log2(size_t n) +{ + return ((n < 2) ? 1 : 1 + ce_log2(n / 2)); +} +static_assert(PMAPBITS <= 16, "PMAPBITS is too large"); +// * This will technically fail in some cases where (XRES * YRES) << PMAPBITS would +// fit in 31 bits but multiplication is evil and wraps around without you knowing it. +// * Whoever runs into a problem with this (e.g. with XRES = 612, YRES = 384 and +// PMAPBITS = 13) should just remove the check and take responsibility otherwise. +static_assert(ce_log2(XRES) + ce_log2(YRES) + PMAPBITS <= 31, "not enough space in pmap");