diff options
-rw-r--r-- | src/ChunkMap.cpp | 17 | ||||
-rw-r--r-- | src/ChunkMap.h | 5 | ||||
-rw-r--r-- | src/World.cpp | 2 |
3 files changed, 7 insertions, 17 deletions
diff --git a/src/ChunkMap.cpp b/src/ChunkMap.cpp index 14d0d0d94..92cce9b55 100644 --- a/src/ChunkMap.cpp +++ b/src/ChunkMap.cpp @@ -909,21 +909,12 @@ void cChunkMap::AddEntity(OwnedEntity a_Entity) -void cChunkMap::AddEntityIfNotPresent(OwnedEntity a_Entity) +void cChunkMap::AddPlayer(std::unique_ptr<cPlayer> a_Player) { cCSLock Lock(m_CSChunks); - const auto Chunk = FindChunk(a_Entity->GetChunkX(), a_Entity->GetChunkZ()); - if (Chunk == nullptr) - { - LOGWARNING("Entity at %p (%s, ID %d) spawning in a non-existent chunk, the entity is lost.", - static_cast<void *>(a_Entity.get()), a_Entity->GetClass(), a_Entity->GetUniqueID() - ); - return; - } - if (!Chunk->HasEntity(a_Entity->GetUniqueID())) - { - Chunk->AddEntity(std::move(a_Entity)); - } + auto & Chunk = ConstructChunk(a_Player->GetChunkX(), a_Player->GetChunkZ()); // Always construct the chunk for players + ASSERT(!Chunk.HasEntity(a_Player->GetUniqueID())); + Chunk.AddEntity(std::move(a_Player)); } diff --git a/src/ChunkMap.h b/src/ChunkMap.h index 1b04ae3da..795672135 100644 --- a/src/ChunkMap.h +++ b/src/ChunkMap.h @@ -201,9 +201,8 @@ public: /** Adds the entity to its appropriate chunk, takes ownership of the entity pointer */ void AddEntity(OwnedEntity a_Entity); - /** Adds the entity to its appropriate chunk, if the entity is not already added. - Takes ownership of the entity pointer */ - void AddEntityIfNotPresent(OwnedEntity a_Entity); + /** Adds the player to its appropriate chunk, takes ownership of the player pointer */ + void AddPlayer(std::unique_ptr<cPlayer> a_Player); /** Returns true if the entity with specified ID is present in the chunks */ bool HasEntity(UInt32 a_EntityID) const; diff --git a/src/World.cpp b/src/World.cpp index c934c3650..f5b64f297 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -3506,7 +3506,7 @@ void cWorld::AddQueuedPlayers(void) // Add to chunkmap, if not already there (Spawn vs MoveToWorld): auto PlayerPtr = Player.get(); - m_ChunkMap->AddEntityIfNotPresent(std::move(Player)); + m_ChunkMap->AddPlayer(std::move(Player)); PlayerPtr->OnAddToWorld(*this); ASSERT(!PlayerPtr->IsTicking()); PlayerPtr->SetIsTicking(true); |