8 #ifndef Navigation_HalfEdgeDataPtrInGrid_H
9 #define Navigation_HalfEdgeDataPtrInGrid_H
17 class HalfEdgeDataPtrInGrid
21 struct NavFloorToEdgeDataPtrBuffer
23 KY_INLINE
void* GetEdgeDataPtr(
NavHalfEdgeIdx navHalfEdgeIdx)
const {
return GetEdgeDataPtrBuffer()[navHalfEdgeIdx]; }
24 KY_INLINE
void SetEdgeDataPtr(
NavHalfEdgeIdx navHalfEdgeIdx,
void* tdata) { GetEdgeDataPtrBuffer()[navHalfEdgeIdx] = tdata; }
26 KY_INLINE
void** GetEdgeDataPtrBuffer()
const {
return (
void**)((
char*)
this + m_offsetToEdgeDataPtrBuffer); }
28 KY_INLINE
bool IsValid()
const {
return m_offsetToEdgeDataPtrBuffer != (UPInt)-1; }
29 UPInt m_offsetToEdgeDataPtrBuffer;
32 struct CellPosToNavFloors
34 KY_INLINE
bool IsValid()
const {
return m_offSetToNavFloorToEdgeDataPtrBuffer !=
KyUInt32MAXVAL; }
35 KY_INLINE NavFloorToEdgeDataPtrBuffer* GetNavFloorToEdgeDataPtrBuffer()
const {
return (NavFloorToEdgeDataPtrBuffer*)((
char*)
this + m_offSetToNavFloorToEdgeDataPtrBuffer); }
37 KyUInt32 m_offSetToNavFloorToEdgeDataPtrBuffer;
42 HalfEdgeDataPtrInGrid() : m_currentOffsetFromBuffer(0) {}
43 HalfEdgeDataPtrInGrid(WorkingMemory* workingMemory, ActiveData* activeData) : m_cellBox(activeData->GetCellBox())
45 m_workingMemContainerBase.Init(workingMemory);
46 m_currentOffsetFromBuffer = 0;
50 void Init(WorkingMemory* workingMemory, ActiveData* activeData)
52 m_workingMemContainerBase.Init(workingMemory);
53 m_cellBox = activeData->GetCellBox();
54 m_currentOffsetFromBuffer = 0;
58 void ReleaseWorkingMemoryBuffer();
60 KyUInt32 GetAvailableSizeInBytes()
const;
62 bool IsEnoughPlaceForAllocation(
KyUInt32 sizeInBytes);
68 void* AllocateInBufferAndMemsetTo1(
KyUInt32 totalSizeToNewOffSet);
69 void* AllocateInBufferAndMemsetTo0(
KyUInt32 totalSizeToNewOffSet);
71 void** AllocateEdgeDataPtrBuffer(
KyUInt32 numberOfEdges);
73 CellPosToNavFloors* AllocateCellPosToNavFloors(
KyUInt32 numberOfCell);
74 NavFloorToEdgeDataPtrBuffer* AllocateNavFloorToEdgeData(
KyUInt32 numberofFloors);
76 CellPosToNavFloors* GetCellPosToNavFloors(
const CellPos& cellPos);
78 KyResult GetNavFloorToEdgeDataPtrBuffer(ActiveData* activeData,
const NavFloorRawPtr& navFloorRawPtr, NavFloorToEdgeDataPtrBuffer*& nodeIndices);
79 NavFloorToEdgeDataPtrBuffer* GetNavFloorToEdgeDataPtrBuffer_Unsafe(
const NavFloorRawPtr& navFloorRawPtr);
81 bool IsInitialized()
const {
return m_workingMemContainerBase.IsInitialized(); }
82 bool HasNavDataChanged(Database* database);
84 WorkingMemContainerBase m_workingMemContainerBase;
90 KY_INLINE
void HalfEdgeDataPtrInGrid::ReleaseWorkingMemoryBuffer() { m_workingMemContainerBase.ReleaseBuffer(); }
91 KY_INLINE
KyUInt32 HalfEdgeDataPtrInGrid::GetAvailableSizeInBytes()
const {
return m_workingMemContainerBase.GetBufferSize() - m_currentOffsetFromBuffer; }
92 KY_INLINE
bool HalfEdgeDataPtrInGrid::IsEnoughPlaceForAllocation(
KyUInt32 sizeInBytes)
94 while (GetAvailableSizeInBytes() < sizeInBytes)
96 if (TryToResize() ==
false)
103 KY_INLINE
void** HalfEdgeDataPtrInGrid::AllocateEdgeDataPtrBuffer(
KyUInt32 numberOfEdges)
105 return (
void**)AllocateInBufferAndMemsetTo0(numberOfEdges *
sizeof(
void*));
108 KY_INLINE HalfEdgeDataPtrInGrid::NavFloorToEdgeDataPtrBuffer* HalfEdgeDataPtrInGrid::AllocateNavFloorToEdgeData(
KyUInt32 numberofFloors)
110 return (NavFloorToEdgeDataPtrBuffer*)AllocateInBufferAndMemsetTo1(
sizeof(NavFloorToEdgeDataPtrBuffer) * numberofFloors);
113 KY_INLINE HalfEdgeDataPtrInGrid::CellPosToNavFloors* HalfEdgeDataPtrInGrid::AllocateCellPosToNavFloors(
KyUInt32 numberOfCell)
115 return (CellPosToNavFloors*)AllocateInBufferAndMemsetTo1(
sizeof(CellPosToNavFloors) * numberOfCell);
119 KY_INLINE HalfEdgeDataPtrInGrid::CellPosToNavFloors* HalfEdgeDataPtrInGrid::GetCellPosToNavFloors(
const CellPos& cellPos)
121 CellPosToNavFloors* memoryStartForGrid = (CellPosToNavFloors*)m_workingMemContainerBase.GetBuffer();
122 return memoryStartForGrid + m_cellBox.GetRowMajorIndex(cellPos);
126 KY_INLINE HalfEdgeDataPtrInGrid::NavFloorToEdgeDataPtrBuffer* HalfEdgeDataPtrInGrid::GetNavFloorToEdgeDataPtrBuffer_Unsafe(
const NavFloorRawPtr& navFloorRawPtr)
128 KY_DEBUG_ASSERTN(m_cellBox.IsInside(navFloorRawPtr.GetCellPos()), (
"Invalid CellBox"));
130 NavFloor* navFloor = navFloorRawPtr.GetNavFloor();
131 const CellPos& cellPos = navFloor->GetCellPos();
133 CellPosToNavFloors* cellPosToNavFloors = GetCellPosToNavFloors(cellPos);
134 KY_DEBUG_ASSERTN(cellPosToNavFloors->IsValid(), (
"Bad usage of UnSafe function"));
136 NavFloorToEdgeDataPtrBuffer& navFloorToNodeIndices = cellPosToNavFloors->GetNavFloorToEdgeDataPtrBuffer()[navFloor->GetIndexInCollection()];
137 KY_DEBUG_ASSERTN(navFloorToNodeIndices.IsValid(), (
"Bad usage of UnSafe function"));
139 return &navFloorToNodeIndices;
147 #endif //Navigation_HalfEdgeDataPtrInGrid_H
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
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