From 9cb88728511c314695731d92cb4ab16c8e3b051e Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Mon, 23 Apr 2012 21:20:32 +0000 Subject: Anvil storage writing (Basic storage is working, NO entities except for chests are working! Don't use for real servers) git-svn-id: http://mc-server.googlecode.com/svn/trunk@475 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/WSSAnvil.h | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) (limited to 'source/WSSAnvil.h') diff --git a/source/WSSAnvil.h b/source/WSSAnvil.h index 1052d0e5a..37d813f28 100644 --- a/source/WSSAnvil.h +++ b/source/WSSAnvil.h @@ -16,8 +16,14 @@ enum { - // The MCA header is 8 KiB - MCA_HEADER_SIZE = 8192, + /// Maximum number of chunks in an MCA file - also the count of the header items + MCA_MAX_CHUNKS = 32 * 32, + + /// The MCA header is 8 KiB + MCA_HEADER_SIZE = MCA_MAX_CHUNKS * 8, + + /// There are 5 bytes of header in front of each chunk + MCA_CHUNK_HEADER_LENGTH = 5, } ; @@ -40,7 +46,7 @@ class cWSSAnvil : public: - cWSSAnvil(cWorld * a_World) : super(a_World) {} + cWSSAnvil(cWorld * a_World); virtual ~cWSSAnvil(); protected: @@ -51,7 +57,9 @@ protected: cMCAFile(const AString & a_FileName, int a_RegionX, int a_RegionZ); - bool GetChunkData(const cChunkCoords & a_Chunk, AString & a_Data); + bool GetChunkData (const cChunkCoords & a_Chunk, AString & a_Data); + bool SetChunkData (const cChunkCoords & a_Chunk, const AString & a_Data); + bool EraseChunkData(const cChunkCoords & a_Chunk); int GetRegionX (void) const {return m_RegionX; } int GetRegionZ (void) const {return m_RegionZ; } @@ -66,23 +74,36 @@ protected: // The header, copied from the file so we don't have to seek to it all the time // First 1024 entries are chunk locations - the 3 + 1 byte sector-offset and sector-count - // The next 1024 entries are chunk timestamps - unused in MCS - unsigned m_Header[MCA_HEADER_SIZE / sizeof(unsigned)]; + unsigned m_Header[MCA_MAX_CHUNKS]; + + // Chunk timestamps, following the chunk headers, are unused by MCS + + /// Finds a free location large enough to hold a_Data. Gets a hint of the chunk coords, places the data there if it fits. Returns the sector number. + unsigned FindFreeLocation(int a_LocalX, int a_LocalZ, const AString & a_Data); } ; typedef std::list cMCAFiles; cCriticalSection m_CS; cMCAFiles m_Files; // a MRU cache of MCA files - /// Gets chunk data from the correct file; locks CS as needed + /// Gets chunk data from the correct file; locks file CS as needed bool GetChunkData(const cChunkCoords & a_Chunk, AString & a_Data); + /// Sets chunk data into the correct file; locks file CS as needed + bool SetChunkData(const cChunkCoords & a_Chunk, const AString & a_Data); + /// Loads the chunk from the data (no locking needed) bool LoadChunkFromData(const cChunkCoords & a_Chunk, const AString & a_Data); + /// Saves the chunk into datastream (no locking needed) + bool SaveChunkToData(const cChunkCoords & a_Chunk, AString & a_Data); + /// Loads the chunk from NBT data (no locking needed) bool LoadChunkFromNBT(const cChunkCoords & a_Chunk, cNBTTag & a_NBT); + /// Saves the chunk into NBT data; returns NULL for failure + cNBTTag * SaveChunkToNBT(const cChunkCoords & a_Chunk); + /// Loads the chunk's entities from NBT data (a_NBT is the Level\\Entities list tag; may be NULL) void LoadEntitiesFromNBT(cEntityList & a_Entitites, const cNBTList * a_NBT); -- cgit v1.2.3