MCPcopy Create free account
hub / github.com/cuberite/cuberite / StreamChunks

Method StreamChunks

src/ClientHandle.cpp:261–355  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

259
260
261void cClientHandle::StreamChunks(void)
262{
263 if ((m_State < csAuthenticated) || (m_State >= csDestroying))
264 {
265 return;
266 }
267
268 ASSERT(m_Player != NULL);
269
270 int ChunkPosX = FAST_FLOOR_DIV((int)m_Player->GetPosX(), cChunkDef::Width);
271 int ChunkPosZ = FAST_FLOOR_DIV((int)m_Player->GetPosZ(), cChunkDef::Width);
272 if ((ChunkPosX == m_LastStreamedChunkX) && (ChunkPosZ == m_LastStreamedChunkZ))
273 {
274 // Already streamed for this position
275 return;
276 }
277 m_LastStreamedChunkX = ChunkPosX;
278 m_LastStreamedChunkZ = ChunkPosZ;
279
280 LOGD("Streaming chunks centered on [%d, %d], view distance %d", ChunkPosX, ChunkPosZ, m_ViewDistance);
281
282 cWorld * World = m_Player->GetWorld();
283 ASSERT(World != NULL);
284
285 // Remove all loaded chunks that are no longer in range; deferred to out-of-CS:
286 cChunkCoordsList RemoveChunks;
287 {
288 cCSLock Lock(m_CSChunkLists);
289 for (cChunkCoordsList::iterator itr = m_LoadedChunks.begin(); itr != m_LoadedChunks.end();)
290 {
291 int RelX = (*itr).m_ChunkX - ChunkPosX;
292 int RelZ = (*itr).m_ChunkZ - ChunkPosZ;
293 if ((RelX > m_ViewDistance) || (RelX < -m_ViewDistance) || (RelZ > m_ViewDistance) || (RelZ < -m_ViewDistance))
294 {
295 RemoveChunks.push_back(*itr);
296 itr = m_LoadedChunks.erase(itr);
297 }
298 else
299 {
300 ++itr;
301 }
302 } // for itr - m_LoadedChunks[]
303 for (cChunkCoordsList::iterator itr = m_ChunksToSend.begin(); itr != m_ChunksToSend.end();)
304 {
305 int RelX = (*itr).m_ChunkX - ChunkPosX;
306 int RelZ = (*itr).m_ChunkZ - ChunkPosZ;
307 if ((RelX > m_ViewDistance) || (RelX < -m_ViewDistance) || (RelZ > m_ViewDistance) || (RelZ < -m_ViewDistance))
308 {
309 itr = m_ChunksToSend.erase(itr);
310 }
311 else
312 {
313 ++itr;
314 }
315 } // for itr - m_ChunksToSend[]
316 }
317 for (cChunkCoordsList::iterator itr = RemoveChunks.begin(); itr != RemoveChunks.end(); ++itr)
318 {

Callers 2

TickMethod · 0.80
MoveToWorldMethod · 0.80

Calls 8

beginMethod · 0.80
endMethod · 0.80
GetPosXMethod · 0.45
GetPosZMethod · 0.45
GetWorldMethod · 0.45
RemoveChunkClientMethod · 0.45
SendUnloadChunkMethod · 0.45
TouchChunkMethod · 0.45

Tested by

no test coverage detected