mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-08-18 06:01:19 +02:00
Make pmap size sanity check more precise
Simulations as big as 2048 by 2048 had been possible, but this change enables sizes such as 1900 by 2100, which would have failed the originally very power-of-2-oriented check. Very useful, no doubt. Also make the tags button span the entire window, fixing the annoying gap or overlap with other buttons when changing the sim size.
This commit is contained in:
@@ -280,7 +280,7 @@ GameView::GameView():
|
|||||||
currentX+=16;
|
currentX+=16;
|
||||||
AddComponent(downVoteButton);
|
AddComponent(downVoteButton);
|
||||||
|
|
||||||
tagSimulationButton = new ui::Button(ui::Point(currentX, Size.Y-16), ui::Point(227, 15), "[no tags set]", "Add simulation tags");
|
tagSimulationButton = new ui::Button(ui::Point(currentX, Size.Y-16), ui::Point(WINDOWW - 402, 15), "[no tags set]", "Add simulation tags");
|
||||||
tagSimulationButton->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
|
tagSimulationButton->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
|
||||||
tagSimulationButton->SetIcon(IconTag);
|
tagSimulationButton->SetIcon(IconTag);
|
||||||
//currentX+=252;
|
//currentX+=252;
|
||||||
|
@@ -4042,13 +4042,5 @@ void Simulation::EnableNewtonianGravity(bool enable)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr size_t ce_log2(size_t n)
|
// we want XRES * YRES <= (1 << (31 - PMAPBITS)), but we do a division because multiplication could silently overflow
|
||||||
{
|
static_assert(uint32_t(XRES) <= (UINT32_C(1) << (31 - PMAPBITS)) / uint32_t(YRES), "not enough space in pmap");
|
||||||
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