Fix PMAPBITS compile-time sanity check
This commit is contained in:
parent
5dfda0c528
commit
3c6ae35cc4
@ -68,13 +68,6 @@
|
||||
|
||||
#define PT_NUM (1<<PMAPBITS)
|
||||
|
||||
#if PMAPBITS > 16
|
||||
#error PMAPBITS is too large
|
||||
#endif
|
||||
#if ((XRES*YRES)<<PMAPBITS) > 0x100000000L
|
||||
#error not enough space in pmap
|
||||
#endif
|
||||
|
||||
struct playerst;
|
||||
|
||||
|
||||
|
@ -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");
|
||||
|
Reference in New Issue
Block a user