gwnavruntime/database/activenavfloorcollection.h Source File
Go to the documentation of this file.
8 #ifndef Navigation_ActiveNavFloorCollection_H
9 #define Navigation_ActiveNavFloorCollection_H
21 class ActiveNavFloorCollection
26 ActiveNavFloorCollection() : m_activeNavFloors(
KY_NULL), m_count(0), m_capacity(0) {}
27 ~ActiveNavFloorCollection() { KY_LOG_ERROR_IF(m_activeNavFloors !=
KY_NULL, (
"memory leak !")); }
29 KY_INLINE
bool IsEmpty()
const {
return m_count == 0; }
30 KY_INLINE
KyUInt32 GetCount()
const {
return m_count; }
32 void GetOwnershipOfData(ActiveNavFloorCollection& other)
36 m_activeNavFloors = other.m_activeNavFloors;
37 m_count = other.m_count;
38 m_capacity = other.m_capacity;
40 other.m_activeNavFloors =
KY_NULL;
46 void InsertActiveNavFloorsOfNavCell(MemoryHeap* heap, NavCell* navCell)
48 const KyUInt32 numberOfNavFloorInCell = navCell->GetNavFloorCount();
49 const KyUInt32 previousCount = m_count;
51 KyUInt32 newCapacity = Max<KyUInt32>(4, m_capacity);
52 if (m_count + numberOfNavFloorInCell > m_capacity)
54 while(previousCount + numberOfNavFloorInCell > newCapacity)
57 Reserve(heap, newCapacity);
61 m_count = m_count + (
KyUInt16)numberOfNavFloorInCell;
62 KY_ASSERT(m_count <= m_capacity);
64 NavFloor** navFloors = GetNavFloors() + previousCount;
65 for(
KyUInt32 idx = 0; idx < numberOfNavFloorInCell; ++idx)
66 navFloors[idx] = navCell->GetNavFloor(idx);
69 NavFloor** GetNavFloors()
const {
return m_activeNavFloors; }
71 void Reserve(MemoryHeap* heap,
KyUInt32 newCapacity)
73 KY_DEBUG_ASSERTN(newCapacity > m_capacity, (
"no shrinking !"));
75 char* newData = (
char*)KY_HEAP_ALLOC(heap, newCapacity * (
KyUInt32)
sizeof(NavFloor*), MemStat_NavData);
77 #if defined(KY_BUILD_DEBUG)
78 memset(newData, 0xFE, newCapacity * (
KyUInt32)
sizeof(NavFloor*));
84 memcpy(newData, (
char*)m_activeNavFloors, m_count *
sizeof(NavFloor*));
86 KY_FREE(m_activeNavFloors);
90 m_activeNavFloors = (NavFloor**)newData;
95 #if defined(KY_BUILD_DEBUG)
97 memset((
char*)m_activeNavFloors, 0, m_capacity * ((
KyUInt32)
sizeof(NavFloor*)));
106 KY_FREE(m_activeNavFloors);
114 KY_ASSERT(m_count == 0);
115 KY_ASSERT(m_capacity == 0);
116 KY_ASSERT(m_activeNavFloors ==
KY_NULL);
121 NavFloor** m_activeNavFloors;
128 #endif //Navigation_ActiveNavFloorCollection_H
#define KY_NULL
Null value.
Definition: types.h:247
Definition: gamekitcrowddispersion.h:20
#define KY_DEFINE_NEW_DELETE_OPERATORS(MemStat)
This macro defines new and delete operators.
Definition: memory.h:137
unsigned short KyUInt16
Type used internally to represent an unsigned 16-bit integer.
Definition: types.h:40
unsigned int KyUInt32
Type used internally to represent an unsigned 32-bit integer.
Definition: types.h:36