9 #ifndef GwNavGen_BoxOfArrays_H
10 #define GwNavGen_BoxOfArrays_H
31 void Init(
KyUInt32 count_, T* values_);
38 explicit BoxOfArrays(MemoryHeap* heap,
KyUInt32 byteCountInChunk = 0) :
39 m_countX(0), m_countY(0), m_columns(
KY_NULL), m_pool(heap, byteCountInChunk), m_heap(heap) {}
41 ~BoxOfArrays() { Release(); }
45 KyUInt32 CountX()
const {
return m_countX; }
46 KyUInt32 CountY()
const {
return m_countY; }
47 KyUInt32 ColumnsCount()
const {
return m_countX * m_countY; }
49 T* InitColumn(
const Vec2i& pos,
KyUInt32 count) {
return InitColumn(pos.x, pos.y, count); }
53 Column& GetColumn(
const Vec2i& pos) {
return GetColumn(pos.x, pos.y); }
54 Column& GetColumn(
KyInt32 x,
KyInt32 y) {
return GetColumn(y * m_countX + x); }
55 Column& GetColumn(
KyInt32 rowMajorIdx) {
return m_columns[rowMajorIdx]; }
57 const Column& GetColumn(
const Vec2i& pos)
const {
return GetColumn(pos.x, pos.y); }
58 const Column& GetColumn(
KyInt32 x,
KyInt32 y)
const {
return GetColumn(y * m_countX + x); }
59 const Column& GetColumn(
KyInt32 rowMajorIdx)
const {
return m_columns[rowMajorIdx]; }
61 const Column* GetColumns()
const {
return m_columns; }
67 KyUInt32 ByteCountAllocated()
const {
return m_pool.ByteCountAllocated(); }
69 BoxOfArrays<T>& operator=(
const BoxOfArrays<T>& other);
75 GrowingSmallBufferPool m_pool;
79 BoxOfArrays<T>(
const BoxOfArrays<T>& other);
87 void BoxOfArrays<T>::Column::Init(
KyUInt32 count_, T* values_)
93 for (
KyUInt32 i = 0; i < m_count; ++i)
94 ::
new(m_values + i) T();
104 m_columns = KY_HEAP_MALLOC(m_heap, Column, countX * countY, MemStat_NavDataGen);
105 memset(m_columns, 0, countX * countY *
sizeof(Column));
111 T* values = (T*)m_pool.GetNewBuffer(count *
sizeof(T));
112 GetColumn(columnIdx).Init(count, values);
117 void BoxOfArrays<T>::Clear()
130 void BoxOfArrays<T>::Release()
138 BoxOfArrays<T>& BoxOfArrays<T>::operator=(
const BoxOfArrays<T>& other)
140 Init(other.CountX(), other.CountY());
142 const Column* otherColumns = other.GetColumns();
143 KyUInt32 columnsCount = ColumnsCount();
145 for (
KyUInt32 columnIdx = 0; columnIdx < columnsCount; ++columnIdx)
147 const Column& otherColumn = otherColumns[columnIdx];
148 T* values = InitColumn(columnIdx, otherColumn.m_count);
149 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