34 [&ChunkSender] (
cChunk & a_Chunk) ->
bool
36 ChunkSender.QueueSendChunkTo(a_Chunk.GetPosX(), a_Chunk.GetPosZ(), cChunkSender::Priority::High, a_Chunk.GetAllClients());
62 Super(
"Chunk Sender"),
64 m_Serializer(m_World.GetDimension())
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->shared_from_this());
113 info.
m_Clients.insert(a_Client->shared_from_this());
132 auto & info = iter->second;
133 if (info.m_Priority < a_Priority)
136 info.m_Priority = a_Priority;
138 for (
const auto & Client : a_Clients)
140 info.m_Clients.insert(Client->shared_from_this());
147 for (
const auto & Client : a_Clients)
149 info.
m_Clients.insert(Client->shared_from_this());
180 auto clients = std::move(itr->second.m_Clients);
184 SendChunk(Chunk.m_ChunkX, Chunk.m_ChunkZ, clients);
197 std::vector<std::shared_ptr<cClientHandle>> Clients;
200 for (
const auto & WeakClient : a_Clients)
202 auto Client = WeakClient.lock();
203 if ((Client !=
nullptr) && Client->WantsSendChunk(a_ChunkX, a_ChunkZ))
205 Clients.push_back(std::move(Client));
243 for (
const auto & Client : Clients)
270 if (!Client->IsDestroyed())
272 a_Entity.SpawnOn(*Client);
310 if (a_BiomeMap[i] < 255)
313 m_BiomeMap[i] =
static_cast<unsigned char>(a_BiomeMap[i]);
318 ASSERT(!
"Unimplemented MCS-specific biome");
#define ARRAYCOUNT(X)
Evaluates to the number of elements in an array (compile-time!)
ChunkBlockData m_BlockData
ChunkLightData m_LightData
Wraps the chunk coords into a single structure.
EMCSBiome BiomeMap[Width *Width]
The type used for any biomemap operations and storage inside Cuberite, using Cuberite biomes (need no...
Interface class used as a callback for operations that involve chunk coords.
Callback that can be used to notify chunk sender upon another chunkcoord notification.
cChunkSender & m_ChunkSender
cNotifyChunkSender(cChunkSender &a_ChunkSender, cWorld &a_World)
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.
virtual void BiomeMap(const cChunkDef::BiomeMap &a_BiomeMap) override
unsigned char m_BiomeMap[cChunkDef::Width *cChunkDef::Width]
virtual void BlockEntity(cBlockEntity *a_Entity) override
virtual void Execute(void) override
This function, overloaded by the descendants, is called in the new thread.
std::set< std::weak_ptr< cClientHandle >, std::owner_less< std::weak_ptr< cClientHandle > >> WeakClients
virtual ~cChunkSender() override
void QueueSendChunkTo(int a_ChunkX, int a_ChunkZ, Priority a_Priority, cClientHandle *a_Client)
Queues a chunk to be sent to a specific client.
void SendChunk(int a_ChunkX, int a_ChunkZ, const WeakClients &a_Clients)
Sends the specified chunk to all the specified clients.
std::vector< UInt32 > m_EntityIDs
cChunkSender(cWorld &a_World)
cChunkDataSerializer m_Serializer
An instance of a chunk serializer, held to maintain its internal cache.
std::priority_queue< sChunkQueue > m_SendChunks
std::unordered_map< cChunkCoords, sSendChunk, cChunkCoordsHash > m_ChunkInfo
Priority
Tag indicating urgency of chunk to be sent.
std::vector< Vector3i > m_BlockEntities
virtual void Entity(cEntity *a_Entity) override
Used for sending chunks to specific clients.
UInt32 GetUniqueID(void) const
RAII for cCriticalSection - locks the CS on creation, unlocks on destruction.
Temporary RAII unlock for a cCSLock.
void Wait(void)
Waits until the event has been set.
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.
void Stop(void)
Signals the thread to terminate and waits until it's finished.
void SendToClients(int a_ChunkX, int a_ChunkZ, const ChunkBlockData &a_BlockData, const ChunkLightData &a_LightData, const unsigned char *a_BiomeMap, const ClientHandles &a_SendTo)
For each client, serializes the chunk into their protocol version and sends it.
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.
bool DoWithChunk(int a_ChunkX, int a_ChunkZ, cChunkCallback a_Callback)
Calls the callback for the chunk specified, with ChunkMapCS locked.
bool GetChunkData(cChunkCoords a_Coords, cChunkDataCallback &a_Callback) const
Calls the callback with the chunk's data, if available (with ChunkCS locked).
bool DoWithEntityByID(UInt32 a_UniqueID, cEntityCallback a_Callback)
Calls the callback if the entity with the specified ID is found, with the entity object as the callba...
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.
bool IsChunkValid(int a_ChunkX, int a_ChunkZ) const
Returns true iff the chunk is present and valid.
bool HasChunkAnyClients(int a_ChunkX, int a_ChunkZ) const
bool IsChunkLighted(int a_ChunkX, int a_ChunkZ)