From ef1f371dab95522343b27c5bed65ffe655666294 Mon Sep 17 00:00:00 2001 From: peterbell10 Date: Tue, 5 Sep 2017 15:11:35 +0100 Subject: Add cWorld::RemoveEntity and use in cEntity (#4003) * Add cWorld::RemoveEntity and use in cEntity * cEntity: Remove uneeded asserts from Destroy and DoMoveToWorld --- src/World.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'src/World.cpp') diff --git a/src/World.cpp b/src/World.cpp index acec3049e..0ecf9a274 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -3709,6 +3709,36 @@ bool cWorld::HasEntity(UInt32 a_UniqueID) +OwnedEntity cWorld::RemoveEntity(cEntity & a_Entity) +{ + // Check if the entity is in the chunkmap: + auto Entity = m_ChunkMap->RemoveEntity(a_Entity); + if (Entity != nullptr) + { + return Entity; + } + + // Check if the entity is in the queue to be added to the world: + cCSLock Lock(m_CSEntitiesToAdd); + auto itr = std::find_if(m_EntitiesToAdd.begin(), m_EntitiesToAdd.end(), + [&a_Entity](const OwnedEntity & a_OwnedEntity) + { + return (a_OwnedEntity.get() == &a_Entity); + } + ); + + if (itr != m_EntitiesToAdd.end()) + { + Entity = std::move(*itr); + m_EntitiesToAdd.erase(itr); + } + return Entity; +} + + + + + /* unsigned int cWorld::GetNumPlayers(void) { -- cgit v1.2.3