Actually implemented interfaces

This commit is contained in:
Tycho 2014-01-20 10:15:19 -08:00
parent 4f09e8df6e
commit ca3389231e
4 changed files with 33 additions and 21 deletions

View File

@ -1,4 +1,8 @@
#pragma once
class cChunkDataCallback;
class cBlockArea; class cBlockArea;
class cForEachChunkProvider class cForEachChunkProvider

View File

@ -22,6 +22,7 @@
#include "Item.h" #include "Item.h"
#include "Mobs/Monster.h" #include "Mobs/Monster.h"
#include "Entities/ProjectileEntity.h" #include "Entities/ProjectileEntity.h"
#include "ForEachChunkProvider.h"

View File

@ -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: // Un-GZip the contents:
AString Contents; AString Contents;
@ -25,32 +32,32 @@ bool cSchematicFileSerializer::LoadFromSchematicFile(const AString & a_FileName)
return false; 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"); cFastNBTWriter Writer("Schematic");
Writer.AddShort("Width", m_SizeX); Writer.AddShort("Width", a_BlockArea.m_SizeX);
Writer.AddShort("Height", m_SizeY); Writer.AddShort("Height", a_BlockArea.m_SizeY);
Writer.AddShort("Length", m_SizeZ); Writer.AddShort("Length", a_BlockArea.m_SizeZ);
Writer.AddString("Materials", "Alpha"); 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 else
{ {
AString Dummy(GetBlockCount(), 0); AString Dummy(a_BlockArea.GetBlockCount(), 0);
Writer.AddByteArray("Blocks", Dummy.data(), Dummy.size()); 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 else
{ {
AString Dummy(GetBlockCount(), 0); AString Dummy(a_BlockArea.GetBlockCount(), 0);
Writer.AddByteArray("Data", Dummy.data(), Dummy.size()); Writer.AddByteArray("Data", Dummy.data(), Dummy.size());
} }
// TODO: Save entities and block entities // TODO: Save entities and block entities
@ -75,7 +82,7 @@ bool cSchematicFileSerializer::SaveToSchematicFile(const AString & a_FileName)
return true; 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"); int TMaterials = a_NBT.FindChildByName(a_NBT.GetRoot(), "Materials");
if ((TMaterials > 0) && (a_NBT.GetType(TMaterials) == TAG_String)) 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); bool AreMetasPresent = (TBlockMetas > 0) && (a_NBT.GetType(TBlockMetas) == TAG_ByteArray);
Clear(); a_BlockArea.Clear();
SetSize(SizeX, SizeY, SizeZ, AreMetasPresent ? (baTypes | baMetas) : baTypes); a_BlockArea.SetSize(SizeX, SizeY, SizeZ, AreMetasPresent ? (cBlockArea::baTypes | cBlockArea::baMetas) : cBlockArea::baTypes);
// Copy the block types and metas: // 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) 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.",
@ -134,11 +141,11 @@ bool cBlockArea::LoadFromSchematicNBT(cParsedNBT & a_NBT)
); );
NumBytes = a_NBT.GetDataLength(TBlockTypes); 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) 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) 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.",
@ -146,7 +153,7 @@ bool cBlockArea::LoadFromSchematicNBT(cParsedNBT & a_NBT)
); );
NumBytes = a_NBT.GetDataLength(TBlockMetas); 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; return true;

View File

@ -9,10 +9,10 @@ class cSchematicFileSerializer
public: public:
/// Loads an area from a .schematic file. Returns true if successful /// 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 /// 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: private:
/// Loads the area from a schematic file uncompressed and parsed into a NBT tree. Returns true if successful. /// Loads the area from a schematic file uncompressed and parsed into a NBT tree. Returns true if successful.