Changeset View
Changeset View
Standalone View
Standalone View
source/simulation2/components/CCmpPathfinder.cpp
Show All 28 Lines | |||||
#include "ps/Profile.h" | #include "ps/Profile.h" | ||||
#include "ps/XML/Xeromyces.h" | #include "ps/XML/Xeromyces.h" | ||||
#include "renderer/Scene.h" | #include "renderer/Scene.h" | ||||
#include "simulation2/MessageTypes.h" | #include "simulation2/MessageTypes.h" | ||||
#include "simulation2/components/ICmpObstruction.h" | #include "simulation2/components/ICmpObstruction.h" | ||||
#include "simulation2/components/ICmpObstructionManager.h" | #include "simulation2/components/ICmpObstructionManager.h" | ||||
#include "simulation2/components/ICmpTerrain.h" | #include "simulation2/components/ICmpTerrain.h" | ||||
#include "simulation2/components/ICmpWaterManager.h" | #include "simulation2/components/ICmpWaterManager.h" | ||||
#include "simulation2/helpers/HierarchicalPathfinder.h" | |||||
#include "simulation2/helpers/LongPathfinder.h" | |||||
#include "simulation2/helpers/Rasterize.h" | #include "simulation2/helpers/Rasterize.h" | ||||
#include "simulation2/helpers/VertexPathfinder.h" | #include "simulation2/helpers/VertexPathfinder.h" | ||||
#include "simulation2/serialization/SerializeTemplates.h" | #include "simulation2/serialization/SerializeTemplates.h" | ||||
REGISTER_COMPONENT_TYPE(Pathfinder) | REGISTER_COMPONENT_TYPE(Pathfinder) | ||||
void CCmpPathfinder::Init(const CParamNode& UNUSED(paramNode)) | void CCmpPathfinder::Init(const CParamNode& UNUSED(paramNode)) | ||||
{ | { | ||||
m_MapSize = 0; | m_MapSize = 0; | ||||
m_Grid = NULL; | m_Grid = NULL; | ||||
m_TerrainOnlyGrid = NULL; | m_TerrainOnlyGrid = NULL; | ||||
FlushAIPathfinderDirtinessInformation(); | FlushAIPathfinderDirtinessInformation(); | ||||
m_NextAsyncTicket = 1; | m_NextAsyncTicket = 1; | ||||
m_AtlasOverlay = NULL; | m_AtlasOverlay = NULL; | ||||
m_SameTurnMovesCount = 0; | m_SameTurnMovesCount = 0; | ||||
m_VertexPathfinder = std::unique_ptr<VertexPathfinder>(new VertexPathfinder(m_MapSize, m_TerrainOnlyGrid)); | m_VertexPathfinder = std::unique_ptr<VertexPathfinder>(new VertexPathfinder(m_MapSize, m_TerrainOnlyGrid)); | ||||
m_LongPathfinder = std::unique_ptr<LongPathfinder>(new LongPathfinder()); | |||||
m_PathfinderHier = std::unique_ptr<HierarchicalPathfinder>(new HierarchicalPathfinder()); | |||||
// Register Relax NG validator | // Register Relax NG validator | ||||
CXeromyces::AddValidator(g_VFS, "pathfinder", "simulation/data/pathfinder.rng"); | CXeromyces::AddValidator(g_VFS, "pathfinder", "simulation/data/pathfinder.rng"); | ||||
// Since this is used as a system component (not loaded from an entity template), | // Since this is used as a system component (not loaded from an entity template), | ||||
// we can't use the real paramNode (it won't get handled properly when deserializing), | // we can't use the real paramNode (it won't get handled properly when deserializing), | ||||
// so load the data from a special XML file. | // so load the data from a special XML file. | ||||
CParamNode externalParamNode; | CParamNode externalParamNode; | ||||
▲ Show 20 Lines • Show All 117 Lines • ▼ Show 20 Lines | case MT_TurnStart: | ||||
m_SameTurnMovesCount = 0; | m_SameTurnMovesCount = 0; | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
void CCmpPathfinder::RenderSubmit(SceneCollector& collector) | void CCmpPathfinder::RenderSubmit(SceneCollector& collector) | ||||
{ | { | ||||
m_VertexPathfinder->RenderSubmit(collector); | m_VertexPathfinder->RenderSubmit(collector); | ||||
m_LongPathfinder.HierarchicalRenderSubmit(collector); | m_PathfinderHier->RenderSubmit(collector); | ||||
} | } | ||||
void CCmpPathfinder::SetDebugPath(entity_pos_t x0, entity_pos_t z0, const PathGoal& goal, pass_class_t passClass) | void CCmpPathfinder::SetDebugPath(entity_pos_t x0, entity_pos_t z0, const PathGoal& goal, pass_class_t passClass) | ||||
{ | { | ||||
m_LongPathfinder.SetDebugPath(x0, z0, goal, passClass); | m_LongPathfinder->SetDebugPath(*m_PathfinderHier, x0, z0, goal, passClass); | ||||
} | } | ||||
void CCmpPathfinder::SetDebugOverlay(bool enabled) | void CCmpPathfinder::SetDebugOverlay(bool enabled) | ||||
{ | { | ||||
m_VertexPathfinder->SetDebugOverlay(enabled); | m_VertexPathfinder->SetDebugOverlay(enabled); | ||||
m_LongPathfinder.SetDebugOverlay(enabled); | m_LongPathfinder->SetDebugOverlay(enabled); | ||||
} | } | ||||
void CCmpPathfinder::SetHierDebugOverlay(bool enabled) | void CCmpPathfinder::SetHierDebugOverlay(bool enabled) | ||||
{ | { | ||||
m_LongPathfinder.SetHierDebugOverlay(enabled, &GetSimContext()); | m_PathfinderHier->SetDebugOverlay(enabled, &GetSimContext()); | ||||
} | } | ||||
void CCmpPathfinder::GetDebugData(u32& steps, double& time, Grid<u8>& grid) const | void CCmpPathfinder::GetDebugData(u32& steps, double& time, Grid<u8>& grid) const | ||||
{ | { | ||||
m_LongPathfinder.GetDebugData(steps, time, grid); | m_LongPathfinder->GetDebugData(steps, time, grid); | ||||
} | } | ||||
void CCmpPathfinder::SetAtlasOverlay(bool enable, pass_class_t passClass) | void CCmpPathfinder::SetAtlasOverlay(bool enable, pass_class_t passClass) | ||||
{ | { | ||||
if (enable) | if (enable) | ||||
{ | { | ||||
if (!m_AtlasOverlay) | if (!m_AtlasOverlay) | ||||
m_AtlasOverlay = new AtlasOverlay(this, passClass); | m_AtlasOverlay = new AtlasOverlay(this, passClass); | ||||
▲ Show 20 Lines • Show All 308 Lines • ▼ Show 20 Lines | for (u16 j = 0; j < m_DirtinessInformation.dirtinessGrid.m_H; ++j) | ||||
for (u16 i = 0; i < m_DirtinessInformation.dirtinessGrid.m_W; ++i) | for (u16 i = 0; i < m_DirtinessInformation.dirtinessGrid.m_W; ++i) | ||||
if (m_DirtinessInformation.dirtinessGrid.get(i, j) == 1) | if (m_DirtinessInformation.dirtinessGrid.get(i, j) == 1) | ||||
m_Grid->set(i, j, m_TerrainOnlyGrid->get(i, j)); | m_Grid->set(i, j, m_TerrainOnlyGrid->get(i, j)); | ||||
} | } | ||||
// Add obstructions onto the grid | // Add obstructions onto the grid | ||||
cmpObstructionManager->Rasterize(*m_Grid, m_PassClasses, m_DirtinessInformation.globallyDirty); | cmpObstructionManager->Rasterize(*m_Grid, m_PassClasses, m_DirtinessInformation.globallyDirty); | ||||
// Update the long-range pathfinder | // Update the long-range and hierarchical pathfinders. | ||||
if (m_DirtinessInformation.globallyDirty) | if (m_DirtinessInformation.globallyDirty) | ||||
{ | { | ||||
std::map<std::string, pass_class_t> nonPathfindingPassClasses, pathfindingPassClasses; | std::map<std::string, pass_class_t> nonPathfindingPassClasses, pathfindingPassClasses; | ||||
GetPassabilityClasses(nonPathfindingPassClasses, pathfindingPassClasses); | GetPassabilityClasses(nonPathfindingPassClasses, pathfindingPassClasses); | ||||
m_LongPathfinder.Reload(m_Grid, nonPathfindingPassClasses, pathfindingPassClasses); | m_LongPathfinder->Reload(m_Grid); | ||||
m_PathfinderHier->Recompute(m_Grid, nonPathfindingPassClasses, pathfindingPassClasses); | |||||
} | } | ||||
else | else | ||||
m_LongPathfinder.Update(m_Grid, m_DirtinessInformation.dirtinessGrid); | { | ||||
m_LongPathfinder->Update(m_Grid); | |||||
m_PathfinderHier->Update(m_Grid, m_DirtinessInformation.dirtinessGrid); | |||||
} | |||||
// Remember the necessary updates that the AI pathfinder will have to perform as well | // Remember the necessary updates that the AI pathfinder will have to perform as well | ||||
m_AIPathfinderDirtinessInformation.MergeAndClear(m_DirtinessInformation); | m_AIPathfinderDirtinessInformation.MergeAndClear(m_DirtinessInformation); | ||||
} | } | ||||
void CCmpPathfinder::MinimalTerrainUpdate() | void CCmpPathfinder::MinimalTerrainUpdate() | ||||
{ | { | ||||
TerrainUpdateHelper(false); | TerrainUpdateHelper(false); | ||||
▲ Show 20 Lines • Show All 136 Lines • ▼ Show 20 Lines | for (PathfinderPassability& passability : m_PassClasses) | ||||
int clearance = (passability.m_Clearance / Pathfinding::NAVCELL_SIZE).ToInt_RoundToInfinity(); | int clearance = (passability.m_Clearance / Pathfinding::NAVCELL_SIZE).ToInt_RoundToInfinity(); | ||||
ExpandImpassableCells(*m_TerrainOnlyGrid, clearance, passability.m_Mask); | ExpandImpassableCells(*m_TerrainOnlyGrid, clearance, passability.m_Mask); | ||||
} | } | ||||
} | } | ||||
////////////////////////////////////////////////////////// | ////////////////////////////////////////////////////////// | ||||
void CCmpPathfinder::ComputePath(entity_pos_t x0, entity_pos_t z0, const PathGoal& goal, pass_class_t passClass, WaypointPath& ret) const | |||||
{ | |||||
m_LongPathfinder->ComputePath(*m_PathfinderHier, x0, z0, goal, passClass, ret); | |||||
} | |||||
u32 CCmpPathfinder::ComputePathAsync(entity_pos_t x0, entity_pos_t z0, const PathGoal& goal, pass_class_t passClass, entity_id_t notify) | u32 CCmpPathfinder::ComputePathAsync(entity_pos_t x0, entity_pos_t z0, const PathGoal& goal, pass_class_t passClass, entity_id_t notify) | ||||
{ | { | ||||
AsyncLongPathRequest req = { m_NextAsyncTicket++, x0, z0, goal, passClass, notify }; | AsyncLongPathRequest req = { m_NextAsyncTicket++, x0, z0, goal, passClass, notify }; | ||||
m_AsyncLongPathRequests.push_back(req); | m_AsyncLongPathRequests.push_back(req); | ||||
return req.ticket; | return req.ticket; | ||||
} | } | ||||
u32 CCmpPathfinder::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) | u32 CCmpPathfinder::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) | ||||
▲ Show 20 Lines • Show All 211 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator