diff options
author | andrew <xdotftw@gmail.com> | 2014-02-13 20:36:24 +0100 |
---|---|---|
committer | andrew <xdotftw@gmail.com> | 2014-02-13 20:36:24 +0100 |
commit | 32b465b8e1e1a6fa9e966a1376209f292331d4ae (patch) | |
tree | ca6e9abef0390dbd377c3cbf77fd25b34bade078 /src/WorldStorage/MapSerializer.cpp | |
parent | Implementation of in-game maps (diff) | |
download | cuberite-32b465b8e1e1a6fa9e966a1376209f292331d4ae.tar cuberite-32b465b8e1e1a6fa9e966a1376209f292331d4ae.tar.gz cuberite-32b465b8e1e1a6fa9e966a1376209f292331d4ae.tar.bz2 cuberite-32b465b8e1e1a6fa9e966a1376209f292331d4ae.tar.lz cuberite-32b465b8e1e1a6fa9e966a1376209f292331d4ae.tar.xz cuberite-32b465b8e1e1a6fa9e966a1376209f292331d4ae.tar.zst cuberite-32b465b8e1e1a6fa9e966a1376209f292331d4ae.zip |
Diffstat (limited to 'src/WorldStorage/MapSerializer.cpp')
-rw-r--r-- | src/WorldStorage/MapSerializer.cpp | 79 |
1 files changed, 78 insertions, 1 deletions
diff --git a/src/WorldStorage/MapSerializer.cpp b/src/WorldStorage/MapSerializer.cpp index ea0d3ec47..aab4c7816 100644 --- a/src/WorldStorage/MapSerializer.cpp +++ b/src/WorldStorage/MapSerializer.cpp @@ -9,6 +9,7 @@ #include "FastNBT.h" #include "../Map.h" +#include "../World.h" @@ -141,7 +142,7 @@ bool cMapSerializer::LoadMapFromNBT(const cParsedNBT & a_NBT) { eDimension Dimension = (eDimension) a_NBT.GetByte(CurrLine); - // ASSERT(Dimension == m_World.GetDimension()); + ASSERT(Dimension == m_Map->m_World->GetDimension()); } CurrLine = a_NBT.FindChildByName(Data, "width"); @@ -184,6 +185,82 @@ bool cMapSerializer::LoadMapFromNBT(const cParsedNBT & a_NBT) +cIDCountSerializer::cIDCountSerializer(const AString & a_WorldName) : m_MapCount(0) +{ + AString DataPath; + Printf(DataPath, "%s/data", a_WorldName.c_str()); + + Printf(m_Path, "%s/idcounts.dat", DataPath.c_str()); + + cFile::CreateFolder(FILE_IO_PREFIX + DataPath); +} + + + + + +bool cIDCountSerializer::Load(void) +{ + AString Data = cFile::ReadWholeFile(FILE_IO_PREFIX + m_Path); + if (Data.empty()) + { + return false; + } + + // NOTE: idcounts.dat is not compressed (raw format) + + // Parse the NBT data: + cParsedNBT NBT(Data.data(), Data.size()); + if (!NBT.IsValid()) + { + // NBT Parsing failed + return false; + } + + int CurrLine = NBT.FindChildByName(0, "map"); + if (CurrLine >= 0) + { + m_MapCount = (int)NBT.GetShort(CurrLine); + } + + return true; +} + + + + + +bool cIDCountSerializer::Save(void) +{ + cFastNBTWriter Writer; + + Writer.AddShort("map", m_MapCount); + + Writer.Finish(); + + #ifdef _DEBUG + cParsedNBT TestParse(Writer.GetResult().data(), Writer.GetResult().size()); + ASSERT(TestParse.IsValid()); + #endif // _DEBUG + + cFile File; + if (!File.Open(FILE_IO_PREFIX + m_Path, cFile::fmWrite)) + { + return false; + } + + // NOTE: idcounts.dat is not compressed (raw format) + + File.Write(Writer.GetResult().data(), Writer.GetResult().size()); + File.Close(); + + return true; +} + + + + + |