BlockArea: Switched internal coords to Vector3i.

This commit is contained in:
madmaxoft 2014-03-25 21:59:25 +01:00
parent 0984cf9deb
commit 87e0bd54b4
4 changed files with 176 additions and 200 deletions

View File

@ -162,13 +162,6 @@ static void MergeCombinatorLake(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBB
// cBlockArea: // cBlockArea:
cBlockArea::cBlockArea(void) : cBlockArea::cBlockArea(void) :
m_OriginX(0),
m_OriginY(0),
m_OriginZ(0),
m_SizeX(0),
m_SizeY(0),
m_SizeZ(0),
m_WEOffset(0, 0, 0),
m_BlockTypes(NULL), m_BlockTypes(NULL),
m_BlockMetas(NULL), m_BlockMetas(NULL),
m_BlockLight(NULL), m_BlockLight(NULL),
@ -195,12 +188,8 @@ void cBlockArea::Clear(void)
delete[] m_BlockMetas; m_BlockMetas = NULL; delete[] m_BlockMetas; m_BlockMetas = NULL;
delete[] m_BlockLight; m_BlockLight = NULL; delete[] m_BlockLight; m_BlockLight = NULL;
delete[] m_BlockSkyLight; m_BlockSkyLight = NULL; delete[] m_BlockSkyLight; m_BlockSkyLight = NULL;
m_OriginX = 0; m_Origin.Set(0, 0, 0);
m_OriginY = 0; m_Size.Set(0, 0, 0);
m_OriginZ = 0;
m_SizeX = 0;
m_SizeY = 0;
m_SizeZ = 0;
} }
@ -243,12 +232,8 @@ void cBlockArea::Create(int a_SizeX, int a_SizeY, int a_SizeZ, int a_DataTypes)
m_BlockSkyLight[i] = 0x0f; m_BlockSkyLight[i] = 0x0f;
} }
} }
m_SizeX = a_SizeX; m_Size.Set(a_SizeX, a_SizeY, a_SizeZ);
m_SizeY = a_SizeY; m_Origin.Set(0, 0, 0);
m_SizeZ = a_SizeZ;
m_OriginX = 0;
m_OriginY = 0;
m_OriginZ = 0;
} }
@ -275,9 +260,7 @@ void cBlockArea::SetWEOffset(const Vector3i & a_Offset)
void cBlockArea::SetOrigin(int a_OriginX, int a_OriginY, int a_OriginZ) void cBlockArea::SetOrigin(int a_OriginX, int a_OriginY, int a_OriginZ)
{ {
m_OriginX = a_OriginX; m_Origin.Set(a_OriginX, a_OriginY, a_OriginZ);
m_OriginY = a_OriginY;
m_OriginZ = a_OriginZ;
} }
@ -286,7 +269,7 @@ void cBlockArea::SetOrigin(int a_OriginX, int a_OriginY, int a_OriginZ)
void cBlockArea::SetOrigin(const Vector3i & a_Origin) void cBlockArea::SetOrigin(const Vector3i & a_Origin)
{ {
SetOrigin(a_Origin.x, a_Origin.y, a_Origin.z); m_Origin.Set(a_Origin.x, a_Origin.y, a_Origin.z);
} }
@ -342,9 +325,7 @@ bool cBlockArea::Read(cForEachChunkProvider * a_ForEachChunkProvider, int a_MinB
{ {
return false; return false;
} }
m_OriginX = a_MinBlockX; m_Origin.Set(a_MinBlockX, a_MinBlockY, a_MinBlockZ);
m_OriginY = a_MinBlockY;
m_OriginZ = a_MinBlockZ;
cChunkReader Reader(*this); cChunkReader Reader(*this);
// Convert block coords to chunks coords: // Convert block coords to chunks coords:
@ -408,10 +389,10 @@ bool cBlockArea::Write(cForEachChunkProvider * a_ForEachChunkProvider, int a_Min
LOGWARNING("%s: MinBlockY less than zero, adjusting to zero", __FUNCTION__); LOGWARNING("%s: MinBlockY less than zero, adjusting to zero", __FUNCTION__);
a_MinBlockY = 0; a_MinBlockY = 0;
} }
else if (a_MinBlockY > cChunkDef::Height - m_SizeY) else if (a_MinBlockY > cChunkDef::Height - m_Size.y)
{ {
LOGWARNING("%s: MinBlockY + m_SizeY more than chunk height, adjusting to chunk height", __FUNCTION__); LOGWARNING("%s: MinBlockY + m_SizeY more than chunk height, adjusting to chunk height", __FUNCTION__);
a_MinBlockY = cChunkDef::Height - m_SizeY; a_MinBlockY = cChunkDef::Height - m_Size.y;
} }
return a_ForEachChunkProvider->WriteBlockArea(*this, a_MinBlockX, a_MinBlockY, a_MinBlockZ, a_DataTypes); return a_ForEachChunkProvider->WriteBlockArea(*this, a_MinBlockX, a_MinBlockY, a_MinBlockZ, a_DataTypes);
@ -443,10 +424,8 @@ void cBlockArea::CopyTo(cBlockArea & a_Into) const
} }
a_Into.Clear(); a_Into.Clear();
a_Into.SetSize(m_SizeX, m_SizeY, m_SizeZ, GetDataTypes()); a_Into.SetSize(m_Size.x, m_Size.y, m_Size.z, GetDataTypes());
a_Into.m_OriginX = m_OriginX; a_Into.m_Origin = m_Origin;
a_Into.m_OriginY = m_OriginY;
a_Into.m_OriginZ = m_OriginZ;
int BlockCount = GetBlockCount(); int BlockCount = GetBlockCount();
if (HasBlockTypes()) if (HasBlockTypes())
{ {
@ -487,9 +466,9 @@ void cBlockArea::DumpToRawFile(const AString & a_FileName)
LOGWARNING("cBlockArea: Cannot open file \"%s\" for raw dump", a_FileName.c_str()); LOGWARNING("cBlockArea: Cannot open file \"%s\" for raw dump", a_FileName.c_str());
return; return;
} }
UInt32 SizeX = ntohl(m_SizeX); UInt32 SizeX = ntohl(m_Size.x);
UInt32 SizeY = ntohl(m_SizeY); UInt32 SizeY = ntohl(m_Size.y);
UInt32 SizeZ = ntohl(m_SizeZ); UInt32 SizeZ = ntohl(m_Size.z);
f.Write(&SizeX, 4); f.Write(&SizeX, 4);
f.Write(&SizeY, 4); f.Write(&SizeY, 4);
f.Write(&SizeZ, 4); f.Write(&SizeZ, 4);
@ -532,13 +511,13 @@ void cBlockArea::DumpToRawFile(const AString & a_FileName)
void cBlockArea::Crop(int a_AddMinX, int a_SubMaxX, int a_AddMinY, int a_SubMaxY, int a_AddMinZ, int a_SubMaxZ) void cBlockArea::Crop(int a_AddMinX, int a_SubMaxX, int a_AddMinY, int a_SubMaxY, int a_AddMinZ, int a_SubMaxZ)
{ {
if ( if (
(a_AddMinX + a_SubMaxX >= m_SizeX) || (a_AddMinX + a_SubMaxX >= m_Size.x) ||
(a_AddMinY + a_SubMaxY >= m_SizeY) || (a_AddMinY + a_SubMaxY >= m_Size.y) ||
(a_AddMinZ + a_SubMaxZ >= m_SizeZ) (a_AddMinZ + a_SubMaxZ >= m_Size.z)
) )
{ {
LOGWARNING("cBlockArea:Crop called with more croping than the dimensions: %d x %d x %d with cropping %d, %d and %d", LOGWARNING("cBlockArea:Crop called with more croping than the dimensions: %d x %d x %d with cropping %d, %d and %d",
m_SizeX, m_SizeY, m_SizeZ, m_Size.x, m_Size.y, m_Size.z,
a_AddMinX + a_SubMaxX, a_AddMinY + a_SubMaxY, a_AddMinZ + a_SubMaxZ a_AddMinX + a_SubMaxX, a_AddMinY + a_SubMaxY, a_AddMinZ + a_SubMaxZ
); );
return; return;
@ -560,12 +539,10 @@ void cBlockArea::Crop(int a_AddMinX, int a_SubMaxX, int a_AddMinY, int a_SubMaxY
{ {
CropNibbles(m_BlockSkyLight, a_AddMinX, a_SubMaxX, a_AddMinY, a_SubMaxY, a_AddMinZ, a_SubMaxZ); CropNibbles(m_BlockSkyLight, a_AddMinX, a_SubMaxX, a_AddMinY, a_SubMaxY, a_AddMinZ, a_SubMaxZ);
} }
m_OriginX += a_AddMinX; m_Origin.Move(a_AddMinX, a_AddMinY, a_AddMinZ);
m_OriginY += a_AddMinY; m_Size.x -= a_AddMinX + a_SubMaxX;
m_OriginZ += a_AddMinZ; m_Size.y -= a_AddMinY + a_SubMaxY;
m_SizeX -= a_AddMinX + a_SubMaxX; m_Size.z -= a_AddMinZ + a_SubMaxZ;
m_SizeY -= a_AddMinY + a_SubMaxY;
m_SizeZ -= a_AddMinZ + a_SubMaxZ;
} }
@ -590,12 +567,10 @@ void cBlockArea::Expand(int a_SubMinX, int a_AddMaxX, int a_SubMinY, int a_AddMa
{ {
ExpandNibbles(m_BlockSkyLight, a_SubMinX, a_AddMaxX, a_SubMinY, a_AddMaxY, a_SubMinZ, a_AddMaxZ); ExpandNibbles(m_BlockSkyLight, a_SubMinX, a_AddMaxX, a_SubMinY, a_AddMaxY, a_SubMinZ, a_AddMaxZ);
} }
m_OriginX -= a_SubMinX; m_Origin.Move(-a_SubMinX, -a_SubMinY, -a_SubMinZ);
m_OriginY -= a_SubMinY; m_Size.x += a_SubMinX + a_AddMaxX;
m_OriginZ -= a_SubMinZ; m_Size.y += a_SubMinY + a_AddMaxY;
m_SizeX += a_SubMinX + a_AddMaxX; m_Size.z += a_SubMinZ + a_AddMaxZ;
m_SizeY += a_SubMinY + a_AddMaxY;
m_SizeZ += a_SubMinZ + a_AddMaxZ;
} }
@ -645,7 +620,7 @@ void cBlockArea::Merge(const cBlockArea & a_Src, int a_RelX, int a_RelY, int a_R
SrcOffX, SrcOffY, SrcOffZ, SrcOffX, SrcOffY, SrcOffZ,
DstOffX, DstOffY, DstOffZ, DstOffX, DstOffY, DstOffZ,
a_Src.GetSizeX(), a_Src.GetSizeY(), a_Src.GetSizeZ(), a_Src.GetSizeX(), a_Src.GetSizeY(), a_Src.GetSizeZ(),
m_SizeX, m_SizeY, m_SizeZ, m_Size.x, m_Size.y, m_Size.z,
MergeCombinatorOverwrite MergeCombinatorOverwrite
); );
break; break;
@ -660,7 +635,7 @@ void cBlockArea::Merge(const cBlockArea & a_Src, int a_RelX, int a_RelY, int a_R
SrcOffX, SrcOffY, SrcOffZ, SrcOffX, SrcOffY, SrcOffZ,
DstOffX, DstOffY, DstOffZ, DstOffX, DstOffY, DstOffZ,
a_Src.GetSizeX(), a_Src.GetSizeY(), a_Src.GetSizeZ(), a_Src.GetSizeX(), a_Src.GetSizeY(), a_Src.GetSizeZ(),
m_SizeX, m_SizeY, m_SizeZ, m_Size.x, m_Size.y, m_Size.z,
MergeCombinatorFillAir MergeCombinatorFillAir
); );
break; break;
@ -675,7 +650,7 @@ void cBlockArea::Merge(const cBlockArea & a_Src, int a_RelX, int a_RelY, int a_R
SrcOffX, SrcOffY, SrcOffZ, SrcOffX, SrcOffY, SrcOffZ,
DstOffX, DstOffY, DstOffZ, DstOffX, DstOffY, DstOffZ,
a_Src.GetSizeX(), a_Src.GetSizeY(), a_Src.GetSizeZ(), a_Src.GetSizeX(), a_Src.GetSizeY(), a_Src.GetSizeZ(),
m_SizeX, m_SizeY, m_SizeZ, m_Size.x, m_Size.y, m_Size.z,
MergeCombinatorImprint MergeCombinatorImprint
); );
break; break;
@ -690,7 +665,7 @@ void cBlockArea::Merge(const cBlockArea & a_Src, int a_RelX, int a_RelY, int a_R
SrcOffX, SrcOffY, SrcOffZ, SrcOffX, SrcOffY, SrcOffZ,
DstOffX, DstOffY, DstOffZ, DstOffX, DstOffY, DstOffZ,
a_Src.GetSizeX(), a_Src.GetSizeY(), a_Src.GetSizeZ(), a_Src.GetSizeX(), a_Src.GetSizeY(), a_Src.GetSizeZ(),
m_SizeX, m_SizeY, m_SizeZ, m_Size.x, m_Size.y, m_Size.z,
MergeCombinatorLake MergeCombinatorLake
); );
break; break;
@ -982,17 +957,17 @@ void cBlockArea::RotateCCW(void)
} }
// We are guaranteed that both blocktypes and blockmetas exist; rotate both at the same time: // We are guaranteed that both blocktypes and blockmetas exist; rotate both at the same time:
BLOCKTYPE * NewTypes = new BLOCKTYPE[m_SizeX * m_SizeY * m_SizeZ]; BLOCKTYPE * NewTypes = new BLOCKTYPE[GetBlockCount()];
NIBBLETYPE * NewMetas = new NIBBLETYPE[m_SizeX * m_SizeY * m_SizeZ]; NIBBLETYPE * NewMetas = new NIBBLETYPE[GetBlockCount()];
for (int x = 0; x < m_SizeX; x++) for (int x = 0; x < m_Size.x; x++)
{ {
int NewZ = m_SizeX - x - 1; int NewZ = m_Size.x - x - 1;
for (int z = 0; z < m_SizeZ; z++) for (int z = 0; z < m_Size.z; z++)
{ {
int NewX = z; int NewX = z;
for (int y = 0; y < m_SizeY; y++) for (int y = 0; y < m_Size.y; y++)
{ {
int NewIdx = NewX + NewZ * m_SizeZ + y * m_SizeX * m_SizeZ; int NewIdx = NewX + NewZ * m_Size.z + y * m_Size.x * m_Size.z;
int OldIdx = MakeIndex(x, y, z); int OldIdx = MakeIndex(x, y, z);
NewTypes[NewIdx] = m_BlockTypes[OldIdx]; NewTypes[NewIdx] = m_BlockTypes[OldIdx];
NewMetas[NewIdx] = BlockHandler(m_BlockTypes[OldIdx])->MetaRotateCCW(m_BlockMetas[OldIdx]); NewMetas[NewIdx] = BlockHandler(m_BlockTypes[OldIdx])->MetaRotateCCW(m_BlockMetas[OldIdx]);
@ -1004,7 +979,7 @@ void cBlockArea::RotateCCW(void)
delete[] NewTypes; delete[] NewTypes;
delete[] NewMetas; delete[] NewMetas;
std::swap(m_SizeX, m_SizeZ); std::swap(m_Size.x, m_Size.z);
} }
@ -1027,17 +1002,17 @@ void cBlockArea::RotateCW(void)
} }
// We are guaranteed that both blocktypes and blockmetas exist; rotate both at the same time: // We are guaranteed that both blocktypes and blockmetas exist; rotate both at the same time:
BLOCKTYPE * NewTypes = new BLOCKTYPE[m_SizeX * m_SizeY * m_SizeZ]; BLOCKTYPE * NewTypes = new BLOCKTYPE[GetBlockCount()];
NIBBLETYPE * NewMetas = new NIBBLETYPE[m_SizeX * m_SizeY * m_SizeZ]; NIBBLETYPE * NewMetas = new NIBBLETYPE[GetBlockCount()];
for (int x = 0; x < m_SizeX; x++) for (int x = 0; x < m_Size.x; x++)
{ {
int NewZ = x; int NewZ = x;
for (int z = 0; z < m_SizeZ; z++) for (int z = 0; z < m_Size.z; z++)
{ {
int NewX = m_SizeZ - z - 1; int NewX = m_Size.z - z - 1;
for (int y = 0; y < m_SizeY; y++) for (int y = 0; y < m_Size.y; y++)
{ {
int NewIdx = NewX + NewZ * m_SizeZ + y * m_SizeX * m_SizeZ; int NewIdx = NewX + NewZ * m_Size.z + y * m_Size.x * m_Size.z;
int OldIdx = MakeIndex(x, y, z); int OldIdx = MakeIndex(x, y, z);
NewTypes[NewIdx] = m_BlockTypes[OldIdx]; NewTypes[NewIdx] = m_BlockTypes[OldIdx];
NewMetas[NewIdx] = BlockHandler(m_BlockTypes[OldIdx])->MetaRotateCW(m_BlockMetas[OldIdx]); NewMetas[NewIdx] = BlockHandler(m_BlockTypes[OldIdx])->MetaRotateCW(m_BlockMetas[OldIdx]);
@ -1049,7 +1024,7 @@ void cBlockArea::RotateCW(void)
delete[] NewTypes; delete[] NewTypes;
delete[] NewMetas; delete[] NewMetas;
std::swap(m_SizeX, m_SizeZ); std::swap(m_Size.x, m_Size.z);
} }
@ -1072,13 +1047,13 @@ void cBlockArea::MirrorXY(void)
} }
// We are guaranteed that both blocktypes and blockmetas exist; mirror both at the same time: // We are guaranteed that both blocktypes and blockmetas exist; mirror both at the same time:
int HalfZ = m_SizeZ / 2; int HalfZ = m_Size.z / 2;
int MaxZ = m_SizeZ - 1; int MaxZ = m_Size.z - 1;
for (int y = 0; y < m_SizeY; y++) for (int y = 0; y < m_Size.y; y++)
{ {
for (int z = 0; z < HalfZ; z++) for (int z = 0; z < HalfZ; z++)
{ {
for (int x = 0; x < m_SizeX; x++) for (int x = 0; x < m_Size.x; x++)
{ {
int Idx1 = MakeIndex(x, y, z); int Idx1 = MakeIndex(x, y, z);
int Idx2 = MakeIndex(x, y, MaxZ - z); int Idx2 = MakeIndex(x, y, MaxZ - z);
@ -1112,13 +1087,13 @@ void cBlockArea::MirrorXZ(void)
} }
// We are guaranteed that both blocktypes and blockmetas exist; mirror both at the same time: // We are guaranteed that both blocktypes and blockmetas exist; mirror both at the same time:
int HalfY = m_SizeY / 2; int HalfY = m_Size.y / 2;
int MaxY = m_SizeY - 1; int MaxY = m_Size.y - 1;
for (int y = 0; y < HalfY; y++) for (int y = 0; y < HalfY; y++)
{ {
for (int z = 0; z < m_SizeZ; z++) for (int z = 0; z < m_Size.z; z++)
{ {
for (int x = 0; x < m_SizeX; x++) for (int x = 0; x < m_Size.x; x++)
{ {
int Idx1 = MakeIndex(x, y, z); int Idx1 = MakeIndex(x, y, z);
int Idx2 = MakeIndex(x, MaxY - y, z); int Idx2 = MakeIndex(x, MaxY - y, z);
@ -1152,11 +1127,11 @@ void cBlockArea::MirrorYZ(void)
} }
// We are guaranteed that both blocktypes and blockmetas exist; mirror both at the same time: // We are guaranteed that both blocktypes and blockmetas exist; mirror both at the same time:
int HalfX = m_SizeX / 2; int HalfX = m_Size.x / 2;
int MaxX = m_SizeX - 1; int MaxX = m_Size.x - 1;
for (int y = 0; y < m_SizeY; y++) for (int y = 0; y < m_Size.y; y++)
{ {
for (int z = 0; z < m_SizeZ; z++) for (int z = 0; z < m_Size.z; z++)
{ {
for (int x = 0; x < HalfX; x++) for (int x = 0; x < HalfX; x++)
{ {
@ -1180,16 +1155,16 @@ void cBlockArea::RotateCCWNoMeta(void)
{ {
if (HasBlockTypes()) if (HasBlockTypes())
{ {
BLOCKTYPE * NewTypes = new BLOCKTYPE[m_SizeX * m_SizeY * m_SizeZ]; BLOCKTYPE * NewTypes = new BLOCKTYPE[GetBlockCount()];
for (int x = 0; x < m_SizeX; x++) for (int x = 0; x < m_Size.x; x++)
{ {
int NewZ = m_SizeX - x - 1; int NewZ = m_Size.x - x - 1;
for (int z = 0; z < m_SizeZ; z++) for (int z = 0; z < m_Size.z; z++)
{ {
int NewX = z; int NewX = z;
for (int y = 0; y < m_SizeY; y++) for (int y = 0; y < m_Size.y; y++)
{ {
NewTypes[NewX + NewZ * m_SizeZ + y * m_SizeX * m_SizeZ] = m_BlockTypes[MakeIndex(x, y, z)]; NewTypes[NewX + NewZ * m_Size.z + y * m_Size.x * m_Size.z] = m_BlockTypes[MakeIndex(x, y, z)];
} // for y } // for y
} // for z } // for z
} // for x } // for x
@ -1198,23 +1173,23 @@ void cBlockArea::RotateCCWNoMeta(void)
} }
if (HasBlockMetas()) if (HasBlockMetas())
{ {
NIBBLETYPE * NewMetas = new NIBBLETYPE[m_SizeX * m_SizeY * m_SizeZ]; NIBBLETYPE * NewMetas = new NIBBLETYPE[GetBlockCount()];
for (int x = 0; x < m_SizeX; x++) for (int x = 0; x < m_Size.x; x++)
{ {
int NewZ = m_SizeX - x - 1; int NewZ = m_Size.x - x - 1;
for (int z = 0; z < m_SizeZ; z++) for (int z = 0; z < m_Size.z; z++)
{ {
int NewX = z; int NewX = z;
for (int y = 0; y < m_SizeY; y++) for (int y = 0; y < m_Size.y; y++)
{ {
NewMetas[NewX + NewZ * m_SizeZ + y * m_SizeX * m_SizeZ] = m_BlockMetas[MakeIndex(x, y, z)]; NewMetas[NewX + NewZ * m_Size.z + y * m_Size.x * m_Size.z] = m_BlockMetas[MakeIndex(x, y, z)];
} // for y } // for y
} // for z } // for z
} // for x } // for x
std::swap(m_BlockMetas, NewMetas); std::swap(m_BlockMetas, NewMetas);
delete[] NewMetas; delete[] NewMetas;
} }
std::swap(m_SizeX, m_SizeZ); std::swap(m_Size.x, m_Size.z);
} }
@ -1225,16 +1200,16 @@ void cBlockArea::RotateCWNoMeta(void)
{ {
if (HasBlockTypes()) if (HasBlockTypes())
{ {
BLOCKTYPE * NewTypes = new BLOCKTYPE[m_SizeX * m_SizeY * m_SizeZ]; BLOCKTYPE * NewTypes = new BLOCKTYPE[GetBlockCount()];
for (int z = 0; z < m_SizeZ; z++) for (int z = 0; z < m_Size.z; z++)
{ {
int NewX = m_SizeZ - z - 1; int NewX = m_Size.z - z - 1;
for (int x = 0; x < m_SizeX; x++) for (int x = 0; x < m_Size.x; x++)
{ {
int NewZ = x; int NewZ = x;
for (int y = 0; y < m_SizeY; y++) for (int y = 0; y < m_Size.y; y++)
{ {
NewTypes[NewX + NewZ * m_SizeZ + y * m_SizeX * m_SizeZ] = m_BlockTypes[MakeIndex(x, y, z)]; NewTypes[NewX + NewZ * m_Size.z + y * m_Size.x * m_Size.z] = m_BlockTypes[MakeIndex(x, y, z)];
} // for y } // for y
} // for x } // for x
} // for z } // for z
@ -1243,23 +1218,23 @@ void cBlockArea::RotateCWNoMeta(void)
} }
if (HasBlockMetas()) if (HasBlockMetas())
{ {
NIBBLETYPE * NewMetas = new NIBBLETYPE[m_SizeX * m_SizeY * m_SizeZ]; NIBBLETYPE * NewMetas = new NIBBLETYPE[GetBlockCount()];
for (int z = 0; z < m_SizeZ; z++) for (int z = 0; z < m_Size.z; z++)
{ {
int NewX = m_SizeZ - z - 1; int NewX = m_Size.z - z - 1;
for (int x = 0; x < m_SizeX; x++) for (int x = 0; x < m_Size.x; x++)
{ {
int NewZ = x; int NewZ = x;
for (int y = 0; y < m_SizeY; y++) for (int y = 0; y < m_Size.y; y++)
{ {
NewMetas[NewX + NewZ * m_SizeZ + y * m_SizeX * m_SizeZ] = m_BlockMetas[MakeIndex(x, y, z)]; NewMetas[NewX + NewZ * m_Size.z + y * m_Size.x * m_Size.z] = m_BlockMetas[MakeIndex(x, y, z)];
} // for y } // for y
} // for x } // for x
} // for z } // for z
std::swap(m_BlockMetas, NewMetas); std::swap(m_BlockMetas, NewMetas);
delete[] NewMetas; delete[] NewMetas;
} }
std::swap(m_SizeX, m_SizeZ); std::swap(m_Size.x, m_Size.z);
} }
@ -1268,15 +1243,15 @@ void cBlockArea::RotateCWNoMeta(void)
void cBlockArea::MirrorXYNoMeta(void) void cBlockArea::MirrorXYNoMeta(void)
{ {
int HalfZ = m_SizeZ / 2; int HalfZ = m_Size.z / 2;
int MaxZ = m_SizeZ - 1; int MaxZ = m_Size.z - 1;
if (HasBlockTypes()) if (HasBlockTypes())
{ {
for (int y = 0; y < m_SizeY; y++) for (int y = 0; y < m_Size.y; y++)
{ {
for (int z = 0; z < HalfZ; z++) for (int z = 0; z < HalfZ; z++)
{ {
for (int x = 0; x < m_SizeX; x++) for (int x = 0; x < m_Size.x; x++)
{ {
std::swap(m_BlockTypes[MakeIndex(x, y, z)], m_BlockTypes[MakeIndex(x, y, MaxZ - z)]); std::swap(m_BlockTypes[MakeIndex(x, y, z)], m_BlockTypes[MakeIndex(x, y, MaxZ - z)]);
} // for x } // for x
@ -1286,11 +1261,11 @@ void cBlockArea::MirrorXYNoMeta(void)
if (HasBlockMetas()) if (HasBlockMetas())
{ {
for (int y = 0; y < m_SizeY; y++) for (int y = 0; y < m_Size.y; y++)
{ {
for (int z = 0; z < HalfZ; z++) for (int z = 0; z < HalfZ; z++)
{ {
for (int x = 0; x < m_SizeX; x++) for (int x = 0; x < m_Size.x; x++)
{ {
std::swap(m_BlockMetas[MakeIndex(x, y, z)], m_BlockMetas[MakeIndex(x, y, MaxZ - z)]); std::swap(m_BlockMetas[MakeIndex(x, y, z)], m_BlockMetas[MakeIndex(x, y, MaxZ - z)]);
} // for x } // for x
@ -1305,15 +1280,15 @@ void cBlockArea::MirrorXYNoMeta(void)
void cBlockArea::MirrorXZNoMeta(void) void cBlockArea::MirrorXZNoMeta(void)
{ {
int HalfY = m_SizeY / 2; int HalfY = m_Size.y / 2;
int MaxY = m_SizeY - 1; int MaxY = m_Size.y - 1;
if (HasBlockTypes()) if (HasBlockTypes())
{ {
for (int y = 0; y < HalfY; y++) for (int y = 0; y < HalfY; y++)
{ {
for (int z = 0; z < m_SizeZ; z++) for (int z = 0; z < m_Size.z; z++)
{ {
for (int x = 0; x < m_SizeX; x++) for (int x = 0; x < m_Size.x; x++)
{ {
std::swap(m_BlockTypes[MakeIndex(x, y, z)], m_BlockTypes[MakeIndex(x, MaxY - y, z)]); std::swap(m_BlockTypes[MakeIndex(x, y, z)], m_BlockTypes[MakeIndex(x, MaxY - y, z)]);
} // for x } // for x
@ -1325,9 +1300,9 @@ void cBlockArea::MirrorXZNoMeta(void)
{ {
for (int y = 0; y < HalfY; y++) for (int y = 0; y < HalfY; y++)
{ {
for (int z = 0; z < m_SizeZ; z++) for (int z = 0; z < m_Size.z; z++)
{ {
for (int x = 0; x < m_SizeX; x++) for (int x = 0; x < m_Size.x; x++)
{ {
std::swap(m_BlockMetas[MakeIndex(x, y, z)], m_BlockMetas[MakeIndex(x, MaxY - y, z)]); std::swap(m_BlockMetas[MakeIndex(x, y, z)], m_BlockMetas[MakeIndex(x, MaxY - y, z)]);
} // for x } // for x
@ -1342,13 +1317,13 @@ void cBlockArea::MirrorXZNoMeta(void)
void cBlockArea::MirrorYZNoMeta(void) void cBlockArea::MirrorYZNoMeta(void)
{ {
int HalfX = m_SizeX / 2; int HalfX = m_Size.x / 2;
int MaxX = m_SizeX - 1; int MaxX = m_Size.x - 1;
if (HasBlockTypes()) if (HasBlockTypes())
{ {
for (int y = 0; y < m_SizeY; y++) for (int y = 0; y < m_Size.y; y++)
{ {
for (int z = 0; z < m_SizeZ; z++) for (int z = 0; z < m_Size.z; z++)
{ {
for (int x = 0; x < HalfX; x++) for (int x = 0; x < HalfX; x++)
{ {
@ -1360,9 +1335,9 @@ void cBlockArea::MirrorYZNoMeta(void)
if (HasBlockMetas()) if (HasBlockMetas())
{ {
for (int y = 0; y < m_SizeY; y++) for (int y = 0; y < m_Size.y; y++)
{ {
for (int z = 0; z < m_SizeZ; z++) for (int z = 0; z < m_Size.z; z++)
{ {
for (int x = 0; x < HalfX; x++) for (int x = 0; x < HalfX; x++)
{ {
@ -1393,7 +1368,7 @@ void cBlockArea::SetRelBlockType(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a
void cBlockArea::SetBlockType(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType) void cBlockArea::SetBlockType(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType)
{ {
SetRelBlockType(a_BlockX - m_OriginX, a_BlockY - m_OriginY, a_BlockZ - m_OriginZ, a_BlockType); SetRelBlockType(a_BlockX - m_Origin.x, a_BlockY - m_Origin.y, a_BlockZ - m_Origin.z, a_BlockType);
} }
@ -1470,7 +1445,7 @@ BLOCKTYPE cBlockArea::GetRelBlockType(int a_RelX, int a_RelY, int a_RelZ) const
BLOCKTYPE cBlockArea::GetBlockType(int a_BlockX, int a_BlockY, int a_BlockZ) const BLOCKTYPE cBlockArea::GetBlockType(int a_BlockX, int a_BlockY, int a_BlockZ) const
{ {
return GetRelBlockType(a_BlockX - m_OriginX, a_BlockY - m_OriginY, a_BlockZ - m_OriginZ); return GetRelBlockType(a_BlockX - m_Origin.x, a_BlockY - m_Origin.y, a_BlockZ - m_Origin.z);
} }
@ -1533,7 +1508,7 @@ NIBBLETYPE cBlockArea::GetBlockSkyLight(int a_BlockX, int a_BlockY, int a_BlockZ
void cBlockArea::SetBlockTypeMeta(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) void cBlockArea::SetBlockTypeMeta(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
{ {
SetRelBlockTypeMeta(a_BlockX - m_OriginX, a_BlockY - m_OriginY, a_BlockZ - m_OriginZ, a_BlockType, a_BlockMeta); SetRelBlockTypeMeta(a_BlockX - m_Origin.x, a_BlockY - m_Origin.y, a_BlockZ - m_Origin.z, a_BlockType, a_BlockMeta);
} }
@ -1567,7 +1542,7 @@ void cBlockArea::SetRelBlockTypeMeta(int a_RelX, int a_RelY, int a_RelZ, B
void cBlockArea::GetBlockTypeMeta(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta) const void cBlockArea::GetBlockTypeMeta(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta) const
{ {
return GetRelBlockTypeMeta(a_BlockX - m_OriginX, a_BlockY - m_OriginY, a_BlockZ - m_OriginZ, a_BlockType, a_BlockMeta); return GetRelBlockTypeMeta(a_BlockX - m_Origin.x, a_BlockY - m_Origin.y, a_BlockZ - m_Origin.z, a_BlockType, a_BlockMeta);
} }
@ -1670,9 +1645,7 @@ bool cBlockArea::SetSize(int a_SizeX, int a_SizeY, int a_SizeZ, int a_DataTypes)
return false; return false;
} }
} }
m_SizeX = a_SizeX; m_Size.Set(a_SizeX, a_SizeY, a_SizeZ);
m_SizeY = a_SizeY;
m_SizeZ = a_SizeZ;
return true; return true;
} }
@ -1683,13 +1656,13 @@ bool cBlockArea::SetSize(int a_SizeX, int a_SizeY, int a_SizeZ, int a_DataTypes)
int cBlockArea::MakeIndex(int a_RelX, int a_RelY, int a_RelZ) const int cBlockArea::MakeIndex(int a_RelX, int a_RelY, int a_RelZ) const
{ {
ASSERT(a_RelX >= 0); ASSERT(a_RelX >= 0);
ASSERT(a_RelX < m_SizeX); ASSERT(a_RelX < m_Size.x);
ASSERT(a_RelY >= 0); ASSERT(a_RelY >= 0);
ASSERT(a_RelY < m_SizeY); ASSERT(a_RelY < m_Size.y);
ASSERT(a_RelZ >= 0); ASSERT(a_RelZ >= 0);
ASSERT(a_RelZ < m_SizeZ); ASSERT(a_RelZ < m_Size.z);
return a_RelX + a_RelZ * m_SizeX + a_RelY * m_SizeX * m_SizeZ; return a_RelX + a_RelZ * m_Size.x + a_RelY * m_Size.x * m_Size.z;
} }
@ -1712,7 +1685,7 @@ void cBlockArea::SetRelNibble(int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE a_V
void cBlockArea::SetNibble(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_Value, NIBBLETYPE * a_Array) void cBlockArea::SetNibble(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_Value, NIBBLETYPE * a_Array)
{ {
SetRelNibble(a_BlockX - m_OriginX, a_BlockY - m_OriginY, a_BlockZ - m_OriginZ, a_Value, a_Array); SetRelNibble(a_BlockX - m_Origin.x, a_BlockY - m_Origin.y, a_BlockZ - m_Origin.z, a_Value, a_Array);
} }
@ -1735,7 +1708,7 @@ NIBBLETYPE cBlockArea::GetRelNibble(int a_RelX, int a_RelY, int a_RelZ, NIBBLETY
NIBBLETYPE cBlockArea::GetNibble(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE * a_Array) const NIBBLETYPE cBlockArea::GetNibble(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE * a_Array) const
{ {
return GetRelNibble(a_BlockX - m_OriginX, a_BlockY - m_OriginY, a_BlockZ - m_OriginZ, a_Array); return GetRelNibble(a_BlockX - m_Origin.x, a_BlockY - m_Origin.y, a_BlockZ - m_Origin.z, a_Array);
} }
@ -1748,9 +1721,7 @@ NIBBLETYPE cBlockArea::GetNibble(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBL
cBlockArea::cChunkReader::cChunkReader(cBlockArea & a_Area) : cBlockArea::cChunkReader::cChunkReader(cBlockArea & a_Area) :
m_Area(a_Area), m_Area(a_Area),
m_OriginX(a_Area.m_OriginX), m_Origin(a_Area.m_Origin.x, a_Area.m_Origin.y, a_Area.m_Origin.z)
m_OriginY(a_Area.m_OriginY),
m_OriginZ(a_Area.m_OriginZ)
{ {
} }
@ -1760,8 +1731,8 @@ cBlockArea::cChunkReader::cChunkReader(cBlockArea & a_Area) :
void cBlockArea::cChunkReader::CopyNibbles(NIBBLETYPE * a_AreaDst, const NIBBLETYPE * a_ChunkSrc) void cBlockArea::cChunkReader::CopyNibbles(NIBBLETYPE * a_AreaDst, const NIBBLETYPE * a_ChunkSrc)
{ {
int SizeY = m_Area.m_SizeY; int SizeY = m_Area.m_Size.y;
int MinY = m_OriginY; int MinY = m_Origin.y;
// SizeX, SizeZ are the dmensions of the block data to copy from the current chunk (size of the geometric union) // SizeX, SizeZ are the dmensions of the block data to copy from the current chunk (size of the geometric union)
// OffX, OffZ are the offsets of the current chunk data from the area origin // OffX, OffZ are the offsets of the current chunk data from the area origin
@ -1770,7 +1741,7 @@ void cBlockArea::cChunkReader::CopyNibbles(NIBBLETYPE * a_AreaDst, const NIBBLET
int SizeZ = cChunkDef::Width; int SizeZ = cChunkDef::Width;
int OffX, OffZ; int OffX, OffZ;
int BaseX, BaseZ; int BaseX, BaseZ;
OffX = m_CurrentChunkX * cChunkDef::Width - m_OriginX; OffX = m_CurrentChunkX * cChunkDef::Width - m_Origin.x;
if (OffX < 0) if (OffX < 0)
{ {
BaseX = -OffX; BaseX = -OffX;
@ -1781,7 +1752,7 @@ void cBlockArea::cChunkReader::CopyNibbles(NIBBLETYPE * a_AreaDst, const NIBBLET
{ {
BaseX = 0; BaseX = 0;
} }
OffZ = m_CurrentChunkZ * cChunkDef::Width - m_OriginZ; OffZ = m_CurrentChunkZ * cChunkDef::Width - m_Origin.z;
if (OffZ < 0) if (OffZ < 0)
{ {
BaseZ = -OffZ; BaseZ = -OffZ;
@ -1793,13 +1764,13 @@ void cBlockArea::cChunkReader::CopyNibbles(NIBBLETYPE * a_AreaDst, const NIBBLET
BaseZ = 0; BaseZ = 0;
} }
// If the chunk extends beyond the area in the X or Z axis, cut off the Size: // If the chunk extends beyond the area in the X or Z axis, cut off the Size:
if ((m_CurrentChunkX + 1) * cChunkDef::Width > m_OriginX + m_Area.m_SizeX) if ((m_CurrentChunkX + 1) * cChunkDef::Width > m_Origin.x + m_Area.m_Size.x)
{ {
SizeX -= (m_CurrentChunkX + 1) * cChunkDef::Width - (m_OriginX + m_Area.m_SizeX); SizeX -= (m_CurrentChunkX + 1) * cChunkDef::Width - (m_Origin.x + m_Area.m_Size.x);
} }
if ((m_CurrentChunkZ + 1) * cChunkDef::Width > m_OriginZ + m_Area.m_SizeZ) if ((m_CurrentChunkZ + 1) * cChunkDef::Width > m_Origin.z + m_Area.m_Size.z)
{ {
SizeZ -= (m_CurrentChunkZ + 1) * cChunkDef::Width - (m_OriginZ + m_Area.m_SizeZ); SizeZ -= (m_CurrentChunkZ + 1) * cChunkDef::Width - (m_Origin.z + m_Area.m_Size.z);
} }
for (int y = 0; y < SizeY; y++) for (int y = 0; y < SizeY; y++)
@ -1843,8 +1814,8 @@ void cBlockArea::cChunkReader::BlockTypes(const BLOCKTYPE * a_BlockTypes)
return; return;
} }
int SizeY = m_Area.m_SizeY; int SizeY = m_Area.m_Size.y;
int MinY = m_OriginY; int MinY = m_Origin.y;
// SizeX, SizeZ are the dmensions of the block data to copy from the current chunk (size of the geometric union) // SizeX, SizeZ are the dmensions of the block data to copy from the current chunk (size of the geometric union)
// OffX, OffZ are the offsets of the current chunk data from the area origin // OffX, OffZ are the offsets of the current chunk data from the area origin
@ -1853,7 +1824,7 @@ void cBlockArea::cChunkReader::BlockTypes(const BLOCKTYPE * a_BlockTypes)
int SizeZ = cChunkDef::Width; int SizeZ = cChunkDef::Width;
int OffX, OffZ; int OffX, OffZ;
int BaseX, BaseZ; int BaseX, BaseZ;
OffX = m_CurrentChunkX * cChunkDef::Width - m_OriginX; OffX = m_CurrentChunkX * cChunkDef::Width - m_Origin.x;
if (OffX < 0) if (OffX < 0)
{ {
BaseX = -OffX; BaseX = -OffX;
@ -1864,7 +1835,7 @@ void cBlockArea::cChunkReader::BlockTypes(const BLOCKTYPE * a_BlockTypes)
{ {
BaseX = 0; BaseX = 0;
} }
OffZ = m_CurrentChunkZ * cChunkDef::Width - m_OriginZ; OffZ = m_CurrentChunkZ * cChunkDef::Width - m_Origin.z;
if (OffZ < 0) if (OffZ < 0)
{ {
BaseZ = -OffZ; BaseZ = -OffZ;
@ -1876,13 +1847,13 @@ void cBlockArea::cChunkReader::BlockTypes(const BLOCKTYPE * a_BlockTypes)
BaseZ = 0; BaseZ = 0;
} }
// If the chunk extends beyond the area in the X or Z axis, cut off the Size: // If the chunk extends beyond the area in the X or Z axis, cut off the Size:
if ((m_CurrentChunkX + 1) * cChunkDef::Width > m_OriginX + m_Area.m_SizeX) if ((m_CurrentChunkX + 1) * cChunkDef::Width > m_Origin.x + m_Area.m_Size.x)
{ {
SizeX -= (m_CurrentChunkX + 1) * cChunkDef::Width - (m_OriginX + m_Area.m_SizeX); SizeX -= (m_CurrentChunkX + 1) * cChunkDef::Width - (m_Origin.x + m_Area.m_Size.x);
} }
if ((m_CurrentChunkZ + 1) * cChunkDef::Width > m_OriginZ + m_Area.m_SizeZ) if ((m_CurrentChunkZ + 1) * cChunkDef::Width > m_Origin.z + m_Area.m_Size.z)
{ {
SizeZ -= (m_CurrentChunkZ + 1) * cChunkDef::Width - (m_OriginZ + m_Area.m_SizeZ); SizeZ -= (m_CurrentChunkZ + 1) * cChunkDef::Width - (m_Origin.z + m_Area.m_Size.z);
} }
for (int y = 0; y < SizeY; y++) for (int y = 0; y < SizeY; y++)
@ -2002,21 +1973,21 @@ void cBlockArea::CropNibbles(NIBBLEARRAY & a_Array, int a_AddMinX, int a_SubMaxX
void cBlockArea::ExpandBlockTypes(int a_SubMinX, int a_AddMaxX, int a_SubMinY, int a_AddMaxY, int a_SubMinZ, int a_AddMaxZ) void cBlockArea::ExpandBlockTypes(int a_SubMinX, int a_AddMaxX, int a_SubMinY, int a_AddMaxY, int a_SubMinZ, int a_AddMaxZ)
{ {
int NewSizeX = m_SizeX + a_SubMinX + a_AddMaxX; int NewSizeX = m_Size.x + a_SubMinX + a_AddMaxX;
int NewSizeY = m_SizeY + a_SubMinY + a_AddMaxY; int NewSizeY = m_Size.y + a_SubMinY + a_AddMaxY;
int NewSizeZ = m_SizeZ + a_SubMinZ + a_AddMaxZ; int NewSizeZ = m_Size.z + a_SubMinZ + a_AddMaxZ;
int BlockCount = NewSizeX * NewSizeY * NewSizeZ; int BlockCount = NewSizeX * NewSizeY * NewSizeZ;
BLOCKTYPE * NewBlockTypes = new BLOCKTYPE[BlockCount]; BLOCKTYPE * NewBlockTypes = new BLOCKTYPE[BlockCount];
memset(NewBlockTypes, 0, BlockCount * sizeof(BLOCKTYPE)); memset(NewBlockTypes, 0, BlockCount * sizeof(BLOCKTYPE));
int OldIndex = 0; int OldIndex = 0;
for (int y = 0; y < m_SizeY; y++) for (int y = 0; y < m_Size.y; y++)
{ {
int IndexBaseY = (y + a_SubMinY) * m_SizeX * m_SizeZ; int IndexBaseY = (y + a_SubMinY) * m_Size.x * m_Size.z;
for (int z = 0; z < m_SizeZ; z++) for (int z = 0; z < m_Size.z; z++)
{ {
int IndexBaseZ = IndexBaseY + (z + a_SubMinZ) * m_SizeX; int IndexBaseZ = IndexBaseY + (z + a_SubMinZ) * m_Size.x;
int idx = IndexBaseZ + a_SubMinX; int idx = IndexBaseZ + a_SubMinX;
for (int x = 0; x < m_SizeX; x++) for (int x = 0; x < m_Size.x; x++)
{ {
NewBlockTypes[idx++] = m_BlockTypes[OldIndex++]; NewBlockTypes[idx++] = m_BlockTypes[OldIndex++];
} // for x } // for x
@ -2032,21 +2003,21 @@ void cBlockArea::ExpandBlockTypes(int a_SubMinX, int a_AddMaxX, int a_SubMinY, i
void cBlockArea::ExpandNibbles(NIBBLEARRAY & a_Array, int a_SubMinX, int a_AddMaxX, int a_SubMinY, int a_AddMaxY, int a_SubMinZ, int a_AddMaxZ) void cBlockArea::ExpandNibbles(NIBBLEARRAY & a_Array, int a_SubMinX, int a_AddMaxX, int a_SubMinY, int a_AddMaxY, int a_SubMinZ, int a_AddMaxZ)
{ {
int NewSizeX = m_SizeX + a_SubMinX + a_AddMaxX; int NewSizeX = m_Size.x + a_SubMinX + a_AddMaxX;
int NewSizeY = m_SizeY + a_SubMinY + a_AddMaxY; int NewSizeY = m_Size.y + a_SubMinY + a_AddMaxY;
int NewSizeZ = m_SizeZ + a_SubMinZ + a_AddMaxZ; int NewSizeZ = m_Size.z + a_SubMinZ + a_AddMaxZ;
int BlockCount = NewSizeX * NewSizeY * NewSizeZ; int BlockCount = NewSizeX * NewSizeY * NewSizeZ;
NIBBLETYPE * NewNibbles = new NIBBLETYPE[BlockCount]; NIBBLETYPE * NewNibbles = new NIBBLETYPE[BlockCount];
memset(NewNibbles, 0, BlockCount * sizeof(NIBBLETYPE)); memset(NewNibbles, 0, BlockCount * sizeof(NIBBLETYPE));
int OldIndex = 0; int OldIndex = 0;
for (int y = 0; y < m_SizeY; y++) for (int y = 0; y < m_Size.y; y++)
{ {
int IndexBaseY = (y + a_SubMinY) * m_SizeX * m_SizeZ; int IndexBaseY = (y + a_SubMinY) * m_Size.x * m_Size.z;
for (int z = 0; z < m_SizeZ; z++) for (int z = 0; z < m_Size.z; z++)
{ {
int IndexBaseZ = IndexBaseY + (z + a_SubMinZ) * m_SizeX; int IndexBaseZ = IndexBaseY + (z + a_SubMinZ) * m_Size.x;
int idx = IndexBaseZ + a_SubMinX; int idx = IndexBaseZ + a_SubMinX;
for (int x = 0; x < m_SizeX; x++) for (int x = 0; x < m_Size.x; x++)
{ {
NewNibbles[idx++] = a_Array[OldIndex++]; NewNibbles[idx++] = a_Array[OldIndex++];
} // for x } // for x
@ -2057,6 +2028,9 @@ void cBlockArea::ExpandNibbles(NIBBLEARRAY & a_Array, int a_SubMinX, int a_AddMa
} }
void cBlockArea::RelSetData( void cBlockArea::RelSetData(
int a_RelX, int a_RelY, int a_RelZ, int a_RelX, int a_RelY, int a_RelZ,
int a_DataTypes, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, int a_DataTypes, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta,

View File

@ -43,6 +43,8 @@ public:
baSkyLight = 8, baSkyLight = 8,
} ; } ;
/** The per-block strategy to use when merging another block area into this object.
See the Merge function for the description of these */
enum eMergeStrategy enum eMergeStrategy
{ {
msOverwrite, msOverwrite,
@ -232,18 +234,24 @@ public:
void GetBlockTypeMeta (int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta) const; void GetBlockTypeMeta (int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta) const;
void GetRelBlockTypeMeta(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta) const; void GetRelBlockTypeMeta(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta) const;
// GetSize() is already exported manually to return 3 numbers, can't auto-export
const Vector3i & GetSize(void) const { return m_Size; }
// GetOrigin() is already exported manually to return 3 numbers, can't auto-export
const Vector3i & GetOrigin(void) const { return m_Origin; }
// tolua_begin // tolua_begin
int GetSizeX(void) const { return m_SizeX; } int GetSizeX(void) const { return m_Size.x; }
int GetSizeY(void) const { return m_SizeY; } int GetSizeY(void) const { return m_Size.y; }
int GetSizeZ(void) const { return m_SizeZ; } int GetSizeZ(void) const { return m_Size.z; }
/** Returns the volume of the area, as number of blocks */ /** Returns the volume of the area, as number of blocks */
int GetVolume(void) const { return m_SizeX * m_SizeY * m_SizeZ; } int GetVolume(void) const { return m_Size.x * m_Size.y * m_Size.z; }
int GetOriginX(void) const { return m_OriginX; } int GetOriginX(void) const { return m_Origin.x; }
int GetOriginY(void) const { return m_OriginY; } int GetOriginY(void) const { return m_Origin.y; }
int GetOriginZ(void) const { return m_OriginZ; } int GetOriginZ(void) const { return m_Origin.z; }
/** Returns the datatypes that are stored in the object (bitmask of baXXX values) */ /** Returns the datatypes that are stored in the object (bitmask of baXXX values) */
int GetDataTypes(void) const; int GetDataTypes(void) const;
@ -261,7 +269,7 @@ public:
NIBBLETYPE * GetBlockMetas (void) const { return m_BlockMetas; } // NOTE: one byte per block! NIBBLETYPE * GetBlockMetas (void) const { return m_BlockMetas; } // NOTE: one byte per block!
NIBBLETYPE * GetBlockLight (void) const { return m_BlockLight; } // NOTE: one byte per block! NIBBLETYPE * GetBlockLight (void) const { return m_BlockLight; } // NOTE: one byte per block!
NIBBLETYPE * GetBlockSkyLight(void) const { return m_BlockSkyLight; } // NOTE: one byte per block! NIBBLETYPE * GetBlockSkyLight(void) const { return m_BlockSkyLight; } // NOTE: one byte per block!
int GetBlockCount(void) const { return m_SizeX * m_SizeY * m_SizeZ; } int GetBlockCount(void) const { return m_Size.x * m_Size.y * m_Size.z; }
int MakeIndex(int a_RelX, int a_RelY, int a_RelZ) const; int MakeIndex(int a_RelX, int a_RelY, int a_RelZ) const;
protected: protected:
@ -276,9 +284,7 @@ protected:
protected: protected:
cBlockArea & m_Area; cBlockArea & m_Area;
int m_OriginX; Vector3i m_Origin;
int m_OriginY;
int m_OriginZ;
int m_CurrentChunkX; int m_CurrentChunkX;
int m_CurrentChunkZ; int m_CurrentChunkZ;
@ -295,12 +301,8 @@ protected:
typedef NIBBLETYPE * NIBBLEARRAY; typedef NIBBLETYPE * NIBBLEARRAY;
int m_OriginX; Vector3i m_Origin;
int m_OriginY; Vector3i m_Size;
int m_OriginZ;
int m_SizeX;
int m_SizeY;
int m_SizeZ;
/** An extra data value sometimes stored in the .schematic file. Used mainly by the WorldEdit plugin. /** An extra data value sometimes stored in the .schematic file. Used mainly by the WorldEdit plugin.
cBlockArea doesn't use this value in any way. */ cBlockArea doesn't use this value in any way. */

View File

@ -343,9 +343,9 @@ void cChunkDesc::ReadBlockArea(cBlockArea & a_Dest, int a_MinRelX, int a_MaxRelX
int SizeY = a_MaxRelY - a_MinRelY; int SizeY = a_MaxRelY - a_MinRelY;
int SizeZ = a_MaxRelZ - a_MinRelZ; int SizeZ = a_MaxRelZ - a_MinRelZ;
a_Dest.Clear(); a_Dest.Clear();
a_Dest.m_OriginX = m_ChunkX * cChunkDef::Width + a_MinRelX; a_Dest.m_Origin.x = m_ChunkX * cChunkDef::Width + a_MinRelX;
a_Dest.m_OriginY = a_MinRelY; a_Dest.m_Origin.y = a_MinRelY;
a_Dest.m_OriginZ = m_ChunkZ * cChunkDef::Width + a_MinRelZ; a_Dest.m_Origin.z = m_ChunkZ * cChunkDef::Width + a_MinRelZ;
a_Dest.SetSize(SizeX, SizeY, SizeZ, cBlockArea::baTypes | cBlockArea::baMetas); a_Dest.SetSize(SizeX, SizeY, SizeZ, cBlockArea::baTypes | cBlockArea::baMetas);
for (int y = 0; y < SizeY; y++) for (int y = 0; y < SizeY; y++)

View File

@ -197,7 +197,7 @@ bool cSchematicFileSerializer::LoadFromSchematicNBT(cBlockArea & a_BlockArea, cP
} }
// Copy the block types and metas: // Copy the block types and metas:
int NumBytes = a_BlockArea.m_SizeX * a_BlockArea.m_SizeY * a_BlockArea.m_SizeZ; int NumBytes = a_BlockArea.GetBlockCount();
if (a_NBT.GetDataLength(TBlockTypes) < NumBytes) if (a_NBT.GetDataLength(TBlockTypes) < NumBytes)
{ {
LOG("BlockTypes truncated in the schematic file (exp %d, got %d bytes). Loading partial.", LOG("BlockTypes truncated in the schematic file (exp %d, got %d bytes). Loading partial.",
@ -209,7 +209,7 @@ bool cSchematicFileSerializer::LoadFromSchematicNBT(cBlockArea & a_BlockArea, cP
if (AreMetasPresent) if (AreMetasPresent)
{ {
int NumBytes = a_BlockArea.m_SizeX * a_BlockArea.m_SizeY * a_BlockArea.m_SizeZ; int NumBytes = a_BlockArea.GetBlockCount();
if (a_NBT.GetDataLength(TBlockMetas) < NumBytes) if (a_NBT.GetDataLength(TBlockMetas) < NumBytes)
{ {
LOG("BlockMetas truncated in the schematic file (exp %d, got %d bytes). Loading partial.", LOG("BlockMetas truncated in the schematic file (exp %d, got %d bytes). Loading partial.",
@ -230,9 +230,9 @@ bool cSchematicFileSerializer::LoadFromSchematicNBT(cBlockArea & a_BlockArea, cP
AString cSchematicFileSerializer::SaveToSchematicNBT(const cBlockArea & a_BlockArea) AString cSchematicFileSerializer::SaveToSchematicNBT(const cBlockArea & a_BlockArea)
{ {
cFastNBTWriter Writer("Schematic"); cFastNBTWriter Writer("Schematic");
Writer.AddShort("Width", a_BlockArea.m_SizeX); Writer.AddShort("Width", a_BlockArea.m_Size.x);
Writer.AddShort("Height", a_BlockArea.m_SizeY); Writer.AddShort("Height", a_BlockArea.m_Size.y);
Writer.AddShort("Length", a_BlockArea.m_SizeZ); Writer.AddShort("Length", a_BlockArea.m_Size.z);
Writer.AddString("Materials", "Alpha"); Writer.AddString("Materials", "Alpha");
if (a_BlockArea.HasBlockTypes()) if (a_BlockArea.HasBlockTypes())
{ {