diff options
Diffstat (limited to '')
-rw-r--r-- | src/BlockArea.cpp | 709 |
1 files changed, 371 insertions, 338 deletions
diff --git a/src/BlockArea.cpp b/src/BlockArea.cpp index 910661f60..40cca8882 100644 --- a/src/BlockArea.cpp +++ b/src/BlockArea.cpp @@ -6,10 +6,9 @@ #include "Globals.h" #include "BlockArea.h" -#include "World.h" #include "OSSupport/GZipFile.h" -#include "WorldStorage/FastNBT.h" #include "Blocks/BlockHandler.h" +#include "Cuboid.h" @@ -55,7 +54,7 @@ template<typename Combinator> void InternalMergeBlocks( /// Combinator used for cBlockArea::msOverwrite merging -static void MergeCombinatorOverwrite(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBBLETYPE & a_DstMeta, NIBBLETYPE a_SrcMeta) +static inline void MergeCombinatorOverwrite(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBBLETYPE & a_DstMeta, NIBBLETYPE a_SrcMeta) { a_DstType = a_SrcType; a_DstMeta = a_SrcMeta; @@ -66,7 +65,7 @@ static void MergeCombinatorOverwrite(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, /// Combinator used for cBlockArea::msFillAir merging -static void MergeCombinatorFillAir(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBBLETYPE & a_DstMeta, NIBBLETYPE a_SrcMeta) +static inline void MergeCombinatorFillAir(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBBLETYPE & a_DstMeta, NIBBLETYPE a_SrcMeta) { if (a_DstType == E_BLOCK_AIR) { @@ -81,7 +80,7 @@ static void MergeCombinatorFillAir(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, N /// Combinator used for cBlockArea::msImprint merging -static void MergeCombinatorImprint(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBBLETYPE & a_DstMeta, NIBBLETYPE a_SrcMeta) +static inline void MergeCombinatorImprint(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBBLETYPE & a_DstMeta, NIBBLETYPE a_SrcMeta) { if (a_SrcType != E_BLOCK_AIR) { @@ -96,7 +95,7 @@ static void MergeCombinatorImprint(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, N /// Combinator used for cBlockArea::msLake merging -static void MergeCombinatorLake(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBBLETYPE & a_DstMeta, NIBBLETYPE a_SrcMeta) +static inline void MergeCombinatorLake(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBBLETYPE & a_DstMeta, NIBBLETYPE a_SrcMeta) { // Sponge is the NOP block if (a_SrcType == E_BLOCK_SPONGE) @@ -159,16 +158,59 @@ static void MergeCombinatorLake(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBB +/** Combinator used for cBlockArea::msSpongePrint merging */ +static inline void MergeCombinatorSpongePrint(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBBLETYPE & a_DstMeta, NIBBLETYPE a_SrcMeta) +{ + // Sponge overwrites nothing, everything else overwrites anything + if (a_SrcType != E_BLOCK_SPONGE) + { + a_DstType = a_SrcType; + a_DstMeta = a_SrcMeta; + } +} + + + + + +/** Combinator used for cBlockArea::msDifference merging */ +static inline void MergeCombinatorDifference(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBBLETYPE & a_DstMeta, NIBBLETYPE a_SrcMeta) +{ + if ((a_DstType == a_SrcType) && (a_DstMeta == a_SrcMeta)) + { + a_DstType = E_BLOCK_AIR; + a_DstMeta = 0; + } + else + { + a_DstType = a_SrcType; + a_DstMeta = a_SrcMeta; + } +} + + + + + +/** Combinator used for cBlockArea::msMask merging */ +static inline void MergeCombinatorMask(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBBLETYPE & a_DstMeta, NIBBLETYPE a_SrcMeta) +{ + // If the blocks are the same, keep the dest; otherwise replace with air + if ((a_SrcType != a_DstType) || (a_SrcMeta != a_DstMeta)) + { + a_DstType = E_BLOCK_AIR; + a_DstMeta = 0; + } +} + + + + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cBlockArea: cBlockArea::cBlockArea(void) : - m_OriginX(0), - m_OriginY(0), - m_OriginZ(0), - m_SizeX(0), - m_SizeY(0), - m_SizeZ(0), m_BlockTypes(NULL), m_BlockMetas(NULL), m_BlockLight(NULL), @@ -195,12 +237,8 @@ void cBlockArea::Clear(void) delete[] m_BlockMetas; m_BlockMetas = NULL; delete[] m_BlockLight; m_BlockLight = NULL; delete[] m_BlockSkyLight; m_BlockSkyLight = NULL; - m_OriginX = 0; - m_OriginY = 0; - m_OriginZ = 0; - m_SizeX = 0; - m_SizeY = 0; - m_SizeZ = 0; + m_Origin.Set(0, 0, 0); + m_Size.Set(0, 0, 0); } @@ -243,12 +281,35 @@ void cBlockArea::Create(int a_SizeX, int a_SizeY, int a_SizeZ, int a_DataTypes) m_BlockSkyLight[i] = 0x0f; } } - m_SizeX = a_SizeX; - m_SizeY = a_SizeY; - m_SizeZ = a_SizeZ; - m_OriginX = 0; - m_OriginY = 0; - m_OriginZ = 0; + m_Size.Set(a_SizeX, a_SizeY, a_SizeZ); + m_Origin.Set(0, 0, 0); +} + + + + + +void cBlockArea::Create(const Vector3i & a_Size, int a_DataTypes) +{ + Create(a_Size.x, a_Size.y, a_Size.z, a_DataTypes); +} + + + + + +void cBlockArea::SetWEOffset(int a_OffsetX, int a_OffsetY, int a_OffsetZ) +{ + m_WEOffset.Set(a_OffsetX, a_OffsetY, a_OffsetZ); +} + + + + + +void cBlockArea::SetWEOffset(const Vector3i & a_Offset) +{ + m_WEOffset.Set(a_Offset.x, a_Offset.y, a_Offset.z); } @@ -257,16 +318,23 @@ void cBlockArea::Create(int a_SizeX, int a_SizeY, int a_SizeZ, int a_DataTypes) void cBlockArea::SetOrigin(int a_OriginX, int a_OriginY, int a_OriginZ) { - m_OriginX = a_OriginX; - m_OriginY = a_OriginY; - m_OriginZ = a_OriginZ; + m_Origin.Set(a_OriginX, a_OriginY, a_OriginZ); +} + + + + + +void cBlockArea::SetOrigin(const Vector3i & a_Origin) +{ + m_Origin.Set(a_Origin.x, a_Origin.y, a_Origin.z); } -bool cBlockArea::Read(cWorld * a_World, int a_MinBlockX, int a_MaxBlockX, int a_MinBlockY, int a_MaxBlockY, int a_MinBlockZ, int a_MaxBlockZ, int a_DataTypes) +bool cBlockArea::Read(cForEachChunkProvider * a_ForEachChunkProvider, int a_MinBlockX, int a_MaxBlockX, int a_MinBlockY, int a_MaxBlockY, int a_MinBlockZ, int a_MaxBlockZ, int a_DataTypes) { // Normalize the coords: if (a_MinBlockX > a_MaxBlockX) @@ -315,9 +383,7 @@ bool cBlockArea::Read(cWorld * a_World, int a_MinBlockX, int a_MaxBlockX, int a_ { return false; } - m_OriginX = a_MinBlockX; - m_OriginY = a_MinBlockY; - m_OriginZ = a_MinBlockZ; + m_Origin.Set(a_MinBlockX, a_MinBlockY, a_MinBlockZ); cChunkReader Reader(*this); // Convert block coords to chunks coords: @@ -327,7 +393,7 @@ bool cBlockArea::Read(cWorld * a_World, int a_MinBlockX, int a_MaxBlockX, int a_ cChunkDef::AbsoluteToRelative(a_MaxBlockX, a_MaxBlockY, a_MaxBlockZ, MaxChunkX, MaxChunkZ); // Query block data: - if (!a_World->ForEachChunkInRect(MinChunkX, MaxChunkX, MinChunkZ, MaxChunkZ, Reader)) + if (!a_ForEachChunkProvider->ForEachChunkInRect(MinChunkX, MaxChunkX, MinChunkZ, MaxChunkZ, Reader)) { Clear(); return false; @@ -340,7 +406,37 @@ bool cBlockArea::Read(cWorld * a_World, int a_MinBlockX, int a_MaxBlockX, int a_ -bool cBlockArea::Write(cWorld * a_World, int a_MinBlockX, int a_MinBlockY, int a_MinBlockZ, int a_DataTypes) +bool cBlockArea::Read(cForEachChunkProvider * a_ForEachChunkProvider, const cCuboid & a_Bounds, int a_DataTypes) +{ + return Read( + a_ForEachChunkProvider, + a_Bounds.p1.x, a_Bounds.p2.x, + a_Bounds.p1.y, a_Bounds.p2.y, + a_Bounds.p1.z, a_Bounds.p2.z, + a_DataTypes + ); +} + + + + + +bool cBlockArea::Read(cForEachChunkProvider * a_ForEachChunkProvider, const Vector3i & a_Point1, const Vector3i & a_Point2, int a_DataTypes) +{ + return Read( + a_ForEachChunkProvider, + a_Point1.x, a_Point2.x, + a_Point1.y, a_Point2.y, + a_Point1.z, a_Point2.z, + a_DataTypes + ); +} + + + + + +bool cBlockArea::Write(cForEachChunkProvider * a_ForEachChunkProvider, int a_MinBlockX, int a_MinBlockY, int a_MinBlockZ, int a_DataTypes) { ASSERT((a_DataTypes & GetDataTypes()) == a_DataTypes); // Are you requesting only the data that I have? a_DataTypes = a_DataTypes & GetDataTypes(); // For release builds, silently cut off the datatypes that I don't have @@ -351,13 +447,26 @@ bool cBlockArea::Write(cWorld * a_World, int a_MinBlockX, int a_MinBlockY, int a LOGWARNING("%s: MinBlockY less than zero, adjusting to zero", __FUNCTION__); 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__); - a_MinBlockY = cChunkDef::Height - m_SizeY; + a_MinBlockY = cChunkDef::Height - m_Size.y; } - return a_World->WriteBlockArea(*this, a_MinBlockX, a_MinBlockY, a_MinBlockZ, a_DataTypes); + return a_ForEachChunkProvider->WriteBlockArea(*this, a_MinBlockX, a_MinBlockY, a_MinBlockZ, a_DataTypes); +} + + + + + +bool cBlockArea::Write(cForEachChunkProvider * a_ForEachChunkProvider, const Vector3i & a_MinCoords, int a_DataTypes) +{ + return Write( + a_ForEachChunkProvider, + a_MinCoords.x, a_MinCoords.y, a_MinCoords.z, + a_DataTypes + ); } @@ -373,10 +482,8 @@ void cBlockArea::CopyTo(cBlockArea & a_Into) const } a_Into.Clear(); - a_Into.SetSize(m_SizeX, m_SizeY, m_SizeZ, GetDataTypes()); - a_Into.m_OriginX = m_OriginX; - a_Into.m_OriginY = m_OriginY; - a_Into.m_OriginZ = m_OriginZ; + a_Into.SetSize(m_Size.x, m_Size.y, m_Size.z, GetDataTypes()); + a_Into.m_Origin = m_Origin; int BlockCount = GetBlockCount(); if (HasBlockTypes()) { @@ -417,13 +524,13 @@ void cBlockArea::DumpToRawFile(const AString & a_FileName) LOGWARNING("cBlockArea: Cannot open file \"%s\" for raw dump", a_FileName.c_str()); return; } - UInt32 SizeX = ntohl(m_SizeX); - UInt32 SizeY = ntohl(m_SizeY); - UInt32 SizeZ = ntohl(m_SizeZ); + UInt32 SizeX = ntohl(m_Size.x); + UInt32 SizeY = ntohl(m_Size.y); + UInt32 SizeZ = ntohl(m_Size.z); f.Write(&SizeX, 4); f.Write(&SizeY, 4); f.Write(&SizeZ, 4); - unsigned char DataTypes = GetDataTypes(); + unsigned char DataTypes = (unsigned char)GetDataTypes(); f.Write(&DataTypes, 1); int NumBlocks = GetBlockCount(); if (HasBlockTypes()) @@ -448,85 +555,12 @@ void cBlockArea::DumpToRawFile(const AString & a_FileName) -bool cBlockArea::LoadFromSchematicFile(const AString & a_FileName) -{ - // Un-GZip the contents: - AString Contents; - cGZipFile File; - if (!File.Open(a_FileName, cGZipFile::fmRead)) - { - LOG("Cannot open the schematic file \"%s\".", a_FileName.c_str()); - return false; - } - int NumBytesRead = File.ReadRestOfFile(Contents); - if (NumBytesRead < 0) - { - LOG("Cannot read GZipped data in the schematic file \"%s\", error %d", a_FileName.c_str(), NumBytesRead); - return false; - } - File.Close(); - - // Parse the NBT: - cParsedNBT NBT(Contents.data(), Contents.size()); - if (!NBT.IsValid()) - { - LOG("Cannot parse the NBT in the schematic file \"%s\".", a_FileName.c_str()); - return false; - } - - return LoadFromSchematicNBT(NBT); -} -bool cBlockArea::SaveToSchematicFile(const AString & a_FileName) -{ - cFastNBTWriter Writer("Schematic"); - Writer.AddShort("Width", m_SizeX); - Writer.AddShort("Height", m_SizeY); - Writer.AddShort("Length", m_SizeZ); - Writer.AddString("Materials", "Alpha"); - if (HasBlockTypes()) - { - Writer.AddByteArray("Blocks", (const char *)m_BlockTypes, GetBlockCount()); - } - else - { - AString Dummy(GetBlockCount(), 0); - Writer.AddByteArray("Blocks", Dummy.data(), Dummy.size()); - } - if (HasBlockMetas()) - { - Writer.AddByteArray("Data", (const char *)m_BlockMetas, GetBlockCount()); - } - else - { - AString Dummy(GetBlockCount(), 0); - Writer.AddByteArray("Data", Dummy.data(), Dummy.size()); - } - // TODO: Save entities and block entities - Writer.BeginList("Entities", TAG_Compound); - Writer.EndList(); - Writer.BeginList("TileEntities", TAG_Compound); - Writer.EndList(); - Writer.Finish(); - - // Save to file - cGZipFile File; - if (!File.Open(a_FileName, cGZipFile::fmWrite)) - { - LOG("Cannot open file \"%s\" for writing.", a_FileName.c_str()); - return false; - } - if (!File.Write(Writer.GetResult())) - { - LOG("Cannot write data to file \"%s\".", a_FileName.c_str()); - return false; - } - return true; -} + @@ -535,13 +569,13 @@ bool cBlockArea::SaveToSchematicFile(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) { if ( - (a_AddMinX + a_SubMaxX >= m_SizeX) || - (a_AddMinY + a_SubMaxY >= m_SizeY) || - (a_AddMinZ + a_SubMaxZ >= m_SizeZ) + (a_AddMinX + a_SubMaxX >= m_Size.x) || + (a_AddMinY + a_SubMaxY >= m_Size.y) || + (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", - 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 ); return; @@ -563,12 +597,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); } - m_OriginX += a_AddMinX; - m_OriginY += a_AddMinY; - m_OriginZ += a_AddMinZ; - m_SizeX -= a_AddMinX + a_SubMaxX; - m_SizeY -= a_AddMinY + a_SubMaxY; - m_SizeZ -= a_AddMinZ + a_SubMaxZ; + m_Origin.Move(a_AddMinX, a_AddMinY, a_AddMinZ); + m_Size.x -= a_AddMinX + a_SubMaxX; + m_Size.y -= a_AddMinY + a_SubMaxY; + m_Size.z -= a_AddMinZ + a_SubMaxZ; } @@ -593,12 +625,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); } - m_OriginX -= a_SubMinX; - m_OriginY -= a_SubMinY; - m_OriginZ -= a_SubMinZ; - m_SizeX += a_SubMinX + a_AddMaxX; - m_SizeY += a_SubMinY + a_AddMaxY; - m_SizeZ += a_SubMinZ + a_AddMaxZ; + m_Origin.Move(-a_SubMinX, -a_SubMinY, -a_SubMinZ); + m_Size.x += a_SubMinX + a_AddMaxX; + m_Size.y += a_SubMinY + a_AddMaxY; + m_Size.z += a_SubMinZ + a_AddMaxZ; } @@ -648,7 +678,7 @@ void cBlockArea::Merge(const cBlockArea & a_Src, int a_RelX, int a_RelY, int a_R SrcOffX, SrcOffY, SrcOffZ, DstOffX, DstOffY, DstOffZ, 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 ); break; @@ -663,7 +693,7 @@ void cBlockArea::Merge(const cBlockArea & a_Src, int a_RelX, int a_RelY, int a_R SrcOffX, SrcOffY, SrcOffZ, DstOffX, DstOffY, DstOffZ, 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 ); break; @@ -678,7 +708,7 @@ void cBlockArea::Merge(const cBlockArea & a_Src, int a_RelX, int a_RelY, int a_R SrcOffX, SrcOffY, SrcOffZ, DstOffX, DstOffY, DstOffZ, 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 ); break; @@ -693,12 +723,57 @@ void cBlockArea::Merge(const cBlockArea & a_Src, int a_RelX, int a_RelY, int a_R SrcOffX, SrcOffY, SrcOffZ, DstOffX, DstOffY, DstOffZ, 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 ); break; } // case msLake + case msSpongePrint: + { + InternalMergeBlocks( + m_BlockTypes, a_Src.GetBlockTypes(), + DstMetas, SrcMetas, + SizeX, SizeY, SizeZ, + SrcOffX, SrcOffY, SrcOffZ, + DstOffX, DstOffY, DstOffZ, + a_Src.GetSizeX(), a_Src.GetSizeY(), a_Src.GetSizeZ(), + m_Size.x, m_Size.y, m_Size.z, + MergeCombinatorSpongePrint + ); + break; + } // case msSpongePrint + + case msDifference: + { + InternalMergeBlocks( + m_BlockTypes, a_Src.GetBlockTypes(), + DstMetas, SrcMetas, + SizeX, SizeY, SizeZ, + SrcOffX, SrcOffY, SrcOffZ, + DstOffX, DstOffY, DstOffZ, + a_Src.GetSizeX(), a_Src.GetSizeY(), a_Src.GetSizeZ(), + m_Size.x, m_Size.y, m_Size.z, + MergeCombinatorDifference + ); + break; + } // case msDifference + + case msMask: + { + InternalMergeBlocks( + m_BlockTypes, a_Src.GetBlockTypes(), + DstMetas, SrcMetas, + SizeX, SizeY, SizeZ, + SrcOffX, SrcOffY, SrcOffZ, + DstOffX, DstOffY, DstOffZ, + a_Src.GetSizeX(), a_Src.GetSizeY(), a_Src.GetSizeZ(), + m_Size.x, m_Size.y, m_Size.z, + MergeCombinatorMask + ); + break; + } // case msMask + default: { LOGWARNING("Unknown block area merge strategy: %d", a_Strategy); @@ -718,6 +793,15 @@ void cBlockArea::Merge(const cBlockArea & a_Src, int a_RelX, int a_RelY, int a_R +void cBlockArea::Merge(const cBlockArea & a_Src, const Vector3i & a_RelMinCoords, eMergeStrategy a_Strategy) +{ + Merge(a_Src, a_RelMinCoords.x, a_RelMinCoords.y, a_RelMinCoords.z, a_Strategy); +} + + + + + void cBlockArea::Fill(int a_DataTypes, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, NIBBLETYPE a_BlockLight, NIBBLETYPE a_BlockSkyLight) { if ((a_DataTypes & GetDataTypes()) != a_DataTypes) @@ -810,6 +894,23 @@ void cBlockArea::FillRelCuboid(int a_MinRelX, int a_MaxRelX, int a_MinRelY, int +void cBlockArea::FillRelCuboid(const cCuboid & a_RelCuboid, + int a_DataTypes, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, + NIBBLETYPE a_BlockLight, NIBBLETYPE a_BlockSkyLight +) +{ + FillRelCuboid( + a_RelCuboid.p1.x, a_RelCuboid.p2.x, + a_RelCuboid.p1.y, a_RelCuboid.p2.y, + a_RelCuboid.p1.z, a_RelCuboid.p2.z, + a_DataTypes, a_BlockType, a_BlockMeta, a_BlockLight, a_BlockSkyLight + ); +} + + + + + void cBlockArea::RelLine(int a_RelX1, int a_RelY1, int a_RelZ1, int a_RelX2, int a_RelY2, int a_RelZ2, int a_DataTypes, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, NIBBLETYPE a_BlockLight, NIBBLETYPE a_BlockSkyLight @@ -927,6 +1028,22 @@ void cBlockArea::RelLine(int a_RelX1, int a_RelY1, int a_RelZ1, int a_RelX2, int +void cBlockArea::RelLine(const Vector3i & a_Point1, const Vector3i & a_Point2, + int a_DataTypes, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, + NIBBLETYPE a_BlockLight, NIBBLETYPE a_BlockSkyLight +) +{ + RelLine( + a_Point1.x, a_Point1.y, a_Point1.z, + a_Point2.x, a_Point2.y, a_Point2.z, + a_DataTypes, a_BlockType, a_BlockMeta, a_BlockLight, a_BlockSkyLight + ); +} + + + + + void cBlockArea::RotateCCW(void) { if (!HasBlockTypes()) @@ -943,17 +1060,17 @@ void cBlockArea::RotateCCW(void) } // 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]; - NIBBLETYPE * NewMetas = new NIBBLETYPE[m_SizeX * m_SizeY * m_SizeZ]; - for (int x = 0; x < m_SizeX; x++) + BLOCKTYPE * NewTypes = new BLOCKTYPE[GetBlockCount()]; + NIBBLETYPE * NewMetas = new NIBBLETYPE[GetBlockCount()]; + for (int x = 0; x < m_Size.x; x++) { - int NewZ = m_SizeX - x - 1; - for (int z = 0; z < m_SizeZ; z++) + int NewZ = m_Size.x - x - 1; + for (int z = 0; z < m_Size.z; 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_SizeX + 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); NewTypes[NewIdx] = m_BlockTypes[OldIdx]; NewMetas[NewIdx] = BlockHandler(m_BlockTypes[OldIdx])->MetaRotateCCW(m_BlockMetas[OldIdx]); @@ -965,7 +1082,7 @@ void cBlockArea::RotateCCW(void) delete[] NewTypes; delete[] NewMetas; - std::swap(m_SizeX, m_SizeZ); + std::swap(m_Size.x, m_Size.z); } @@ -988,17 +1105,17 @@ void cBlockArea::RotateCW(void) } // 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]; - NIBBLETYPE * NewMetas = new NIBBLETYPE[m_SizeX * m_SizeY * m_SizeZ]; - for (int x = 0; x < m_SizeX; x++) + BLOCKTYPE * NewTypes = new BLOCKTYPE[GetBlockCount()]; + NIBBLETYPE * NewMetas = new NIBBLETYPE[GetBlockCount()]; + for (int x = 0; x < m_Size.x; 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; - for (int y = 0; y < m_SizeY; y++) + int NewX = m_Size.z - z - 1; + for (int y = 0; y < m_Size.y; y++) { - int NewIdx = NewX + NewZ * m_SizeX + 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); NewTypes[NewIdx] = m_BlockTypes[OldIdx]; NewMetas[NewIdx] = BlockHandler(m_BlockTypes[OldIdx])->MetaRotateCW(m_BlockMetas[OldIdx]); @@ -1010,7 +1127,7 @@ void cBlockArea::RotateCW(void) delete[] NewTypes; delete[] NewMetas; - std::swap(m_SizeX, m_SizeZ); + std::swap(m_Size.x, m_Size.z); } @@ -1033,13 +1150,13 @@ void cBlockArea::MirrorXY(void) } // We are guaranteed that both blocktypes and blockmetas exist; mirror both at the same time: - int HalfZ = m_SizeZ / 2; - int MaxZ = m_SizeZ - 1; - for (int y = 0; y < m_SizeY; y++) + int HalfZ = m_Size.z / 2; + int MaxZ = m_Size.z - 1; + for (int y = 0; y < m_Size.y; y++) { 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 Idx2 = MakeIndex(x, y, MaxZ - z); @@ -1073,13 +1190,13 @@ void cBlockArea::MirrorXZ(void) } // We are guaranteed that both blocktypes and blockmetas exist; mirror both at the same time: - int HalfY = m_SizeY / 2; - int MaxY = m_SizeY - 1; + int HalfY = m_Size.y / 2; + int MaxY = m_Size.y - 1; 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 Idx2 = MakeIndex(x, MaxY - y, z); @@ -1113,11 +1230,11 @@ void cBlockArea::MirrorYZ(void) } // We are guaranteed that both blocktypes and blockmetas exist; mirror both at the same time: - int HalfX = m_SizeX / 2; - int MaxX = m_SizeX - 1; - for (int y = 0; y < m_SizeY; y++) + int HalfX = m_Size.x / 2; + int MaxX = m_Size.x - 1; + 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++) { @@ -1141,16 +1258,16 @@ void cBlockArea::RotateCCWNoMeta(void) { if (HasBlockTypes()) { - BLOCKTYPE * NewTypes = new BLOCKTYPE[m_SizeX * m_SizeY * m_SizeZ]; - for (int x = 0; x < m_SizeX; x++) + BLOCKTYPE * NewTypes = new BLOCKTYPE[GetBlockCount()]; + for (int x = 0; x < m_Size.x; x++) { - int NewZ = m_SizeX - x - 1; - for (int z = 0; z < m_SizeZ; z++) + int NewZ = m_Size.x - x - 1; + for (int z = 0; z < m_Size.z; 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_SizeX + 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 z } // for x @@ -1159,23 +1276,23 @@ void cBlockArea::RotateCCWNoMeta(void) } if (HasBlockMetas()) { - NIBBLETYPE * NewMetas = new NIBBLETYPE[m_SizeX * m_SizeY * m_SizeZ]; - for (int x = 0; x < m_SizeX; x++) + NIBBLETYPE * NewMetas = new NIBBLETYPE[GetBlockCount()]; + for (int x = 0; x < m_Size.x; x++) { - int NewZ = m_SizeX - x - 1; - for (int z = 0; z < m_SizeZ; z++) + int NewZ = m_Size.x - x - 1; + for (int z = 0; z < m_Size.z; 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_SizeX + 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 z } // for x std::swap(m_BlockMetas, NewMetas); delete[] NewMetas; } - std::swap(m_SizeX, m_SizeZ); + std::swap(m_Size.x, m_Size.z); } @@ -1186,16 +1303,16 @@ void cBlockArea::RotateCWNoMeta(void) { if (HasBlockTypes()) { - BLOCKTYPE * NewTypes = new BLOCKTYPE[m_SizeX * m_SizeY * m_SizeZ]; - for (int z = 0; z < m_SizeZ; z++) + BLOCKTYPE * NewTypes = new BLOCKTYPE[GetBlockCount()]; + for (int z = 0; z < m_Size.z; z++) { - int NewX = m_SizeZ - z - 1; - for (int x = 0; x < m_SizeX; x++) + int NewX = m_Size.z - z - 1; + for (int x = 0; x < m_Size.x; 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_SizeX + 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 x } // for z @@ -1204,23 +1321,23 @@ void cBlockArea::RotateCWNoMeta(void) } if (HasBlockMetas()) { - NIBBLETYPE * NewMetas = new NIBBLETYPE[m_SizeX * m_SizeY * m_SizeZ]; - for (int z = 0; z < m_SizeZ; z++) + NIBBLETYPE * NewMetas = new NIBBLETYPE[GetBlockCount()]; + for (int z = 0; z < m_Size.z; z++) { - int NewX = m_SizeZ - z - 1; - for (int x = 0; x < m_SizeX; x++) + int NewX = m_Size.z - z - 1; + for (int x = 0; x < m_Size.x; 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_SizeX + 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 x } // for z std::swap(m_BlockMetas, NewMetas); delete[] NewMetas; } - std::swap(m_SizeX, m_SizeZ); + std::swap(m_Size.x, m_Size.z); } @@ -1229,15 +1346,15 @@ void cBlockArea::RotateCWNoMeta(void) void cBlockArea::MirrorXYNoMeta(void) { - int HalfZ = m_SizeZ / 2; - int MaxZ = m_SizeZ - 1; + int HalfZ = m_Size.z / 2; + int MaxZ = m_Size.z - 1; 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 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)]); } // for x @@ -1247,11 +1364,11 @@ void cBlockArea::MirrorXYNoMeta(void) 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 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)]); } // for x @@ -1266,15 +1383,15 @@ void cBlockArea::MirrorXYNoMeta(void) void cBlockArea::MirrorXZNoMeta(void) { - int HalfY = m_SizeY / 2; - int MaxY = m_SizeY - 1; + int HalfY = m_Size.y / 2; + int MaxY = m_Size.y - 1; if (HasBlockTypes()) { 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)]); } // for x @@ -1286,9 +1403,9 @@ void cBlockArea::MirrorXZNoMeta(void) { 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)]); } // for x @@ -1303,13 +1420,13 @@ void cBlockArea::MirrorXZNoMeta(void) void cBlockArea::MirrorYZNoMeta(void) { - int HalfX = m_SizeX / 2; - int MaxX = m_SizeX - 1; + int HalfX = m_Size.x / 2; + int MaxX = m_Size.x - 1; 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++) { @@ -1321,9 +1438,9 @@ void cBlockArea::MirrorYZNoMeta(void) 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++) { @@ -1354,7 +1471,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) { - 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); } @@ -1431,7 +1548,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 { - 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); } @@ -1494,7 +1611,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) { - 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); } @@ -1528,7 +1645,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 { - 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); } @@ -1631,9 +1748,7 @@ bool cBlockArea::SetSize(int a_SizeX, int a_SizeY, int a_SizeZ, int a_DataTypes) return false; } } - m_SizeX = a_SizeX; - m_SizeY = a_SizeY; - m_SizeZ = a_SizeZ; + m_Size.Set(a_SizeX, a_SizeY, a_SizeZ); return true; } @@ -1644,13 +1759,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 { ASSERT(a_RelX >= 0); - ASSERT(a_RelX < m_SizeX); + ASSERT(a_RelX < m_Size.x); ASSERT(a_RelY >= 0); - ASSERT(a_RelY < m_SizeY); + ASSERT(a_RelY < m_Size.y); 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; } @@ -1673,7 +1788,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) { - 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); } @@ -1696,7 +1811,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 { - 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); } @@ -1709,9 +1824,7 @@ NIBBLETYPE cBlockArea::GetNibble(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBL cBlockArea::cChunkReader::cChunkReader(cBlockArea & a_Area) : m_Area(a_Area), - m_OriginX(a_Area.m_OriginX), - m_OriginY(a_Area.m_OriginY), - m_OriginZ(a_Area.m_OriginZ) + m_Origin(a_Area.m_Origin.x, a_Area.m_Origin.y, a_Area.m_Origin.z) { } @@ -1721,8 +1834,8 @@ cBlockArea::cChunkReader::cChunkReader(cBlockArea & a_Area) : void cBlockArea::cChunkReader::CopyNibbles(NIBBLETYPE * a_AreaDst, const NIBBLETYPE * a_ChunkSrc) { - int SizeY = m_Area.m_SizeY; - int MinY = m_OriginY; + int SizeY = m_Area.m_Size.y; + 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) // OffX, OffZ are the offsets of the current chunk data from the area origin @@ -1731,7 +1844,7 @@ void cBlockArea::cChunkReader::CopyNibbles(NIBBLETYPE * a_AreaDst, const NIBBLET int SizeZ = cChunkDef::Width; int OffX, OffZ; int BaseX, BaseZ; - OffX = m_CurrentChunkX * cChunkDef::Width - m_OriginX; + OffX = m_CurrentChunkX * cChunkDef::Width - m_Origin.x; if (OffX < 0) { BaseX = -OffX; @@ -1742,7 +1855,7 @@ void cBlockArea::cChunkReader::CopyNibbles(NIBBLETYPE * a_AreaDst, const NIBBLET { BaseX = 0; } - OffZ = m_CurrentChunkZ * cChunkDef::Width - m_OriginZ; + OffZ = m_CurrentChunkZ * cChunkDef::Width - m_Origin.z; if (OffZ < 0) { BaseZ = -OffZ; @@ -1754,13 +1867,13 @@ void cBlockArea::cChunkReader::CopyNibbles(NIBBLETYPE * a_AreaDst, const NIBBLET BaseZ = 0; } // 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++) @@ -1804,8 +1917,8 @@ void cBlockArea::cChunkReader::BlockTypes(const BLOCKTYPE * a_BlockTypes) return; } - int SizeY = m_Area.m_SizeY; - int MinY = m_OriginY; + int SizeY = m_Area.m_Size.y; + 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) // OffX, OffZ are the offsets of the current chunk data from the area origin @@ -1814,7 +1927,7 @@ void cBlockArea::cChunkReader::BlockTypes(const BLOCKTYPE * a_BlockTypes) int SizeZ = cChunkDef::Width; int OffX, OffZ; int BaseX, BaseZ; - OffX = m_CurrentChunkX * cChunkDef::Width - m_OriginX; + OffX = m_CurrentChunkX * cChunkDef::Width - m_Origin.x; if (OffX < 0) { BaseX = -OffX; @@ -1825,7 +1938,7 @@ void cBlockArea::cChunkReader::BlockTypes(const BLOCKTYPE * a_BlockTypes) { BaseX = 0; } - OffZ = m_CurrentChunkZ * cChunkDef::Width - m_OriginZ; + OffZ = m_CurrentChunkZ * cChunkDef::Width - m_Origin.z; if (OffZ < 0) { BaseZ = -OffZ; @@ -1837,13 +1950,13 @@ void cBlockArea::cChunkReader::BlockTypes(const BLOCKTYPE * a_BlockTypes) BaseZ = 0; } // 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++) @@ -1963,21 +2076,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) { - int NewSizeX = m_SizeX + a_SubMinX + a_AddMaxX; - int NewSizeY = m_SizeY + a_SubMinY + a_AddMaxY; - int NewSizeZ = m_SizeZ + a_SubMinZ + a_AddMaxZ; + int NewSizeX = m_Size.x + a_SubMinX + a_AddMaxX; + int NewSizeY = m_Size.y + a_SubMinY + a_AddMaxY; + int NewSizeZ = m_Size.z + a_SubMinZ + a_AddMaxZ; int BlockCount = NewSizeX * NewSizeY * NewSizeZ; BLOCKTYPE * NewBlockTypes = new BLOCKTYPE[BlockCount]; memset(NewBlockTypes, 0, BlockCount * sizeof(BLOCKTYPE)); 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; - for (int z = 0; z < m_SizeZ; z++) + int IndexBaseY = (y + a_SubMinY) * m_Size.x * m_Size.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; - for (int x = 0; x < m_SizeX; x++) + for (int x = 0; x < m_Size.x; x++) { NewBlockTypes[idx++] = m_BlockTypes[OldIndex++]; } // for x @@ -1993,21 +2106,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) { - int NewSizeX = m_SizeX + a_SubMinX + a_AddMaxX; - int NewSizeY = m_SizeY + a_SubMinY + a_AddMaxY; - int NewSizeZ = m_SizeZ + a_SubMinZ + a_AddMaxZ; + int NewSizeX = m_Size.x + a_SubMinX + a_AddMaxX; + int NewSizeY = m_Size.y + a_SubMinY + a_AddMaxY; + int NewSizeZ = m_Size.z + a_SubMinZ + a_AddMaxZ; int BlockCount = NewSizeX * NewSizeY * NewSizeZ; NIBBLETYPE * NewNibbles = new NIBBLETYPE[BlockCount]; memset(NewNibbles, 0, BlockCount * sizeof(NIBBLETYPE)); 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; - for (int z = 0; z < m_SizeZ; z++) + int IndexBaseY = (y + a_SubMinY) * m_Size.x * m_Size.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; - for (int x = 0; x < m_SizeX; x++) + for (int x = 0; x < m_Size.x; x++) { NewNibbles[idx++] = a_Array[OldIndex++]; } // for x @@ -2021,86 +2134,6 @@ void cBlockArea::ExpandNibbles(NIBBLEARRAY & a_Array, int a_SubMinX, int a_AddMa -bool cBlockArea::LoadFromSchematicNBT(cParsedNBT & a_NBT) -{ - int TMaterials = a_NBT.FindChildByName(a_NBT.GetRoot(), "Materials"); - if ((TMaterials > 0) && (a_NBT.GetType(TMaterials) == TAG_String)) - { - AString Materials = a_NBT.GetString(TMaterials); - if (Materials.compare("Alpha") != 0) - { - LOG("Materials tag is present and \"%s\" instead of \"Alpha\". Possibly a wrong-format schematic file.", Materials.c_str()); - return false; - } - } - int TSizeX = a_NBT.FindChildByName(a_NBT.GetRoot(), "Width"); - int TSizeY = a_NBT.FindChildByName(a_NBT.GetRoot(), "Height"); - int TSizeZ = a_NBT.FindChildByName(a_NBT.GetRoot(), "Length"); - if ( - (TSizeX < 0) || (TSizeY < 0) || (TSizeZ < 0) || - (a_NBT.GetType(TSizeX) != TAG_Short) || - (a_NBT.GetType(TSizeY) != TAG_Short) || - (a_NBT.GetType(TSizeZ) != TAG_Short) - ) - { - LOG("Dimensions are missing from the schematic file (%d, %d, %d), (%d, %d, %d)", - TSizeX, TSizeY, TSizeZ, - a_NBT.GetType(TSizeX), a_NBT.GetType(TSizeY), a_NBT.GetType(TSizeZ) - ); - return false; - } - - int SizeX = a_NBT.GetShort(TSizeX); - int SizeY = a_NBT.GetShort(TSizeY); - int SizeZ = a_NBT.GetShort(TSizeZ); - if ((SizeX < 1) || (SizeY < 1) || (SizeZ < 1)) - { - LOG("Dimensions are invalid in the schematic file: %d, %d, %d", SizeX, SizeY, SizeZ); - return false; - } - - int TBlockTypes = a_NBT.FindChildByName(a_NBT.GetRoot(), "Blocks"); - int TBlockMetas = a_NBT.FindChildByName(a_NBT.GetRoot(), "Data"); - if ((TBlockTypes < 0) || (a_NBT.GetType(TBlockTypes) != TAG_ByteArray)) - { - LOG("BlockTypes are invalid in the schematic file: %d", TBlockTypes); - return false; - } - bool AreMetasPresent = (TBlockMetas > 0) && (a_NBT.GetType(TBlockMetas) == TAG_ByteArray); - - Clear(); - SetSize(SizeX, SizeY, SizeZ, AreMetasPresent ? (baTypes | baMetas) : baTypes); - - // Copy the block types and metas: - int NumBytes = m_SizeX * m_SizeY * m_SizeZ; - if (a_NBT.GetDataLength(TBlockTypes) < NumBytes) - { - LOG("BlockTypes truncated in the schematic file (exp %d, got %d bytes). Loading partial.", - NumBytes, a_NBT.GetDataLength(TBlockTypes) - ); - NumBytes = a_NBT.GetDataLength(TBlockTypes); - } - memcpy(m_BlockTypes, a_NBT.GetData(TBlockTypes), NumBytes); - - if (AreMetasPresent) - { - int NumBytes = m_SizeX * m_SizeY * m_SizeZ; - if (a_NBT.GetDataLength(TBlockMetas) < NumBytes) - { - LOG("BlockMetas truncated in the schematic file (exp %d, got %d bytes). Loading partial.", - NumBytes, a_NBT.GetDataLength(TBlockMetas) - ); - NumBytes = a_NBT.GetDataLength(TBlockMetas); - } - memcpy(m_BlockMetas, a_NBT.GetData(TBlockMetas), NumBytes); - } - - return true; -} - - - - void cBlockArea::RelSetData( int a_RelX, int a_RelY, int a_RelZ, int a_DataTypes, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, |