summaryrefslogtreecommitdiffstats
path: root/src/WorldStorage
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2014-12-10 22:35:16 +0100
committerMattes D <github@xoft.cz>2014-12-10 22:35:16 +0100
commitfcd3d1bfedbfbe535f406e3db933486bad913ab4 (patch)
tree24ad1b9b30473e686ded1e2a89a02ce04fb2cc91 /src/WorldStorage
parentLighting thread: skip chunks that are already lit. (diff)
downloadcuberite-fcd3d1bfedbfbe535f406e3db933486bad913ab4.tar
cuberite-fcd3d1bfedbfbe535f406e3db933486bad913ab4.tar.gz
cuberite-fcd3d1bfedbfbe535f406e3db933486bad913ab4.tar.bz2
cuberite-fcd3d1bfedbfbe535f406e3db933486bad913ab4.tar.lz
cuberite-fcd3d1bfedbfbe535f406e3db933486bad913ab4.tar.xz
cuberite-fcd3d1bfedbfbe535f406e3db933486bad913ab4.tar.zst
cuberite-fcd3d1bfedbfbe535f406e3db933486bad913ab4.zip
Diffstat (limited to '')
-rw-r--r--src/WorldStorage/WorldStorage.cpp58
-rw-r--r--src/WorldStorage/WorldStorage.h6
2 files changed, 47 insertions, 17 deletions
diff --git a/src/WorldStorage/WorldStorage.cpp b/src/WorldStorage/WorldStorage.cpp
index 31318ee67..c7a295175 100644
--- a/src/WorldStorage/WorldStorage.cpp
+++ b/src/WorldStorage/WorldStorage.cpp
@@ -140,11 +140,11 @@ size_t cWorldStorage::GetSaveQueueLength(void)
-void cWorldStorage::QueueLoadChunk(int a_ChunkX, int a_ChunkZ)
+void cWorldStorage::QueueLoadChunk(int a_ChunkX, int a_ChunkZ, cChunkCoordCallback * a_Callback)
{
ASSERT(m_World->IsChunkQueued(a_ChunkX, a_ChunkZ));
- m_LoadQueue.EnqueueItem(cChunkCoords(a_ChunkX, a_ChunkZ));
+ m_LoadQueue.EnqueueItem(cChunkCoordsWithCallback(a_ChunkX, a_ChunkZ, a_Callback));
m_Event.Set();
}
@@ -152,11 +152,11 @@ void cWorldStorage::QueueLoadChunk(int a_ChunkX, int a_ChunkZ)
-void cWorldStorage::QueueSaveChunk(int a_ChunkX, int a_ChunkZ)
+void cWorldStorage::QueueSaveChunk(int a_ChunkX, int a_ChunkZ, cChunkCoordCallback * a_Callback)
{
ASSERT(m_World->IsChunkValid(a_ChunkX, a_ChunkZ));
- m_SaveQueue.EnqueueItemIfNotPresent(cChunkCoords(a_ChunkX, a_ChunkZ));
+ m_SaveQueue.EnqueueItem(cChunkCoordsWithCallback(a_ChunkX, a_ChunkZ, a_Callback));
m_Event.Set();
}
@@ -166,7 +166,11 @@ void cWorldStorage::QueueSaveChunk(int a_ChunkX, int a_ChunkZ)
void cWorldStorage::UnqueueLoad(int a_ChunkX, int a_ChunkZ)
{
- m_LoadQueue.Remove(cChunkCoords(a_ChunkX, a_ChunkZ));
+ m_LoadQueue.RemoveIf([=](cChunkCoordsWithCallback & a_Item)
+ {
+ return (a_Item.m_ChunkX == a_ChunkX) && (a_Item.m_ChunkZ == a_ChunkZ);
+ }
+ );
}
@@ -175,7 +179,11 @@ void cWorldStorage::UnqueueLoad(int a_ChunkX, int a_ChunkZ)
void cWorldStorage::UnqueueSave(const cChunkCoords & a_Chunk)
{
- m_SaveQueue.Remove(a_Chunk);
+ m_SaveQueue.RemoveIf([=](cChunkCoordsWithCallback & a_Item)
+ {
+ return (a_Item.m_ChunkX == a_Chunk.m_ChunkX) && (a_Item.m_ChunkZ == a_Chunk.m_ChunkZ);
+ }
+ );
}
@@ -244,14 +252,23 @@ void cWorldStorage::Execute(void)
bool cWorldStorage::LoadOneChunk(void)
{
- cChunkCoords ToLoad(0, 0);
+ // Dequeue an item, bail out if there's none left:
+ cChunkCoordsWithCallback ToLoad(0, 0, nullptr);
bool ShouldLoad = m_LoadQueue.TryDequeueItem(ToLoad);
+ if (!ShouldLoad)
+ {
+ return false;
+ }
- if (ShouldLoad)
+ // Load the chunk:
+ bool res = LoadChunk(ToLoad.m_ChunkX, ToLoad.m_ChunkZ);
+
+ // Call the callback, if specified:
+ if (ToLoad.m_Callback != nullptr)
{
- return LoadChunk(ToLoad.m_ChunkX, ToLoad.m_ChunkZ);
+ ToLoad.m_Callback->Call(ToLoad.m_ChunkX, ToLoad.m_ChunkZ);
}
- return false;
+ return res;
}
@@ -260,17 +277,30 @@ bool cWorldStorage::LoadOneChunk(void)
bool cWorldStorage::SaveOneChunk(void)
{
- cChunkCoords ToSave(0, 0);
+ // Dequeue one chunk to save:
+ cChunkCoordsWithCallback ToSave(0, 0, nullptr);
bool ShouldSave = m_SaveQueue.TryDequeueItem(ToSave);
- if (ShouldSave && m_World->IsChunkValid(ToSave.m_ChunkX, ToSave.m_ChunkZ))
+ if (!ShouldSave)
+ {
+ return false;
+ }
+
+ // Save the chunk, if it's valid:
+ if (m_World->IsChunkValid(ToSave.m_ChunkX, ToSave.m_ChunkZ))
{
m_World->MarkChunkSaving(ToSave.m_ChunkX, ToSave.m_ChunkZ);
- if (m_SaveSchema->SaveChunk(ToSave))
+ if (m_SaveSchema->SaveChunk(cChunkCoords(ToSave.m_ChunkX, ToSave.m_ChunkZ)))
{
m_World->MarkChunkSaved(ToSave.m_ChunkX, ToSave.m_ChunkZ);
}
}
- return ShouldSave;
+
+ // Call the callback, if specified:
+ if (ToSave.m_Callback != nullptr)
+ {
+ ToSave.m_Callback->Call(ToSave.m_ChunkX, ToSave.m_ChunkZ);
+ }
+ return true;
}
diff --git a/src/WorldStorage/WorldStorage.h b/src/WorldStorage/WorldStorage.h
index fc7e9f84c..e9ba2a8e2 100644
--- a/src/WorldStorage/WorldStorage.h
+++ b/src/WorldStorage/WorldStorage.h
@@ -25,7 +25,7 @@
// fwd:
class cWorld;
-typedef cQueue<cChunkCoords> cChunkCoordsQueue;
+typedef cQueue<cChunkCoordsWithCallback> cChunkCoordsQueue;
@@ -64,8 +64,8 @@ public:
cWorldStorage(void);
~cWorldStorage();
- void QueueLoadChunk(int a_ChunkX, int a_ChunkZ);
- void QueueSaveChunk(int a_ChunkX, int a_ChunkZ);
+ void QueueLoadChunk(int a_ChunkX, int a_ChunkZ, cChunkCoordCallback * a_Callback = nullptr);
+ void QueueSaveChunk(int a_ChunkX, int a_ChunkZ, cChunkCoordCallback * a_Callback = nullptr);
void UnqueueLoad(int a_ChunkX, int a_ChunkZ);
void UnqueueSave(const cChunkCoords & a_Chunk);