From be31652c40af10b0410c76c6bd37b60717c385be Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Fri, 23 Mar 2012 21:12:48 +0000 Subject: Encapsulated cWorld functions needed in cWorldStorage into an interface, so that cWorldStorage can actually be used outside of MC-Server (such as storage conversion tools and chunk analyzers) git-svn-id: http://mc-server.googlecode.com/svn/trunk@427 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/WorldStorage.h | 50 ++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 44 insertions(+), 6 deletions(-) (limited to 'source/WorldStorage.h') diff --git a/source/WorldStorage.h b/source/WorldStorage.h index da78b69f2..047c358ba 100644 --- a/source/WorldStorage.h +++ b/source/WorldStorage.h @@ -22,8 +22,45 @@ -// fwd: -class cWorld; +/** Interface between cWorld and cWorldStorage, contains all calls into cWorld that cWorldStorage needs +Defining this as an interface lets us re-use the cWorldStorage outside of MC-Server's main executable, +for example for tools such as storage converters or chunk analytics +*/ +class cWSInterface +{ +public: + /// Asks the world if the chunk is fully valid + virtual bool WSIIsChunkValid(int a_ChunkX, int a_ChunkY, int a_ChunkZ) = 0; + + /// Marks the chunk as being saved + virtual void WSIMarkChunkSaving(int a_ChunkX, int a_ChunkY, int a_ChunkZ) = 0; + + /// Marks the chunk as having been saved (if there was no change since the last MarkSaving) + virtual void WSIMarkChunkSaved(int a_ChunkX, int a_ChunkY, int a_ChunkZ) = 0; + + /// Marks the chunk as unable to load + virtual void WSIChunkLoadFailed(int a_ChunkX, int a_ChunkY, int a_ChunkZ) = 0; + + /// Called when chunk generation has been specified for a chunk that cannot be loaded + virtual void WSIGenerateChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ) = 0; + + /// Marks the chunk as having been saved (if there was no change since the last MarkSaving) + virtual bool WSIGetChunkData(int a_ChunkX, int a_ChunkY, int a_ChunkZ, cChunkDataCallback & a_Callback) = 0; + + /// Gets the folder where the world is saved + virtual AString WSIGetFolder(void) = 0; + + virtual void WSIChunkDataLoaded( + int a_ChunkX, int a_ChunkY, int a_ChunkZ, + const BLOCKTYPE * a_BlockTypes, + const BLOCKTYPE * a_BlockMeta, + const BLOCKTYPE * a_BlockLight, + const BLOCKTYPE * a_BlockSkyLight, + const cChunkDef::HeightMap * a_HeightMap, + cEntityList & a_Entities, + cBlockEntityList & a_BlockEntities + ) = 0; +} ; @@ -33,7 +70,7 @@ class cWorld; class cWSSchema abstract { public: - cWSSchema(cWorld * a_World) : m_World(a_World) {} + cWSSchema(cWSInterface * a_WSI) : m_WSI(a_WSI) {} virtual ~cWSSchema() {} // Force the descendants' destructors to be virtual virtual bool LoadChunk(const cChunkCoords & a_Chunk) = 0; @@ -42,7 +79,7 @@ public: protected: - cWorld * m_World; + cWSInterface * m_WSI; } ; typedef std::list cWSSchemaList; @@ -103,7 +140,7 @@ public: 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 + bool Start(cWSInterface * a_WSI, const AString & a_StorageSchemaName); // Hide the cIsThread's Start() method, we need to provide args void WaitForFinish(void); void WaitForQueuesEmpty(void); @@ -124,7 +161,8 @@ protected: typedef std::list sChunkLoadQueue; - cWorld * m_World; + cWSInterface * m_WSI; + AString m_StorageSchemaName; // Both queues are locked by the same CS -- cgit v1.2.3