From 423f49d175d8db6283232bd8bdc106e26bdcff4d Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Thu, 16 Feb 2012 13:42:35 +0000 Subject: Chunk is now marked as dirty; saving only dirty chunks; rewritten load / save not to use cChunkPtr; set VC2008 project to level4 warnings; block entities are now loaded and saved properly git-svn-id: http://mc-server.googlecode.com/svn/trunk@273 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/WorldStorage.h | 76 ++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 66 insertions(+), 10 deletions(-) (limited to 'source/WorldStorage.h') diff --git a/source/WorldStorage.h b/source/WorldStorage.h index 52573caf0..5de7f49fa 100644 --- a/source/WorldStorage.h +++ b/source/WorldStorage.h @@ -4,6 +4,7 @@ // Interfaces to the cWorldStorage class representing the chunk loading / saving thread // This class decides which storage schema to use for saving; it queries all available schemas for loading // Also declares the base class for all storage schemas, cWSSchema +// Helper serialization class cJsonChunkSerializer is declared as well @@ -15,6 +16,15 @@ #include "cChunk.h" #include "cIsThread.h" +#include + + + + + +// fwd: +class cEntity; +class cBlockEntity; @@ -27,8 +37,8 @@ public: cWSSchema(cWorld * a_World) : m_World(a_World) {} virtual ~cWSSchema() {} // Force the descendants' destructors to be virtual - virtual bool LoadChunk(const cChunkPtr & a_Chunk) = 0; - virtual bool SaveChunk(const cChunkPtr & a_Chunk) = 0; + virtual bool LoadChunk(const cChunkCoords & a_Chunk) = 0; + virtual bool SaveChunk(const cChunkCoords & a_Chunk) = 0; virtual const AString GetName(void) const = 0; protected: @@ -42,6 +52,41 @@ typedef std::list cWSSchemaList; +/// Helper class for serializing a chunk into Json +class cJsonChunkSerializer : + public cChunkDataCallback +{ +public: + + cJsonChunkSerializer(void); + + Json::Value & GetRoot (void) {return m_Root; } + AString & GetBlockData(void) {return m_BlockData; } + bool HasJsonData (void) const {return m_HasJsonData; } + +protected: + + // BlockData is serialized into string + AString m_BlockData; + + // Entities and BlockEntities are serialized to Json + Json::Value m_Root; + Json::Value m_AllChests; + Json::Value m_AllFurnaces; + Json::Value m_AllSigns; + bool m_HasJsonData; + + // cChunkDataCallback overrides: + virtual void BlockData (const char * a_Data) override; + virtual void Entity (cEntity * a_Entity) override; + virtual void BlockEntity(cBlockEntity * a_Entity) override; +} ; + + + + + +/// The actual world storage class class cWorldStorage : public cIsThread { @@ -52,11 +97,11 @@ public: cWorldStorage(void); ~cWorldStorage(); - void QueueLoadChunk(cChunkPtr & a_Chunk); // Queues the chunk for loading; if not loaded, the chunk will be generated - void QueueSaveChunk(cChunkPtr & a_Chunk); + void QueueLoadChunk(int a_ChunkX, int a_ChunkZ); // Queues the chunk for loading; if not loaded, the chunk will be generated + void QueueSaveChunk(int a_ChunkX, int a_ChunkZ); - void UnqueueLoad(const cChunkPtr & a_Chunk); - void UnqueueSave(const cChunkPtr & a_Chunk); + void UnqueueLoad(const cChunkCoords & a_Chunk); + void UnqueueSave(const cChunkCoords & a_Chunk); bool Start(cWorld * a_World, const AString & a_StorageSchemaName); // Hide the cIsThread's Start() method, we need to provide args void WaitForFinish(void); @@ -67,20 +112,31 @@ protected: AString m_StorageSchemaName; cCriticalSection m_CSLoadQueue; - cChunkPtrList m_LoadQueue; + cChunkCoordsList m_LoadQueue; cCriticalSection m_CSSaveQueue; - cChunkPtrList m_SaveQueue; + cChunkCoordsList m_SaveQueue; cEvent m_Event; // Set when there's any addition to the queues + /// All the storage schemas (all used for loading) cWSSchemaList m_Schemas; - cWSSchema * m_SaveSchema; + + /// The one storage schema used for saving + cWSSchema * m_SaveSchema; void InitSchemas(void); virtual void Execute(void) override; - bool LoadChunk(const cChunkPtr & a_Chunk); + + /// Loads one chunk from the queue (if any queued); returns true if there are more chunks in the load queue + bool LoadOneChunk(void); + + /// Saves one chunk from the queue (if any queued); returns true if there are more chunks in the save queue + bool SaveOneChunk(void); + + /// Loads the chunk specified; returns true on success, false on failure + bool LoadChunk(const cChunkCoords & a_Chunk); } ; -- cgit v1.2.3