18 class AStarContextConfig
21 AStarContextConfig() : m_abstractGraphTraversalMode(PATHFINDER_DO_NOT_TRAVERSE_ABSTRACT_GRAPHS) {}
23 bool CanUseAbstractGraphs()
const;
26 PathFinderAbstractGraphTraversalMode m_abstractGraphTraversalMode;
28 KyArray<CellBox>* m_additionalActiveDataCellBoxes;
31 class AstarNodeIndexInGrid
35 KY_INLINE
KyUInt32 GetNumberOfWordsForNodeIndices(
KyUInt32 numberOfNodes) {
return numberOfNodes; }
37 struct NavGraphToNodeIndices
39 KY_INLINE AStarNodeIndex GetAStarNodeIndex(
NavGraphVertexIdx navGraphVertexIdx)
const {
return GetNodeIndices()[navGraphVertexIdx]; }
40 KY_INLINE
void SetAStarNodeIndex(
NavGraphVertexIdx navGraphVertexIdx, AStarNodeIndex index) { GetNodeIndices()[navGraphVertexIdx] = index; }
42 KY_INLINE AStarNodeIndex* GetNodeIndices()
const {
return (AStarNodeIndex*)((
char*)
this + m_offsetToNodeIndices); }
44 KY_INLINE
bool IsValid()
const {
return m_offsetToNodeIndices !=
KyUInt32MAXVAL; }
48 struct AbstractGraphToNodeIndices
50 KY_INLINE AStarNodeIndex GetAStarNodeIndex(AbstractGraphNodeIdx abstractGraphNodeIdx)
const {
return GetNodeIndices()[abstractGraphNodeIdx]; }
51 KY_INLINE
void SetAStarNodeIndex(AbstractGraphNodeIdx abstractGraphNodeIdx, AStarNodeIndex index) { GetNodeIndices()[abstractGraphNodeIdx] = index; }
53 KY_INLINE AStarNodeIndex* GetNodeIndices()
const {
return (AStarNodeIndex*)((
char*)
this + m_offsetToNodeIndices); }
55 KY_INLINE
bool IsValid()
const {
return m_offsetToNodeIndices !=
KyUInt32MAXVAL; }
59 struct NavFloorToNodeIndices
61 KY_INLINE AStarNodeIndex GetAStarNodeIndex(
NavHalfEdgeIdx navHalfEdgeIdx)
const {
return GetNodeIndices()[navHalfEdgeIdx]; }
62 KY_INLINE
void SetAStarNodeIndex(
NavHalfEdgeIdx navHalfEdgeIdx, AStarNodeIndex index) { GetNodeIndices()[navHalfEdgeIdx] = index; }
64 KY_INLINE AStarNodeIndex* GetNodeIndices()
const {
return (AStarNodeIndex*)((
char*)
this + m_offsetToNodeIndices); }
65 KY_INLINE
bool IsValid()
const {
return m_offsetToNodeIndices !=
KyUInt32MAXVAL; }
70 struct CellPosToNavFloors
72 KY_INLINE
bool IsValid()
const {
return m_offSetToNavFloorToNodeIndices !=
KyUInt32MAXVAL; }
73 KY_INLINE NavFloorToNodeIndices* GetNavFloorToNodeIndices()
const {
return (NavFloorToNodeIndices*)((
char*)
this + m_offSetToNavFloorToNodeIndices); }
75 KyUInt32 m_offSetToNavFloorToNodeIndices;
80 AstarNodeIndexInGrid() : m_numberOfNavGraph(0), m_numberOfAbstractGraph(0), m_navGraphChangeIdx(0), m_abstractGraphChangeIdx(0), m_currentOffsetFromBuffer(0) {}
82 AstarNodeIndexInGrid(WorkingMemory* workingMemory, ActiveData* activeData,
const AStarContextConfig& astarContextConfig) { Init(workingMemory, activeData, astarContextConfig); }
84 void Init(WorkingMemory* workingMemory, ActiveData* activeData,
const AStarContextConfig& astarContextConfig);
86 void ReleaseWorkingMemoryBuffer();
88 KyUInt32 GetAvailableSizeInBytes()
const;
90 bool IsEnoughPlaceForAllocation(
KyUInt32 sizeInBytes);
96 void* AllocateInBufferAndMemsetTo1(
KyUInt32 totalSizeToNewOffSet);
98 AStarNodeIndex* AllocateAstarNodeIndices(
KyUInt32 numberOfEdges);
100 CellPosToNavFloors* AllocateCellPosToNavFloors(
KyUInt32 numberOfCell);
101 NavFloorToNodeIndices* AllocateNavFloorToNodeIndex(
KyUInt32 numberOfFloors);
102 NavGraphToNodeIndices* AllocateNavGraphToNodeIndex(
KyUInt32 numberOfGraphs);
103 AbstractGraphToNodeIndices* AllocateAbstractGraphToNodeIndex(
KyUInt32 numberOfAbstractGraphs);
105 bool IsInside(
const CellPos& cellPos);
106 CellPosToNavFloors* GetCellPosToNavFloors(
const CellPos& cellPos);
108 KyResult GetNavFloorToNodeIndices(ActiveData* activeData,
const NavFloorRawPtr& navFloorRawPtr, NavFloorToNodeIndices*& nodeIndices);
109 KyResult GetNavGraphToNodeIndices(
const NavGraphVertexRawPtr& navGraphVertexRawPtr, NavGraphToNodeIndices*& nodeIndices);
110 KyResult GetAbstractGraphToNodeIndices(
const AbstractGraphNodeRawPtr& abstractGraphNodeRawPtr, AbstractGraphToNodeIndices*& nodeIndices);
112 NavGraphToNodeIndices* GetNavGraphToNodeIndices_Unsafe(
const NavGraphVertexRawPtr& navGraphVertexRawPtr);
113 NavFloorToNodeIndices* GetNavFloorToNodeIndices_Unsafe(
const NavFloorRawPtr& navFloorRawPtr);
114 AbstractGraphToNodeIndices* GetAbstractGraphToNodeIndices_Unsafe(
const AbstractGraphNodeRawPtr& abstractGraphNodeRawPtr);
116 bool IsInitialized()
const {
return m_buffer.IsInitialized(); }
117 bool HasVisitedNavDataChanged(Database* database);
120 NavGraphToNodeIndices* GetNavGraphToNodeIndicesBuffer();
121 AbstractGraphToNodeIndices* GetAbstractGraphToNodeIndicesBuffer();
122 CellPosToNavFloors* GetCellPosToNavFloorsBuffer();
125 WorkingMemContainerBase m_buffer;
135 KyArray<CellBox> m_additionalActiveDataCellBoxes;
138 KY_INLINE
void AstarNodeIndexInGrid::ReleaseWorkingMemoryBuffer() { m_buffer.ReleaseBuffer(); }
140 KY_INLINE
KyUInt32 AstarNodeIndexInGrid::GetAvailableSizeInBytes()
const {
return m_buffer.GetBufferSize() - m_currentOffsetFromBuffer; }
142 KY_INLINE
bool AstarNodeIndexInGrid::IsEnoughPlaceForAllocation(
KyUInt32 sizeInBytes)
144 while (GetAvailableSizeInBytes() < sizeInBytes)
146 if (TryToResize() ==
false)
153 KY_INLINE AStarNodeIndex* AstarNodeIndexInGrid::AllocateAstarNodeIndices(
KyUInt32 numberOfEdges)
155 return (AStarNodeIndex*)AllocateInBufferAndMemsetTo1(
sizeof(
KyUInt32) * GetNumberOfWordsForNodeIndices(numberOfEdges));
158 KY_INLINE AstarNodeIndexInGrid::NavFloorToNodeIndices* AstarNodeIndexInGrid::AllocateNavFloorToNodeIndex(
KyUInt32 numberOfFloors)
160 return (NavFloorToNodeIndices*)AllocateInBufferAndMemsetTo1(
sizeof(NavFloorToNodeIndices) * numberOfFloors);
163 KY_INLINE AstarNodeIndexInGrid::NavGraphToNodeIndices* AstarNodeIndexInGrid::AllocateNavGraphToNodeIndex(
KyUInt32 numberOfGraphs)
165 return (NavGraphToNodeIndices*)AllocateInBufferAndMemsetTo1(
sizeof(NavGraphToNodeIndices) * numberOfGraphs);
168 KY_INLINE AstarNodeIndexInGrid::AbstractGraphToNodeIndices* AstarNodeIndexInGrid::AllocateAbstractGraphToNodeIndex(
KyUInt32 numberOfAbstractGraphs)
170 return (AbstractGraphToNodeIndices*)AllocateInBufferAndMemsetTo1(
sizeof(AbstractGraphToNodeIndices) * numberOfAbstractGraphs);
173 KY_INLINE AstarNodeIndexInGrid::CellPosToNavFloors* AstarNodeIndexInGrid::AllocateCellPosToNavFloors(
KyUInt32 numberOfCell)
175 return (CellPosToNavFloors*)AllocateInBufferAndMemsetTo1(
sizeof(CellPosToNavFloors) * numberOfCell);
179 KY_INLINE AstarNodeIndexInGrid::NavGraphToNodeIndices* AstarNodeIndexInGrid::GetNavGraphToNodeIndicesBuffer()
180 {
return (NavGraphToNodeIndices*)m_buffer.GetBuffer(); }
182 KY_INLINE AstarNodeIndexInGrid::AbstractGraphToNodeIndices* AstarNodeIndexInGrid::GetAbstractGraphToNodeIndicesBuffer()
183 {
return (AbstractGraphToNodeIndices*) (GetNavGraphToNodeIndicesBuffer() + m_numberOfNavGraph); }
185 KY_INLINE AstarNodeIndexInGrid::CellPosToNavFloors* AstarNodeIndexInGrid::GetCellPosToNavFloorsBuffer()
186 {
return (CellPosToNavFloors*) (GetAbstractGraphToNodeIndicesBuffer() + m_numberOfAbstractGraph); }
188 KY_INLINE
bool AstarNodeIndexInGrid::IsInside(
const CellPos& cellPos)
190 if (m_activeDataCellBox.DoesContain(cellPos))
193 for (
KyUInt32 i = 0; i < m_additionalActiveDataCellBoxes.GetCount(); ++i)
194 if (m_additionalActiveDataCellBoxes[i].DoesContain(cellPos))
200 KY_INLINE AstarNodeIndexInGrid::CellPosToNavFloors* AstarNodeIndexInGrid::GetCellPosToNavFloors(
const CellPos& cellPos)
202 CellPosToNavFloors* memoryStartForGrid = GetCellPosToNavFloorsBuffer();
203 if (m_numberOfAbstractGraph == 0 || m_activeDataCellBox.DoesContain(cellPos) ==
true)
204 return memoryStartForGrid + m_activeDataCellBox.GetRowMajorIndex(cellPos);
207 KyUInt32 base = (m_activeDataCellBox.CountX() * m_activeDataCellBox.CountY());
208 for(
KyUInt32 i = 0; i < m_additionalActiveDataCellBoxes.GetCount(); ++i)
210 const CellBox& destCellBox = m_additionalActiveDataCellBoxes[i];
211 if (m_additionalActiveDataCellBoxes[i].DoesContain(cellPos) ==
true)
212 return memoryStartForGrid + base + destCellBox.GetRowMajorIndex(cellPos);
214 base += (destCellBox.CountX() * destCellBox.CountY());
221 KY_INLINE AstarNodeIndexInGrid::NavGraphToNodeIndices* AstarNodeIndexInGrid::GetNavGraphToNodeIndices_Unsafe(
const NavGraphVertexRawPtr& navGraphVertexRawPtr)
223 NavGraphToNodeIndices* memoryStartForGraphs = GetNavGraphToNodeIndicesBuffer();
224 return &memoryStartForGraphs[navGraphVertexRawPtr.GetNavGraph()->m_idxInTheActiveDataBuffer];
227 KY_INLINE AstarNodeIndexInGrid::NavFloorToNodeIndices* AstarNodeIndexInGrid::GetNavFloorToNodeIndices_Unsafe(
const NavFloorRawPtr& navFloorRawPtr)
229 KY_DEBUG_ASSERTN(IsInside(navFloorRawPtr.GetCellPos()), (
"Invalid CellBox"));
231 NavFloor* navFloor = navFloorRawPtr.GetNavFloor();
232 const CellPos& cellPos = navFloor->GetCellPos();
234 CellPosToNavFloors* cellPosToNavFloors = GetCellPosToNavFloors(cellPos);
235 KY_DEBUG_ASSERTN(cellPosToNavFloors->IsValid(), (
"Bad usage of UnSafe function"));
237 NavFloorToNodeIndices& navFloorToNodeIndices = cellPosToNavFloors->GetNavFloorToNodeIndices()[navFloor->GetIndexInCollection()];
238 KY_DEBUG_ASSERTN(navFloorToNodeIndices.IsValid(), (
"Bad usage of UnSafe function"));
240 return &navFloorToNodeIndices;
243 KY_INLINE AstarNodeIndexInGrid::AbstractGraphToNodeIndices* AstarNodeIndexInGrid::GetAbstractGraphToNodeIndices_Unsafe(
const AbstractGraphNodeRawPtr& abstractGraphNodeRawPtr)
245 AbstractGraphToNodeIndices* memoryStartForAbstractGraphs = GetAbstractGraphToNodeIndicesBuffer();
246 return &memoryStartForAbstractGraphs[abstractGraphNodeRawPtr.m_abstractGraph->m_abstractGraphIdx];
KyUInt32 NavGraphVertexIdx
An index that uniquely identifies a single vertex within the set of vertices owned by a NavGraph...
Definition: navgraphtypes.h:45
Box2i CellBox
A type that represents a bounding box around cells in a 2D grid.
Definition: navmeshtypes.h:31
Vec2i CellPos
A type that represents the position of a cell within a 2D grid.
Definition: navmeshtypes.h:30
std::uint32_t KyUInt32
uint32_t
Definition: types.h:29
KyUInt32 NavHalfEdgeIdx
An index that uniquely identifies a single edge of a triangle within the set of edges owned by a NavF...
Definition: navmeshtypes.h:84
Navigation return code class.
Definition: types.h:108
The Autodesk Navigation namespace.
Definition: gamekitcrowddispersion.cpp:17
#define KyUInt32MAXVAL
KyUInt32 max value
Definition: types.h:68