diff options
author | madmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2012-02-13 22:47:03 +0100 |
---|---|---|
committer | madmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2012-02-13 22:47:03 +0100 |
commit | 4f17362aeb80e5339c58a5d3b0fbaeb88d9e701c (patch) | |
tree | febea3ecd89c0d4aa83924e430bf11366d754733 /source/WSSCompact.h | |
parent | New makefile with automatic *.cpp sourcefile import, automatic header file dependencies and switchable debug / release configuration. gnumake-specific :( (diff) | |
download | cuberite-4f17362aeb80e5339c58a5d3b0fbaeb88d9e701c.tar cuberite-4f17362aeb80e5339c58a5d3b0fbaeb88d9e701c.tar.gz cuberite-4f17362aeb80e5339c58a5d3b0fbaeb88d9e701c.tar.bz2 cuberite-4f17362aeb80e5339c58a5d3b0fbaeb88d9e701c.tar.lz cuberite-4f17362aeb80e5339c58a5d3b0fbaeb88d9e701c.tar.xz cuberite-4f17362aeb80e5339c58a5d3b0fbaeb88d9e701c.tar.zst cuberite-4f17362aeb80e5339c58a5d3b0fbaeb88d9e701c.zip |
Diffstat (limited to '')
-rw-r--r-- | source/WSSCompact.h | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/source/WSSCompact.h b/source/WSSCompact.h new file mode 100644 index 000000000..dc5ecfe9e --- /dev/null +++ b/source/WSSCompact.h @@ -0,0 +1,84 @@ +
+// WSSCompact.h
+
+// Interfaces to the cWSSCompact class representing the "Compact" storage schema (PAK-files)
+
+
+
+
+
+#pragma once
+#ifndef WSSCOMPACT_H_INCLUDED
+#define WSSCOMPACT_H_INCLUDED
+
+#include "WorldStorage.h"
+
+
+
+
+
+class cWSSCompact :
+ public cWSSchema
+{
+public:
+ cWSSCompact(cWorld * a_World) : cWSSchema(a_World) {}
+ virtual ~cWSSCompact();
+
+protected:
+
+ struct sChunkHeader;
+ typedef std::vector<sChunkHeader *> sChunkHeaders;
+
+ /// Implements a cache for a single PAK file; implements lazy-write in order to be able to write multiple chunks fast
+ class cPAKFile
+ {
+ public:
+
+ cPAKFile(const AString & a_FileName, int a_LayerX, int a_LayerZ);
+ ~cPAKFile();
+
+ bool SaveChunk(const cChunkPtr & a_Chunk);
+ bool LoadChunk(const cChunkPtr & a_Chunk);
+
+ int GetLayerX(void) const {return m_LayerX; }
+ int GetLayerZ(void) const {return m_LayerZ; }
+
+ protected:
+
+ AString m_FileName;
+ int m_LayerX;
+ int m_LayerZ;
+
+ sChunkHeaders m_ChunkHeaders;
+ AString m_DataContents; // Data contents of the file, cached
+
+ int m_NumDirty; // Number of chunks that were written into m_DataContents but not into the file
+
+ bool LoadChunk(const cChunkPtr & a_Chunk, int a_Offset, sChunkHeader * a_Header);
+ void EraseChunk(const cChunkPtr & a_Chunk); // Erases the chunk data from m_DataContents and updates m_ChunkHeaders
+ bool SaveChunkToData(const cChunkPtr & a_Chunk); // Saves the chunk to m_DataContents, updates headers and m_NumDirty
+ void SynchronizeFile(void); // Writes m_DataContents along with the headers to file, resets m_NumDirty
+ } ;
+
+ typedef std::list<cPAKFile *> cPAKFiles;
+
+ cPAKFiles m_PAKFiles; // A MRU cache of PAK files
+
+ /// Loads the correct PAK file either from cache or from disk, manages the m_PAKFiles cache
+ cPAKFile * LoadPAKFile(const cChunkPtr & a_Chunk);
+
+ // cWSSchema overrides:
+ virtual bool LoadChunk(const cChunkPtr & a_Chunk) override;
+ virtual bool SaveChunk(const cChunkPtr & a_Chunk) override;
+ virtual const AString GetName(void) const override {return "compact"; }
+} ;
+
+
+
+
+
+#endif // WSSCOMPACT_H_INCLUDED
+
+
+
+
|