summaryrefslogtreecommitdiffstats
path: root/src/Entities/Entity.cpp
diff options
context:
space:
mode:
authorTiger Wang <ziwei.tiger@outlook.com>2017-08-18 12:17:56 +0200
committerGitHub <noreply@github.com>2017-08-18 12:17:56 +0200
commit72d7027861a3b7e7e8bb5fdcbbc5a1a778fa7f82 (patch)
treec1c1a040332d4ba1f784be25c67c9800e85015eb /src/Entities/Entity.cpp
parentSitting cats block enderchests from opening (#3906) (diff)
parentChanged entity ownership model to use smart pointers (diff)
downloadcuberite-72d7027861a3b7e7e8bb5fdcbbc5a1a778fa7f82.tar
cuberite-72d7027861a3b7e7e8bb5fdcbbc5a1a778fa7f82.tar.gz
cuberite-72d7027861a3b7e7e8bb5fdcbbc5a1a778fa7f82.tar.bz2
cuberite-72d7027861a3b7e7e8bb5fdcbbc5a1a778fa7f82.tar.lz
cuberite-72d7027861a3b7e7e8bb5fdcbbc5a1a778fa7f82.tar.xz
cuberite-72d7027861a3b7e7e8bb5fdcbbc5a1a778fa7f82.tar.zst
cuberite-72d7027861a3b7e7e8bb5fdcbbc5a1a778fa7f82.zip
Diffstat (limited to 'src/Entities/Entity.cpp')
-rw-r--r--src/Entities/Entity.cpp19
1 files changed, 10 insertions, 9 deletions
diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp
index 245ae84bf..a38a6552d 100644
--- a/src/Entities/Entity.cpp
+++ b/src/Entities/Entity.cpp
@@ -135,9 +135,9 @@ const char * cEntity::GetParentClass(void) const
-bool cEntity::Initialize(cWorld & a_World)
+bool cEntity::Initialize(OwnedEntity a_Self, cWorld & a_EntityWorld)
{
- if (cPluginManager::Get()->CallHookSpawningEntity(a_World, *this))
+ if (cPluginManager::Get()->CallHookSpawningEntity(a_EntityWorld, *this))
{
return false;
}
@@ -151,13 +151,13 @@ bool cEntity::Initialize(cWorld & a_World)
ASSERT(m_World == nullptr);
ASSERT(GetParentChunk() == nullptr);
- a_World.AddEntity(this);
+ a_EntityWorld.AddEntity(std::move(a_Self));
ASSERT(m_World != nullptr);
- cPluginManager::Get()->CallHookSpawnedEntity(a_World, *this);
+ cPluginManager::Get()->CallHookSpawnedEntity(a_EntityWorld, *this);
// Spawn the entity on the clients:
- a_World.BroadcastSpawnEntity(*this);
+ a_EntityWorld.BroadcastSpawnEntity(*this);
return true;
}
@@ -230,8 +230,10 @@ void cEntity::Destroy(bool a_ShouldBroadcast)
this->GetUniqueID(), this->GetClass(),
ParentChunk->GetPosX(), ParentChunk->GetPosZ()
);
- ParentChunk->RemoveEntity(this);
- delete this;
+
+ // Make sure that RemoveEntity returned a valid smart pointer
+ // Also, not storing the returned pointer means automatic destruction
+ VERIFY(ParentChunk->RemoveEntity(*this));
});
Destroyed();
}
@@ -1581,8 +1583,7 @@ bool cEntity::DoMoveToWorld(cWorld * a_World, bool a_ShouldSendRespawn, Vector3d
a_OldWorld.GetName().c_str(), a_World->GetName().c_str(),
ParentChunk->GetPosX(), ParentChunk->GetPosZ()
);
- ParentChunk->RemoveEntity(this);
- a_World->AddEntity(this);
+ a_World->AddEntity(ParentChunk->RemoveEntity(*this));
cRoot::Get()->GetPluginManager()->CallHookEntityChangedWorld(*this, a_OldWorld);
});
return true;