1
0
forked from 0ad/0ad
Commit Graph

48 Commits

Author SHA1 Message Date
41f2ab87ed Fixes macOS warnings after adding final keyword to simulation classes in 3eee3a444d.
Also fixes GLES.

Differential Revision: https://code.wildfiregames.com/D4528
This was SVN commit r26605.
2022-03-07 23:04:11 +00:00
0ebc08b13c Thread the pathfinder computations using the task manager.
The pathfinder computations are run asynchronously (and potentially on
the main thread) in-between simulation turns, thus reducing
pathfinder-related lag considerably in common cases.

To make this most efficient, the number of paths computed during a turn
via MaxSameTurnMoves is reduced from 64 to 20.

This has a hard dependency on the obstruction manager (via the vertex
pathfinder) not being modified in-between simulation turn (or to put it
more generally on the simulation state not changing outside of turn
computation), otherwise results will be non-deterministic and go OOS.
This is currently entirely safe (as in, it indeed does not happen that
the simulation state changes in-between turn), but future work towards
improving simulation sandboxing would be good.

Thanks to Kuba386 for maintaining & improving the patch in 2020
Thanks to everyone who tested the various iterations of this patch.

Fixes #4324

Differential Revision: https://code.wildfiregames.com/D14
This was SVN commit r25657.
2021-06-03 16:21:28 +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
0308c2390a Rework the pathfinder path computation setup for threading.
Essentially reverts D1918 / d592bf9cb6.
Instead of copying path requests to workers, setup the result vector,
then setup an index, and compute 'in-place'.
To send messages, the result vectors are read in order. This makes the
order trivially constant no matter how many workers there are, and the
architecture overall makes it much easier to efficiently paralellise.

Tested by: Langbart, Stan
Differential Revision: https://code.wildfiregames.com/D3849
This was SVN commit r25256.
2021-04-14 07:23:47 +00:00
ad7ac8d595 Fix UpdateComponents logic for pathfinding following d592bf9cb6
Following d592bf9cb6, paths requested at turn N were set-up to be
computed between the end of turn N and the start of turn N+1 (which
would ultimately allow threading this computation), via calls to
'StartProcessingMoves' and 'FetchAsyncResultsAndSendMessages'.

However, the call to UpdateGrid() remained at the start of turn N+1,
between the 'start' and 'fetch' calls. Since all paths are currently
computed on the 'start' call, this means all paths are computed on a
(possibly) dirty pathfinder grid.
In particular, this leads to OOS on rejoin since the rejoiner will
recompute the grid before computing the outstanding paths.

This would also obviously be buggy in a threaded environment, since some
paths might be computed on the fresh and some on the dirty grid.

Finally, MT_TurnStart was sent before the paths were computed, which
might lead to further pathfinder grid changes (not a crashing problem
without threading, but still conceptually odd). The 'fetch' call is thus
moved before it.
This thus fixes d592bf9cb6/D1918, after 92ad6a61fa already fixed a first
issue.

Since the grid is now only updated at the end of a turn, we need to
ensure that it is correct on Turn 0, thus the pathfinder recomputes it
on InitGame.

Refs D14

Reported by: Itms
Fixes #5851

Differential Revision: https://code.wildfiregames.com/D3064
This was SVN commit r24142.
2020-11-08 08:58:19 +00:00
375c319639 Improve ship pickup.
Improve unitAI: don't move if the requester can reach us and we are
close enough. This avoids an issue where ships moved more than necessary
when picking up many units.
Also improve requester UnitAI -> retry pickup if the target entity is
Idle.
Improve unitMotion: periodically recompute paths in "known bad path"
mode to adapt to moving targets.
Expose UnitMotion reachability to scripts and other code.

This adds a test map for some common and some tricky pickup cases, using
triggers.

Based on a patch by: causative
Reviewed By: Freagarach
Fixes #3472

Differential Revision: https://code.wildfiregames.com/D665
This was SVN commit r23925.
2020-08-03 12:02:24 +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
c3ded34cf7 Improves performance of Atlas terrain elevation by updating the only changed terrain.
Reviewed By: Itms
Comments By: Stan
Differential Revision: https://code.wildfiregames.com/D2557
This was SVN commit r23361.
2020-01-10 19:54:35 +00:00
92ad6a61fa Fix OOS introduced by pathfinder threading preparation diff d592bf9cb6
Following d592bf9cb6, paths were computed at the end of turn N, and then
messages were sent at the beginning of turn N+1. However, the path
requests were removed at the end of turn N and so weren't serialised,
and neither were computed paths. This meant rejoiners would OOS when the
game was serialised with pending path results.

To fix this in preparation for threading, the architecture needs to
change slightly so that requests are kept and serialised correctly, and
rejoiners can compute the paths after deserialisation, in order to send
the messages at the beginning of turn N+1.

Fixes #5604

Reported By: elexis
Differential Revision: https://code.wildfiregames.com/D2317
This was SVN commit r22979.
2019-09-23 06:38:16 +00:00
d592bf9cb6 Move path computations to an actual worker to prepare for threading.
This moves the "async" pathfinding computations to a worker, preparing
the architecture for threading.

Tested By: Kuba386, Stan`
Differential Revision: https://code.wildfiregames.com/D1918
This was SVN commit r22902.
2019-09-15 09:27: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
32b2c01c7c Decouple long and hierarchical pathfinders to an extent.
Following 809f297707, this decouples the hierarchical pathfinder and the
long pathfinder. The long pathfinder was the class owning the
hierarchical pathfinder, which didn't particularly make sense and
resulted in some interface awkwardness.

At the moment, the long pathfinder still needs to hierarchical
pathfinder to compute paths (to make sure they are reachable).

Differential Revision: https://code.wildfiregames.com/D1867
This was SVN commit r22278.
2019-05-13 16:58:00 +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
d56692d9e1 Rewrite the pathfinder dirtiness information system.
Remove all hacks while keeping most optimizations in memory management.
This fixes incomplete grid updates that could cause OOS on rejoin, fixes
#4596.

Tested by: elexis, ffffffff
Reviewers: leper, wraitii
Differential Revision: https://code.wildfiregames.com/D675
This was SVN commit r19916.
2017-07-14 10:09:32 +00:00
be1a205f91 Add support for const methods in components and make those that can be const const.
Reviewed By: Itms
Differential Revision: https://code.wildfiregames.com/D75
This was SVN commit r19156.
2017-01-20 02:25:19 +00:00
b18f74da44 Remove trailing whitespace and whitespace in empty lines of source/ except source/third_party/.
This was SVN commit r18987.
2016-11-23 11:18:37 +00:00
5a384f4eaf Fix an OOS on rejoin when a ptolemian lighthouse revealing the shoreline was built prior. Patch by Itms and wraitii, fixes #4277.
Serialize the mapsize in the pathfinder and the reveal shoreline flag in
the range manager.
Reload the rangemanager data after other components have been
deserialized.
Use the SerializeCommon pattern in the pathfinder to avoid code
duplication.
Move the shoreline logic from the Vision component to the range manager.
Remove unused interface mocks from the rangemanager test following
b05879e151.

This was SVN commit r18879.
2016-10-28 15:34:24 +00:00
01603708de Reuse vectors in the short-range pathfinder, making SplitAAEdges much faster and reducing memory fragmentation substantially. Refs #3588
This was SVN commit r18349.
2016-06-09 17:38:59 +00:00
9e35f7d68b The over-rasterization of obstructions introduced in [17161] could in very rare cases lead to an OOS in the passability grid. Fixes #3612.
This was SVN commit r17278.
2015-11-16 22:03:10 +00:00
913545aa41 Mark several CFixedVector2D as const and passed by reference in Geometry and a few other places. Mark some functions (that probably already were) inline.
Also make sure we don't include Geometry.h where it's not necessary.

This was SVN commit r17238.
2015-11-11 20:50:02 +00:00
d60940ac59 Code improvements and style fixes.
This was SVN commit r17095.
2015-10-03 08:27:19 +00:00
128a603287 Use the terrain-only grid for terrain edges in the short pathfinder algorithm. This grid is updated on each terrain change, whereas the passability grid is updated once a turn. This caused OOS on rejoin, fixes #3292.
However, using the terrain-only grid reveals one discrepancy between the
short pathfinder (which uses unit radii) and the long one (which uses
unit clearances). So I implemented the change proposed by sanderd17 in
#3294, which is removing unit radius and using only the pathfinder
clearance. Refs #3294
Now some tweaking has to be done in the templates, so that units get a
passability class suited to their apparent size. In the meantime the
unit motion is quite bugged.

This was SVN commit r16867.
2015-07-18 08:37:49 +00:00
11c9471ad6 Change back the long pathfinder to take into account non-pathfinding classes, but only when reloading, to avoid impacting the performance.
Also make the GetPassabilityClasses functions use references instead of
wild allocations. Use a reference when passing pass classes to the AI
worker.

This was SVN commit r16833.
2015-07-05 19:14:52 +00:00
3018359576 Improve a little bit Atlas performance when modifying terrain elevation.
This was SVN commit r16827.
2015-07-01 19:13:56 +00:00
30e5f032d8 Adapt Atlas to the new pathfinder. Fixes #3298
This was SVN commit r16824.
2015-06-29 19:59:41 +00:00
0b7343dccc Preserve the dirtiness informations of the passability grid at deserialization for proper AI updates.
Refs #3310

This was SVN commit r16814.
2015-06-24 20:15:06 +00:00
1709353e2c Changes the general behavior of non-pathfinding passability classes, in order to make the handling of foundation obstructions less difficult. This will allow the AI to be fixed, as reported in #3295.
Also some cleanup and comments updates.

Refs #3295.

This was SVN commit r16784.
2015-06-17 20:19:53 +00:00
473b282265 Refactor the grid update code. Should give a significant performance boost to the simulation update.
Also fixes some bad code that could lead to hidden bugs.

Fixes #3296, thanks elexis for testing ;)

This was SVN commit r16764.
2015-06-14 19:22:07 +00:00
6581796103 New long-range pathfinder.
Based on Philip's work located at
http://git.wildfiregames.com/gitweb/?p=0ad.git;a=shortlog;h=refs/heads/projects/philip/pathfinder
Includes code by wraitii, sanderd17 and kanetaka.

An updated version of docs/pathfinder.pdf describing the changes in
detail will be committed ASAP.

Running update-workspaces is needed after this change.

Fixes #1756.
Fixes #930, #1259, #2908, #2960, #3097
Refs #1200, #1914, #1942, #2568, #2132, #2563

This was SVN commit r16751.
2015-06-12 18:58:24 +00:00
642500b49e Make the Ptolemaic lighthouse reveal the shore on the entire map.
Fixes #3174

This was SVN commit r16628.
2015-05-06 18:47:02 +00:00
db39d742f0 Fix units falling off the edge of the world.
I guess changes to the map loading sequence caused the TerrainChanged
message to be sent before the map was switched from square to circular
instead of after. The pathfinder didn't notice the switch, so it
continued treating the map as if it were square, allowing units to walk
into the permanent map-corner SOD and vanish, and allowing territories
to expand into the SOD.

Tell the pathfinder explicitly when the map shape changes, so it can
discard its cached data correctly.

This was SVN commit r15277.
2014-06-03 22:35:40 +00:00
1871daab0d Fix pathfinding and territories not being recomputed when water height changes.
This was SVN commit r15227.
2014-05-26 13:45:10 +00:00
041855e547 Allow building walls along the shore. Patch by sanderd17. Fix #1610.
This was SVN commit r13542.
2013-07-07 22:44:47 +00:00
ca92e50048 Adds notification tooltips for building placement, fixes #921.
Tweaks info tooltip borders and padding to improve readability.

This was SVN commit r13191.
2013-02-24 00:12:41 +00:00
ce67dfd333 Rename CELL_SIZE to TERRAIN_TILE_SIZE, to free up the term "cell" for other concepts.
This was SVN commit r10902.
2012-01-12 12:51:10 +00:00
609f1643d5 Fix -Wconversion warnings in simulation code.
Cast to smaller integer types explicitly.
Generally avoid platform-dependent types (size_t) in simulation code.
Use float versions of math.h functions, not double.

This was SVN commit r10017.
2011-08-16 11:18:32 +00:00
f378e2e651 Implements building restrictions (by terrain, territory, category, and distance). See #41. Fixes #804, #287.
Implements build limits. See #687.
Implements autorotation for dock placement.
Fixes unit spawning to consider terrain passability. See #893.
Adds new passability criteria based on distance from shore.
Updates build restrictions on some templates.
Changes unit spawning search to 4 tiles away from foundation.
Changes garrison/training spawn failure to nicer UI notification.

This was SVN commit r9970.
2011-08-06 08:11:05 +00:00
df2e499efc Post code review version - previous commit was pre code review version.
This was SVN commit r9666.
2011-06-26 07:47:03 +00:00
2aedf48304 #788 Eliminate delay in path finding (and therefore moving)
This was SVN commit r9665.
2011-06-26 07:03:08 +00:00
794584ea11 Optimise tile-based pathfinder, particularly for large maps.
This was SVN commit r9000.
2011-02-28 00:35:53 +00:00
b8925fbbc9 # Support AI construction of buildings.
Pass terrain passability data to AI scripts.
Expand pathfinder passability data to 16 bits per tile, to allow more
classes.
Support 16-bit ints in serializer.
Partially support JS typed arrays.
Allow foundations to be placed on top of units (fixes #499).
Stop farms and fishes blocking movement (fixes #534).
Add obstruction flags to allow finer control over what they block.
Associate entity IDs with obstruction shapes, to allow finding colliding
entities.
Support moving to the edge of a target entity with inactive obstruction.
Support foundation entities in AI.
Support playing as non-hele civs.

This was SVN commit r8899.
2011-02-10 16:06:28 +00:00
c3b734775b Simplify component interface: remove explicit context parameter, use GetSimContext() instead.
This was SVN commit r8867.
2011-01-16 14:08:38 +00:00
ab186c2b16 Update UnitMotion logic, to partially simplify it.
Do all pathfinding asynchronously.
Recalculate paths when the target has moved.
Fix vertex pathfinder start point heuristic, to avoid finding
zero-length paths.
When units fail to reach a resource to gather, look for another resource
of the same type.

This was SVN commit r8751.
2010-11-30 12:31:54 +00:00
e13196e7a2 Fix serialization of most components
This was SVN commit r8449.
2010-10-23 19:59:40 +00:00
8a98102195 Fix serialize/deserialize API asymmetry.
Add serialization support to more components.

This was SVN commit r8122.
2010-09-17 17:53:26 +00:00
2e7436434d warning fixes: mostly size_t vs. specialized API type and other type conversion.
added player_id_t typedef and INVALID_PLAYER, use that instead of -1.
also added sanity checks to cpu.cpp to ensure ARCH_* is correct (see
http://www.wildfiregames.com/forum/index.php?showtopic=13327&hl=)
and further predefined macros to arch.h just to be sure.

This was SVN commit r8079.
2010-09-05 09:38:30 +00:00
2b57f4f998 # Initial support for formation movement.
Support asynchronous path queries.
Allow escaping when stuck in impassable terrain tiles.
Split Update message in multiple phases, to cope with ordering
requirements.
Support automatic walk/run animation switching.

This was SVN commit r8058.
2010-09-03 09:55:14 +00:00
188a3cab12 Split pathfinder into multiple files, to make it more manageable.
This was SVN commit r8055.
2010-09-03 09:32:12 +00:00