Commit Graph

95 Commits

Author SHA1 Message Date
teinarss
4a1e4f3e16 Use expression body syntax 2021-03-07 13:00:52 +00:00
Paul Chote
5a7dc385a3 Remove obsolete LocomotorInfo caching. 2020-10-18 18:19:56 +02:00
teinarss
27f1a7ab27 Use out var syntax 2020-08-19 18:11:07 +01:00
teinarss
19b02875c7 Use Tuple syntax 2020-08-15 10:37:10 +01:00
Andre Mohren
006a87692a Removed unused imports. 2020-07-28 18:22:51 +02:00
reaperrr
55e85bd9ca Save Mobile look-up in BasePathSearch
By casting to OccupiesSpace and then
looking up Info.LocomotorInfo directly.
2020-06-02 20:08:34 +02:00
abcdefg30
23b3c237b7 Update the year numbers in all license headers to 2020 2020-01-05 17:00:34 +00:00
RoosterDragon
04912ea996 Expose a setting for Weighted A*
Replace Constants.CellCost and Constants.DiagonalCellCost with a dynamically calculated value based on the lowest cost terrain to traverse. Using a fixed value meant the pathfinder heuristics would be incorrect.

In the four default mods, the minimum cost is in fact 100, not 125. This increase would essentially allow the pathfinder to return suboptimal paths up to 25% longer in the worst case, but it would be quicker to do so.

This is exactly what Weighted A* does - overestimate the heuristic by some factor in order to speed up the search by checking fewer routes. This makes the heuristic inadmissible and it may now return suboptimal paths, but their worst case length is bounded by the weight. A weight of 125% will never produce paths more than 25% longer than the shortest, optimal, path.

We set the default weight to 25% to effectively maintain the existing, suboptimal, behaviour due to the choice of the old constant - in future it may prove a useful tuning knob for performance.
2019-11-15 13:05:41 +01:00
tovl
4a609bbee8 Allow units to give way when path is blocked by oncoming unit. 2019-09-15 17:51:34 +01:00
Tomase
98602cb1cb Change impassable terrain to short.max 2019-08-10 17:34:11 +02:00
teinarss
cc84daacea Added cache for cell cost and blocking 2019-07-26 15:54:22 +02:00
teinarss
2ddf9fa826 Using Locomotor instead of Info for pathfinding 2019-07-26 15:54:22 +02:00
Paul Chote
ebf2ce32c0 Make sure braces for multi-line statements are on their own lines. 2019-06-08 19:26:53 +02:00
Paul Chote
ab4a7e3558 Replace System.Drawing primitives with our own. 2019-03-04 18:26:42 +00:00
abcdefg30
cadbd0d9ab Change the year number in all cs headers from 2018 to 2019 2019-01-26 23:15:21 +01:00
Andre Mohren
b1a44086a0 Removed unused using directives. 2018-11-17 17:23:22 +00:00
reaperrr
81343926b6 Split Locomotor trait from Mobile
Add GrantConditionOn*Layer traits

This allows to
- drop some booleans from Locomotor
- drop a good part of the subterranean- and jumpjet-specific code/hacks from Mobile
- grant more than 1 condition per layer type (via multiple traits)
- easily add more traits of this kind for other layers
2018-05-03 10:49:21 +02:00
Arular101
8a60918841 Update copyright notice year to 2018 2018-01-17 00:47:34 +01:00
rob-v
fb1d8d780f Fix Service Depot Rally point path finding (+rename ignoredActor) 2017-05-06 19:49:40 +02:00
Paul Chote
38ea7dbc5a Fix units climbing tunnel faces. 2017-01-29 18:58:33 +00:00
Paul Chote
2bd5a392d1 Add plumbing for custom movement layers. 2017-01-29 18:58:33 +00:00
Taryn Hill
43317e0f5d Update copyright notice year to 2017 2016-12-31 23:46:13 -06:00
Paul Chote
32eb98c17d Remove legacy A* visualisation. 2016-08-26 16:55:46 +01:00
Paul Chote
e71225496b Clarify GPL version. 2016-02-21 16:30:48 +00:00
Paul Chote
b396965fd9 Update licence header year. 2016-02-21 16:27:31 +00:00
RoosterDragon
8e89a6a696 Simplify names, remove unused usings, remove redundant casts. 2016-01-17 21:35:36 +00:00
RoosterDragon
b0619a3e25 Added comments in performance sensitive code. 2015-12-13 16:24:54 +00:00
Pavel Penev
bb3aea338a Rename enum TileShape to MapGridType 2015-10-26 00:41:21 +02:00
Pavel Penev
642468ce0c Add MapGrid class
MapGrid is a mod Manifest field which includes (and thus makes redundant) TileSize, TileShape, SubCells info and MaximumTerrainHeight.
2015-09-27 04:14:43 +03:00
RoosterDragon
519be4374c Fixed pooling of layers used for pathfinding.
The previous implementation:
- Was failing to dispose of pooled layers.
- Was using a finalizer to allow undisposed layers to be reused.

This means all pooled layers are kept alive indefinitely until the map changes. If the finalizer is slow for any reason then the pathfiinder will allocate new layers when the pool runs out. Since these new layers are eventually stuffed back into the pool when the finalizer does run, this can theoretically leak unbounded memory until the pool goes out of scope. In practice it would leak tens of megabytes.

The new implementation ensures layers are disposed and pooled correctly to allow proper memory reuse. It also introduces some safeguards against memory leaks:
- A cap is set on the number of pooled layers. If more concurrent layers are needed than this, then the excess layers will not be pooled but instead be allowed to be garbage collected.
- No finalizer. An implementation that fails to call dispose simply allows the layer to be garbage collected instead.
2015-09-16 21:25:46 +01:00
RoosterDragon
ac55c5bf09 Fix pathfinding using PriorityQueue incorrectly.
By providing a comparer that could change over time (as estimated costs on the graph were updated), this meant the priority queue could have its heap property invalidated and thus not maintain a correct ordering. Instead we store elements into the queue with their estimations at the time. This preserves the heap property and thus ensures the queue returns properly ordered results, although it may contain out of date estimations.

This also improves performance. The fixed comparer need not perform expensive lookups into the graph, but can instead use the readily available value. This speeds up adds and removes on the queue significantly.
2015-09-01 17:29:36 +01:00
RoosterDragon
77923a27c1 Tweak IPathSearch to avoid exposing the OpenQueue directly. 2015-09-01 17:29:36 +01:00
RoosterDragon
774992c246 Cache only unit paths in the pathfinder.
The path caching works on the assumption that the time saved from reusing a cached path outweights the cost of caching it in the first place.

For unit paths, this assumption holds. For path searchs, we spend more time caching them then we save when we get to reuse these cached paths. This is because they are reused less often, and calculating their key is more expensive in comparison.
2015-09-01 17:29:35 +01:00
RoosterDragon
76303e9699 In PathGraph.GetConnections, return a List of neighbors directly, rather than a LinkedList typed an IEnumerable.
The caller can enumerate the list more efficiently without the IEnumerable indirection, and the reduced memory allocation is marginally faster than allocating a linked list and several nodes.
2015-08-31 20:45:31 +01:00
RoosterDragon
7d44eb953e Reduce size of GraphConnection for allocation efficiency. 2015-08-31 20:45:29 +01:00
RoosterDragon
ac1658c9ce Refactor movement cost method to avoid repeated terrain information lookups.
As the world tileset is fixed, the pathfinder can look up the terrain information for that tileset on creation. This is implemented by the WorldMovementInfo struct. When calculating node costs, this allows the pathfinder to avoid having to repeat this expensive dictionary lookup on every node.
2015-08-31 20:43:18 +01:00
Oliver Brakmann
1e7da8514a Merge pull request #8735 from reaperrr/safe-pf-changes
Minor pathfinder-related changes (preparation for mobile refactor)
2015-07-22 14:42:52 +02:00
reaperrr
711ec0c600 Minor pathfinder changes 2015-07-22 06:36:00 +02:00
David Jiménez
787609d51e Improved the performance and intelligence of resource harvesting by
refactoring the Harvesters' pathfinding. Now they in first place assess
which is the closest resource inside their search area and then a path is
calculated

Changed the way harvesters find resources by always trying to find the
closest resource to their refinery.

Changed the strategy of finding to find resources in Annulus.
2015-07-22 02:31:26 +02:00
reaperrr
0ef5312931 Minor cosmetic cleanups for Harvester and BasePathSearch 2015-07-12 23:36:59 +02:00
Matthias Mailänder
7447e0bf93 rename WRange to WDist 2015-07-09 10:55:38 +02:00
David Jiménez
044b51742f Remove plumbing for trait unit tests. 2015-05-01 16:24:14 +12:00
David Jiménez
6d96a43341 Fixes #7955. Improves pathfinder performance a bit. 2015-04-15 23:43:14 +02:00
David Jiménez
ea32c20450 Changed the harvester heuristic so that now takes into account the distance from the initial search location. This makes harvesters somewhat more "intelligent" and gather nearer resources. Also solved several regressions introduced in the recent changes in the Pathfinder 2015-03-12 12:28:34 +01:00
David Jiménez
54ae572303 - Introduced Unit Testing capabilities to the PathFinder trait and algorithm.
Introduced also a small Unit test project to prove it.

- Separated caching capabilities from PathFinder class to increase cohesion and maintainability.
Refactored the pathfinding algorithm by extracting methods based on responsibilities like
calculating costs and reordering functions. These changes should provide a in average a small increase in
pathfinding performance and maintainability.

- Optimized the pathfinder algorithm to reuse calculations like the
MovementCost and heuristics.

- Introduced base classes, IPathSearch and IPriorityQueue interfaces,
and restructured code to ease readability and testability

- Renamed the PathFinder related classes to more appropriate names. Made the
traits rely on the interface IPathfinder instead of concrete PathFinder
implementation.

- Massive performance improvements

- Solved error with harvesters' Heuristic

- Updated the heuristic to ease redability and adjustability. D can be
adjusted to offer best paths by decreasing and more performance by
increasing it

- Refactored the CellLayer<CellInfo> creation in its own Singleton class

- Extracted the graph abstraction onto an IGraph interface, making the
Pathfinder agnostic to the definition of world and terrain. This
abstraction can help in the future to be able to cache graphs for similar
classes and their costs, speeding up the pathfinder and being able to feed
the A* algorithm with different types of graphs like Hierarchical graphs
2015-03-03 20:11:11 +01:00