Repository navigation
PWA1: re-query only the pins a navigation change can reach - #6
Merged
Merged
Conversation
Every navigation update, selection change, pin change and visibility change marked the whole pin set dirty, so the next refresh re-ran a range query for every pin and rebuilt the combined outline mesh. The game's range service reuses a single flow field, so with two or more pins each of those queries was a full refill. Selection changes were not throttled. Add PinRefreshPlanner, a Unity-free planner linked into tests/Checks.csproj. Each pin keeps its cached cells, the key its query depends on (access point, live or preview graph, terrain or road spill) and a bounding box of access +/- (NavigationDistance.ResourceBuildings + 2), the same box BuildingTerrainRange uses to skip navigation updates (22 cells in 1.1.2.4). - A navigation update re-queries only pins whose box meets NavMeshUpdate.Bounds. Road-spill ranges follow the district road network, so they have no bound and are always re-queried. - Every pass re-reads each pin's key and re-queries pins whose access or graph changed, which catches a finished construction site cheaply. - The outline is rebuilt only when the combined cells change, or when an update meets the cached cells (blocking objects and previews there change the drawn outline even when the cells do not). - Selecting or deselecting a pinned building rebuilds the outline from the cache with no queries. Selecting an unpinned building does nothing. A selected pin's query waits until it is deselected. - Construction-mode toggles still re-query every pin; visible-level changes only redraw, because range queries do not depend on the visible level. All queries still run in UpdateSingleton at most five times per second. The navigation listeners only mark the mod's own per-pin records. No tick, save or persistence interfaces are added. Display only. Checks: 23 new, 61 total. The planner checks count queries and rebuilds in a fake navigation world, and a game check drives the service's real BoundingBox test with an asymmetric box. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Review found that the planner checks drive PinRefreshPlanner through a fake world, so a regression in WorkAreaService's glue (the reach margin, which planner call each event makes, the preview navigation listener) still passed every check. Build a WorkAreaService outside the game (its constructor only stores its dependencies and reads NavigationDistance), add an entity to its planner, and call each handler through reflection: - the pin reach is ResourceBuildings + 2, read from the game at run time; - a visible-level change redraws without marking the pin for a query; - a construction-mode change marks every pin for a query; - live and preview navigation updates mark the pin only inside its reach and keep the 0.2 s throttle; - deselecting a pinned building rebuilds the outline from the cache. This replaces the check that NavigationDistance.ResourceBuildings + 2 is exactly 22: it pinned a game constant the service already reads at run time, so a game change there would have blocked packaging a working build while a dropped margin in the service would still have passed. The fake-world CellBox check is renamed, since production code tests bounds with the game's BoundingBox. Each new check fails when its handler is mutated (reach 1, no redraw on visible level, redraw instead of invalidate on construction, empty preview listener, no deselect). Checks: 67 (was 61). Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This was referenced Sep 22, 2026
- WorkAreaService constructor: keep PWA1's NavigationDistance parameter, _reach and _planner alongside PWA2's ILoc. - tests/Program.cs: keep the planner checks above the game-free split so CI runs them, and raise GameChecks from 34 to 42. Full run: 74/74; no-argument run: 32 passed, 42 skipped. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kramsey458
marked this pull request as ready for review
September 22, 2026 16:40
kramsey458
added a commit
that referenced
this pull request
Sep 22, 2026
- WorkAreaService constructor: keep PWA4's EntityComponentRegistry and PWA2's ILoc. - tests/Program.cs: move the planting-rule and planner Show checks above the game-free split so CI runs them, and raise GameChecks to 56. Full run: 104/104; no-argument run: 48 passed, 56 skipped. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kramsey458
added a commit
that referenced
this pull request
Sep 22, 2026
- WorkAreaService constructor: keep PWA2's ILoc alongside PWA3's EntityRegistry and SettlementReferenceService, and keep the localized clear button next to the pin-file restore in PostLoad. - tests/Program.cs: keep the PinStore checks above the game-free split, raise GameChecks to 65, and allow the pin file's format, file names and argument-check text in the hard-coded UI text check. Full run: 142/142; no-argument run: 77 passed, 65 skipped. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Before this change, any navigation update, selection change, pin change or visible-level change marked every pin dirty. The next pass then re-ran a range query for every pinned building and rebuilt the whole outline mesh. The game's range service refills one shared flow field per query, so with two or more pins every one of those queries was a full refill. Selection changes also skipped the refresh throttle.
This PR adds
PinRefreshPlanner, which has no Unity dependency and is linked intotests/Checks.csproj. Each pin now keeps its cached cells, the key its query depends on (access point, live or preview graph, terrain or road spill) and a box of access ± (NavigationDistance.ResourceBuildings+ 2). That is the boxBuildingTerrainRange.UpdateBoundingBoxuses; in 1.1.2.4 it is 22 cells.NavMeshUpdate.Boundsare re-queried. Road-spill ranges follow the district road network, so they have no bound and are always re-queried.ILevelVisibilityService; only the drawing code does.All queries still run in
UpdateSingleton. Passes started by navigation changes stay capped at 5 per second. Pin, selection, construction-mode and visible-level events still start the next pass right away, as in 1.0.0, but those passes now query only stale pins. The navigation listeners only mark the mod's own per-pin records. No tick, save or persistence interfaces were added, and the checks still enforce that. This is display only.Items
PWA1: any navigation change re-queries every pin and rebuilds the whole outline mesh (fixed)
7a1c32badds the planner, movesWorkAreaServiceonto it and adds 23 checks.bb694ddadds checks of the service wiring, added after review.tests/Program.cs.Touchesdelegate against the game'sBoundingBoxwith an asymmetric box, which catches swapped axes and checks that edges are inclusive;WorkAreaServiceoutside the game and checks the wiring through reflection: reach =ResourceBuildings+ 2; visible-level events redraw without a query; construction-mode events mark every pin; live and preview navigation updates mark a pin only inside its reach and stay throttled; deselecting rebuilds from the cache.CS2001).FAIL: Navigation change missing every pin: 0 queries and 0 rebuilds.ResourceBuildings+ 2; no redraw on visible level;Redrawinstead ofInvalidateAllon construction; an empty preview listener; noSelect(null)on deselect; theTouchesresult inverted.Tests
Checks:
build.ps1 -GameDir <Timberborn>, thendotnet run --project tests/Checks.csproj -c Release -- <Timberborn> source/bin/Release/netstandard2.1/PersistentWorkAreas.dll packaging/PersistentWorkAreas/version-1.1.Of the 29 new checks, 21 are pure planner checks, 1 is the game
BoundingBoxcheck and 7 check the service wiring.Co-op impact
None. This is display only.
UpdateSingleton, as before, and there are fewer of them.AccessFlowField.OnNodesChangedclears the shared field on any change it can reach, and each fill is a fresh search.BoundingBox.Builder.Buildthrows only when nothing was added, andToBoundingBoxalways adds two points.Proposed CHANGELOG lines
Release-time follow-ups (not in this PR)
README.md("38 automated lifecycle/API checks") andVALIDATION.md("38 checks passed") describe the 1.0.0 release, so they are unchanged here. At the next release, set the count once, after PWA2 has landed too, since it adds more checks. This PR alone makes it 67.docs/troubleshooting.htmlanddocs/faq.htmldescribe the released 1.0.0 behaviour, so they are left alone. Two lines there need updating when this ships:claude/localize-ui) will also change theWorkAreaServiceconstructor andtests/Program.cs. Whichever PR lands second needs a small rebase.Needs in-game testing (solo; two-player not needed)
Review
Three adversarial reviewers approved
7a1c32b.NavigationDistanceconstructor argument resolves in the Game context.ResourceBuildings + 2 == 22could block packaging after a game update, even though the service reads the value at run time. It is replaced by a check of the service's own reach.bb694ddadds 7 checks that build a realWorkAreaServiceand call its handlers; the listed mutations now fail. Three pieces still need Unity components and stay on the in-game checklist:OnSelected(the event'sGetComponentneeds the game's component cache), theDescribebranches (road spill andWorldToGrid), and whether the service acts on the planner's redraw result.BoundingBoxcheck covers production code.🤖 Generated with Claude Code