Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/simulation2/components/CCmpPathfinder_Common.h
Show All 29 Lines | |||||
#include "simulation2/system/Component.h" | #include "simulation2/system/Component.h" | ||||
#include "ICmpPathfinder.h" | #include "ICmpPathfinder.h" | ||||
#include "graphics/Overlay.h" | #include "graphics/Overlay.h" | ||||
#include "graphics/Terrain.h" | #include "graphics/Terrain.h" | ||||
#include "maths/MathUtil.h" | #include "maths/MathUtil.h" | ||||
#include "ps/CLogger.h" | #include "ps/CLogger.h" | ||||
#include "ps/TaskManager.h" | |||||
#include "renderer/TerrainOverlay.h" | #include "renderer/TerrainOverlay.h" | ||||
#include "simulation2/components/ICmpObstructionManager.h" | #include "simulation2/components/ICmpObstructionManager.h" | ||||
#include "simulation2/helpers/Grid.h" | #include "simulation2/helpers/Grid.h" | ||||
#include <vector> | #include <vector> | ||||
class HierarchicalPathfinder; | class HierarchicalPathfinder; | ||||
class LongPathfinder; | class LongPathfinder; | ||||
▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | public: | ||||
// Keep clever updates in memory to avoid memory fragmentation from the grid. | // Keep clever updates in memory to avoid memory fragmentation from the grid. | ||||
// This should be used only in UpdateGrid(), there is no guarantee the data is properly initialized anywhere else. | // This should be used only in UpdateGrid(), there is no guarantee the data is properly initialized anywhere else. | ||||
GridUpdateInformation m_DirtinessInformation; | GridUpdateInformation m_DirtinessInformation; | ||||
// The data from clever updates is stored for the AI manager | // The data from clever updates is stored for the AI manager | ||||
GridUpdateInformation m_AIPathfinderDirtinessInformation; | GridUpdateInformation m_AIPathfinderDirtinessInformation; | ||||
bool m_TerrainDirty; | bool m_TerrainDirty; | ||||
std::unique_ptr<VertexPathfinder> m_VertexPathfinder; | std::vector<VertexPathfinder> m_VertexPathfinders; | ||||
std::unique_ptr<HierarchicalPathfinder> m_PathfinderHier; | std::unique_ptr<HierarchicalPathfinder> m_PathfinderHier; | ||||
std::unique_ptr<LongPathfinder> m_LongPathfinder; | std::unique_ptr<LongPathfinder> m_LongPathfinder; | ||||
// One per live asynchronous path computing task. | |||||
std::vector<Future<void>> m_Futures; | |||||
template<typename T> | template<typename T> | ||||
class PathRequests { | class PathRequests { | ||||
public: | public: | ||||
std::vector<T> m_Requests; | std::vector<T> m_Requests; | ||||
std::vector<PathResult> m_Results; | std::vector<PathResult> m_Results; | ||||
// This is the array index of the next path to compute. | // This is the array index of the next path to compute. | ||||
size_t m_NextPathToCompute = 0; | std::atomic<size_t> m_NextPathToCompute = 0; | ||||
// This is false until all scheduled paths have been computed. | // This is false until all scheduled paths have been computed. | ||||
bool m_ComputeDone = true; | std::atomic<bool> m_ComputeDone = true; | ||||
void ClearComputed() | void ClearComputed() | ||||
{ | { | ||||
if (m_Results.size() == m_Requests.size()) | if (m_Results.size() == m_Requests.size()) | ||||
m_Requests.clear(); | m_Requests.clear(); | ||||
else | else | ||||
m_Requests.erase(m_Requests.end() - m_Results.size(), m_Requests.end()); | m_Requests.erase(m_Requests.end() - m_Results.size(), m_Requests.end()); | ||||
m_Results.clear(); | m_Results.clear(); | ||||
▲ Show 20 Lines • Show All 177 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator