Pyrogenesis  trunk
ICmpPathfinder.h
Go to the documentation of this file.
1 /* Copyright (C) 2017 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 
26 
27 #include "maths/FixedVector2D.h"
28 
29 #include <map>
30 #include <vector>
31 
33 
34 template<typename T> class Grid;
35 
36 /**
37  * Pathfinder algorithms.
38  *
39  * There are two different modes: a tile-based pathfinder that works over long distances and
40  * accounts for terrain costs but ignore units, and a 'short' vertex-based pathfinder that
41  * provides precise paths and avoids other units.
42  *
43  * Both use the same concept of a PathGoal: either a point, circle or square.
44  * (If the starting point is inside the goal shape then the path will move outwards
45  * to reach the shape's outline.)
46  *
47  * The output is a list of waypoints.
48  */
49 class ICmpPathfinder : public IComponent
50 {
51 public:
52 
53  /**
54  * Get the list of all known passability classes.
55  */
56  virtual void GetPassabilityClasses(std::map<std::string, pass_class_t>& passClasses) const = 0;
57 
58  /**
59  * Get the list of passability classes, separating pathfinding classes and others.
60  */
61  virtual void GetPassabilityClasses(
62  std::map<std::string, pass_class_t>& nonPathfindingPassClasses,
63  std::map<std::string, pass_class_t>& pathfindingPassClasses) const = 0;
64 
65  /**
66  * Get the tag for a given passability class name.
67  * Logs an error and returns something acceptable if the name is unrecognised.
68  */
69  virtual pass_class_t GetPassabilityClass(const std::string& name) const = 0;
70 
71  virtual entity_pos_t GetClearance(pass_class_t passClass) const = 0;
72 
73  /**
74  * Get the larger clearance in all passability classes.
75  */
76  virtual entity_pos_t GetMaximumClearance() const = 0;
77 
78  virtual const Grid<NavcellData>& GetPassabilityGrid() = 0;
79 
80  /**
81  * Passes the lazily-stored dirtiness data collected from
82  * the obstruction manager during the previous grid update.
83  */
84  virtual const GridUpdateInformation& GetDirtinessData() const = 0;
85 
86  /**
87  * Get a grid representing the distance to the shore of the terrain tile.
88  */
89  virtual Grid<u16> ComputeShoreGrid(bool expandOnWater = false) = 0;
90 
91  /**
92  * Compute a tile-based path from the given point to the goal, and return the set of waypoints.
93  * The waypoints correspond to the centers of horizontally/vertically adjacent tiles
94  * along the path.
95  */
96  virtual void ComputePath(entity_pos_t x0, entity_pos_t z0, const PathGoal& goal, pass_class_t passClass, WaypointPath& ret) = 0;
97 
98  /**
99  * Asynchronous version of ComputePath.
100  * The result will be sent as CMessagePathResult to 'notify'.
101  * Returns a unique non-zero number, which will match the 'ticket' in the result,
102  * so callers can recognise each individual request they make.
103  */
104  virtual u32 ComputePathAsync(entity_pos_t x0, entity_pos_t z0, const PathGoal& goal, pass_class_t passClass, entity_id_t notify) = 0;
105 
106  /**
107  * If the debug overlay is enabled, render the path that will computed by ComputePath.
108  */
109  virtual void SetDebugPath(entity_pos_t x0, entity_pos_t z0, const PathGoal& goal, pass_class_t passClass) = 0;
110 
111  /**
112  * Compute a precise path from the given point to the goal, and return the set of waypoints.
113  * The path is based on the full set of obstructions that pass the filter, such that
114  * a unit of clearance 'clearance' will be able to follow the path with no collisions.
115  * The path is restricted to a box of radius 'range' from the starting point.
116  */
117  virtual void ComputeShortPath(const IObstructionTestFilter& filter, entity_pos_t x0, entity_pos_t z0, entity_pos_t clearance, entity_pos_t range, const PathGoal& goal, pass_class_t passClass, WaypointPath& ret) = 0;
118 
119  /**
120  * Asynchronous version of ComputeShortPath (using ControlGroupObstructionFilter).
121  * The result will be sent as CMessagePathResult to 'notify'.
122  * Returns a unique non-zero number, which will match the 'ticket' in the result,
123  * so callers can recognise each individual request they make.
124  */
125  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;
126 
127  /**
128  * Check whether the given movement line is valid and doesn't hit any obstructions
129  * or impassable terrain.
130  * Returns true if the movement is okay.
131  */
132  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;
133 
134  /**
135  * Check whether a unit placed here is valid and doesn't hit any obstructions
136  * or impassable terrain.
137  * When onlyCenterPoint = true, only check the center tile of the unit
138  * @return ICmpObstruction::FOUNDATION_CHECK_SUCCESS if the placement is okay, else
139  * a value describing the type of failure.
140  */
141  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;
142 
143  /**
144  * Check whether a building placed here is valid and doesn't hit any obstructions
145  * or impassable terrain.
146  * @return ICmpObstruction::FOUNDATION_CHECK_SUCCESS if the placement is okay, else
147  * a value describing the type of failure.
148  */
150 
151  /**
152  * Check whether a building placed here is valid and doesn't hit any obstructions
153  * or impassable terrain.
154  * when onlyCenterPoint = true, only check the center tile of the building
155  * @return ICmpObstruction::FOUNDATION_CHECK_SUCCESS if the placement is okay, else
156  * a value describing the type of failure.
157  */
159 
160 
161  /**
162  * Toggle the storage and rendering of debug info.
163  */
164  virtual void SetDebugOverlay(bool enabled) = 0;
165 
166  /**
167  * Toggle the storage and rendering of debug info for the hierarchical pathfinder.
168  */
169  virtual void SetHierDebugOverlay(bool enabled) = 0;
170 
171  /**
172  * Finish computing asynchronous path requests and send the CMessagePathResult messages.
173  */
174  virtual void FinishAsyncRequests() = 0;
175 
176  /**
177  * Process moves during the same turn they were created in to improve responsiveness.
178  */
179  virtual void ProcessSameTurnMoves() = 0;
180 
181  /**
182  * Regenerates the grid based on the current obstruction list, if necessary
183  */
184  virtual void UpdateGrid() = 0;
185 
186  /**
187  * Returns some stats about the last ComputePath.
188  */
189  virtual void GetDebugData(u32& steps, double& time, Grid<u8>& grid) const = 0;
190 
191  /**
192  * Sets up the pathfinder passability overlay in Atlas.
193  */
194  virtual void SetAtlasOverlay(bool enable, pass_class_t passClass = 0) = 0;
195 
196  DECLARE_INTERFACE_TYPE(Pathfinder)
197 };
198 
199 #endif // INCLUDED_ICMPPATHFINDER
Definition: IComponent.h:33
A simple fixed-point number class.
Definition: Fixed.h:115
Interface for ICmpObstructionManager Test functions to filter out unwanted shapes.
Definition: ICmpObstructionManager.h:282
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.
u16 pass_class_t
Definition: Pathfinding.h:29
virtual Grid< u16 > ComputeShoreGrid(bool expandOnWater=false)=0
Get a grid representing the distance to the shore of the terrain tile.
virtual pass_class_t GetPassabilityClass(const std::string &name) const =0
Get the tag for a given passability class name.
virtual void SetAtlasOverlay(bool enable, pass_class_t passClass=0)=0
Sets up the pathfinder passability overlay in Atlas.
Returned path.
Definition: Pathfinding.h:40
virtual void ProcessSameTurnMoves()=0
Process moves during the same turn they were created in to improve responsiveness.
virtual void FinishAsyncRequests()=0
Finish computing asynchronous path requests and send the CMessagePathResult messages.
virtual void SetHierDebugOverlay(bool enabled)=0
Toggle the storage and rendering of debug info for the hierarchical pathfinder.
virtual entity_pos_t GetMaximumClearance() const =0
Get the larger clearance in all passability classes.
Pathfinder goal.
Definition: PathGoal.h:32
Structure holding grid dirtiness informations, for clever updates.
Definition: Grid.h:208
Basic 2D array, intended for storing tile data, plus support for lazy updates by ICmpObstructionManag...
Definition: ICmpPathfinder.h:34
EFoundationCheck
Definition: ICmpObstruction.h:33
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&#39;t hit any obstructions or impassable terrain...
Pathfinder algorithms.
Definition: ICmpPathfinder.h:49
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
Asynchronous version of ComputeShortPath (using ControlGroupObstructionFilter).
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.
uint32_t u32
Definition: types.h:39
virtual void ComputePath(entity_pos_t x0, entity_pos_t z0, const PathGoal &goal, pass_class_t passClass, WaypointPath &ret)=0
Compute a tile-based path from the given point to the goal, and return the set of waypoints...
#define DECLARE_INTERFACE_TYPE(iname)
Definition: Interface.h:23
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&#39;t hit any obstructions or impassable terrain...
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&#39;t hit any obstructions or impassable terrain...
virtual const Grid< NavcellData > & GetPassabilityGrid()=0
virtual void ComputeShortPath(const IObstructionTestFilter &filter, entity_pos_t x0, entity_pos_t z0, entity_pos_t clearance, entity_pos_t range, const PathGoal &goal, pass_class_t passClass, WaypointPath &ret)=0
Compute a precise path from the given point to the goal, and return the set of waypoints.
virtual entity_pos_t GetClearance(pass_class_t passClass) const =0
virtual void GetPassabilityClasses(std::map< std::string, pass_class_t > &passClasses) const =0
Get the list of all known passability classes.
virtual void UpdateGrid()=0
Regenerates the grid based on the current obstruction list, if necessary.
virtual void SetDebugOverlay(bool enabled)=0
Toggle the storage and rendering of debug info.
virtual void GetDebugData(u32 &steps, double &time, Grid< u8 > &grid) const =0
Returns some stats about the last ComputePath.
u32 entity_id_t
Entity ID type.
Definition: Entity.h:23
virtual const GridUpdateInformation & GetDirtinessData() const =0
Passes the lazily-stored dirtiness data collected from the obstruction manager during the previous gr...