35 [&ChunkSender] (
cChunk & a_Chunk) ->
bool 37 ChunkSender.QueueSendChunkTo(a_Chunk.GetPosX(), a_Chunk.GetPosZ(), cChunkSender::E_CHUNK_PRIORITY_MIDHIGH, a_Chunk.GetAllClients());
49 m_ChunkSender(a_ChunkSender),
94 ASSERT(a_Client !=
nullptr);
101 auto & info = iter->second;
102 if (info.m_Priority > a_Priority)
105 info.m_Priority = a_Priority;
107 info.m_Clients.insert(a_Client);
132 auto & info = iter->second;
133 if (info.m_Priority > a_Priority)
136 info.m_Priority = a_Priority;
138 info.m_Clients.insert(a_Clients.
begin(), a_Clients.
end());
161 auto && clients = pair.second.m_Clients;
162 clients.erase(a_Client);
192 std::unordered_set<cClientHandle *> clients;
193 std::swap(itr->second.m_Clients, clients);
197 SendChunk(Chunk.m_ChunkX, Chunk.m_ChunkZ, clients);
212 for (
auto itr = a_Clients.begin(); itr != a_Clients.end();)
214 if (!(*itr)->WantsSendChunk(a_ChunkX, a_ChunkZ))
216 itr = a_Clients.erase(itr);
250 for (
const auto client : a_Clients)
253 client->SendChunkData(a_ChunkX, a_ChunkZ, Data);
294 if ((*a_BiomeMap)[i] < 255)
297 m_BiomeMap[i] =
static_cast<unsigned char>((*a_BiomeMap)[i]);
302 ASSERT(!
"Unimplemented MCS-specific biome");
std::unordered_set< cClientHandle * > m_Clients
void Set(void)
Sets the event - releases one thread that has been waiting in Wait().
std::atomic< bool > m_ShouldTerminate
The overriden Execute() method should check this value periodically and terminate if this is true...
cChunkSender(cWorld &a_World)
void SendChunk(int a_ChunkX, int a_ChunkZ, std::unordered_set< cClientHandle * > a_Clients)
Sends the specified chunk to all the specified clients.
bool DoWithChunk(int a_ChunkX, int a_ChunkZ, cChunkCallback a_Callback)
Calls the callback for the chunk specified, with ChunkMapCS locked.
unsigned char m_BiomeMap[cChunkDef::Width *cChunkDef::Width]
bool HasChunkAnyClients(int a_ChunkX, int a_ChunkZ) const
virtual void Call(cChunkCoords a_Coords, bool a_IsSuccess) override
Called with the chunk's coords, and an optional operation status flag for operations that support it...
Used for sending chunks to specific clients.
void Wait(void)
Waits until the event has been set.
std::vector< Vector3i > m_BlockEntities
virtual void BiomeData(const cChunkDef::BiomeMap *a_BiomeMap) override
cNotifyChunkSender(cChunkSender &a_ChunkSender, cWorld &a_World)
std::priority_queue< sChunkQueue > m_SendChunks
std::unordered_map< cChunkCoords, sSendChunk, cChunkCoordsHash > m_ChunkInfo
Serializes one chunk's data to (possibly multiple) protocol versions.
Temporary RAII unlock for a cCSLock.
bool IsChunkLighted(int a_ChunkX, int a_ChunkZ)
virtual eDimension GetDimension(void) const override
void Stop(void)
Signals the thread to terminate and waits until it's finished.
bool IsChunkValid(int a_ChunkX, int a_ChunkZ) const
Returns true iff the chunk is present and valid.
bool GetChunkData(cChunkCoords a_Coords, cChunkDataCallback &a_Callback) const
Calls the callback with the chunk's data, if available (with ChunkCS locked).
void RemoveClient(cClientHandle *a_Client)
Removes the a_Client from all waiting chunk send operations.
const_iterator begin() const
virtual ~cChunkSender() override
virtual void Entity(cEntity *a_Entity) override
Interface class used as a callback for operations that involve chunk coords.
const_iterator end() const
RAII for cCriticalSection - locks the CS on creation, unlocks on destruction.
void QueueLightChunk(int a_ChunkX, int a_ChunkZ, std::unique_ptr< cChunkCoordCallback > a_Callback={})
Queues a chunk for lighting; a_Callback is called after the chunk is lighted.
Callback that can be used to notify chunk sender upon another chunkcoord notification.
void SendBlockEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cClientHandle &a_Client)
If there is a block entity at the specified coords, sends it to the client specified.
virtual void BlockEntity(cBlockEntity *a_Entity) override
virtual void Execute(void) override
This is the main thread entrypoint.
cChunkSender & m_ChunkSender
EMCSBiome BiomeMap[Width *Width]
The type used for any biomemap operations and storage inside Cuberite, using Cuberite biomes (need no...
void QueueSendChunkTo(int a_ChunkX, int a_ChunkZ, eChunkPriority a_Priority, cClientHandle *a_Client)
Queues a chunk to be sent to a specific client.
void Clear()
Clears all data.
#define ARRAYCOUNT(X)
Evaluates to the number of elements in an array (compile-time!)
void SetAll(void)
Sets the event - releases all threads that have been waiting in Wait().
Non-owning view of a chunk's client handles.