summaryrefslogtreecommitdiffstats
path: root/src/WorldStorage/WorldStorage.h
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2014-01-04 12:52:58 +0100
committerMattes D <github@xoft.cz>2014-01-04 12:52:58 +0100
commit4d7f2139981ac6947cc987a6b4d6d46646ebc480 (patch)
tree4a5067e4a9fe55486d08ac1d2e9517aa8531cebe /src/WorldStorage/WorldStorage.h
parentMerge pull request #502 from bitdeli-chef/master (diff)
parentFixed Documentation (diff)
downloadcuberite-4d7f2139981ac6947cc987a6b4d6d46646ebc480.tar
cuberite-4d7f2139981ac6947cc987a6b4d6d46646ebc480.tar.gz
cuberite-4d7f2139981ac6947cc987a6b4d6d46646ebc480.tar.bz2
cuberite-4d7f2139981ac6947cc987a6b4d6d46646ebc480.tar.lz
cuberite-4d7f2139981ac6947cc987a6b4d6d46646ebc480.tar.xz
cuberite-4d7f2139981ac6947cc987a6b4d6d46646ebc480.tar.zst
cuberite-4d7f2139981ac6947cc987a6b4d6d46646ebc480.zip
Diffstat (limited to 'src/WorldStorage/WorldStorage.h')
-rw-r--r--src/WorldStorage/WorldStorage.h40
1 files changed, 28 insertions, 12 deletions
diff --git a/src/WorldStorage/WorldStorage.h b/src/WorldStorage/WorldStorage.h
index 007d37571..06cae1717 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<cChunkCoords> cChunkCoordsQueue;
+
@@ -76,10 +79,11 @@ public:
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);
+ void WaitForLoadQueueEmpty(void);
+ void WaitForSaveQueueEmpty(void);
- int GetLoadQueueLength(void);
- int GetSaveQueueLength(void);
+ size_t GetLoadQueueLength(void);
+ size_t GetSaveQueueLength(void);
protected:
@@ -91,20 +95,30 @@ 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<sChunkLoad> 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<sChunkLoad,FuncTable> 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
+ cChunkCoordsQueue m_SaveQueue;
/// All the storage schemas (all used for loading)
cWSSchemaList m_Schemas;
@@ -116,6 +130,8 @@ protected:
virtual void Execute(void) override;
+ cEvent m_Event; // Set when there's any addition to the queues
+
/// Loads one chunk from the queue (if any queued); returns true if there are more chunks in the load queue
bool LoadOneChunk(void);