1
0
forked from 0ad/0ad
Commit Graph

11 Commits

Author SHA1 Message Date
f1467d10fd Make pathfinder debug rendering thread-safe.
Also cleans up the jump point cache const-correctness.

Differential Revision: https://code.wildfiregames.com/D3966
This was SVN commit r25452.
2021-05-17 09:38:24 +00:00
bb49fbe793 Further reduce usage of TERRAIN_TILE_SIZE in non-terrain components
TERRAIN_TILE_SIZE is now only used in relevant places in the simulation.
This also makes it mostly possible to use CFixed in constexpr contexts.

Refs #5566

Differential Revision: https://code.wildfiregames.com/D3078
This was SVN commit r25360.
2021-05-02 17:40:00 +00:00
70ec7812de Improve UnitMotion behaviour when working around obstructions.
This improves behaviour when units need to go around a concave obstacle.
They would tend to clump inside the 'dead-end' before realising they
needed to go around. This was rather easy to trigger on Acropolis. See
included Unit Motion Integration Test.

The cause is the logic that removed the next long waypoint when
obstructed. While that behaviour is desirable, removing too many
waypoints means the unit tries to short-path, using a small domain
range, to a goal that's impassable, meaning they go as close as they can
in Euclidian distance, i.e. towards the dead end.

This changes that behaviour by only deleting waypoints within a certain
distance from the entity, scaling with search-space range. It's tricky
to find a good compromise between performance and behaviour here, but
the values I've picked seem OK.

However, the fact that the entity would ultimately remove all waypoints
and thus trigger a full path recomputation was actually a feature,
inherited from D2754 / 892f97743b. This diff therefore handles that
explicitly, doing so on a more regular basis to behave better overall.

As a further cleanup, "m_FailedPathComputations" is incremented in
HandleObstructedMove, as it is quite possible to never increment it in
PathResult despite not getting actionnable paths. This thus renames it
to m_FailedMovements, and uses the opportunity to clean up PathResult(),
by only having one path for both short and long-range paths. Further,
PathResult now does not immediately request new paths, leaving that to
Move(), to avoid requesting transient paths that aren't actionnable.
This also makes it possible to revert 9e41ff39fc. It requires increasing
the MAX_FAILED variable, or more units get stuck as they reach the max
more often.

The search-space expansion is slightly slowed, and with a little more
delay, as a performance optimisation. From testing, this doesn't impact
real movement much as units short paths tend to be invalidated by the
next turn, as other units move, anyways.

Clarify comment around the vertex-pathfinder search-space bounds hack,
and ensure it isn't used for the very worst cases of units being stuck,
as it could be a pessimisation then.

Finally, this explicits a 2011 hack where if the long-pathfinder fails
to return a valid path the goal's center is used directly. This happens
when the goal is unreachable to the long-pathfinder, which may be
because it is actually unreachable or because only the short-pathfinder
can reach it. In those situations, the hack allows a last-ditch attempt
at reaching it before failing to move entirely. Performance wise, this
is faster overall for actually unreachable goals, since it skips all the
intermediate steps. For reachable goals, it might be occasionally
slower, but that case is quite rare (certainly rarer than unreachable
goals).

Reported By: Angen
Fixes #5795

Differential Revision: https://code.wildfiregames.com/D3203
This was SVN commit r24429.
2020-12-19 10:45:07 +00:00
6b2b071ad5 Move LOS to a los helper header and cleanup Grid.h includes.
Changing Grid.h should recompile faster, as it is now included in fewer
TUs.

Differential Revision: https://code.wildfiregames.com/D2784
This was SVN commit r23774.
2020-06-14 20:39:03 +00:00
7985ea4b8e Removes usages of duplication of Clamp function in simulation and atlas. Refs D1763.
This was SVN commit r22927.
2019-09-18 15:02:36 +00:00
32e8ed51aa UnitMotion - Send messages to UnitAI when obstructed, to allow stopping early when walking and avoiding pathfinding lag.
As reported by #5521, Ordering units to walk to a point in a forest can
lag terribly, as units will end up computing long short paths in the
forest, which can result in `ComputeShortPath` calls that individually
take upwards of 80ms.

This can be alleviated by allowing units to stop a bit earlier. A23
handled this in UnitMotion directly, but it's better to handle this in
UnitAI to avoid surprises and to make it customisable on a per-state
level.

This diff further speeds up using the short pathfinder by starting with
a smaller search range, limiting the max-range more and moving the range
slightly towards the goal.

This also refactors UM sending messages to UnitAI so that we may in the
future push more information (in particular, the entity_id that a unit
was obstructed by could be interesting for COMBAT).

This doesn't fix the possibility of lag, but it reduces its occurrence
to levels that should be similar to A23 and thus acceptable enough.

Tested By: Freagarach
Fixes #5521

Differential Revision: https://code.wildfiregames.com/D2105
This was SVN commit r22526.
2019-07-22 18:07:24 +00:00
7e2512a739 Fix undefined behaviour introduced in 5c642611c4
5c642611c4 introduces undefined behaviour: for vertices that are part of
non-AA squares, the value of "quadOutward" is undefined. This fixes that
by again setting it to QUADRANT_ALL by default, as it was pre
5c642611c4. This led to OOS.

Reviewed By: elexis
Fixes #5508

Differential Revision: https://code.wildfiregames.com/D2082
This was SVN commit r22483.
2019-07-15 18:05:03 +00:00
5c642611c4 Vertex pathfinder - fixes to quadrant optimisation to ensure units don't take detours around obstructions.
Compute the outward quadrants once and for all instead of setting them
dynamically, because there is no reason why we should always arrive from
the same quadrant as the first time we see a vertex.
Don't consider quadrants for the start-vertex, because of the edge
expansion (which can put us in illegal quadrants)

These result in (much) better paths, the tradeoff being that we now look
at some more vertices.

Fixes #5476

Differential Revision: https://code.wildfiregames.com/D1908
This was SVN commit r22473.
2019-07-14 10:19:18 +00:00
e06285279a Vertex pathfinder: add the domain edges back to improve behaviour (reverts c42160ec10)
This adds back the "domain" edges to the short/vertex pathfinder.
Without these edges, units could use points far away from the path
search that they inaccurately thought were reachable, leading to some
pathing oddities in rare cases.

Reviewed By: temple
Differential Revision: https://code.wildfiregames.com/D443
This was SVN commit r22465.
2019-07-13 16:01:10 +00:00
12f893b1e3 Remove 'Async' from short/long path requests names
Having Async in the name was not really informative and made it awkward
to reuse for non-async code.

Reviewed By: Kuba386
Differential Revision: https://code.wildfiregames.com/D1854
This was SVN commit r22305.
2019-05-26 13:47:41 +00:00
809f297707 Move the Vertex Pathfinder to its own helper class
The vertex pathfinder was implemented directly in CCmpPathfinder,
instead of being a separate helper like the hierarchical pathfinder or
the long pathfinder.

This moves it to its own helper VertexPathfinder, which gets us ready
for D14 and pathfinder threading. Some struct definitions need to be
moved around.

Differential Revision: https://code.wildfiregames.com/D1855
This was SVN commit r22253.
2019-05-08 11:53:02 +00:00