From ca3389231e111d8ca0bf4ca60ae4f96896da48b0 Mon Sep 17 00:00:00 2001 From: Tycho Date: Mon, 20 Jan 2014 10:15:19 -0800 Subject: Actually implemented interfaces --- src/ForEachChunkProvider.h | 4 +++ src/World.h | 1 + src/WorldStorage/SchematicFileSerilizer.cpp | 45 +++++++++++++++++------------ src/WorldStorage/SchematicFileSerilizer.h | 4 +-- 4 files changed, 33 insertions(+), 21 deletions(-) (limited to 'src') diff --git a/src/ForEachChunkProvider.h b/src/ForEachChunkProvider.h index 9092fcb0a..70cd2196a 100644 --- a/src/ForEachChunkProvider.h +++ b/src/ForEachChunkProvider.h @@ -1,4 +1,8 @@ +#pragma once + +class cChunkDataCallback; + class cBlockArea; class cForEachChunkProvider diff --git a/src/World.h b/src/World.h index 9d342aceb..f0dd45c90 100644 --- a/src/World.h +++ b/src/World.h @@ -22,6 +22,7 @@ #include "Item.h" #include "Mobs/Monster.h" #include "Entities/ProjectileEntity.h" +#include "ForEachChunkProvider.h" 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; diff --git a/src/WorldStorage/SchematicFileSerilizer.h b/src/WorldStorage/SchematicFileSerilizer.h index b8a7162c6..e4dcf3eb9 100644 --- a/src/WorldStorage/SchematicFileSerilizer.h +++ b/src/WorldStorage/SchematicFileSerilizer.h @@ -9,10 +9,10 @@ class cSchematicFileSerializer public: /// Loads an area from a .schematic file. Returns true if successful - static bool LoadFromSchematicFile(const AString & a_FileName); + static bool LoadFromSchematicFile(cBlockArea& a_BlockArea, const AString & a_FileName); /// Saves the area into a .schematic file. Returns true if successful - static bool SaveToSchematicFile(const AString & a_FileName); + static bool SaveToSchematicFile(cBlockArea& a_BlockArea, const AString & a_FileName); private: /// Loads the area from a schematic file uncompressed and parsed into a NBT tree. Returns true if successful. -- cgit v1.2.3