gwnavgeneration/common/boxoflists.h Source File
Go to the documentation of this file.
10 #ifndef GwNavGen_BoxOfLists_H
11 #define GwNavGen_BoxOfLists_H
21 template <
class T, KyUInt32 NbEl = 8>
26 typedef GrowingListPool<T, NbEl> Pool;
27 typedef typename Pool::List Column;
30 explicit BoxOfLists(MemoryHeap* heap,
KyUInt32 byteCountInChunk = 0) :
31 m_countX(0), m_countY(0), m_columns(
KY_NULL), m_pool(heap, byteCountInChunk), m_heap(heap) {}
35 KyUInt32 CountX() {
return m_countX; }
36 KyUInt32 CountY() {
return m_countY; }
37 KyUInt32 ColumnsCount() {
return m_countX * m_countY; }
39 T* GetNew(
KyInt32 x,
KyInt32 y) {
return GetNew(y * m_countX + x); }
40 T* GetNew(
KyInt32 rowMajorIdx) {
return GetOrCreateColumn(rowMajorIdx)->GetNew(); }
42 Column* GetOrCreateColumn(
KyInt32 x,
KyInt32 y) {
return GetOrCreateColumn(y * m_countX + x); }
43 Column* GetOrCreateColumn(
KyInt32 rowMajorIdx);
45 const Column* GetColumn(
KyInt32 x,
KyInt32 y)
const {
return m_columns[y * m_countX + x]; }
46 const Column* GetColumn(
KyInt32 rowMajorIdx)
const {
return m_columns[rowMajorIdx]; }
52 KyUInt32 ByteCountAllocated()
const {
return m_pool.m_byteCountAllocated; }
54 KyUInt32 ElementCount()
const {
return m_pool.ElementCount(); }
68 template <
class T, KyUInt32 NbEl>
74 m_columns = KY_HEAP_MALLOC(m_heap, Column*, countX * countY, Stat_Default_Mem);
75 memset(m_columns, 0, countX * countY *
sizeof(Column*));
79 template <
class T, KyUInt32 NbEl>
80 inline typename BoxOfLists<T, NbEl>::Column* BoxOfLists<T, NbEl>::GetOrCreateColumn(
KyInt32 rowMajorIdx)
82 Column*& column = m_columns[rowMajorIdx];
84 column = m_pool.GetNewList();
89 template <
class T, KyUInt32 NbEl>
90 inline void BoxOfLists<T, NbEl>::Clear()
103 template <
class T, KyUInt32 NbEl>
104 inline void BoxOfLists<T, NbEl>::Release()
int KyInt32
Type used internally to represent a 32-bit integer.
Definition: types.h:35
#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 int KyUInt32
Type used internally to represent an unsigned 32-bit integer.
Definition: types.h:36