From 675b4aa878f16291ce33fced48a2bc7425f635ae Mon Sep 17 00:00:00 2001 From: Alexander Harkness Date: Sun, 24 Nov 2013 14:19:41 +0000 Subject: Moved source to src --- src/WorldStorage/WorldStorage.h | 135 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 135 insertions(+) create mode 100644 src/WorldStorage/WorldStorage.h (limited to 'src/WorldStorage/WorldStorage.h') diff --git a/src/WorldStorage/WorldStorage.h b/src/WorldStorage/WorldStorage.h new file mode 100644 index 000000000..bf8dbd3d5 --- /dev/null +++ b/src/WorldStorage/WorldStorage.h @@ -0,0 +1,135 @@ + +// WorldStorage.h + +// 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 + + + + + +#pragma once +#ifndef WORLDSTORAGE_H_INCLUDED +#define WORLDSTORAGE_H_INCLUDED + +#include "../ChunkDef.h" +#include "../OSSupport/IsThread.h" +#include + + + + + +// fwd: +class cWorld; + + + + + +/// Interface that all the world storage schemas need to implement +class cWSSchema abstract +{ +public: + cWSSchema(cWorld * a_World) : m_World(a_World) {} + virtual ~cWSSchema() {} // Force the descendants' destructors to be virtual + + virtual bool LoadChunk(const cChunkCoords & a_Chunk) = 0; + virtual bool SaveChunk(const cChunkCoords & a_Chunk) = 0; + virtual const AString GetName(void) const = 0; + +protected: + + cWorld * m_World; +} ; + +typedef std::list cWSSchemaList; + + + + + +/// The actual world storage class +class cWorldStorage : + public cIsThread +{ + typedef cIsThread super; + +public: + + cWorldStorage(void); + ~cWorldStorage(); + + void QueueLoadChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ, bool a_Generate); // Queues the chunk for loading; if not loaded, the chunk will be generated if a_Generate is true + void QueueSaveChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ); + + /// Signals that a message should be output to the console when all the chunks have been saved + void QueueSavedMessage(void); + + /// Loads the chunk specified; returns true on success, false on failure + bool LoadChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ); + + void UnqueueLoad(int a_ChunkX, int a_ChunkY, int a_ChunkZ); + 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 Stop(void); // Hide the cIsThread's Stop() method, we need to signal the event + void WaitForFinish(void); + void WaitForQueuesEmpty(void); + + int GetLoadQueueLength(void); + int GetSaveQueueLength(void); + +protected: + + struct sChunkLoad + { + int m_ChunkX; + int m_ChunkY; + int m_ChunkZ; + bool m_Generate; // If true, the chunk will be generated if it cannot be loaded + + sChunkLoad(int a_ChunkX, int a_ChunkY, int a_ChunkZ, bool a_Generate) : m_ChunkX(a_ChunkX), m_ChunkY(a_ChunkY), m_ChunkZ(a_ChunkZ), m_Generate(a_Generate) {} + } ; + + typedef std::list sChunkLoadQueue; + + cWorld * m_World; + AString m_StorageSchemaName; + + // Both queues are locked by the same CS + cCriticalSection m_CSQueues; + sChunkLoadQueue m_LoadQueue; + cChunkCoordsList m_SaveQueue; + + cEvent m_Event; // Set when there's any addition to the queues + cEvent m_evtRemoved; // Set when an item has been removed from the queue, either by the worker thread or the Unqueue methods + + /// All the storage schemas (all used for loading) + cWSSchemaList m_Schemas; + + /// The one storage schema used for saving + cWSSchema * m_SaveSchema; + + void InitSchemas(void); + + virtual void Execute(void) override; + + /// 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); +} ; + + + + + +#endif // WORLDSTORAGE_H_INCLUDED + + + + -- cgit v1.2.3 From e3db69c4ae5d373ea1f1b31c0fc1889f328ea2ed Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 24 Nov 2013 18:44:22 +0000 Subject: Attempt to fix compilation --- src/WorldStorage/WorldStorage.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/WorldStorage/WorldStorage.h') diff --git a/src/WorldStorage/WorldStorage.h b/src/WorldStorage/WorldStorage.h index bf8dbd3d5..384ade081 100644 --- a/src/WorldStorage/WorldStorage.h +++ b/src/WorldStorage/WorldStorage.h @@ -16,7 +16,7 @@ #include "../ChunkDef.h" #include "../OSSupport/IsThread.h" -#include +#include "../lib/jsoncpp/include/json/json.h" -- cgit v1.2.3 From 32449f1fca8379d0c7f38e95834b2a01e62de06c Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Mon, 25 Nov 2013 18:29:36 +0000 Subject: Further attempts to fix compile --- src/WorldStorage/WorldStorage.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/WorldStorage/WorldStorage.h') diff --git a/src/WorldStorage/WorldStorage.h b/src/WorldStorage/WorldStorage.h index 384ade081..b2c6dfb4b 100644 --- a/src/WorldStorage/WorldStorage.h +++ b/src/WorldStorage/WorldStorage.h @@ -16,7 +16,7 @@ #include "../ChunkDef.h" #include "../OSSupport/IsThread.h" -#include "../lib/jsoncpp/include/json/json.h" +#include "lib/jsoncpp/include/json/json.h" -- cgit v1.2.3 From d925cf4def76d6db05a46d3ead77e6c76cfdd268 Mon Sep 17 00:00:00 2001 From: Alexander Harkness Date: Wed, 27 Nov 2013 07:40:59 +0000 Subject: Fixed the remaining derps --- src/WorldStorage/WorldStorage.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/WorldStorage/WorldStorage.h') diff --git a/src/WorldStorage/WorldStorage.h b/src/WorldStorage/WorldStorage.h index b2c6dfb4b..720c04759 100644 --- a/src/WorldStorage/WorldStorage.h +++ b/src/WorldStorage/WorldStorage.h @@ -16,7 +16,7 @@ #include "../ChunkDef.h" #include "../OSSupport/IsThread.h" -#include "lib/jsoncpp/include/json/json.h" +#include "jsoncpp/include/json/json.h" -- cgit v1.2.3 From 2113ca384450eb0155c43452690bda08b62cb6aa Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Wed, 27 Nov 2013 09:17:25 +0100 Subject: Fixed VC2008 compilation, normalized include paths. --- src/WorldStorage/WorldStorage.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/WorldStorage/WorldStorage.h') diff --git a/src/WorldStorage/WorldStorage.h b/src/WorldStorage/WorldStorage.h index 720c04759..98e7e1686 100644 --- a/src/WorldStorage/WorldStorage.h +++ b/src/WorldStorage/WorldStorage.h @@ -16,7 +16,7 @@ #include "../ChunkDef.h" #include "../OSSupport/IsThread.h" -#include "jsoncpp/include/json/json.h" +#include "json/json.h" -- cgit v1.2.3