Page MenuHomeWildfire Games

Update the pathfinder grid before computing paths 'in-between' turns.
ClosedPublic

Authored by wraitii on Nov 5 2020, 11:55 AM.

Details

Summary

As preparation for D14, D1918 started computing paths at the end of a turn and not at the beginning of a new one.
However, this changed the relative position of UpdateGrid() to be "before start-of-turn computation" to after.

This makes it possible, since D1918, to compute paths with a dirty pathfinder grid (since it's been modified, but will be updated on the start of the next turn). Deserialized games (i.e. rejoins) don't have this dirty grid since they recompute it from existing obstruction data.

The solution is simply to update the grid at the end of a turn, before computing paths. Since obstructions still can't change between turns, this is good to go.

For safety, subscrite to MT_Create and UpdateGrid(), but this ought to be called by the changing terrain at game start anyways.
Also clean up pathfinder subscriptions.

Test Plan

Analyse the flow of the code and notice that there was a bug before in case of a rejoin.

Diff Detail

Repository
rP 0 A.D. Public Repository
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

wraitii created this revision.Nov 5 2020, 11:55 AM
wraitii edited the test plan for this revision. (Show Details)Nov 5 2020, 12:05 PM

Successful build - Chance fights ever on the side of the prudent.

builderr-release-macos.txt
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: ../../../binaries/system/libsimulation2.a(precompiled.o) has no symbols

Link to build: https://jenkins.wildfiregames.com/job/macos-differential/1732/display/redirect

wraitii requested review of this revision.Nov 5 2020, 12:42 PM
wraitii added a comment.EditedNov 6 2020, 2:05 PM

Careful readers might notice that UpdateGrid() is called on the beginning of a turn since rP16751 (aka the new pathfinder commit). Before that, it was called on any path computation. This means that the Process move commands for formations (group proxy) calls are now taking place on a possibly out-dated obstruction map. This is arguably buggy too.

Edit: unfortunately it also happens to be rather slow (300µs per call) in my profiling... I'm not certain we want to add this.

wraitii updated this revision to Diff 13759.Nov 6 2020, 2:59 PM

Update, cleanly update the grid at game init.

Vulcan added a comment.Nov 6 2020, 3:09 PM

Successful build - Chance fights ever on the side of the prudent.

builderr-debug-macos.txt
../../../source/simulation2/scripting/JSInterface_Simulation.cpp:155:4: warning: suggest braces around initialization of subobject [-Wmissing-braces]
                        CFixedVector2D(-halfSize.X, -halfSize.Y),
                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 warning generated.
builderr-release-macos.txt
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: ../../../binaries/system/libnetwork.a(precompiled.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: ../../../binaries/system/liblobby.a(precompiled.o) has no symbols
../../../source/simulation2/scripting/JSInterface_Simulation.cpp:155:4: warning: suggest braces around initialization of subobject [-Wmissing-braces]
                        CFixedVector2D(-halfSize.X, -halfSize.Y),
                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 warning generated.
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: ../../../binaries/system/libsimulation2.a(precompiled.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: ../../../binaries/system/libengine.a(precompiled.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: ../../../binaries/system/libgraphics.a(precompiled.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: ../../../binaries/system/libatlas.a(precompiled.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: ../../../binaries/system/libgui.a(precompiled.o) has no symbols

Link to build: https://jenkins.wildfiregames.com/job/macos-differential/1756/display/redirect

How it behaves in atlas?

wraitii added a comment.EditedNov 6 2020, 7:32 PM

How it behaves in atlas?

Ought to make no difference. The change is only an OOS fix, by itself pathfinding worked before and works now.

wraitii added inline comments.Nov 7 2020, 12:03 PM
binaries/data/mods/public/simulation/helpers/InitGame.js
76 ↗(On Diff #13759)

I've verified this to be required, though on most map the SetPassabilityCircular call in LoadMapSettings makes it redundant.

This revision was not accepted when it landed; it landed in state Needs Review.Nov 8 2020, 9:58 AM
This revision was automatically updated to reflect the committed changes.