1
0

Fixed unloading of chunks that contain player entities (#4508)

Co-authored-by: peterbell10 <peterbell10@live.co.uk>
Co-authored-by: mluchterhand <mluchterhand@max.de>
This commit is contained in:
Max Luchterhand 2020-03-18 17:17:59 +00:00 committed by GitHub
parent 57da82524b
commit 384ba18812
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 0 deletions

1
.gitignore vendored
View File

@ -27,6 +27,7 @@ cloc.xsl
/UploadLuaAPI.cmd /UploadLuaAPI.cmd
GPUCache GPUCache
AllFiles.lst AllFiles.lst
GPUCache
# IDE Stuff # IDE Stuff
## Sublime Text ## Sublime Text

View File

@ -194,10 +194,25 @@ void cChunk::MarkRegenerating(void)
bool cChunk::HasPlayerEntities()
{
return std::any_of(m_Entities.begin(), m_Entities.end(),
[](std::unique_ptr<cEntity>& Entity)
{
return Entity->IsPlayer();
}
);
}
bool cChunk::CanUnload(void) bool cChunk::CanUnload(void)
{ {
return return
m_LoadedByClient.empty() && // The chunk is not used by any client 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_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_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) (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 return
m_LoadedByClient.empty() && // The chunk is not used by any client 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_IsDirty && // The chunk is dirty
(m_StayCount == 0) && // The chunk is not in a ChunkStay (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) (m_Presence != cpQueued) ; // The chunk is not queued for loading / generating (otherwise multi-load / multi-gen could occur)

View File

@ -683,6 +683,9 @@ private:
/** Called by Tick() when an entity moves out of this chunk into a neighbor; moves the entity and sends spawn / despawn packet to clients */ /** Called by Tick() when an entity moves out of this chunk into a neighbor; moves the entity and sends spawn / despawn packet to clients */
void MoveEntityToNewChunk(OwnedEntity a_Entity); void MoveEntityToNewChunk(OwnedEntity a_Entity);
/** Check m_Entities for cPlayer objects. */
bool HasPlayerEntities();
}; };
typedef cChunk * cChunkPtr; typedef cChunk * cChunkPtr;