summaryrefslogtreecommitdiffstats
path: root/src/WorldStorage/SchematicFileSerilizer.cpp
diff options
context:
space:
mode:
authorTycho <work.tycho+git@gmail.com>2014-01-20 19:15:19 +0100
committerTycho <work.tycho+git@gmail.com>2014-01-20 19:15:19 +0100
commitca3389231e111d8ca0bf4ca60ae4f96896da48b0 (patch)
treee56f4354cbbf10fd935d46b9577f55da0bcfdcbb /src/WorldStorage/SchematicFileSerilizer.cpp
parentMoved Schematic file methods to seperate class (diff)
downloadcuberite-ca3389231e111d8ca0bf4ca60ae4f96896da48b0.tar
cuberite-ca3389231e111d8ca0bf4ca60ae4f96896da48b0.tar.gz
cuberite-ca3389231e111d8ca0bf4ca60ae4f96896da48b0.tar.bz2
cuberite-ca3389231e111d8ca0bf4ca60ae4f96896da48b0.tar.lz
cuberite-ca3389231e111d8ca0bf4ca60ae4f96896da48b0.tar.xz
cuberite-ca3389231e111d8ca0bf4ca60ae4f96896da48b0.tar.zst
cuberite-ca3389231e111d8ca0bf4ca60ae4f96896da48b0.zip
Diffstat (limited to 'src/WorldStorage/SchematicFileSerilizer.cpp')
-rw-r--r--src/WorldStorage/SchematicFileSerilizer.cpp45
1 files changed, 26 insertions, 19 deletions
diff --git a/src/WorldStorage/SchematicFileSerilizer.cpp b/src/WorldStorage/SchematicFileSerilizer.cpp
index bce0119ec..df68f3436 100644
--- a/src/WorldStorage/SchematicFileSerilizer.cpp
+++ b/src/WorldStorage/SchematicFileSerilizer.cpp
@@ -1,5 +1,12 @@
-bool cSchematicFileSerializer::LoadFromSchematicFile(const AString & a_FileName)
+#include "Globals.h"
+
+#include "OSSupport/GZipFile.h"
+#include "FastNBT.h"
+
+#include "SchematicFileSerilizer.h"
+
+bool cSchematicFileSerializer::LoadFromSchematicFile(cBlockArea& a_BlockArea, const AString & a_FileName)
{
// Un-GZip the contents:
AString Contents;
@@ -25,32 +32,32 @@ bool cSchematicFileSerializer::LoadFromSchematicFile(const AString & a_FileName)
return false;
}
- return LoadFromSchematicNBT(NBT);
+ return LoadFromSchematicNBT(a_BlockArea, NBT);
}
-bool cSchematicFileSerializer::SaveToSchematicFile(const AString & a_FileName)
+bool cSchematicFileSerializer::SaveToSchematicFile(cBlockArea& a_BlockArea, const AString & a_FileName)
{
cFastNBTWriter Writer("Schematic");
- Writer.AddShort("Width", m_SizeX);
- Writer.AddShort("Height", m_SizeY);
- Writer.AddShort("Length", m_SizeZ);
+ Writer.AddShort("Width", a_BlockArea.m_SizeX);
+ Writer.AddShort("Height", a_BlockArea.m_SizeY);
+ Writer.AddShort("Length", a_BlockArea.m_SizeZ);
Writer.AddString("Materials", "Alpha");
- if (HasBlockTypes())
+ if (a_BlockArea.HasBlockTypes())
{
- Writer.AddByteArray("Blocks", (const char *)m_BlockTypes, GetBlockCount());
+ Writer.AddByteArray("Blocks", (const char *)a_BlockArea.m_BlockTypes, a_BlockArea.GetBlockCount());
}
else
{
- AString Dummy(GetBlockCount(), 0);
+ AString Dummy(a_BlockArea.GetBlockCount(), 0);
Writer.AddByteArray("Blocks", Dummy.data(), Dummy.size());
}
- if (HasBlockMetas())
+ if (a_BlockArea.HasBlockMetas())
{
- Writer.AddByteArray("Data", (const char *)m_BlockMetas, GetBlockCount());
+ Writer.AddByteArray("Data", (const char *)a_BlockArea.m_BlockMetas, a_BlockArea.GetBlockCount());
}
else
{
- AString Dummy(GetBlockCount(), 0);
+ AString Dummy(a_BlockArea.GetBlockCount(), 0);
Writer.AddByteArray("Data", Dummy.data(), Dummy.size());
}
// TODO: Save entities and block entities
@@ -75,7 +82,7 @@ bool cSchematicFileSerializer::SaveToSchematicFile(const AString & a_FileName)
return true;
}
-bool cBlockArea::LoadFromSchematicNBT(cParsedNBT & a_NBT)
+bool cSchematicFileSerializer::LoadFromSchematicNBT(cBlockArea& a_BlockArea, cParsedNBT & a_NBT)
{
int TMaterials = a_NBT.FindChildByName(a_NBT.GetRoot(), "Materials");
if ((TMaterials > 0) && (a_NBT.GetType(TMaterials) == TAG_String))
@@ -122,11 +129,11 @@ bool cBlockArea::LoadFromSchematicNBT(cParsedNBT & a_NBT)
}
bool AreMetasPresent = (TBlockMetas > 0) && (a_NBT.GetType(TBlockMetas) == TAG_ByteArray);
- Clear();
- SetSize(SizeX, SizeY, SizeZ, AreMetasPresent ? (baTypes | baMetas) : baTypes);
+ a_BlockArea.Clear();
+ a_BlockArea.SetSize(SizeX, SizeY, SizeZ, AreMetasPresent ? (cBlockArea::baTypes | cBlockArea::baMetas) : cBlockArea::baTypes);
// Copy the block types and metas:
- int NumBytes = m_SizeX * m_SizeY * m_SizeZ;
+ int NumBytes = a_BlockArea.m_SizeX * a_BlockArea.m_SizeY * a_BlockArea.m_SizeZ;
if (a_NBT.GetDataLength(TBlockTypes) < NumBytes)
{
LOG("BlockTypes truncated in the schematic file (exp %d, got %d bytes). Loading partial.",
@@ -134,11 +141,11 @@ bool cBlockArea::LoadFromSchematicNBT(cParsedNBT & a_NBT)
);
NumBytes = a_NBT.GetDataLength(TBlockTypes);
}
- memcpy(m_BlockTypes, a_NBT.GetData(TBlockTypes), NumBytes);
+ memcpy(a_BlockArea.m_BlockTypes, a_NBT.GetData(TBlockTypes), NumBytes);
if (AreMetasPresent)
{
- int NumBytes = m_SizeX * m_SizeY * m_SizeZ;
+ int NumBytes = a_BlockArea.m_SizeX * a_BlockArea.m_SizeY * a_BlockArea.m_SizeZ;
if (a_NBT.GetDataLength(TBlockMetas) < NumBytes)
{
LOG("BlockMetas truncated in the schematic file (exp %d, got %d bytes). Loading partial.",
@@ -146,7 +153,7 @@ bool cBlockArea::LoadFromSchematicNBT(cParsedNBT & a_NBT)
);
NumBytes = a_NBT.GetDataLength(TBlockMetas);
}
- memcpy(m_BlockMetas, a_NBT.GetData(TBlockMetas), NumBytes);
+ memcpy(a_BlockArea.m_BlockMetas, a_NBT.GetData(TBlockMetas), NumBytes);
}
return true;