From f5842062d3f9594d8f22f8938915194d20ebdf5f Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Sat, 13 Apr 2013 21:28:55 +0000 Subject: Proper entity removal functions git-svn-id: http://mc-server.googlecode.com/svn/trunk@1386 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/ChunkMap.cpp | 48 ++++++++++++++---------------------------------- 1 file changed, 14 insertions(+), 34 deletions(-) (limited to 'source/ChunkMap.cpp') diff --git a/source/ChunkMap.cpp b/source/ChunkMap.cpp index 76835ee74..6be49e399 100644 --- a/source/ChunkMap.cpp +++ b/source/ChunkMap.cpp @@ -1370,42 +1370,39 @@ void cChunkMap::RemoveClientFromChunks(cClientHandle * a_Client) -// TODO: This function should not be needed, remove? -void cChunkMap::MoveEntityToChunk(cEntity * a_Entity, int a_ChunkX, int a_ChunkZ) +void cChunkMap::AddEntity(cEntity * a_Entity) { cCSLock Lock(m_CSLayers); - cChunkPtr OldChunk = GetChunkNoGen(a_Entity->GetChunkX(), ZERO_CHUNK_Y, a_Entity->GetChunkZ()); - if (OldChunk != NULL) - { - OldChunk->RemoveEntity(a_Entity); - } - cChunkPtr NewChunk = GetChunkNoGen(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ); - if (NewChunk != NULL) + cChunkPtr Chunk = GetChunkNoGen(a_Entity->GetChunkX(), ZERO_CHUNK_Y, a_Entity->GetChunkZ()); + if ((Chunk == NULL) && !Chunk->IsValid()) { - NewChunk->AddEntity(a_Entity); + return; } + Chunk->AddEntity(a_Entity); } -void cChunkMap::RemoveEntityFromChunk(cEntity * a_Entity, int a_ChunkX, int a_ChunkZ) +bool cChunkMap::HasEntity(int a_UniqueID) { cCSLock Lock(m_CSLayers); - cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ); - if ((Chunk == NULL) && !Chunk->IsValid()) + for (cChunkLayerList::const_iterator itr = m_Layers.begin(); itr != m_Layers.end(); ++itr) { - return; + if ((*itr)->HasEntity(a_UniqueID)) + { + return true; + } } - Chunk->RemoveEntity(a_Entity); + return false; } -void cChunkMap::AddEntity(cEntity * a_Entity) +void cChunkMap::RemoveEntity(cEntity * a_Entity) { cCSLock Lock(m_CSLayers); cChunkPtr Chunk = GetChunkNoGen(a_Entity->GetChunkX(), ZERO_CHUNK_Y, a_Entity->GetChunkZ()); @@ -1413,24 +1410,7 @@ void cChunkMap::AddEntity(cEntity * a_Entity) { return; } - Chunk->AddEntity(a_Entity); -} - - - - - -bool cChunkMap::HasEntity(int a_UniqueID) -{ - cCSLock Lock(m_CSLayers); - for (cChunkLayerList::const_iterator itr = m_Layers.begin(); itr != m_Layers.end(); ++itr) - { - if ((*itr)->HasEntity(a_UniqueID)) - { - return true; - } - } - return false; + Chunk->RemoveEntity(a_Entity); } -- cgit v1.2.3