Skip to content

Pathfinding cost history - #1839

Closed
joaoks wants to merge 5 commits into
SFTtech:masterfrom
joaoks:pathfinding-cost-history
Closed

joaoks wants to merge 5 commits into
SFTtech:masterfrom
joaoks:pathfinding-cost-history

Conversation

@joaoks

@joaoks joaoks commented Nov 16, 2026

Copy link
Copy Markdown

path: record the history of cost field changes

Cost changes overwrote the previous values, so earlier states of the
pathfinding grid could not be looked up, e.g. to roll back changes in
multiplayer matches.

CostField now records every cell change in a curve, separate from the
current values to keep cost lookups fast. Changes are recorded at the
time passed to set_cost/set_costs. A change erases the later recorded
changes of its cell, so the latest recorded costs always match the
current ones.

curve::Array needs its size at compile time, but cost fields are
sized at runtime. A new curve::Vector container therefore tracks each
element over time like Array, with the number of elements set on
construction. Its set_last always makes the new value the one
returned at t, and never erases the default keyframe at -inf.

The curve needs an event loop, which is passed down through Game, Map,
Grid and Sector.

New tests cover the Vector container, the cost history, portal
creation and path requests. The portal and path tests run on
hand-made maps and are checked against a flood fill of each map.

Fixes #1680.

joaoks and others added 5 commits November 16, 2026 10:31
Array curves need their size at compile time, which does not fit
containers sized at runtime, e.g. the pathfinder's cost fields.

Vector tracks each element over time like Array, but takes its default
values, and thereby its number of elements, on construction. Changing
the number of elements over time is not supported.

Unlike BaseCurve and Array, set_last appends the new keyframe after
the remaining same-time keyframe, so the new value is the one returned
at t, and never erases the default keyframe at -inf.

Part of #1677.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Cost changes overwrote the previous values, so earlier states of the
grid could not be restored, e.g. to roll back changes.

CostField now records every cell change in a curve::Vector at the time
passed to set_cost/set_costs, separate from the current values to keep
lookups fast. A change erases the later recorded changes of its cell,
so the latest recorded costs always match the current ones.

The curve needs an event loop, which is passed down through Grid,
Sector and Map.

Fixes #1680.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Portal creation, portal connections and path requests had no automated
tests; only the interactive demo exercised them.

The portals test checks every portal of two small maps, including
split sector regions, single-cell portals, blocked edges and portals
that are only connected through a winding corridor.

The pathfinder test requests paths from several starts to every cell
and checks the result against a flood fill of the map: reachable
targets must be found with valid waypoints, unreachable and
impassable ones must not, and targets outside the grid must be out of
bounds.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@joaoks joaoks closed this Nov 16, 2026
@joaoks
joaoks deleted the pathfinding-cost-history branch November 16, 2026 15:55
@joaoks
joaoks restored the pathfinding-cost-history branch November 16, 2026 15:56
@joaoks
joaoks deleted the pathfinding-cost-history branch November 16, 2026 15:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Record history of cost changes in pathfinder

1 participant