From 384ba1881237bbefd03488d7de3e4eaae80d9d27 Mon Sep 17 00:00:00 2001 From: Max Luchterhand <52720531+maxluchterhand1@users.noreply.github.com> Date: Wed, 18 Mar 2020 17:17:59 +0000 Subject: Fixed unloading of chunks that contain player entities (#4508) Co-authored-by: peterbell10 Co-authored-by: mluchterhand --- src/Chunk.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/Chunk.cpp') diff --git a/src/Chunk.cpp b/src/Chunk.cpp index 52464f4da..574c00132 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -194,10 +194,25 @@ void cChunk::MarkRegenerating(void) +bool cChunk::HasPlayerEntities() +{ + return std::any_of(m_Entities.begin(), m_Entities.end(), + [](std::unique_ptr& Entity) + { + return Entity->IsPlayer(); + } + ); +} + + + + + bool cChunk::CanUnload(void) { return m_LoadedByClient.empty() && // The chunk is not used by any client + !HasPlayerEntities() && // Ensure not only the absence of ClientHandlers, but also of cPlayer objects !m_IsDirty && // The chunk has been saved properly or hasn't been touched since the load / gen (m_StayCount == 0) && // The chunk is not in a ChunkStay (m_Presence != cpQueued) ; // The chunk is not queued for loading / generating (otherwise multi-load / multi-gen could occur) @@ -211,6 +226,7 @@ bool cChunk::CanUnloadAfterSaving(void) { return m_LoadedByClient.empty() && // The chunk is not used by any client + !HasPlayerEntities() && // Ensure not only the absence of ClientHandlers, but also of cPlayer objects m_IsDirty && // The chunk is dirty (m_StayCount == 0) && // The chunk is not in a ChunkStay (m_Presence != cpQueued) ; // The chunk is not queued for loading / generating (otherwise multi-load / multi-gen could occur) -- cgit v1.2.3