18#ifndef INCLUDED_CCMPPATHFINDER_COMMON
19#define INCLUDED_CCMPPATHFINDER_COMMON
56#define PATHFIND_DEBUG 0
58#define PATHFIND_DEBUG 1
114 std::atomic<size_t> m_NextPathToCompute = 0;
116 std::atomic<bool> m_ComputeDone =
true;
120 if (m_Results.size() == m_Requests.size())
123 m_Requests.erase(m_Requests.end() - m_Results.size(), m_Requests.end());
132 size_t n = m_Requests.size();
135 m_NextPathToCompute = 0;
137 m_ComputeDone = n == 0;
141 void Compute(
const CCmpPathfinder& cmpPathfinder,
const U& pathfinder);
153 return "<a:component type='system'/><empty/>";
173 std::map<std::string, pass_class_t>& nonPathfindingPassClasses,
174 std::map<std::string, pass_class_t>& pathfindingPassClasses)
const override;
192 if (passability.m_Clearance > max)
193 max = passability.m_Clearance;
246 template <
typename T>
247 std::vector<T>
GetMovesToProcess(std::vector<T>& requests,
bool useMax =
false,
size_t maxMoves = 0);
249 template <
typename T>
267 void TerrainUpdateHelper(
bool expandPassability =
true,
int itile0 = -1,
int jtile0 = -1,
int itile1 = -1,
int jtile1 = -1);
#define DEFAULT_COMPONENT_ALLOCATOR(cname)
Definition: Component.h:39
std::uint16_t NavcellData
Definition: ICmpObstructionManager.h:37
std::uint16_t pass_class_t
Definition: Pathfinding.h:33
Definition: CCmpPathfinder_Common.h:109
void ClearComputed()
Definition: CCmpPathfinder_Common.h:118
void PrepareForComputation(std::uint16_t max)
Definition: CCmpPathfinder_Common.h:130
std::vector< T > m_Requests
Definition: CCmpPathfinder_Common.h:111
std::vector< PathResult > m_Results
Definition: CCmpPathfinder_Common.h:112
Implementation of ICmpPathfinder.
Definition: CCmpPathfinder_Common.h:65
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 override
Check whether the given movement line is valid and doesn't hit any obstructions or impassable terrain...
Definition: CCmpPathfinder.cpp:993
GridUpdateInformation m_DirtinessInformation
Definition: CCmpPathfinder_Common.h:96
void StartProcessingMoves(bool useMax) override
Tell asynchronous pathfinder threads that they can begin computing paths.
Definition: CCmpPathfinder.cpp:873
void Deserialize(const CParamNode ¶mNode, IDeserializer &deserialize) override
Definition: CCmpPathfinder.cpp:210
void HandleMessage(const CMessage &msg, bool global) override
Definition: CCmpPathfinder.cpp:217
void GetDebugData(std::uint32_t &steps, double &time, Grid< std::uint8_t > &grid) const override
Returns some stats about the last ComputePath.
Definition: CCmpPathfinder.cpp:273
std::uint32_t 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) override
Request a short path computation, asynchronously.
Definition: CCmpPathfinder.cpp:794
void Serialize(ISerializer &serialize) override
Definition: CCmpPathfinder.cpp:205
std::uint32_t ComputePathAsync(entity_pos_t x0, entity_pos_t z0, const PathGoal &goal, pass_class_t passClass, entity_id_t notify) override
Asynchronous version of ComputePath.
Definition: CCmpPathfinder.cpp:786
static std::string GetSchema()
Definition: CCmpPathfinder_Common.h:151
void MinimalTerrainUpdate(int itile0, int jtile0, int itile1, int jtile1)
Updates the terrain-only grid without updating the dirtiness informations.
Definition: CCmpPathfinder.cpp:623
GridUpdateInformation m_AIPathfinderDirtinessInformation
Definition: CCmpPathfinder_Common.h:98
entity_pos_t GetMaximumClearance() const override
Get the larger clearance in all passability classes.
Definition: CCmpPathfinder_Common.h:187
const GridUpdateInformation & GetAIPathfinderDirtinessInformation() const override
Get the accumulated dirtiness information since the last time the AI accessed and flushed it.
Definition: CCmpPathfinder_Common.h:200
void SetDebugOverlay(bool enabled) override
Toggle the storage and rendering of debug info.
Definition: CCmpPathfinder.cpp:262
void GetPassabilityClasses(std::map< std::string, pass_class_t > &passClasses) const override
Get the list of all known passability classes.
Definition: CCmpPathfinder.cpp:305
void TerrainUpdateHelper(bool expandPassability=true, int itile0=-1, int jtile0=-1, int itile1=-1, int jtile1=-1)
Regenerates the terrain-only grid.
Definition: CCmpPathfinder.cpp:628
std::uint32_t m_NextAsyncTicket
Definition: CCmpPathfinder_Common.h:146
std::vector< Future< void > > m_Futures
Definition: CCmpPathfinder_Common.h:106
void UpdateGrid() override
Regenerates the grid based on the current obstruction list, if necessary.
Definition: CCmpPathfinder.cpp:530
void SetDebugPath(entity_pos_t x0, entity_pos_t z0, const PathGoal &goal, pass_class_t passClass) override
If the debug overlay is enabled, render the path that will computed by ComputePath.
Definition: CCmpPathfinder.cpp:257
static void ClassInit(CComponentManager &componentManager)
Definition: CCmpPathfinder_Common.h:67
pass_class_t m_OverlayPassClass
Definition: CCmpPathfinder_Common.h:148
Grid< std::uint16_t > ComputeShoreGrid(bool expandOnWater=false) override
Get a grid representing the distance to the shore of the terrain tile.
Definition: CCmpPathfinder.cpp:413
void SendRequestedPaths() override
Finish computing asynchronous path requests and send the CMessagePathResult messages.
Definition: CCmpPathfinder.cpp:840
void SetHierDebugOverlay(bool enabled) override
Toggle the storage and rendering of debug info for the hierarchical pathfinder.
Definition: CCmpPathfinder.cpp:268
std::vector< PathfinderPassability > m_PassClasses
Definition: CCmpPathfinder_Common.h:83
Grid< NavcellData > * m_TerrainOnlyGrid
Definition: CCmpPathfinder_Common.h:92
void SerializeCommon(S &serialize)
Definition: CCmpPathfinder.cpp:197
void SetAtlasOverlay(bool enable, pass_class_t passClass=0) override
Sets up the pathfinder passability overlay in Atlas.
Definition: CCmpPathfinder.cpp:278
void RenderSubmit(SceneCollector &collector)
Definition: CCmpPathfinder.cpp:251
ICmpObstruction::EFoundationCheck CheckUnitPlacement(const IObstructionTestFilter &filter, entity_pos_t x, entity_pos_t z, entity_pos_t r, pass_class_t passClass, bool onlyCenterPoint) const override
Check whether a unit placed here is valid and doesn't hit any obstructions or impassable terrain.
Definition: CCmpPathfinder.cpp:1009
const PathfinderPassability * GetPassabilityFromMask(pass_class_t passClass) const
Definition: CCmpPathfinder.cpp:321
std::unique_ptr< LongPathfinder > m_LongPathfinder
Definition: CCmpPathfinder_Common.h:103
std::uint16_t m_MaxSameTurnMoves
Definition: CCmpPathfinder_Common.h:84
pass_class_t GetPassabilityClass(const std::string &name) const override
Get the tag for a given passability class name.
Definition: CCmpPathfinder.cpp:293
entity_pos_t GetClearance(pass_class_t passClass) const override
Definition: CCmpPathfinder_Common.h:178
void ComputePathImmediate(entity_pos_t x0, entity_pos_t z0, const PathGoal &goal, pass_class_t passClass, WaypointPath &ret) const override
Definition: CCmpPathfinder.cpp:803
std::map< std::string, pass_class_t > m_PassClassMasks
Definition: CCmpPathfinder_Common.h:82
std::vector< T > GetMovesToProcess(std::vector< T > &requests, bool useMax=false, size_t maxMoves=0)
std::uint16_t m_GridSize
Definition: CCmpPathfinder_Common.h:90
PathRequests< ShortPathRequest > m_ShortPathRequests
Definition: CCmpPathfinder_Common.h:144
bool IsGoalReachable(entity_pos_t x0, entity_pos_t z0, const PathGoal &goal, pass_class_t passClass) override
Definition: CCmpPathfinder.cpp:898
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 override
Check whether a building placed here is valid and doesn't hit any obstructions or impassable terrain.
Definition: CCmpPathfinder.cpp:1035
void FlushAIPathfinderDirtinessInformation() override
Definition: CCmpPathfinder_Common.h:205
void Init(const CParamNode ¶mNode) override
Definition: CCmpPathfinder.cpp:95
~CCmpPathfinder()
Definition: CCmpPathfinder.cpp:148
std::unique_ptr< HierarchicalPathfinder > m_PathfinderHier
Definition: CCmpPathfinder_Common.h:102
void PushRequestsToWorkers(std::vector< T > &from)
std::vector< CFixedVector2D > DistributeAround(std::vector< entity_id_t > units, entity_pos_t x, entity_pos_t z) const override
Distribute units around a point, returning a list of positions.
Definition: CCmpPathfinder.cpp:910
std::vector< VertexPathfinder > m_VertexPathfinders
Definition: CCmpPathfinder_Common.h:101
bool m_TerrainDirty
Definition: CCmpPathfinder_Common.h:99
void Deinit() override
Definition: CCmpPathfinder.cpp:150
TerrainTextureOverlay * m_AtlasOverlay
Definition: CCmpPathfinder_Common.h:149
Grid< NavcellData > * m_Grid
Definition: CCmpPathfinder_Common.h:91
WaypointPath ComputeShortPathImmediate(const ShortPathRequest &request) const override
Definition: CCmpPathfinder.cpp:808
PathRequests< LongPathRequest > m_LongPathRequests
Definition: CCmpPathfinder_Common.h:143
const Grid< NavcellData > & GetPassabilityGrid() override
Definition: CCmpPathfinder.cpp:332
Definition: ComponentManager.h:46
void SubscribeToMessageType(MessageTypeId mtid)
Subscribe the current component type to the given message type.
Definition: ComponentManager.cpp:576
A simple fixed-point number class.
Definition: Fixed.h:129
static CFixed Zero()
Definition: Fixed.h:140
An entity initialisation parameter node.
Definition: ParamNode.h:153
Corresponds to std::future.
Definition: Future.h:224
Basic 2D array, intended for storing tile data, plus support for lazy updates by ICmpObstructionManag...
Definition: Grid.h:46
Definition: HierarchicalPathfinder.h:71
EFoundationCheck
Definition: ICmpObstruction.h:42
Pathfinder algorithms.
Definition: ICmpPathfinder.h:63
Deserialization interface; see serialization overview.
Definition: IDeserializer.h:40
Interface for ICmpObstructionManager Test functions to filter out unwanted shapes.
Definition: ICmpObstructionManager.h:357
Serialization interface; see serialization overview.
Definition: ISerializer.h:126
Definition: LongPathfinder.h:170
Pathfinder goal.
Definition: PathGoal.h:34
Definition: Pathfinding.h:219
fixed m_Clearance
Definition: Pathfinding.h:230
This interface accepts renderable objects.
Definition: Scene.h:90
Base class for texture-based terrain overlays, with an arbitrary number of texels per terrain tile,...
Definition: TerrainOverlay.h:202
Definition: VertexPathfinder.h:88
constexpr entity_pos_t CLEARANCE_EXTENSION_RADIUS
To make sure the long-range pathfinder is more strict than the short-range one, we need to slightly o...
Definition: Pathfinding.h:159
Definition: ShaderDefines.cpp:43
#define T(string_literal)
Definition: secure_crt.cpp:81
std::uint32_t entity_id_t
Entity ID type.
Definition: Entity.h:29
Definition: Pathfinding.h:46
Returned path.
Definition: Pathfinding.h:69