From 6711d42c2e67e546b911b53f25cb98c561a4da9c Mon Sep 17 00:00:00 2001 From: Frotty Date: Thu, 3 Sep 2026 22:23:59 +0200 Subject: [PATCH] Stamp the sweep tick where the grid rebuild reads live positions Every other site that caches a position records when it read it: registerUnit, refreshUnit on both its branches, and the query write-back. The grid rebuild did not, and it re-buckets every unit from a fresh getPos. That only skewed a diagnostic while lastSweepTick fed nothing but the sweep's worst-age counter. Now that the query derives an entry's padding from it, a rebuild leaves every entry looking maximally stale while its cache is in fact exact, so queries pad by a whole sweep cycle and read positions they already have, until the sweep works its way around. The rule is that the stamp belongs with the read, not with the link: writing it inside linkIntoCell instead would tie freshness to bucketing and quietly depend on every future caller passing a live position. --- wurst/util/UnitSpatialIndex.wurst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/wurst/util/UnitSpatialIndex.wurst b/wurst/util/UnitSpatialIndex.wurst index 15e0235a..0551a997 100644 --- a/wurst/util/UnitSpatialIndex.wurst +++ b/wurst/util/UnitSpatialIndex.wurst @@ -304,6 +304,9 @@ public function rebuildSpatialIndexGrid(vec2 worldMin, vec2 worldMax) let u = indexedUnit[idx] if u != null let pos = u.getPos() + // Stamp the tick wherever a live position is read, or the query would keep padding this + // entry by a full sweep cycle despite its cache having just been made exact. + lastSweepTick[idx] = sweepTick linkIntoCell(idx, cellAt(pos.x, pos.y), pos.x, pos.y) /** Internal-grid cell for tests and diagnostics. */