diff --git a/source/ChunkMap.cpp b/source/ChunkMap.cpp index 76835ee74..6be49e399 100644 --- a/source/ChunkMap.cpp +++ b/source/ChunkMap.cpp @@ -1370,41 +1370,6 @@ 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) -{ - 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) - { - NewChunk->AddEntity(a_Entity); - } -} - - - - - -void cChunkMap::RemoveEntityFromChunk(cEntity * a_Entity, int a_ChunkX, int a_ChunkZ) -{ - cCSLock Lock(m_CSLayers); - cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ); - if ((Chunk == NULL) && !Chunk->IsValid()) - { - return; - } - Chunk->RemoveEntity(a_Entity); -} - - - - - void cChunkMap::AddEntity(cEntity * a_Entity) { cCSLock Lock(m_CSLayers); @@ -1437,6 +1402,21 @@ bool cChunkMap::HasEntity(int a_UniqueID) +void cChunkMap::RemoveEntity(cEntity * a_Entity) +{ + cCSLock Lock(m_CSLayers); + cChunkPtr Chunk = GetChunkNoGen(a_Entity->GetChunkX(), ZERO_CHUNK_Y, a_Entity->GetChunkZ()); + if ((Chunk == NULL) && !Chunk->IsValid()) + { + return; + } + Chunk->RemoveEntity(a_Entity); +} + + + + + bool cChunkMap::ForEachEntity(cEntityCallback & a_Callback) { cCSLock Lock(m_CSLayers); diff --git a/source/ChunkMap.h b/source/ChunkMap.h index d52b2f263..e3dfdc88f 100644 --- a/source/ChunkMap.h +++ b/source/ChunkMap.h @@ -183,18 +183,15 @@ public: /// Removes the client from all chunks it is present in void RemoveClientFromChunks(cClientHandle * a_Client); - /// Moves the entity from its current chunk to the new chunk specified - void MoveEntityToChunk(cEntity * a_Entity, int a_ChunkX, int a_ChunkZ); - - /// Removes the entity from the chunk specified - void RemoveEntityFromChunk(cEntity * a_Entity, int a_ChunkX, int a_ChunkZ); - /// Adds the entity to its appropriate chunk, takes ownership of the entity pointer void AddEntity(cEntity * a_Entity); /// Returns true if the entity with specified ID is present in the chunks bool HasEntity(int a_EntityID); + /// Removes the entity from its appropriate chunk + void RemoveEntity(cEntity * a_Entity); + /// Calls the callback for each entity in the entire world; returns true if all entities processed, false if the callback aborted by returning true bool ForEachEntity(cEntityCallback & a_Callback); // Lua-accessible diff --git a/source/Player.cpp b/source/Player.cpp index cfbf5cdff..2cb96ca9c 100644 --- a/source/Player.cpp +++ b/source/Player.cpp @@ -853,7 +853,7 @@ bool cPlayer::MoveToWorld( const char* a_WorldName ) /* Remove all links to the old world */ m_World->RemovePlayer( this ); m_ClientHandle->RemoveFromAllChunks(); - m_World->RemoveEntityFromChunk(this, GetChunkX(), GetChunkZ()); + m_World->RemoveEntity(this); /* Add player to all the necessary parts of the new world */ SetWorld( World ); diff --git a/source/World.cpp b/source/World.cpp index 6e321d63a..74a7ea399 100644 --- a/source/World.cpp +++ b/source/World.cpp @@ -1722,7 +1722,7 @@ void cWorld::AddPlayer(cPlayer * a_Player) void cWorld::RemovePlayer(cPlayer * a_Player) { - m_ChunkMap->RemoveEntityFromChunk(a_Player, a_Player->GetChunkX(), a_Player->GetChunkZ()); + m_ChunkMap->RemoveEntity(a_Player); cCSLock Lock(m_CSPlayers); m_Players.remove(a_Player); } @@ -1853,15 +1853,6 @@ void cWorld::SendPlayerList(cPlayer * a_DestPlayer) -void cWorld::RemoveEntityFromChunk(cEntity * a_Entity, int a_ChunkX, int a_ChunkZ) -{ - m_ChunkMap->RemoveEntityFromChunk(a_Entity, a_ChunkX, a_ChunkZ); -} - - - - - bool cWorld::ForEachEntity(cEntityCallback & a_Callback) { return m_ChunkMap->ForEachEntity(a_Callback); @@ -2084,6 +2075,15 @@ bool cWorld::HasEntity(int a_UniqueID) +void cWorld::RemoveEntity(cEntity * a_Entity) +{ + m_ChunkMap->RemoveEntity(a_Entity); +} + + + + + unsigned int cWorld::GetNumPlayers(void) { cCSLock Lock(m_CSPlayers); diff --git a/source/World.h b/source/World.h index 38506d1a0..70e203bc3 100644 --- a/source/World.h +++ b/source/World.h @@ -207,12 +207,13 @@ public: void SendPlayerList(cPlayer * a_DestPlayer); // Sends playerlist to the player + /// Adds the entity into its appropriate chunk; takes ownership of the entity ptr void AddEntity(cEntity * a_Entity); bool HasEntity(int a_UniqueID); - /// Removes the entity from the chunk specified - void RemoveEntityFromChunk(cEntity * a_Entity, int a_ChunkX, int a_ChunkZ); + /// Removes the entity, the entity ptr ownership is assumed taken by the caller + void RemoveEntity(cEntity * a_Entity); /// Calls the callback for each entity in the entire world; returns true if all entities processed, false if the callback aborted by returning true bool ForEachEntity(cEntityCallback & a_Callback); // Exported in ManualBindings.cpp @@ -558,8 +559,6 @@ private: void TickWeather(float a_Dt); // Handles weather each tick void TickSpawnMobs(float a_Dt); // Handles mob spawning each tick - void RemoveEntity( cEntity * a_Entity ); - /// Creates a new fluid simulator, loads its settings from the inifile (a_FluidName section) cFluidSimulator * InitializeFluidSimulator(cIniFile & a_IniFile, const char * a_FluidName, BLOCKTYPE a_SimulateBlock, BLOCKTYPE a_StationaryBlock); }; // tolua_export