9 #ifndef GwNavGen_BoxOfArrays_H
10 #define GwNavGen_BoxOfArrays_H
31 void Init(
KyUInt32 count_, T* values_);
32 KyUInt32 GetCount()
const {
return m_count; }
33 T& Get(
KyUInt32 index) { KY_ASSERT(index < m_count);
return m_values[index]; }
34 const T& Get(
KyUInt32 index)
const { KY_ASSERT(index < m_count);
return m_values[index]; }
41 explicit BoxOfArrays(MemoryHeap* heap,
KyUInt32 byteCountInChunk = 0) :
42 m_countX(0), m_countY(0), m_columns(
KY_NULL), m_pool(heap, byteCountInChunk), m_heap(heap) {}
44 ~BoxOfArrays() { Release(); }
48 KyUInt32 CountX()
const {
return m_countX; }
49 KyUInt32 CountY()
const {
return m_countY; }
50 KyUInt32 ColumnsCount()
const {
return m_countX * m_countY; }
52 T* InitColumn(
const Vec2i& pos,
KyUInt32 count) {
return InitColumn(pos.x, pos.y, count); }
56 Column& GetColumn(
const Vec2i& pos) {
return GetColumn(pos.x, pos.y); }
57 Column& GetColumn(
KyInt32 x,
KyInt32 y) {
return GetColumn(y * m_countX + x); }
58 Column& GetColumn(
KyInt32 rowMajorIdx) {
return m_columns[rowMajorIdx]; }
60 const Column& GetColumn(
const Vec2i& pos)
const {
return GetColumn(pos.x, pos.y); }
61 const Column& GetColumn(
KyInt32 x,
KyInt32 y)
const {
return GetColumn(y * m_countX + x); }
62 const Column& GetColumn(
KyInt32 rowMajorIdx)
const {
return m_columns[rowMajorIdx]; }
64 const Column* GetColumns()
const {
return m_columns; }
70 KyUInt32 ByteCountAllocated()
const {
return m_pool.ByteCountAllocated(); }
72 BoxOfArrays<T>& operator=(
const BoxOfArrays<T>& other);
78 GrowingSmallBufferPool m_pool;
82 BoxOfArrays<T>(
const BoxOfArrays<T>& other);
90 void BoxOfArrays<T>::Column::Init(
KyUInt32 count_, T* values_)
96 for (
KyUInt32 i = 0; i < m_count; ++i)
97 ::
new(m_values + i) T();
107 m_columns = KY_HEAP_MALLOC(m_heap, Column, countX * countY, MemStat_NavDataGen);
108 memset(m_columns, 0, countX * countY *
sizeof(Column));
114 T* values = (T*)m_pool.GetNewBuffer(count *
sizeof(T));
115 GetColumn(columnIdx).Init(count, values);
120 void BoxOfArrays<T>::Clear()
133 void BoxOfArrays<T>::Release()
141 BoxOfArrays<T>& BoxOfArrays<T>::operator=(
const BoxOfArrays<T>& other)
143 Init(other.CountX(), other.CountY());
145 const Column* otherColumns = other.GetColumns();
146 KyUInt32 columnsCount = ColumnsCount();
148 for (
KyUInt32 columnIdx = 0; columnIdx < columnsCount; ++columnIdx)
150 const Column& otherColumn = otherColumns[columnIdx];
151 T* values = InitColumn(columnIdx, otherColumn.m_count);
152 memcpy(values, otherColumn.m_values, otherColumn.m_count *
sizeof(T));
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