Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
ICmpPathfinder.h
Go to the documentation of this file.
1/* Copyright (C) 2021 Wildfire Games.
2 * This file is part of 0 A.D.
3 *
4 * 0 A.D. is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * 0 A.D. is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef INCLUDED_ICMPPATHFINDER
19#define INCLUDED_ICMPPATHFINDER
20
22
25
26#include <map>
27
29class PathGoal;
30
31template<typename T> class Grid;
32
33// Returned by asynchronous workers, used to send messages in the main thread.
34struct WaypointPath;
35
37{
38 PathResult() = default;
40
44};
45
46/**
47 * Pathfinder algorithms.
48 *
49 * There are two different modes: a tile-based pathfinder that works over long distances and
50 * accounts for terrain costs but ignore units, and a 'short' vertex-based pathfinder that
51 * provides precise paths and avoids other units.
52 *
53 * Both use the same concept of a PathGoal: either a point, circle or square.
54 * (If the starting point is inside the goal shape then the path will move outwards
55 * to reach the shape's outline.)
56 *
57 * The output is a list of waypoints.
58 */
60{
61public:
62
63 /**
64 * Get the list of all known passability classes.
65 */
66 virtual void GetPassabilityClasses(std::map<std::string, pass_class_t>& passClasses) const = 0;
67
68 /**
69 * Get the list of passability classes, separating pathfinding classes and others.
70 */
72 std::map<std::string, pass_class_t>& nonPathfindingPassClasses,
73 std::map<std::string, pass_class_t>& pathfindingPassClasses) const = 0;
74
75 /**
76 * Get the tag for a given passability class name.
77 * Logs an error and returns something acceptable if the name is unrecognised.
78 */
79 virtual pass_class_t GetPassabilityClass(const std::string& name) const = 0;
80
81 virtual entity_pos_t GetClearance(pass_class_t passClass) const = 0;
82
83 /**
84 * Get the larger clearance in all passability classes.
85 */
86 virtual entity_pos_t GetMaximumClearance() const = 0;
87
89
90 /**
91 * Get the accumulated dirtiness information since the last time the AI accessed and flushed it.
92 */
95
96 /**
97 * Get a grid representing the distance to the shore of the terrain tile.
98 */
99 virtual Grid<u16> ComputeShoreGrid(bool expandOnWater = false) = 0;
100
101 /**
102 * Asynchronous version of ComputePath.
103 * Request a long path computation, asynchronously.
104 * The result will be sent as CMessagePathResult to 'notify'.
105 * Returns a unique non-zero number, which will match the 'ticket' in the result,
106 * so callers can recognise each individual request they make.
107 */
108 virtual u32 ComputePathAsync(entity_pos_t x0, entity_pos_t z0, const PathGoal& goal, pass_class_t passClass, entity_id_t notify) = 0;
109
110 /*
111 * Request a long-path computation immediately
112 */
113 virtual void ComputePathImmediate(entity_pos_t x0, entity_pos_t z0, const PathGoal& goal, pass_class_t passClass, WaypointPath& ret) const = 0;
114
115 /**
116 * Request a short path computation, asynchronously.
117 * The result will be sent as CMessagePathResult to 'notify'.
118 * Returns a unique non-zero number, which will match the 'ticket' in the result,
119 * so callers can recognise each individual request they make.
120 */
121 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;
122
123 /*
124 * Request a short-path computation immediately.
125 */
126 virtual WaypointPath ComputeShortPathImmediate(const ShortPathRequest& request) const = 0;
127
128 /**
129 * If the debug overlay is enabled, render the path that will computed by ComputePath.
130 */
131 virtual void SetDebugPath(entity_pos_t x0, entity_pos_t z0, const PathGoal& goal, pass_class_t passClass) = 0;
132
133 /**
134 * @return true if the goal is reachable from (x0, z0) for the given passClass, false otherwise.
135 * Warning: this is synchronous, somewhat expensive and not should not be called too liberally.
136 */
137 virtual bool IsGoalReachable(entity_pos_t x0, entity_pos_t z0, const PathGoal& goal, pass_class_t passClass) = 0;
138
139 /**
140 * Check whether the given movement line is valid and doesn't hit any obstructions
141 * or impassable terrain.
142 * Returns true if the movement is okay.
143 */
144 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;
145
146 /**
147 * Check whether a unit placed here is valid and doesn't hit any obstructions
148 * or impassable terrain.
149 * When onlyCenterPoint = true, only check the center tile of the unit
150 * @return ICmpObstruction::FOUNDATION_CHECK_SUCCESS if the placement is okay, else
151 * a value describing the type of failure.
152 */
153 virtual ICmpObstruction::EFoundationCheck CheckUnitPlacement(const IObstructionTestFilter& filter, entity_pos_t x, entity_pos_t z, entity_pos_t r, pass_class_t passClass, bool onlyCenterPoint = false) const = 0;
154
155 /**
156 * Check whether a building placed here is valid and doesn't hit any obstructions
157 * or impassable terrain.
158 * @return ICmpObstruction::FOUNDATION_CHECK_SUCCESS if the placement is okay, else
159 * a value describing the type of failure.
160 */
162
163 /**
164 * Check whether a building placed here is valid and doesn't hit any obstructions
165 * or impassable terrain.
166 * when onlyCenterPoint = true, only check the center tile of the building
167 * @return ICmpObstruction::FOUNDATION_CHECK_SUCCESS if the placement is okay, else
168 * a value describing the type of failure.
169 */
171
172
173 /**
174 * Toggle the storage and rendering of debug info.
175 */
176 virtual void SetDebugOverlay(bool enabled) = 0;
177
178 /**
179 * Toggle the storage and rendering of debug info for the hierarchical pathfinder.
180 */
181 virtual void SetHierDebugOverlay(bool enabled) = 0;
182
183 /**
184 * Finish computing asynchronous path requests and send the CMessagePathResult messages.
185 */
186 virtual void SendRequestedPaths() = 0;
187
188 /**
189 * Tell asynchronous pathfinder threads that they can begin computing paths.
190 */
191 virtual void StartProcessingMoves(bool useMax) = 0;
192
193 /**
194 * Regenerates the grid based on the current obstruction list, if necessary
195 */
196 virtual void UpdateGrid() = 0;
197
198 /**
199 * Returns some stats about the last ComputePath.
200 */
201 virtual void GetDebugData(u32& steps, double& time, Grid<u8>& grid) const = 0;
202
203 /**
204 * Sets up the pathfinder passability overlay in Atlas.
205 */
206 virtual void SetAtlasOverlay(bool enable, pass_class_t passClass = 0) = 0;
207
208 DECLARE_INTERFACE_TYPE(Pathfinder)
209};
210
211#endif // INCLUDED_ICMPPATHFINDER
#define DECLARE_INTERFACE_TYPE(iname)
Definition: Interface.h:23
u16 pass_class_t
Definition: Pathfinding.h:29
A simple fixed-point number class.
Definition: Fixed.h:120
Basic 2D array, intended for storing tile data, plus support for lazy updates by ICmpObstructionManag...
Definition: Grid.h:38
EFoundationCheck
Definition: ICmpObstruction.h:33
Pathfinder algorithms.
Definition: ICmpPathfinder.h:60
virtual void FlushAIPathfinderDirtinessInformation()=0
virtual void SetDebugPath(entity_pos_t x0, entity_pos_t z0, const PathGoal &goal, pass_class_t passClass)=0
If the debug overlay is enabled, render the path that will computed by ComputePath.
virtual ICmpObstruction::EFoundationCheck CheckBuildingPlacement(const IObstructionTestFilter &filter, entity_pos_t x, entity_pos_t z, entity_pos_t a, entity_pos_t w, entity_pos_t h, entity_id_t id, pass_class_t passClass, bool onlyCenterPoint) const =0
Check whether a building placed here is valid and doesn't hit any obstructions or impassable terrain.
virtual void GetDebugData(u32 &steps, double &time, Grid< u8 > &grid) const =0
Returns some stats about the last ComputePath.
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
Check whether the given movement line is valid and doesn't hit any obstructions or impassable terrain...
virtual WaypointPath ComputeShortPathImmediate(const ShortPathRequest &request) const =0
virtual u32 ComputePathAsync(entity_pos_t x0, entity_pos_t z0, const PathGoal &goal, pass_class_t passClass, entity_id_t notify)=0
Asynchronous version of ComputePath.
virtual bool IsGoalReachable(entity_pos_t x0, entity_pos_t z0, const PathGoal &goal, pass_class_t passClass)=0
virtual const GridUpdateInformation & GetAIPathfinderDirtinessInformation() const =0
Get the accumulated dirtiness information since the last time the AI accessed and flushed it.
virtual void SetDebugOverlay(bool enabled)=0
Toggle the storage and rendering of debug info.
virtual entity_pos_t GetMaximumClearance() const =0
Get the larger clearance in all passability classes.
virtual void SetHierDebugOverlay(bool enabled)=0
Toggle the storage and rendering of debug info for the hierarchical pathfinder.
virtual ICmpObstruction::EFoundationCheck CheckBuildingPlacement(const IObstructionTestFilter &filter, entity_pos_t x, entity_pos_t z, entity_pos_t a, entity_pos_t w, entity_pos_t h, entity_id_t id, pass_class_t passClass) const =0
Check whether a building placed here is valid and doesn't hit any obstructions or impassable terrain.
virtual const Grid< NavcellData > & GetPassabilityGrid()=0
virtual void SetAtlasOverlay(bool enable, pass_class_t passClass=0)=0
Sets up the pathfinder passability overlay in Atlas.
virtual void GetPassabilityClasses(std::map< std::string, pass_class_t > &nonPathfindingPassClasses, std::map< std::string, pass_class_t > &pathfindingPassClasses) const =0
Get the list of passability classes, separating pathfinding classes and others.
virtual pass_class_t GetPassabilityClass(const std::string &name) const =0
Get the tag for a given passability class name.
virtual entity_pos_t GetClearance(pass_class_t passClass) const =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, asynchronously.
virtual void SendRequestedPaths()=0
Finish computing asynchronous path requests and send the CMessagePathResult messages.
virtual Grid< u16 > ComputeShoreGrid(bool expandOnWater=false)=0
Get a grid representing the distance to the shore of the terrain tile.
virtual void StartProcessingMoves(bool useMax)=0
Tell asynchronous pathfinder threads that they can begin computing paths.
virtual void UpdateGrid()=0
Regenerates the grid based on the current obstruction list, if necessary.
virtual void GetPassabilityClasses(std::map< std::string, pass_class_t > &passClasses) const =0
Get the list of all known passability classes.
virtual ICmpObstruction::EFoundationCheck CheckUnitPlacement(const IObstructionTestFilter &filter, entity_pos_t x, entity_pos_t z, entity_pos_t r, pass_class_t passClass, bool onlyCenterPoint=false) const =0
Check whether a unit placed here is valid and doesn't hit any obstructions or impassable terrain.
virtual void ComputePathImmediate(entity_pos_t x0, entity_pos_t z0, const PathGoal &goal, pass_class_t passClass, WaypointPath &ret) const =0
Definition: IComponent.h:33
Interface for ICmpObstructionManager Test functions to filter out unwanted shapes.
Definition: ICmpObstructionManager.h:352
Pathfinder goal.
Definition: PathGoal.h:33
u32 entity_id_t
Entity ID type.
Definition: Entity.h:29
Structure holding grid dirtiness informations, for clever updates.
Definition: Grid.h:379
Definition: ICmpPathfinder.h:37
PathResult(u32 t, entity_id_t n, WaypointPath p)
Definition: ICmpPathfinder.h:39
entity_id_t notify
Definition: ICmpPathfinder.h:42
WaypointPath path
Definition: ICmpPathfinder.h:43
PathResult()=default
u32 ticket
Definition: ICmpPathfinder.h:41
Definition: Pathfinding.h:44
Returned path.
Definition: Pathfinding.h:67
uint32_t u32
Definition: types.h:39