7 #ifndef Navigation_StatusInGridBase_H
8 #define Navigation_StatusInGridBase_H
17 class StatusInGridBase
24 KY_INLINE StatusWord* GetBufferOfStatus()
const {
return (StatusWord*)((
char*)
this + m_offSetToStatus); }
26 KY_INLINE
bool IsValid()
const {
return m_offSetToStatus !=
KyUInt32MAXVAL; }
28 KY_INLINE
bool IsNodeOpen(
KyUInt32 triangleIdx)
const {
return BitFieldUtils::IsBitSet(GetBufferOfStatus(), triangleIdx); }
29 KY_INLINE
void OpenNode(
KyUInt32 triangleIdx)
const { BitFieldUtils::SetBit(GetBufferOfStatus(), triangleIdx); }
31 KY_INLINE
void SetBufferOfStatusWord(StatusWord* buffer) { m_offSetToStatus = (
KyUInt32)((
char*)buffer - (
char*)(
this)); }
37 template <
class UnderlyingClass>
38 struct IntermediateStatusAccessor
40 KY_INLINE
bool IsValid()
const {
return m_offSetToUnderlyingClass !=
KyUInt32MAXVAL; }
41 KY_INLINE UnderlyingClass* GetUnderlyingObjectBuffer()
const {
return (UnderlyingClass*)((
char*)
this + m_offSetToUnderlyingClass); }
42 KY_INLINE UnderlyingClass* GetUnderlyingObject(
KyUInt32 objectVertexIdx)
const {
return &GetUnderlyingObjectBuffer()[objectVertexIdx]; }
44 KY_INLINE
void SetBufferOfUnderlyingObjects(UnderlyingClass* buffer) { m_offSetToUnderlyingClass = (
KyUInt32)((
char*)buffer - (
char*)(
this)); }
52 StatusInGridBase(WorkingMemory* workingMemory,
const CellBox& cellBox) : m_cellBox(cellBox)
54 m_workingMemContainerBase.Init(workingMemory);
55 m_currentOffsetFromBuffer = 0;
58 void Init(WorkingMemory* workingMemory,
const CellBox& cellBox)
60 m_workingMemContainerBase.Init(workingMemory);
62 m_currentOffsetFromBuffer = 0;
65 void ReleaseWorkingMemoryBuffer() { m_workingMemContainerBase.ReleaseBuffer(); }
67 KY_INLINE
KyUInt32 GetAvailableSizeInBytes()
const {
return m_workingMemContainerBase.GetBufferSize() - m_currentOffsetFromBuffer; }
69 KY_INLINE
bool IsEnoughPlaceForAllocation(
KyUInt32 sizeInBytes)
71 while (GetAvailableSizeInBytes() < sizeInBytes)
73 if (TryToResize() ==
false)
82 void* oldBuffer = GetBuffer();
83 KyUInt32 oldSize = m_workingMemContainerBase.GetBufferSize();
85 void* newBuffer = m_workingMemContainerBase.Resize();
89 memcpy(newBuffer, oldBuffer, oldSize);
90 #if defined(KY_BUILD_DEBUG)
91 memset(oldBuffer, 0xAB, oldSize);
93 m_workingMemContainerBase.ReleaseMemory((
void*)oldBuffer);
97 void* AllocateInBufferAndMemset(
KyUInt32 sizeOfOneElementInBytes,
KyUInt32 numberOfElements,
KyUInt8 memsetValue);
98 StatusWord* AllocateStatusWords(
KyUInt32 numberOfNodes);
100 void* GetBuffer()
const;
101 bool IsInitialized()
const;
103 WorkingMemContainerBase m_workingMemContainerBase;
108 KY_INLINE
void* StatusInGridBase::GetBuffer()
const {
return m_workingMemContainerBase.GetBuffer(); }
109 KY_INLINE
bool StatusInGridBase::IsInitialized()
const {
return m_workingMemContainerBase.IsInitialized(); }
111 KY_INLINE
void* StatusInGridBase::AllocateInBufferAndMemset(
KyUInt32 sizeOfOneElementInBytes,
KyUInt32 numberOfElements,
KyUInt8 memSetValue)
113 KY_DEBUG_ASSERTN(sizeOfOneElementInBytes %4 == 0, (
"this function cannot be called with other values multiple of 4"));
115 const KyUInt32 totalSizeToNewOffSet = sizeOfOneElementInBytes * numberOfElements;
116 if (IsEnoughPlaceForAllocation(totalSizeToNewOffSet) ==
false)
119 void* returnValue = (
void*)((
char*)GetBuffer() + m_currentOffsetFromBuffer);
121 memset((
char*)GetBuffer() + m_currentOffsetFromBuffer, memSetValue, totalSizeToNewOffSet);
123 m_currentOffsetFromBuffer += totalSizeToNewOffSet;
127 KY_INLINE StatusInGridBase::StatusWord* StatusInGridBase::AllocateStatusWords(
KyUInt32 numberOfNodes)
129 return (StatusInGridBase::StatusWord*)AllocateInBufferAndMemset(
sizeof(StatusInGridBase::StatusWord), BitFieldUtils::GetWordsCount(numberOfNodes), 0);
Box2i CellBox
A type that represents a bounding box around cells in a 2D grid.
Definition: navmeshtypes.h:34
#define KY_NULL
Null value.
Definition: types.h:247
unsigned char KyUInt8
Type used internally to represent an unsigned 8-bit integer.
Definition: types.h:41
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