Page MenuHomeWildfire Games

Long range pathfinder cleanup/speedup
ClosedPublic

Authored by wraitii on Jan 21 2017, 10:46 AM.

Details

Summary

I was looking at the long-range pathfinder, hoping to see where the inefficiencies lied. I've posted my thoughts on the forum, but there are at least two things I believe we should do ASAP, and this diff does:

  • Remove ACCEPT_DIAGONAL_GAPS stuff, since we do not and never will (barring a pathfinder rewrite which would make it irrelevant anyways).
  • Since MakeGoalReachable returns a Point goal, we can simplify/Optimise OnTheWay considerably.
  • Reuse the PASSABLE macro everywhere
Test Plan

Validate that pathfinding still works I guess? This is relatively safe.

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.Jan 21 2017, 10:46 AM
Vulcan added a subscriber: Vulcan.Jan 21 2017, 12:43 PM

Build is green

Updating workspaces.
Build (release)...
Build (debug)...
Running debug tests...
Running cxxtest tests (302 tests)..............................................................................................................................................................................................................................................................................................................OK!

http://jw:8080/job/phabricator/217/ for more details.

wraitii updated this revision to Diff 300.Jan 21 2017, 4:34 PM
wraitii edited the summary of this revision. (Show Details)

Forgot some macro cleanup.

Build is green

Updating workspaces.
Build (release)...
Build (debug)...
Running debug tests...
Running cxxtest tests (302 tests)..............................................................................................................................................................................................................................................................................................................OK!

http://jw:8080/job/phabricator/218/ for more details.

Itms requested changes to this revision.Jan 22 2017, 1:19 PM
Itms added a subscriber: Itms.

That looks nice but I'm just suggesting a small change so your new ENSURE is ensured by design. Didn't test yet.

source/simulation2/helpers/LongPathfinder.cpp
746 ↗(On Diff #300)

Instead of doing that, I think it would be nicer to change the PathfinderState struct so it only has iGoal and jGoal and no actual PathGoal. That way you ensure state.goal doesn't get changed to a non-point one somewhere else.

809 ↗(On Diff #300)

Extra space

814 ↗(On Diff #300)

Extra space

824 ↗(On Diff #300)

Extra space

829 ↗(On Diff #300)

Extra space

853 ↗(On Diff #300)

No need for extra spaces either, even if they look nice here :P

This revision now requires changes to proceed.Jan 22 2017, 1:19 PM
wraitii added inline comments.Jan 22 2017, 1:58 PM
source/simulation2/helpers/LongPathfinder.cpp
746 ↗(On Diff #300)

Sure, I'll actually do both because this also ensures early-catastrophic-fail if someone tries to change MakeGoalReachable to return something besides a point goal.
(what I like to call "self-tested design" :P)

853 ↗(On Diff #300)

I seem to have failed my regex :P

wraitii updated this revision to Diff 365.Jan 27 2017, 1:47 PM
wraitii edited edge metadata.

I actually didn't change the state having the goal because we rely on calling PathGoal functions in a bunch of places and changing that would make it far uglier at the moment and I'm feeling too lazy to fix it properly for now. It should be done when we switch to the JPS cache, which ought to be done someday.

Build is green

Updating workspaces.
Build (release)...
Build (debug)...
Running debug tests...
Running cxxtest tests (302 tests)..............................................................................................................................................................................................................................................................................................................OK!

http://jw:8080/job/phabricator/254/ for more details.

Itms requested changes to this revision.Mar 8 2017, 12:27 PM

The code looked good but when actually testing the patch, units now have a stupid behavior. Easiest to reproduce is giving a gathering order: the unit won't go there in a straight line but will follow a strange path. It must come from the OnTheWay changes.

This revision now requires changes to proceed.Mar 8 2017, 12:27 PM

Mh, that is rather odd, must have messed something up. Will look into it whenever I start working on patches again.

wraitii updated this revision to Diff 4400.Nov 26 2017, 4:52 PM

Fixes the above issue, there was some weird goal thing in the main function that made it go wrong.

Executing section Default...
Executing section Source...
Executing section JS...

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

Updating workspaces...
Build (release)...
Build (debug)...
Running release tests...
Running cxxtest tests (308 tests)....................................................................................................................................................................................................................................................................................................................OK!
Running debug tests...
Running cxxtest tests (308 tests)....................................................................................................................................................................................................................................................................................................................OK!
Checking XML files...
temple added a subscriber: temple.Nov 27 2017, 9:39 PM

Looks good. Checked a replay for the fun of it and the hashes were identical.

I'd add spaces around all the *, +, -, but I guess that's personal preference.

In HierarchicalPathfinder.h, maybe we could be more explicit with "Updates @p goal to a point goal that's guaranteed...".

	/**
	 * Updates @p goal so that it's guaranteed to be reachable from the navcell
	 * @p i0, @p j0 (which is assumed to be on a passable navcell).
	 *
	 * If the goal is not reachable, it is replaced with a point goal nearest to
	 * the goal center.
	 *
	 * In the case of a non-point reachable goal, it is replaced with a point goal
	 * at the reachable navcell of the goal which is nearest to the starting navcell.
	 */
	void MakeGoalReachable(u16 i0, u16 j0, PathGoal& goal, pass_class_t passClass);
source/simulation2/helpers/LongPathfinder.cpp
757–758 ↗(On Diff #4400)

x before z

Stan added a subscriber: Stan.Nov 27 2017, 9:55 PM

Just smalls conventions nitpicks for when you commit : https://trac.wildfiregames.com/wiki/Coding_Conventions

I think comments should start with caps (484,492), and the conventions above states "As wrapped block comments are extremely unreadable. Always try to keep each line of those below 80 chars (counting tabs as 4 chars)."

elexis added a subscriber: elexis.Nov 27 2017, 11:05 PM

(In case of nitpicking I also wouldn't be opposed to having comments on separate lines, spaces between operators and x && y for x ? y : false where possible)

In HierarchicalPathfinder.h, maybe we could be more explicit with "Updates @p goal to a point goal that's guaranteed...".

Done in D53 where I feel it fits better.

wraitii updated this revision to Diff 4503.Dec 3 2017, 1:06 PM
wraitii changed the visibility from "All Users" to "Public (No Login Required)".

Nits picked.

Vulcan added a comment.Dec 3 2017, 5:43 PM
Executing section Default...
Executing section Source...
Executing section JS...
Vulcan added a comment.Dec 3 2017, 5:54 PM

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

Updating workspaces...
Build (release)...
Build (debug)...
Running release tests...
Running cxxtest tests (308 tests)....................................................................................................................................................................................................................................................................................................................OK!
Running debug tests...
Running cxxtest tests (308 tests)....................................................................................................................................................................................................................................................................................................................OK!
Checking XML files...
temple accepted this revision.Dec 4 2017, 10:13 PM

Thanks for the review temple.

I've checked again that hashes are similar on a 1v1 AI game on a normal map, confirmed correct. Running profiling seemed to show this was very, very slightly faster (by a few µs per call) which is as expected. Committing now.

This revision was automatically updated to reflect the committed changes.