private static void InsulateChunks(AnvilWorldProvider provider, int radius = 3) { var spawn = new ChunkCoordinates(provider.GetSpawnPoint()); for (var x = -radius; x < radius; x++) { for (var z = -radius; z < radius; z++) { var location = new ChunkCoordinates(spawn.X + x, spawn.Z + z); provider._chunkCache.TryGetValue(location, out var column); if (column != null) { continue; } column = new ChunkColumn { isAllAir = true, x = location.X, z = location.Z }; column.GetBatch(); provider._chunkCache[location] = column; } } }
public void McpeFullChunk_worst_case_encode_test() { int numberOfSubChunks = 16; var column = new ChunkColumn(); column.DisableCache = true; int block = 0; var watch = Stopwatch.StartNew(); for (int x = 0; x < 16; x++) { for (int z = 0; z < 16; z++) { for (int y = 0; y < numberOfSubChunks * 16; y++) { column.SetBlockByRuntimeId(x, y, z, block++); } } } foreach (SubChunk subChunk in column) { subChunk.DisableCache = true; } Console.WriteLine($"Setup chunks: {watch.ElapsedMilliseconds}ms"); // 319761 int topEmpty = column.GetTopEmpty(); Console.WriteLine($"Top {topEmpty}"); var bytes = column.GetBytes(topEmpty); Console.WriteLine($"Bytes: Size={bytes.Length} bytes"); //Assert.AreEqual(319761, bytes.Length); // warmup for (int i = 0; i < 100; i++) { column.GetBytes(topEmpty); column.GetBatch(); } double count = 1500; watch.Restart(); for (int i = 0; i < count; i++) { column.GetBytes(topEmpty); } Console.WriteLine($"Bytes: Avg {watch.ElapsedTicks / count:F0} ticks"); var packet = column.GetBatch(); Console.WriteLine($"Batch: Size={packet.payload.Length} bytes"); watch.Restart(); for (int i = 0; i < count; i++) { column.GetBatch(); } Console.WriteLine($"Batch: Avg {watch.ElapsedTicks / count:F0} ticks"); }
public ChunkColumn GenerateChunkColumn(ChunkCoordinates chunkCoordinates) { lock (_chunkCache) { ChunkColumn cachedChunk; if (_chunkCache.TryGetValue(chunkCoordinates, out cachedChunk)) { return cachedChunk; } ChunkColumn chunk = new ChunkColumn(); chunk.x = chunkCoordinates.X; chunk.z = chunkCoordinates.Z; //chunk.biomeId = ArrayOf<byte>.Create(256, (byte) rand.Next(0, 37)); int h = PopulateChunk(chunk); chunk.SetBlock(0, h + 1, 0, 7); chunk.SetBlock(1, h + 1, 0, 41); chunk.SetBlock(2, h + 1, 0, 41); chunk.SetBlock(3, h + 1, 0, 41); chunk.SetBlock(3, h + 1, 0, 41); //chunk.SetBlock(6, h + 1, 6, 57); chunk.SetBlock(0, h, 0, 31); chunk.SetBlock(0, h, 1, 161); chunk.SetBlock(0, h, 2, 18); chunk.SetBlock(0, h, 15, 31); chunk.SetBlock(0, h, 14, 161); chunk.SetBlock(0, h, 13, 18); chunk.SetBlock(6, h, 9, 63); chunk.SetMetadata(6, h, 9, 12); var blockEntity = GetBlockEntity((chunkCoordinates.X*16) + 6, h, (chunkCoordinates.Z*16) + 9); chunk.SetBlockEntity(blockEntity.Coordinates, blockEntity.GetCompound()); if (chunkCoordinates.X == 1 && chunkCoordinates.Z == 1) { for (int x = 0; x < 10; x++) { for (int z = 0; z < 10; z++) { for (int y = h - 2; y < h; y++) { chunk.SetBlock(x, y, z, 8); } } } } if (chunkCoordinates.X == 3 && chunkCoordinates.Z == 1) { for (int x = 0; x < 10; x++) { for (int z = 0; z < 10; z++) { for (int y = h - 1; y < h; y++) { chunk.SetBlock(x, y, z, 10); } } } } for (int x = 0; x < 16; x++) { for (int z = 0; z < 16; z++) { for (int y = 127; y != 0; y--) { if (chunk.GetBlock(x, y, z) == 0x00) { chunk.SetSkylight(x, y, z, 0xff); } else { chunk.SetSkylight(x, y, z, 0x00); } } } } // Cache chunk.GetBatch(); _chunkCache[chunkCoordinates] = chunk; return chunk; } }