internal void UpdateChunks(bool block = false) { var newChunks = new HashSet <Coordinates2D>(); var toLoad = new List <Tuple <Coordinates2D, IChunk> >(); Profiler.Start("client.new-chunks"); for (int x = -ChunkRadius; x < ChunkRadius; x++) { for (int z = -ChunkRadius; z < ChunkRadius; z++) { var coords = new Coordinates2D( ((int)Entity.Position.X >> 4) + x, ((int)Entity.Position.Z >> 4) + z); newChunks.Add(coords); if (!LoadedChunks.Contains(coords)) { toLoad.Add(new Tuple <Coordinates2D, IChunk>( coords, World.GetChunk(coords, generate: block))); } } } Profiler.Done(); var encode = new Action(() => { Profiler.Start("client.encode-chunks"); foreach (var tup in toLoad) { var coords = tup.Item1; var chunk = tup.Item2; if (chunk == null) { chunk = World.GetChunk(coords); } chunk.LastAccessed = DateTime.UtcNow; LoadChunk(chunk); } Profiler.Done(); }); if (block) { encode(); } else { Task.Factory.StartNew(encode); } Profiler.Start("client.old-chunks"); LoadedChunks.IntersectWith(newChunks); Profiler.Done(); Profiler.Start("client.update-entities"); ((EntityManager)Server.GetEntityManagerForWorld(World)).UpdateClientEntities(this); Profiler.Done(); }