2021-09-13 12:10:06 -04:00
|
|
|
#include "blockarray3d.h"
|
2021-09-17 10:03:32 -04:00
|
|
|
|
|
|
|
BlockArray3d::BlockArray3d(int x, int y, int z) : m_x(x), m_y(y), m_z(z) {
|
|
|
|
m_blocks = new BlockType[x * y * z];
|
|
|
|
Reset(BTYPE_AIR);
|
|
|
|
}
|
|
|
|
|
|
|
|
BlockArray3d::BlockArray3d(BlockArray3d& ba) : m_x(ba.m_x), m_y(ba.m_y), m_z(ba.m_z) {
|
|
|
|
m_blocks = new BlockType[ba.m_x*ba.m_y*ba.m_z];
|
|
|
|
|
|
|
|
for (int index = 0; index < (m_x * m_y * m_z); ++index)
|
|
|
|
m_blocks[index] = ba.m_blocks[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
BlockArray3d::~BlockArray3d() { delete[] m_blocks; }
|
|
|
|
|
|
|
|
void BlockArray3d::Set(int x, int y, int z, BlockType type) { m_blocks[GetPosition(x, y, z)] = type; }
|
|
|
|
|
|
|
|
BlockType BlockArray3d::Get(int x, int y, int z) const { return m_blocks[GetPosition(x, y, z)]; }
|
|
|
|
|
|
|
|
void BlockArray3d::Reset(BlockType type) {
|
|
|
|
for (int index = 0; index < (m_x * m_y * m_z); ++index)
|
|
|
|
m_blocks[index] = type;
|
|
|
|
}
|
|
|
|
|
|
|
|
int BlockArray3d::GetPosition(int x, int y, int z) const { return x + (z * m_x) + (y * m_z * m_x); }
|