| 187 | |
| 188 | |
| 189 | void cChunkSender::SendChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ, cClientHandle * a_Client) |
| 190 | { |
| 191 | ASSERT(m_World != NULL); |
| 192 | |
| 193 | // Ask the client if it still wants the chunk: |
| 194 | if (a_Client != NULL) |
| 195 | { |
| 196 | if (!a_Client->WantsSendChunk(a_ChunkX, a_ChunkY, a_ChunkZ)) |
| 197 | { |
| 198 | return; |
| 199 | } |
| 200 | } |
| 201 | |
| 202 | // If the chunk has no clients, no need to packetize it: |
| 203 | if (!m_World->HasChunkAnyClients(a_ChunkX, a_ChunkZ)) |
| 204 | { |
| 205 | return; |
| 206 | } |
| 207 | |
| 208 | // If the chunk is not valid, do nothing - whoever needs it has queued it for loading / generating |
| 209 | if (!m_World->IsChunkValid(a_ChunkX, a_ChunkZ)) |
| 210 | { |
| 211 | return; |
| 212 | } |
| 213 | |
| 214 | // If the chunk is not lighted, queue it for relighting and get notified when it's ready: |
| 215 | if (!m_World->IsChunkLighted(a_ChunkX, a_ChunkZ)) |
| 216 | { |
| 217 | m_World->QueueLightChunk(a_ChunkX, a_ChunkZ, &m_Notify); |
| 218 | return; |
| 219 | } |
| 220 | |
| 221 | // Query and prepare chunk data: |
| 222 | if (!m_World->GetChunkData(a_ChunkX, a_ChunkZ, *this)) |
| 223 | { |
| 224 | return; |
| 225 | } |
| 226 | cChunkDataSerializer Data(m_BlockTypes, m_BlockMetas, m_BlockLight, m_BlockSkyLight, m_BiomeMap); |
| 227 | |
| 228 | // Send: |
| 229 | if (a_Client == NULL) |
| 230 | { |
| 231 | m_World->BroadcastChunkData(a_ChunkX, a_ChunkZ, Data); |
| 232 | } |
| 233 | else |
| 234 | { |
| 235 | a_Client->SendChunkData(a_ChunkX, a_ChunkZ, Data); |
| 236 | } |
| 237 | |
| 238 | // Send block-entity packets: |
| 239 | for (sBlockCoords::iterator itr = m_BlockEntities.begin(); itr != m_BlockEntities.end(); ++itr) |
| 240 | { |
| 241 | if (a_Client == NULL) |
| 242 | { |
| 243 | m_World->BroadcastBlockEntity(itr->m_BlockX, itr->m_BlockY, itr->m_BlockZ); |
| 244 | } |
| 245 | else |
| 246 | { |
nothing calls this directly
no test coverage detected