summaryrefslogtreecommitdiffstats
path: root/src/ChunkMap.cpp
diff options
context:
space:
mode:
authorTiger Wang <ziwei.tiger@hotmail.co.uk>2016-12-19 21:12:23 +0100
committerTiger Wang <ziwei.tiger@hotmail.co.uk>2017-08-07 20:24:16 +0200
commit4ef47aed62364f9cf1474864e5cf94232b4477af (patch)
tree28ca15247c2437b91e9aada48c2da4a1a3c00c17 /src/ChunkMap.cpp
parentRemoved unneeded includes (#3902) (diff)
downloadcuberite-4ef47aed62364f9cf1474864e5cf94232b4477af.tar
cuberite-4ef47aed62364f9cf1474864e5cf94232b4477af.tar.gz
cuberite-4ef47aed62364f9cf1474864e5cf94232b4477af.tar.bz2
cuberite-4ef47aed62364f9cf1474864e5cf94232b4477af.tar.lz
cuberite-4ef47aed62364f9cf1474864e5cf94232b4477af.tar.xz
cuberite-4ef47aed62364f9cf1474864e5cf94232b4477af.tar.zst
cuberite-4ef47aed62364f9cf1474864e5cf94232b4477af.zip
Diffstat (limited to '')
-rw-r--r--src/ChunkMap.cpp23
1 files changed, 12 insertions, 11 deletions
diff --git a/src/ChunkMap.cpp b/src/ChunkMap.cpp
index b1a7d6ec5..e4fdb6ec7 100644
--- a/src/ChunkMap.cpp
+++ b/src/ChunkMap.cpp
@@ -1497,38 +1497,38 @@ void cChunkMap::RemoveClientFromChunks(cClientHandle * a_Client)
-void cChunkMap::AddEntity(cEntity * a_Entity)
+void cChunkMap::AddEntity(OwnedEntity a_Entity)
{
cCSLock Lock(m_CSChunks);
cChunkPtr Chunk = GetChunk(a_Entity->GetChunkX(), a_Entity->GetChunkZ());
if (Chunk == nullptr) // This will assert inside GetChunk in Debug builds
{
LOGWARNING("Entity at %p (%s, ID %d) spawning in a non-existent chunk, the entity is lost.",
- static_cast<void *>(a_Entity), a_Entity->GetClass(), a_Entity->GetUniqueID()
+ static_cast<void *>(a_Entity.get()), a_Entity->GetClass(), a_Entity->GetUniqueID()
);
return;
}
- Chunk->AddEntity(a_Entity);
+ Chunk->AddEntity(std::move(a_Entity));
}
-void cChunkMap::AddEntityIfNotPresent(cEntity * a_Entity)
+void cChunkMap::AddEntityIfNotPresent(OwnedEntity a_Entity)
{
cCSLock Lock(m_CSChunks);
cChunkPtr Chunk = GetChunk(a_Entity->GetChunkX(), a_Entity->GetChunkZ());
if (Chunk == nullptr) // This will assert inside GetChunk in Debug builds
{
LOGWARNING("Entity at %p (%s, ID %d) spawning in a non-existent chunk, the entity is lost.",
- static_cast<void *>(a_Entity), a_Entity->GetClass(), a_Entity->GetUniqueID()
+ static_cast<void *>(a_Entity.get()), a_Entity->GetClass(), a_Entity->GetUniqueID()
);
return;
}
if (!Chunk->HasEntity(a_Entity->GetUniqueID()))
{
- Chunk->AddEntity(a_Entity);
+ Chunk->AddEntity(std::move(a_Entity));
}
}
@@ -1553,17 +1553,18 @@ bool cChunkMap::HasEntity(UInt32 a_UniqueID)
-void cChunkMap::RemoveEntity(cEntity * a_Entity)
+OwnedEntity cChunkMap::RemoveEntity(cEntity & a_Entity)
{
cCSLock Lock(m_CSChunks);
- cChunkPtr Chunk = a_Entity->GetParentChunk();
+ cChunkPtr Chunk = a_Entity.GetParentChunk();
- // Even if a chunk is not valid, it may still contain entities such as players; make sure to remove them (#1190)
if (Chunk == nullptr)
{
- return;
+ return nullptr;
}
- Chunk->RemoveEntity(a_Entity);
+
+ // Remove the entity no matter whether the chunk itself is valid or not (#1190)
+ return Chunk->RemoveEntity(a_Entity);
}