From 054a89dd9e5d6819adede9d7ba781b69f98ff2f4 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Wed, 6 Jan 2021 00:35:42 +0000 Subject: Clarify cClientHandle, cPlayer ownership semantics + A cPlayer, once created, has a strong pointer to the cClientHandle. The player ticks the clienthandle. If he finds the handle destroyed, he destroys himself in turn. Nothing else can kill the player. * The client handle has a pointer to the player. Once a player is created, the client handle never outlasts the player, nor does it manage the player's lifetime. The pointer is always safe to use after FinishAuthenticate, which is also the point where cProtocol is put into the Game state that allows player manipulation. + Entities are once again never lost by constructing a chunk when they try to move into one that doesn't exist. * Fixed a forgotten Super invocation in cPlayer::OnRemoveFromWorld. * Fix SaveToDisk usage in destructor by only saving things cPlayer owns, instead of accessing cWorld. --- src/ChunkSender.h | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'src/ChunkSender.h') diff --git a/src/ChunkSender.h b/src/ChunkSender.h index be7b55b16..43246ad64 100644 --- a/src/ChunkSender.h +++ b/src/ChunkSender.h @@ -74,11 +74,10 @@ public: void QueueSendChunkTo(int a_ChunkX, int a_ChunkZ, Priority a_Priority, cClientHandle * a_Client); void QueueSendChunkTo(int a_ChunkX, int a_ChunkZ, Priority a_Priority, cChunkClientHandles a_Client); - /** Removes the a_Client from all waiting chunk send operations */ - void RemoveClient(cClientHandle * a_Client); - protected: + using WeakClients = std::set, std::owner_less>>; + struct sChunkQueue { Priority m_Priority; @@ -96,7 +95,7 @@ protected: struct sSendChunk { cChunkCoords m_Chunk; - std::unordered_set m_Clients; + WeakClients m_Clients; Priority m_Priority; sSendChunk(cChunkCoords a_Chunk, Priority a_Priority) : m_Chunk(a_Chunk), @@ -114,7 +113,6 @@ protected: std::priority_queue m_SendChunks; std::unordered_map m_ChunkInfo; cEvent m_evtQueue; // Set when anything is added to m_ChunksReady - cEvent m_evtRemoved; // Set when removed clients are safe to be deleted // Data about the chunk that is being sent: // NOTE that m_BlockData[] is inherited from the cChunkDataCollector @@ -132,7 +130,7 @@ protected: virtual void BlockEntity (cBlockEntity * a_Entity) override; /** Sends the specified chunk to all the specified clients */ - void SendChunk(int a_ChunkX, int a_ChunkZ, std::unordered_set a_Clients); + void SendChunk(int a_ChunkX, int a_ChunkZ, const WeakClients & a_Clients); } ; -- cgit v1.2.3