2012-02-13 16:47:03 -05:00
|
|
|
|
|
|
|
// 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"
|
2012-03-04 10:59:10 -05:00
|
|
|
#include "Vector3i.h"
|
2012-02-13 16:47:03 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
2012-02-28 05:45:53 -05:00
|
|
|
bool GetChunkData(const cChunkCoords & a_Chunk, int & a_UncompressedSize, AString & a_Data);
|
|
|
|
bool SetChunkData(const cChunkCoords & a_Chunk, int a_UncompressedSize, const AString & a_Data);
|
|
|
|
bool EraseChunkData(const cChunkCoords & a_Chunk);
|
|
|
|
|
2012-02-16 08:42:35 -05:00
|
|
|
bool SaveChunk(const cChunkCoords & a_Chunk, cWorld * a_World);
|
|
|
|
bool LoadChunk(const cChunkCoords & a_Chunk, cWorld * a_World);
|
2012-02-13 16:47:03 -05:00
|
|
|
|
|
|
|
int GetLayerX(void) const {return m_LayerX; }
|
|
|
|
int GetLayerZ(void) const {return m_LayerZ; }
|
|
|
|
|
2012-03-04 10:59:10 -05:00
|
|
|
static const int PAK_VERSION = 1;
|
|
|
|
static const int CHUNK_VERSION = 2;
|
2012-02-13 16:47:03 -05:00
|
|
|
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
|
2012-03-04 10:59:10 -05:00
|
|
|
|
|
|
|
Vector3i m_ChunkSize; // Is related to m_ChunkVersion
|
|
|
|
char m_ChunkVersion;
|
|
|
|
char m_PakVersion;
|
2012-02-13 16:47:03 -05:00
|
|
|
|
2012-02-16 08:42:35 -05:00
|
|
|
bool LoadChunk(const cChunkCoords & a_Chunk, int a_Offset, sChunkHeader * a_Header, cWorld * a_World);
|
|
|
|
bool SaveChunkToData(const cChunkCoords & a_Chunk, cWorld * a_World); // Saves the chunk to m_DataContents, updates headers and m_NumDirty
|
2012-02-13 16:47:03 -05:00
|
|
|
void SynchronizeFile(void); // Writes m_DataContents along with the headers to file, resets m_NumDirty
|
2012-03-04 10:59:10 -05:00
|
|
|
|
|
|
|
void UpdateChunk1To2(void);
|
2012-02-13 16:47:03 -05:00
|
|
|
} ;
|
|
|
|
|
|
|
|
typedef std::list<cPAKFile *> cPAKFiles;
|
|
|
|
|
2012-02-28 05:45:53 -05:00
|
|
|
cCriticalSection m_CS;
|
2012-02-13 16:47:03 -05:00
|
|
|
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
|
2012-02-16 08:42:35 -05:00
|
|
|
cPAKFile * LoadPAKFile(const cChunkCoords & a_Chunk);
|
2012-02-13 16:47:03 -05:00
|
|
|
|
2012-02-28 05:45:53 -05:00
|
|
|
/// Gets chunk data from the correct file; locks CS as needed
|
|
|
|
bool GetChunkData(const cChunkCoords & a_Chunk, int & a_UncompressedSize, AString & a_Data);
|
|
|
|
|
|
|
|
/// Sets chunk data to the correct file; locks CS as needed
|
|
|
|
bool SetChunkData(const cChunkCoords & a_Chunk, int a_UncompressedSize, const AString & a_Data);
|
|
|
|
|
|
|
|
/// Erases chunk data from the correct file; locks CS as needed
|
|
|
|
bool EraseChunkData(const cChunkCoords & a_Chunk);
|
|
|
|
|
|
|
|
/// Loads the chunk from the data (no locking needed)
|
|
|
|
bool LoadChunkFromData(const cChunkCoords & a_Chunk, int & a_UncompressedSize, const AString & a_Data, cWorld * a_World);
|
|
|
|
|
|
|
|
void LoadEntitiesFromJson(Json::Value & a_Value, cEntityList & a_Entities, cBlockEntityList & a_BlockEntities, cWorld * a_World);
|
|
|
|
|
2012-02-13 16:47:03 -05:00
|
|
|
// cWSSchema overrides:
|
2012-02-16 08:42:35 -05:00
|
|
|
virtual bool LoadChunk(const cChunkCoords & a_Chunk) override;
|
|
|
|
virtual bool SaveChunk(const cChunkCoords & a_Chunk) override;
|
2012-02-13 16:47:03 -05:00
|
|
|
virtual const AString GetName(void) const override {return "compact"; }
|
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif // WSSCOMPACT_H_INCLUDED
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|