From 352beda47c3f0a57519edb3c0a9df847b6b3f23e Mon Sep 17 00:00:00 2001 From: Malte Langkabel Date: Sat, 8 Aug 2026 19:42:24 +0200 Subject: [PATCH] let the world renderer hold the simulation by const reference The renderer documented itself as reading the simulation and never writing it, while holding a mutable reference to it -- because hasAll() forced that on every caller. With hasAll const the claim and the type can agree, and the const overloads of getAdmin, forEach and get cover everything the renderer does. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_01JcReq7hVk4KUPhTDKWAG7K --- src/ui/WorldRenderer.cpp | 2 +- src/ui/WorldRenderer.h | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/ui/WorldRenderer.cpp b/src/ui/WorldRenderer.cpp index a7e5bd5..21c3f8c 100644 --- a/src/ui/WorldRenderer.cpp +++ b/src/ui/WorldRenderer.cpp @@ -109,7 +109,7 @@ QColor statusLightFill(ProductionStatus status, const StatusLightVisuals& sl) } // namespace -WorldRenderer::WorldRenderer(Simulation& sim, const VisualsConfig& visuals, +WorldRenderer::WorldRenderer(const Simulation& sim, const VisualsConfig& visuals, ItemIconCache* itemIcons, const std::string& configDir) : m_sim(sim) , m_visuals(visuals) diff --git a/src/ui/WorldRenderer.h b/src/ui/WorldRenderer.h index babe154..81e348a 100644 --- a/src/ui/WorldRenderer.h +++ b/src/ui/WorldRenderer.h @@ -77,7 +77,7 @@ public: // `itemIcons` is the window-wide per-item icon cache (REQ-UI-ITEM-ICON); not // owned, must outlive this renderer. `configDir` is used once, to load the // per-building world icons. - WorldRenderer(Simulation& sim, const VisualsConfig& visuals, + WorldRenderer(const Simulation& sim, const VisualsConfig& visuals, ItemIconCache* itemIcons, const std::string& configDir); ~WorldRenderer(); @@ -141,9 +141,8 @@ private: std::optional entityPosition(entt::entity entity) const; - // Non-const only because EntityAdmin's component accessors are; the renderer - // reads the simulation and never writes it. - Simulation& m_sim; + // The renderer reads the simulation and never writes it. + const Simulation& m_sim; const VisualsConfig& m_visuals; // Per-item icon cache (REQ-UI-ITEM-ICON), shared window-wide and owned by