From f3736b1eb7bf698518cdb853ee29ee96b9c24a52 Mon Sep 17 00:00:00 2001 From: Tycho Bickerstaff Date: Tue, 31 Dec 2013 15:48:57 +0000 Subject: refactored chunk Queue to seperate class --- src/WorldStorage/WorldStorage.h | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) (limited to 'src/WorldStorage/WorldStorage.h') diff --git a/src/WorldStorage/WorldStorage.h b/src/WorldStorage/WorldStorage.h index 007d37571..c3eb96ce8 100644 --- a/src/WorldStorage/WorldStorage.h +++ b/src/WorldStorage/WorldStorage.h @@ -16,6 +16,7 @@ #include "../ChunkDef.h" #include "../OSSupport/IsThread.h" +#include "../OSSupport/Queue.h" @@ -24,6 +25,8 @@ // fwd: class cWorld; +typedef cQueue cChunkCoordsQueue; + @@ -78,8 +81,8 @@ public: void WaitForFinish(void); void WaitForQueuesEmpty(void); - int GetLoadQueueLength(void); - int GetSaveQueueLength(void); + size_t GetLoadQueueLength(void); + size_t GetSaveQueueLength(void); protected: @@ -91,9 +94,24 @@ protected: 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) {} + + bool operator==(const sChunkLoad other) const + { + return this->m_ChunkX == other.m_ChunkX && + this->m_ChunkY == other.m_ChunkY && + this->m_ChunkZ == other.m_ChunkZ; + } } ; - - typedef std::list sChunkLoadQueue; + + struct FuncTable { + static void Delete(sChunkLoad) {}; + static void Combine(sChunkLoad& a_orig, const sChunkLoad a_new) + { + a_orig.m_Generate |= a_new.m_Generate; + }; + }; + + typedef cQueue sChunkLoadQueue; cWorld * m_World; AString m_StorageSchemaName; @@ -101,7 +119,7 @@ protected: // Both queues are locked by the same CS cCriticalSection m_CSQueues; sChunkLoadQueue m_LoadQueue; - cChunkCoordsList m_SaveQueue; + cChunkCoordsQueue 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 -- cgit v1.2.3