From d24a70d6d1a9952980f74d601a0e91cea13cbd9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20B=C3=A1lint=20Misius?= Date: Sat, 6 Jul 2024 16:53:47 +0200 Subject: [PATCH] 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. --- src/gui/game/GameView.cpp | 2 +- src/simulation/Simulation.cpp | 12 ++---------- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/src/gui/game/GameView.cpp b/src/gui/game/GameView.cpp index 2c6636f38..d457e11b8 100644 --- a/src/gui/game/GameView.cpp +++ b/src/gui/game/GameView.cpp @@ -280,7 +280,7 @@ GameView::GameView(): currentX+=16; 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->SetIcon(IconTag); //currentX+=252; diff --git a/src/simulation/Simulation.cpp b/src/simulation/Simulation.cpp index 66f1ddf9a..4bf9de212 100644 --- a/src/simulation/Simulation.cpp +++ b/src/simulation/Simulation.cpp @@ -4042,13 +4042,5 @@ void Simulation::EnableNewtonianGravity(bool enable) } } -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"); +// 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");