8 #ifndef Navigation_AstarNodeIndexInGrid_H
9 #define Navigation_AstarNodeIndexInGrid_H
19 class AStarContextConfig
22 AStarContextConfig() : m_abstractGraphTraversalMode(PATHFINDER_DO_NOT_TRAVERSE_ABSTRACT_GRAPHS) {}
24 bool CanUseAbstractGraphs()
const;
28 CellBox m_startActiveDataCellBoxForAbstractGraph;
29 CellBox m_destActiveDataCellBoxForAbstractGraph;
32 class AstarNodeIndexInGrid
39 KY_INLINE
KyUInt32 GetNumberOfWordsForNodeIndices(
KyUInt32 numberOfNodes) {
return numberOfNodes; }
41 struct NavGraphToNodeIndices
43 KY_INLINE AStarNodeIndex GetAStarNodeIndex(
NavGraphVertexIdx navGraphVertexIdx)
const {
return GetNodeIndices()[navGraphVertexIdx]; }
44 KY_INLINE
void SetAStarNodeIndex(
NavGraphVertexIdx navGraphVertexIdx, AStarNodeIndex index) { GetNodeIndices()[navGraphVertexIdx] = index; }
46 KY_INLINE AStarNodeIndex* GetNodeIndices()
const {
return (AStarNodeIndex*)((
char*)
this + m_offsetToNodeIndices); }
48 KY_INLINE
bool IsValid()
const {
return m_offsetToNodeIndices !=
KyUInt32MAXVAL; }
52 struct AbstractGraphToNodeIndices
54 KY_INLINE AStarNodeIndex GetAStarNodeIndex(AbstractGraphNodeIdx abstractGraphNodeIdx)
const {
return GetNodeIndices()[abstractGraphNodeIdx]; }
55 KY_INLINE
void SetAStarNodeIndex(AbstractGraphNodeIdx abstractGraphNodeIdx, AStarNodeIndex index) { GetNodeIndices()[abstractGraphNodeIdx] = index; }
57 KY_INLINE AStarNodeIndex* GetNodeIndices()
const {
return (AStarNodeIndex*)((
char*)
this + m_offsetToNodeIndices); }
59 KY_INLINE
bool IsValid()
const {
return m_offsetToNodeIndices !=
KyUInt32MAXVAL; }
63 struct NavFloorToNodeIndices
65 KY_INLINE AStarNodeIndex GetAStarNodeIndex(
NavHalfEdgeIdx navHalfEdgeIdx)
const {
return GetNodeIndices()[navHalfEdgeIdx]; }
66 KY_INLINE
void SetAStarNodeIndex(
NavHalfEdgeIdx navHalfEdgeIdx, AStarNodeIndex index) { GetNodeIndices()[navHalfEdgeIdx] = index; }
68 KY_INLINE AStarNodeIndex* GetNodeIndices()
const {
return (AStarNodeIndex*)((
char*)
this + m_offsetToNodeIndices); }
69 KY_INLINE
bool IsValid()
const {
return m_offsetToNodeIndices !=
KyUInt32MAXVAL; }
74 struct CellPosToNavFloors
76 KY_INLINE
bool IsValid()
const {
return m_offSetToNavFloorToNodeIndices !=
KyUInt32MAXVAL; }
77 KY_INLINE NavFloorToNodeIndices* GetNavFloorToNodeIndices()
const {
return (NavFloorToNodeIndices*)((
char*)
this + m_offSetToNavFloorToNodeIndices); }
79 KyUInt32 m_offSetToNavFloorToNodeIndices;
84 AstarNodeIndexInGrid() : m_numberOfNavGraph(0), m_numberOfAbstractGraph(0), m_currentOffsetFromBuffer(0) {}
86 AstarNodeIndexInGrid(WorkingMemory* workingMemory, ActiveData* activeData,
const AStarContextConfig& astarContextConfig) { Init(workingMemory, activeData, astarContextConfig); }
88 void Init(WorkingMemory* workingMemory, ActiveData* activeData,
const AStarContextConfig& astarContextConfig);
90 void ReleaseWorkingMemoryBuffer();
92 KyUInt32 GetAvailableSizeInBytes()
const;
94 bool IsEnoughPlaceForAllocation(
KyUInt32 sizeInBytes);
100 void* AllocateInBufferAndMemsetTo1(
KyUInt32 totalSizeToNewOffSet);
102 AStarNodeIndex* AllocateAstarNodeIndices(
KyUInt32 numberOfEdges);
104 CellPosToNavFloors* AllocateCellPosToNavFloors(
KyUInt32 numberOfCell);
105 NavFloorToNodeIndices* AllocateNavFloorToNodeIndex(
KyUInt32 numberOfFloors);
106 NavGraphToNodeIndices* AllocateNavGraphToNodeIndex(
KyUInt32 numberOfGraphs);
107 AbstractGraphToNodeIndices* AllocateAbstractGraphToNodeIndex(
KyUInt32 numberOfAbstractGraphs);
109 CellPosToNavFloors* GetCellPosToNavFloors(
const CellPos& cellPos);
111 KyResult GetNavFloorToNodeIndices(ActiveData* activeData,
const NavFloorRawPtr& navFloorRawPtr, NavFloorToNodeIndices*& nodeIndices);
112 KyResult GetNavGraphToNodeIndices(
const NavGraphVertexRawPtr& navGraphVertexRawPtr, NavGraphToNodeIndices*& nodeIndices);
113 KyResult GetAbstractGraphToNodeIndices(
const AbstractGraphNodeRawPtr& abstractGraphNodeRawPtr, AbstractGraphToNodeIndices*& nodeIndices);
115 NavGraphToNodeIndices* GetNavGraphToNodeIndices_Unsafe(
const NavGraphVertexRawPtr& navGraphVertexRawPtr);
116 NavFloorToNodeIndices* GetNavFloorToNodeIndices_Unsafe(
const NavFloorRawPtr& navFloorRawPtr);
117 AbstractGraphToNodeIndices* GetAbstractGraphToNodeIndices_Unsafe(
const AbstractGraphNodeRawPtr& abstractGraphNodeRawPtr);
119 bool IsInitialized()
const {
return m_workingMemContainerBase.IsInitialized(); }
120 bool HasNavDataChanged(Database* database);
123 NavGraphToNodeIndices* GetNavGraphToNodeIndicesBuffer();
124 AbstractGraphToNodeIndices* GetAbstractGraphToNodeIndicesBuffer();
125 CellPosToNavFloors* GetCellPosToNavFloorsBuffer();
128 WorkingMemContainerBase m_workingMemContainerBase;
138 CellBox m_activeDataCellBoxOfAbstractGraphDestination;
141 KY_INLINE
void AstarNodeIndexInGrid::ReleaseWorkingMemoryBuffer() { m_workingMemContainerBase.ReleaseBuffer(); }
143 KY_INLINE
KyUInt32 AstarNodeIndexInGrid::GetAvailableSizeInBytes()
const {
return m_workingMemContainerBase.GetBufferSize() - m_currentOffsetFromBuffer; }
145 KY_INLINE
bool AstarNodeIndexInGrid::IsEnoughPlaceForAllocation(
KyUInt32 sizeInBytes)
147 while (GetAvailableSizeInBytes() < sizeInBytes)
149 if (TryToResize() ==
false)
156 KY_INLINE AStarNodeIndex* AstarNodeIndexInGrid::AllocateAstarNodeIndices(
KyUInt32 numberOfEdges)
158 return (AStarNodeIndex*)AllocateInBufferAndMemsetTo1(
sizeof(
KyUInt32) * GetNumberOfWordsForNodeIndices(numberOfEdges));
161 KY_INLINE AstarNodeIndexInGrid::NavFloorToNodeIndices* AstarNodeIndexInGrid::AllocateNavFloorToNodeIndex(
KyUInt32 numberOfFloors)
163 return (NavFloorToNodeIndices*)AllocateInBufferAndMemsetTo1(
sizeof(NavFloorToNodeIndices) * numberOfFloors);
166 KY_INLINE AstarNodeIndexInGrid::NavGraphToNodeIndices* AstarNodeIndexInGrid::AllocateNavGraphToNodeIndex(
KyUInt32 numberOfGraphs)
168 return (NavGraphToNodeIndices*)AllocateInBufferAndMemsetTo1(
sizeof(NavGraphToNodeIndices) * numberOfGraphs);
171 KY_INLINE AstarNodeIndexInGrid::AbstractGraphToNodeIndices* AstarNodeIndexInGrid::AllocateAbstractGraphToNodeIndex(
KyUInt32 numberOfAbstractGraphs)
173 return (AbstractGraphToNodeIndices*)AllocateInBufferAndMemsetTo1(
sizeof(AbstractGraphToNodeIndices) * numberOfAbstractGraphs);
176 KY_INLINE AstarNodeIndexInGrid::CellPosToNavFloors* AstarNodeIndexInGrid::AllocateCellPosToNavFloors(
KyUInt32 numberOfCell)
178 return (CellPosToNavFloors*)AllocateInBufferAndMemsetTo1(
sizeof(CellPosToNavFloors) * numberOfCell);
182 KY_INLINE AstarNodeIndexInGrid::NavGraphToNodeIndices* AstarNodeIndexInGrid::GetNavGraphToNodeIndicesBuffer()
183 {
return (NavGraphToNodeIndices*)m_workingMemContainerBase.GetBuffer(); }
185 KY_INLINE AstarNodeIndexInGrid::AbstractGraphToNodeIndices* AstarNodeIndexInGrid::GetAbstractGraphToNodeIndicesBuffer()
186 {
return (AbstractGraphToNodeIndices*) (GetNavGraphToNodeIndicesBuffer() + m_numberOfNavGraph); }
188 KY_INLINE AstarNodeIndexInGrid::CellPosToNavFloors* AstarNodeIndexInGrid::GetCellPosToNavFloorsBuffer()
189 {
return (CellPosToNavFloors*) (GetAbstractGraphToNodeIndicesBuffer() + m_numberOfAbstractGraph); }
191 KY_INLINE AstarNodeIndexInGrid::CellPosToNavFloors* AstarNodeIndexInGrid::GetCellPosToNavFloors(
const CellPos& cellPos)
193 CellPosToNavFloors* memoryStartForGrid = GetCellPosToNavFloorsBuffer();
194 if (m_numberOfAbstractGraph == 0 || m_activeDataCellBox.IsInside(cellPos) ==
true)
195 return memoryStartForGrid + m_activeDataCellBox.GetRowMajorIndex(cellPos);
196 else if (m_activeDataCellBoxOfAbstractGraphDestination.IsInside(cellPos) ==
true)
197 return memoryStartForGrid + (m_activeDataCellBox.CountX() * m_activeDataCellBox.CountY()) + m_activeDataCellBoxOfAbstractGraphDestination.GetRowMajorIndex(cellPos);
202 KY_INLINE AstarNodeIndexInGrid::NavGraphToNodeIndices* AstarNodeIndexInGrid::GetNavGraphToNodeIndices_Unsafe(
const NavGraphVertexRawPtr& navGraphVertexRawPtr)
204 NavGraphToNodeIndices* memoryStartForGraphs = GetNavGraphToNodeIndicesBuffer();
205 return &memoryStartForGraphs[navGraphVertexRawPtr.GetNavGraph()->m_idxInTheActiveDataBuffer];
208 KY_INLINE AstarNodeIndexInGrid::NavFloorToNodeIndices* AstarNodeIndexInGrid::GetNavFloorToNodeIndices_Unsafe(
const NavFloorRawPtr& navFloorRawPtr)
210 KY_DEBUG_ASSERTN(m_activeDataCellBox.IsInside(navFloorRawPtr.GetCellPos()) || m_activeDataCellBoxOfAbstractGraphDestination.IsInside(navFloorRawPtr.GetCellPos()), (
"Invalid CellBox"));
212 NavFloor* navFloor = navFloorRawPtr.GetNavFloor();
213 const CellPos& cellPos = navFloor->GetCellPos();
215 CellPosToNavFloors* cellPosToNavFloors = GetCellPosToNavFloors(cellPos);
216 KY_DEBUG_ASSERTN(cellPosToNavFloors->IsValid(), (
"Bad usage of UnSafe function"));
218 NavFloorToNodeIndices& navFloorToNodeIndices = cellPosToNavFloors->GetNavFloorToNodeIndices()[navFloor->GetIndexInCollection()];
219 KY_DEBUG_ASSERTN(navFloorToNodeIndices.IsValid(), (
"Bad usage of UnSafe function"));
221 return &navFloorToNodeIndices;
224 KY_INLINE AstarNodeIndexInGrid::AbstractGraphToNodeIndices* AstarNodeIndexInGrid::GetAbstractGraphToNodeIndices_Unsafe(
const AbstractGraphNodeRawPtr& abstractGraphNodeRawPtr)
226 AbstractGraphToNodeIndices* memoryStartForAbstractGraphs = GetAbstractGraphToNodeIndicesBuffer();
227 return &memoryStartForAbstractGraphs[abstractGraphNodeRawPtr.m_abstractGraph->m_abstractGraphIdx];
233 #endif //Navigation_AstarNodeIndexInGrid_H
KyUInt32 NavGraphVertexIdx
An index that uniquely identifies a single vertex within the set of vertices owned by a NavGraph...
Definition: navgraphtypes.h:47
KyInt32 KyResult
Defines a type that can be returned by methods or functions in the Gameware Navigation SDK to indicat...
Definition: types.h:254
Box2i CellBox
A type that represents a bounding box around cells in a 2D grid.
Definition: navmeshtypes.h:34
Vec2i CellPos
A type that represents the position of a cell within a 2D grid.
Definition: navmeshtypes.h:33
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:87
#define KY_NULL
Null value.
Definition: types.h:247
PathFinderAbstractGraphTraversalMode
Enumerates the possible way of dealing with AbstractGraphs.
Definition: pathfinderabstractgraphtraversalmode.h:16
Definition: gamekitcrowddispersion.h:20
unsigned int KyUInt32
Type used internally to represent an unsigned 32-bit integer.
Definition: types.h:36
#define KyUInt32MAXVAL
The maximum value that can be stored in the KyUInt32 variable type.
Definition: types.h:226