summaryrefslogtreecommitdiffstats
path: root/src/WorldStorage
diff options
context:
space:
mode:
authorMasy98 <masy@antheruscraft.de>2014-09-06 22:03:35 +0200
committerMasy98 <masy@antheruscraft.de>2014-09-06 22:03:35 +0200
commit029eb3d4fac9d480ab2f4bac4ac8fd981a378d9e (patch)
treedd6dce68bf9f1951f6aa663ebc7b4ff3cec38172 /src/WorldStorage
parentMerge remote-tracking branch 'upstream/master' (diff)
parentMerge pull request #1385 from mc-server/clangWarnings (diff)
downloadcuberite-029eb3d4fac9d480ab2f4bac4ac8fd981a378d9e.tar
cuberite-029eb3d4fac9d480ab2f4bac4ac8fd981a378d9e.tar.gz
cuberite-029eb3d4fac9d480ab2f4bac4ac8fd981a378d9e.tar.bz2
cuberite-029eb3d4fac9d480ab2f4bac4ac8fd981a378d9e.tar.lz
cuberite-029eb3d4fac9d480ab2f4bac4ac8fd981a378d9e.tar.xz
cuberite-029eb3d4fac9d480ab2f4bac4ac8fd981a378d9e.tar.zst
cuberite-029eb3d4fac9d480ab2f4bac4ac8fd981a378d9e.zip
Diffstat (limited to 'src/WorldStorage')
-rw-r--r--src/WorldStorage/ScoreboardSerializer.cpp20
-rw-r--r--src/WorldStorage/WSSAnvil.cpp14
-rw-r--r--src/WorldStorage/WorldStorage.cpp34
-rw-r--r--src/WorldStorage/WorldStorage.h39
4 files changed, 40 insertions, 67 deletions
diff --git a/src/WorldStorage/ScoreboardSerializer.cpp b/src/WorldStorage/ScoreboardSerializer.cpp
index da8236e0d..e30eecf67 100644
--- a/src/WorldStorage/ScoreboardSerializer.cpp
+++ b/src/WorldStorage/ScoreboardSerializer.cpp
@@ -283,37 +283,37 @@ bool cScoreboardSerializer::LoadScoreboardFromNBT(const cParsedNBT & a_NBT)
bool AllowsFriendlyFire = true, CanSeeFriendlyInvisible = false;
int CurrLine = a_NBT.FindChildByName(Child, "Name");
- if (CurrLine >= 0)
+ if ((CurrLine >= 0) && (a_NBT.GetType(CurrLine) == TAG_String))
{
- Name = a_NBT.GetInt(CurrLine);
+ Name = a_NBT.GetString(CurrLine);
}
CurrLine = a_NBT.FindChildByName(Child, "DisplayName");
- if (CurrLine >= 0)
+ if ((CurrLine >= 0) && (a_NBT.GetType(CurrLine) == TAG_String))
{
- DisplayName = a_NBT.GetInt(CurrLine);
+ DisplayName = a_NBT.GetString(CurrLine);
}
CurrLine = a_NBT.FindChildByName(Child, "Prefix");
- if (CurrLine >= 0)
+ if ((CurrLine >= 0) && (a_NBT.GetType(CurrLine) == TAG_String))
{
- Prefix = a_NBT.GetInt(CurrLine);
+ Prefix = a_NBT.GetString(CurrLine);
}
CurrLine = a_NBT.FindChildByName(Child, "Suffix");
- if (CurrLine >= 0)
+ if ((CurrLine >= 0) && (a_NBT.GetType(CurrLine) == TAG_String))
{
- Suffix = a_NBT.GetInt(CurrLine);
+ Suffix = a_NBT.GetString(CurrLine);
}
CurrLine = a_NBT.FindChildByName(Child, "AllowFriendlyFire");
- if (CurrLine >= 0)
+ if ((CurrLine >= 0) && (a_NBT.GetType(CurrLine) == TAG_Int))
{
AllowsFriendlyFire = (a_NBT.GetInt(CurrLine) != 0);
}
CurrLine = a_NBT.FindChildByName(Child, "SeeFriendlyInvisibles");
- if (CurrLine >= 0)
+ if ((CurrLine >= 0) && (a_NBT.GetType(CurrLine) == TAG_Int))
{
CanSeeFriendlyInvisible = (a_NBT.GetInt(CurrLine) != 0);
}
diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp
index 4d2f92173..fe309ce4e 100644
--- a/src/WorldStorage/WSSAnvil.cpp
+++ b/src/WorldStorage/WSSAnvil.cpp
@@ -323,7 +323,13 @@ bool cWSSAnvil::LoadChunkFromNBT(const cChunkCoords & a_Chunk, const cParsedNBT
return false;
}
int Sections = a_NBT.FindChildByName(Level, "Sections");
- if ((Sections < 0) || (a_NBT.GetType(Sections) != TAG_List) || (a_NBT.GetChildrenType(Sections) != TAG_Compound))
+ if ((Sections < 0) || (a_NBT.GetType(Sections) != TAG_List))
+ {
+ LOAD_FAILED(a_Chunk.m_ChunkX, a_Chunk.m_ChunkZ);
+ return false;
+ }
+ eTagType SectionsType = a_NBT.GetChildrenType(Sections);
+ if ((SectionsType != TAG_Compound) && (SectionsType != TAG_End))
{
LOAD_FAILED(a_Chunk.m_ChunkX, a_Chunk.m_ChunkZ);
return false;
@@ -589,7 +595,7 @@ void cWSSAnvil::LoadBlockEntitiesFromNBT(cBlockEntityList & a_BlockEntities, con
// Get the BlockEntity's position
int x, y, z;
- if (!GetBlockEntityNBTPos(a_NBT, Child, x, y, z))
+ if (!GetBlockEntityNBTPos(a_NBT, Child, x, y, z) || (y < 0) || (y >= cChunkDef::Height))
{
LOGWARNING("Bad block entity, missing the coords. Will be ignored.");
continue;
@@ -617,6 +623,8 @@ void cWSSAnvil::LoadBlockEntitiesFromNBT(cBlockEntityList & a_BlockEntities, con
cBlockEntity * cWSSAnvil::LoadBlockEntityFromNBT(const cParsedNBT & a_NBT, int a_Tag, int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
{
+ ASSERT((a_BlockY >= 0) && (a_BlockY < cChunkDef::Height));
+
// Load the specific BlockEntity type:
switch (a_BlockType)
{
@@ -2815,7 +2823,7 @@ bool cWSSAnvil::cMCAFile::GetChunkData(const cChunkCoords & a_Chunk, AString & a
}
unsigned ChunkLocation = ntohl(m_Header[LocalX + 32 * LocalZ]);
unsigned ChunkOffset = ChunkLocation >> 8;
- if (ChunkOffset <= 2)
+ if (ChunkOffset < 2)
{
return false;
}
diff --git a/src/WorldStorage/WorldStorage.cpp b/src/WorldStorage/WorldStorage.cpp
index 667a28470..179cf9393 100644
--- a/src/WorldStorage/WorldStorage.cpp
+++ b/src/WorldStorage/WorldStorage.cpp
@@ -141,9 +141,11 @@ size_t cWorldStorage::GetSaveQueueLength(void)
-void cWorldStorage::QueueLoadChunk(int a_ChunkX, int a_ChunkZ, bool a_Generate)
+void cWorldStorage::QueueLoadChunk(int a_ChunkX, int a_ChunkZ)
{
- m_LoadQueue.EnqueueItem(sChunkLoad(a_ChunkX, a_ChunkZ, a_Generate));
+ ASSERT(m_World->IsChunkQueued(a_ChunkX, a_ChunkZ));
+
+ m_LoadQueue.EnqueueItem(cChunkCoords(a_ChunkX, a_ChunkZ));
m_Event.Set();
}
@@ -153,6 +155,8 @@ void cWorldStorage::QueueLoadChunk(int a_ChunkX, int a_ChunkZ, bool a_Generate)
void cWorldStorage::QueueSaveChunk(int a_ChunkX, int a_ChunkZ)
{
+ ASSERT(m_World->IsChunkValid(a_ChunkX, a_ChunkZ));
+
m_SaveQueue.EnqueueItemIfNotPresent(cChunkCoords(a_ChunkX, a_ChunkZ));
m_Event.Set();
}
@@ -163,7 +167,7 @@ void cWorldStorage::QueueSaveChunk(int a_ChunkX, int a_ChunkZ)
void cWorldStorage::UnqueueLoad(int a_ChunkX, int a_ChunkZ)
{
- m_LoadQueue.Remove(sChunkLoad(a_ChunkX, a_ChunkZ, true));
+ m_LoadQueue.Remove(cChunkCoords(a_ChunkX, a_ChunkZ));
}
@@ -242,22 +246,14 @@ void cWorldStorage::Execute(void)
bool cWorldStorage::LoadOneChunk(void)
{
- sChunkLoad ToLoad(0, 0, false);
+ cChunkCoords ToLoad(0, 0);
bool ShouldLoad = m_LoadQueue.TryDequeueItem(ToLoad);
- if (ShouldLoad && !LoadChunk(ToLoad.m_ChunkX, ToLoad.m_ChunkZ))
+
+ if (ShouldLoad)
{
- if (ToLoad.m_Generate)
- {
- // The chunk couldn't be loaded, generate it:
- m_World->GetGenerator().QueueGenerateChunk(ToLoad.m_ChunkX, ToLoad.m_ChunkZ, false);
- }
- else
- {
- // TODO: Notify the world that the load has failed:
- // m_World->ChunkLoadFailed(ToLoad.m_ChunkX, ToLoad.m_ChunkZ);
- }
+ return LoadChunk(ToLoad.m_ChunkX, ToLoad.m_ChunkZ);
}
- return ShouldLoad;
+ return false;
}
@@ -285,11 +281,7 @@ bool cWorldStorage::SaveOneChunk(void)
bool cWorldStorage::LoadChunk(int a_ChunkX, int a_ChunkZ)
{
- if (m_World->IsChunkValid(a_ChunkX, a_ChunkZ))
- {
- // Already loaded (can happen, since the queue is async)
- return true;
- }
+ ASSERT(m_World->IsChunkQueued(a_ChunkX, a_ChunkZ));
cChunkCoords Coords(a_ChunkX, a_ChunkZ);
diff --git a/src/WorldStorage/WorldStorage.h b/src/WorldStorage/WorldStorage.h
index 5f89ead53..fc7e9f84c 100644
--- a/src/WorldStorage/WorldStorage.h
+++ b/src/WorldStorage/WorldStorage.h
@@ -64,12 +64,9 @@ public:
cWorldStorage(void);
~cWorldStorage();
- void QueueLoadChunk(int a_ChunkX, int a_ChunkZ, bool a_Generate); // Queues the chunk for loading; if not loaded, the chunk will be generated if a_Generate is true
+ void QueueLoadChunk(int a_ChunkX, int a_ChunkZ);
void QueueSaveChunk(int a_ChunkX, int a_ChunkZ);
- /// Loads the chunk specified; returns true on success, false on failure
- bool LoadChunk(int a_ChunkX, int a_ChunkZ);
-
void UnqueueLoad(int a_ChunkX, int a_ChunkZ);
void UnqueueSave(const cChunkCoords & a_Chunk);
@@ -84,38 +81,10 @@ public:
protected:
- struct sChunkLoad
- {
- int m_ChunkX;
- int m_ChunkZ;
- bool m_Generate; // If true, the chunk will be generated if it cannot be loaded
-
- sChunkLoad(int a_ChunkX, int a_ChunkZ, bool a_Generate) : m_ChunkX(a_ChunkX), m_ChunkZ(a_ChunkZ), m_Generate(a_Generate) {}
-
- bool operator ==(const sChunkLoad other) const
- {
- return (
- (this->m_ChunkX == other.m_ChunkX) &&
- (this->m_ChunkZ == other.m_ChunkZ)
- );
- }
- } ;
-
- 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;
- sChunkLoadQueue m_LoadQueue;
+ cChunkCoordsQueue m_LoadQueue;
cChunkCoordsQueue m_SaveQueue;
/// All the storage schemas (all used for loading)
@@ -123,7 +92,11 @@ protected:
/// The one storage schema used for saving
cWSSchema * m_SaveSchema;
+
+ /// Loads the chunk specified; returns true on success, false on failure
+ bool LoadChunk(int a_ChunkX, int a_ChunkZ);
+
void InitSchemas(int a_StorageCompressionFactor);
virtual void Execute(void) override;