Skip to content
This repository was archived by the owner on Jan 5, 2024. It is now read-only.

Pathfinding Improvements - #444

Merged
garethyr merged 48 commits into
developmentfrom
experimental-pathfinding-changes
Nov 24, 2022
Merged

garethyr merged 48 commits into
developmentfrom
experimental-pathfinding-changes

Conversation

@Causeless

@Causeless Causeless commented Nov 2, 2022 •

Copy link
Copy Markdown
  • If a node has cost in any direction, that cost becomes spread a little out and averaged out. This encourages the AI to avoid hard surfaces, for example when jetpacking around. Likely needs some Lua script enhancements to get the full advantage, however.
  • Actors now have a much higher default diggability, even without digging tools. This means that actors will be far less likely to avoid soft debris (like body parts), as they'll be able to push though it.
  • Use a separate pathfinder per team. This allows us to do team-specific pathfinding (avoiding doors etc) without requiring that we constantly update the pathing node costs for each actor.
  • Improvements to brain placement detection. Now the brain path is no longer blocked by light debris or it's own team's doors.
  • Added change detection to the pathfinder. If the change to the node costs isn't significant (below some sentinel value), we ignore them. This allows us to skip doing the team-specific pathing updates in this case, and also means we don't need to Reset() MicroPather's cache unless things have changed
  • No longer do intermittent two-minute resets of the the entire pathfinding grid. This seems unnecessary and expensive, the partial updating should handle it fine.
  • Fixed issue where the AI woudn't pathfind around enemy doors (Actor AI refuses to pathfind around enemy doors #396)
  • Throttled AI to only update every other frame by default. Will likely tweak this value as I further improve and look at the AI, but this halves the time spent in AI script and seems to have no significant regressions in AI behaviour.

@garethyr garethyr left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work!
Various little cleanups and changes to do

Comment thread Entities/Actor.h Outdated
Comment thread Entities/Actor.cpp Outdated
Comment thread System/PathFinder.cpp Outdated
Comment thread System/PathFinder.h Outdated
Comment thread System/PathFinder.h
Comment thread Entities/Scene.cpp Outdated
Comment thread Entities/Scene.cpp
@@ -2891,7 +2905,25 @@ void Scene::ResetPathFinding()

void Scene::UpdatePathFinding()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assuming it's not too unwieldy, I'd rather have the method comment explain what's going on in a bit more detail, rather than all these inline comments.

I.e. explain that the method updates the shared pathfinder and, if there are changes, updates the individual ones, ensuring that doors for each team are ignored.

@Causeless Causeless Nov 5, 2022 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case I'd prefer that they're inline. Externally, the only thing that a user of the function needs to know is that this recalculates outdated pathing data - how it does that in this case (using several pathfinders and swapping around door materials and all that crap) are entirely internal implementation details that could change. The function contract is that this recalculates outdated pathing data, the details of how shouldn't matter.

Furthermore, having the comments be next to the actual lines of code means that if or when things do change, it's easier to remember to update them.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm, I don't really agree. Inline comments are valuable to explain

  1. Why a seemingly odd decision was made
  2. What some piece of unclear, complicated (or math-heavy) code is doing

If you need them for stuff other than that, things need to be renamed and fiddled with to make the code clearer, imo.

For the most part, these comments don't really do either of those 2 things. They're not as useless as some dancomments that would just, for example, say something like:

// Override door material for team
g_MovableMan.OverrideMaterialDoors(true, team);

But they're also mostly explaining pretty clear things.
I guess the only part of it that's at all non-obvious is the shared pathfinder being NoTeam, and I'd rather that be more of a note that the shared pathfinder uses NoTeam, instead of basically saying "RecalculateAreaCosts updates the pathfinder". Also, I think the shared pathfinder using NoTeam is explained in other places anyway, right?

@Causeless Causeless Nov 6, 2022 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that the overriding material doors being used for team-specific pathing is not obvious. I didn't understand it initially, so that's why I'm being explicit.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's an easy solve though isn't it - this method exists solely for this purpose, so you can just rename it to be more clear.
Heck, I don't even think the method really belongs in movableman, it's just there cause that's where Data put it. It'd be perfectly reasonable as a private Scene method imo - EraseOrRedrawDoorTerrainLayerForTeamPathfindinging or something like that.

Comment thread Entities/Scene.cpp Outdated
Comment thread Entities/Scene.cpp Outdated
Comment thread Entities/Scene.cpp Outdated
@garethyr
garethyr requested a review from MaximDude November 3, 2022 18:57
Comment thread System/Constants.h Outdated
Comment thread Entities/Scene.cpp Outdated
@Causeless Causeless linked an issue Nov 8, 2022 that may be closed by this pull request
Causeless and others added 10 commits November 11, 2022 16:06
Changing max to std::max in AHuman
Tweaking formatting, whitespace, etc. in areas that were touched by existing changes
Fixing up a few method comments
Killing a few unnecessary inline comments, and tweaking others
Other stuff
garethyr
garethyr previously approved these changes Nov 17, 2022

@garethyr garethyr left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work!

@garethyr
garethyr force-pushed the experimental-pathfinding-changes branch from f198582 to 9d124fe Compare November 17, 2022 05:36

@MaximDude MaximDude left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting junk for the most part

Comment thread Entities/Actor.cpp Outdated
Comment thread Entities/Actor.h
Comment thread Entities/Actor.h Outdated
Comment thread Entities/Scene.cpp Outdated
Comment thread Entities/Scene.h Outdated
Comment thread System/PathFinder.cpp Outdated
Comment thread System/PathFinder.cpp Outdated
Comment thread System/PathFinder.cpp Outdated
Comment thread Entities/Actor.cpp Outdated
Comment thread Managers/MovableMan.h Outdated
Causeless and others added 4 commits November 23, 2022 20:12
Made Scene::GetPathfinder private and moved its definition into header
Made AIUpdateInterval lua property readwrite
Fiddled with SettingsMan pathfinder grid node size stuff
Fixed AIDeltaTime stuff in timerman
Fixed region in controller
Made magic number 8 a static constexpr in pathfinder, reorganized and made protected methods private
The comment doesn't make sense as a method remark, it's an internal detail, not related to actually using the method.
Also tweaked the member variable comment  for m_pPathFidners so it has a bit more detail
@garethyr
garethyr requested a review from MaximDude November 24, 2022 22:33
@garethyr
garethyr merged commit f6571ff into development Nov 24, 2022
@garethyr
garethyr deleted the experimental-pathfinding-changes branch November 24, 2022 22:34
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Actor AI refuses to pathfind around enemy doors

3 participants