summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTiger Wang <ziwei.tiger@outlook.com>2020-08-28 22:36:46 +0200
committerTiger Wang <ziwei.tiger@outlook.com>2020-08-28 22:36:46 +0200
commitda9158937d96e84bd39a7fbbbaace7cd4f8fe18c (patch)
tree0bd2613828e8ff500097760a91afaa6d7ca6d234 /src
parentClean up pickup collection to use ForEachEntityInBox (diff)
downloadcuberite-da9158937d96e84bd39a7fbbbaace7cd4f8fe18c.tar
cuberite-da9158937d96e84bd39a7fbbbaace7cd4f8fe18c.tar.gz
cuberite-da9158937d96e84bd39a7fbbbaace7cd4f8fe18c.tar.bz2
cuberite-da9158937d96e84bd39a7fbbbaace7cd4f8fe18c.tar.lz
cuberite-da9158937d96e84bd39a7fbbbaace7cd4f8fe18c.tar.xz
cuberite-da9158937d96e84bd39a7fbbbaace7cd4f8fe18c.tar.zst
cuberite-da9158937d96e84bd39a7fbbbaace7cd4f8fe18c.zip
Diffstat (limited to 'src')
-rw-r--r--src/ChunkDef.h21
-rw-r--r--src/WorldStorage/WorldStorage.cpp26
-rw-r--r--src/WorldStorage/WorldStorage.h16
3 files changed, 13 insertions, 50 deletions
diff --git a/src/ChunkDef.h b/src/ChunkDef.h
index 8f46c5f8f..82e7e518e 100644
--- a/src/ChunkDef.h
+++ b/src/ChunkDef.h
@@ -629,27 +629,6 @@ public:
-/** Provides storage for a set of chunk coords together with a callback.
-Used for chunk queues that notify about processed items. */
-class cChunkCoordsWithCallback
-{
-public:
- cChunkCoordsWithCallback(int a_ChunkX, int a_ChunkZ, cChunkCoordCallback * a_Callback):
- m_ChunkX(a_ChunkX),
- m_ChunkZ(a_ChunkZ),
- m_Callback(a_Callback)
- {
- }
-
- int m_ChunkX;
- int m_ChunkZ;
- cChunkCoordCallback * m_Callback;
-};
-
-
-
-
-
/** Generic template that can store any kind of data together with a triplet of 3 coords */
template <typename X> class cCoordWithData
{
diff --git a/src/WorldStorage/WorldStorage.cpp b/src/WorldStorage/WorldStorage.cpp
index 63e6e9625..c913eb15c 100644
--- a/src/WorldStorage/WorldStorage.cpp
+++ b/src/WorldStorage/WorldStorage.cpp
@@ -138,13 +138,13 @@ size_t cWorldStorage::GetSaveQueueLength(void)
-void cWorldStorage::QueueLoadChunk(int a_ChunkX, int a_ChunkZ, cChunkCoordCallback * a_Callback)
+void cWorldStorage::QueueLoadChunk(int a_ChunkX, int a_ChunkZ)
{
ASSERT((a_ChunkX > -0x08000000) && (a_ChunkX < 0x08000000));
ASSERT((a_ChunkZ > -0x08000000) && (a_ChunkZ < 0x08000000));
ASSERT(m_World->IsChunkQueued(a_ChunkX, a_ChunkZ));
- m_LoadQueue.EnqueueItem(cChunkCoordsWithCallback(a_ChunkX, a_ChunkZ, a_Callback));
+ m_LoadQueue.EnqueueItem({ a_ChunkX, a_ChunkZ });
m_Event.Set();
}
@@ -152,11 +152,11 @@ void cWorldStorage::QueueLoadChunk(int a_ChunkX, int a_ChunkZ, cChunkCoordCallba
-void cWorldStorage::QueueSaveChunk(int a_ChunkX, int a_ChunkZ, cChunkCoordCallback * a_Callback)
+void cWorldStorage::QueueSaveChunk(int a_ChunkX, int a_ChunkZ)
{
ASSERT(m_World->IsChunkValid(a_ChunkX, a_ChunkZ));
- m_SaveQueue.EnqueueItem(cChunkCoordsWithCallback(a_ChunkX, a_ChunkZ, a_Callback));
+ m_SaveQueue.EnqueueItem({ a_ChunkX, a_ChunkZ });
m_Event.Set();
}
@@ -227,7 +227,7 @@ void cWorldStorage::Execute(void)
bool cWorldStorage::LoadOneChunk(void)
{
// Dequeue an item, bail out if there's none left:
- cChunkCoordsWithCallback ToLoad(0, 0, nullptr);
+ cChunkCoords ToLoad(0, 0);
bool ShouldLoad = m_LoadQueue.TryDequeueItem(ToLoad);
if (!ShouldLoad)
{
@@ -235,14 +235,7 @@ bool cWorldStorage::LoadOneChunk(void)
}
// Load the chunk:
- bool res = LoadChunk(ToLoad.m_ChunkX, ToLoad.m_ChunkZ);
-
- // Call the callback, if specified:
- if (ToLoad.m_Callback != nullptr)
- {
- ToLoad.m_Callback->Call({ToLoad.m_ChunkX, ToLoad.m_ChunkZ}, res);
- }
- return res;
+ return LoadChunk(ToLoad.m_ChunkX, ToLoad.m_ChunkZ);
}
@@ -252,7 +245,7 @@ bool cWorldStorage::LoadOneChunk(void)
bool cWorldStorage::SaveOneChunk(void)
{
// Dequeue one chunk to save:
- cChunkCoordsWithCallback ToSave(0, 0, nullptr);
+ cChunkCoords ToSave(0, 0);
bool ShouldSave = m_SaveQueue.TryDequeueItem(ToSave);
if (!ShouldSave)
{
@@ -271,11 +264,6 @@ bool cWorldStorage::SaveOneChunk(void)
}
}
- // Call the callback, if specified:
- if (ToSave.m_Callback != nullptr)
- {
- ToSave.m_Callback->Call({ToSave.m_ChunkX, ToSave.m_ChunkZ}, Status);
- }
return true;
}
diff --git a/src/WorldStorage/WorldStorage.h b/src/WorldStorage/WorldStorage.h
index 1cdf75542..dc4bb2e17 100644
--- a/src/WorldStorage/WorldStorage.h
+++ b/src/WorldStorage/WorldStorage.h
@@ -22,8 +22,6 @@
// fwd:
class cWorld;
-typedef cQueue<cChunkCoordsWithCallback> cChunkCoordsQueue;
-
@@ -61,13 +59,11 @@ public:
cWorldStorage();
virtual ~cWorldStorage() override;
- /** Queues a chunk to be loaded, asynchronously.
- The callback, if specified, will be called with the result of the load operation. */
- void QueueLoadChunk(int a_ChunkX, int a_ChunkZ, cChunkCoordCallback * a_Callback = nullptr);
+ /** Queues a chunk to be loaded, asynchronously. */
+ void QueueLoadChunk(int a_ChunkX, int a_ChunkZ);
- /** Queues a chunk to be saved, asynchronously.
- The callback, if specified, will be called with the result of the save operation. */
- void QueueSaveChunk(int a_ChunkX, int a_ChunkZ, cChunkCoordCallback * a_Callback = nullptr);
+ /** Queues a chunk to be saved, asynchronously. */
+ void QueueSaveChunk(int a_ChunkX, int a_ChunkZ);
/** Initializes the storage schemas, ready to be started. */
void Initialize(cWorld & a_World, const AString & a_StorageSchemaName, int a_StorageCompressionFactor);
@@ -84,8 +80,8 @@ protected:
cWorld * m_World;
AString m_StorageSchemaName;
- cChunkCoordsQueue m_LoadQueue;
- cChunkCoordsQueue m_SaveQueue;
+ cQueue<cChunkCoords> m_LoadQueue;
+ cQueue<cChunkCoords> m_SaveQueue;
/** All the storage schemas (all used for loading) */
cWSSchemaList m_Schemas;