Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/simulation2/components/ICmpPathfinder.h
Show All 27 Lines | |||||
#include <map> | #include <map> | ||||
#include <vector> | #include <vector> | ||||
class IObstructionTestFilter; | class IObstructionTestFilter; | ||||
template<typename T> class Grid; | template<typename T> class Grid; | ||||
// Returned by asynchronous workers, used to send messages in the main thread. | |||||
struct WaypointPath; | |||||
struct PathResult | |||||
{ | |||||
PathResult() = default; | |||||
PathResult(u32 t, entity_id_t n, WaypointPath p) : ticket(t), notify(n), path(p) {}; | |||||
u32 ticket; | |||||
entity_id_t notify; | |||||
WaypointPath path; | |||||
}; | |||||
/** | /** | ||||
* Pathfinder algorithms. | * Pathfinder algorithms. | ||||
* | * | ||||
* There are two different modes: a tile-based pathfinder that works over long distances and | * There are two different modes: a tile-based pathfinder that works over long distances and | ||||
* accounts for terrain costs but ignore units, and a 'short' vertex-based pathfinder that | * accounts for terrain costs but ignore units, and a 'short' vertex-based pathfinder that | ||||
* provides precise paths and avoids other units. | * provides precise paths and avoids other units. | ||||
* | * | ||||
* Both use the same concept of a PathGoal: either a point, circle or square. | * Both use the same concept of a PathGoal: either a point, circle or square. | ||||
Show All 40 Lines | public: | ||||
virtual void FlushAIPathfinderDirtinessInformation() = 0; | virtual void FlushAIPathfinderDirtinessInformation() = 0; | ||||
/** | /** | ||||
* Get a grid representing the distance to the shore of the terrain tile. | * Get a grid representing the distance to the shore of the terrain tile. | ||||
*/ | */ | ||||
virtual Grid<u16> ComputeShoreGrid(bool expandOnWater = false) = 0; | virtual Grid<u16> ComputeShoreGrid(bool expandOnWater = false) = 0; | ||||
/** | /** | ||||
* Compute a tile-based path from the given point to the goal, and return the set of waypoints. | |||||
* The waypoints correspond to the centers of horizontally/vertically adjacent tiles | |||||
* along the path. | |||||
*/ | |||||
virtual void ComputePath(entity_pos_t x0, entity_pos_t z0, const PathGoal& goal, pass_class_t passClass, WaypointPath& ret) const = 0; | |||||
/** | |||||
* Asynchronous version of ComputePath. | * Asynchronous version of ComputePath. | ||||
* Request a long path computation, asynchronously. | |||||
* The result will be sent as CMessagePathResult to 'notify'. | * The result will be sent as CMessagePathResult to 'notify'. | ||||
* Returns a unique non-zero number, which will match the 'ticket' in the result, | * Returns a unique non-zero number, which will match the 'ticket' in the result, | ||||
* so callers can recognise each individual request they make. | * so callers can recognise each individual request they make. | ||||
*/ | */ | ||||
virtual u32 ComputePathAsync(entity_pos_t x0, entity_pos_t z0, const PathGoal& goal, pass_class_t passClass, entity_id_t notify) = 0; | virtual u32 ComputePathAsync(entity_pos_t x0, entity_pos_t z0, const PathGoal& goal, pass_class_t passClass, entity_id_t notify) = 0; | ||||
/** | /* | ||||
* If the debug overlay is enabled, render the path that will computed by ComputePath. | * Request a long-path computation immediately | ||||
*/ | */ | ||||
virtual void SetDebugPath(entity_pos_t x0, entity_pos_t z0, const PathGoal& goal, pass_class_t passClass) = 0; | virtual void ComputePathImmediate(entity_pos_t x0, entity_pos_t z0, const PathGoal& goal, pass_class_t passClass, WaypointPath& ret) const = 0; | ||||
/** | /** | ||||
* Compute a precise path from the given point to the goal, and return the set of waypoints. | * Request a short path computation, asynchronously. | ||||
* The path is based on the full set of obstructions that pass the filter, such that | |||||
* a unit of clearance 'clearance' will be able to follow the path with no collisions. | |||||
* The path is restricted to a box of radius 'range' from the starting point. | |||||
*/ | |||||
virtual WaypointPath ComputeShortPath(const ShortPathRequest& request) const = 0; | |||||
/** | |||||
* Asynchronous version of ComputeShortPath (using ControlGroupObstructionFilter). | |||||
* The result will be sent as CMessagePathResult to 'notify'. | * The result will be sent as CMessagePathResult to 'notify'. | ||||
* Returns a unique non-zero number, which will match the 'ticket' in the result, | * Returns a unique non-zero number, which will match the 'ticket' in the result, | ||||
* so callers can recognise each individual request they make. | * so callers can recognise each individual request they make. | ||||
*/ | */ | ||||
virtual u32 ComputeShortPathAsync(entity_pos_t x0, entity_pos_t z0, entity_pos_t clearance, entity_pos_t range, const PathGoal& goal, pass_class_t passClass, bool avoidMovingUnits, entity_id_t group, entity_id_t notify) = 0; | virtual u32 ComputeShortPathAsync(entity_pos_t x0, entity_pos_t z0, entity_pos_t clearance, entity_pos_t range, const PathGoal& goal, pass_class_t passClass, bool avoidMovingUnits, entity_id_t controller, entity_id_t notify) = 0; | ||||
/* | |||||
* Request a short-path computation immediately. | |||||
*/ | |||||
virtual WaypointPath ComputeShortPathImmediate(const ShortPathRequest& request) const = 0; | |||||
/** | |||||
* If the debug overlay is enabled, render the path that will computed by ComputePath. | |||||
*/ | |||||
virtual void SetDebugPath(entity_pos_t x0, entity_pos_t z0, const PathGoal& goal, pass_class_t passClass) = 0; | |||||
/** | /** | ||||
* Check whether the given movement line is valid and doesn't hit any obstructions | * Check whether the given movement line is valid and doesn't hit any obstructions | ||||
* or impassable terrain. | * or impassable terrain. | ||||
* Returns true if the movement is okay. | * Returns true if the movement is okay. | ||||
*/ | */ | ||||
virtual bool CheckMovement(const IObstructionTestFilter& filter, entity_pos_t x0, entity_pos_t z0, entity_pos_t x1, entity_pos_t z1, entity_pos_t r, pass_class_t passClass) const = 0; | virtual bool CheckMovement(const IObstructionTestFilter& filter, entity_pos_t x0, entity_pos_t z0, entity_pos_t x1, entity_pos_t z1, entity_pos_t r, pass_class_t passClass) const = 0; | ||||
Show All 32 Lines | public: | ||||
/** | /** | ||||
* Toggle the storage and rendering of debug info for the hierarchical pathfinder. | * Toggle the storage and rendering of debug info for the hierarchical pathfinder. | ||||
*/ | */ | ||||
virtual void SetHierDebugOverlay(bool enabled) = 0; | virtual void SetHierDebugOverlay(bool enabled) = 0; | ||||
/** | /** | ||||
* Finish computing asynchronous path requests and send the CMessagePathResult messages. | * Finish computing asynchronous path requests and send the CMessagePathResult messages. | ||||
*/ | */ | ||||
virtual void FinishAsyncRequests() = 0; | virtual void FetchAsyncResultsAndSendMessages() = 0; | ||||
/** | /** | ||||
* Process moves during the same turn they were created in to improve responsiveness. | * Tell asynchronous pathfinder threads that they can begin computing paths. | ||||
*/ | */ | ||||
virtual void ProcessSameTurnMoves() = 0; | virtual void StartProcessingMoves(bool useMax) = 0; | ||||
/** | /** | ||||
* Regenerates the grid based on the current obstruction list, if necessary | * Regenerates the grid based on the current obstruction list, if necessary | ||||
*/ | */ | ||||
virtual void UpdateGrid() = 0; | virtual void UpdateGrid() = 0; | ||||
/** | /** | ||||
* Returns some stats about the last ComputePath. | * Returns some stats about the last ComputePath. | ||||
Show All 12 Lines |
Wildfire Games · Phabricator