27 lines
886 B
C++
27 lines
886 B
C++
#include "blockarray3d.h"
|
|
|
|
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); }
|