public void FillChunk(MemoryStream ms, int primaryBitMask, bool groundUpContinuous) { for (int i = 0; i < Sections.Length; i++) { ChunkSection section = Sections[i]; if ((primaryBitMask & 1 << i) == 0) { if (groundUpContinuous) { Sections[i] = null; } } else { if (section == null) { Sections[i] = section = CreateSection(i); } section.FillSection(ms); ms.Read(section.BlocklightArray.Data); if (World.Overworld) { ms.Read(section.SkylightArray.Data); } section.Rend(); } } if (groundUpContinuous) { ms.Read(BlockBiomeArray); } }
public void TryRendFromQueue(int centerX, int centerY, int centerZ) { ChunkSection bestSection = null; ChunkSection[] bestSectionSides = new ChunkSection[6]; float bestDistance = 999999; foreach (ChunkSection section in RenderQueue) { ChunkManager chunkLeft = GetChunk(section.Chunk.Position.Left(), false); if (chunkLeft == null) { continue; } ChunkManager chunkRight = GetChunk(section.Chunk.Position.Right(), false); if (chunkRight == null) { continue; } ChunkManager chunkFront = GetChunk(section.Chunk.Position.Front(), false); if (chunkFront == null) { continue; } ChunkManager chunkBack = GetChunk(section.Chunk.Position.Back(), false); if (chunkBack == null) { continue; } float distance = Vector3.Distance(new Vector3(centerX, 0, centerZ), section.Chunk.Position); int yDist = Math.Abs(centerY - section.Y); if (yDist > 2) { yDist *= 4; } distance += yDist; if (distance < bestDistance) { bestDistance = distance; bestSection = section; bestSectionSides[0] = chunkLeft.Sections[section.Y]; bestSectionSides[1] = chunkRight.Sections[section.Y]; bestSectionSides[2] = chunkFront.Sections[section.Y]; bestSectionSides[3] = chunkBack.Sections[section.Y]; if (section.Y > 0) { bestSectionSides[4] = section.Chunk.Sections[section.Y - 1]; } else { bestSectionSides[4] = null; } if (section.Y < 15) { bestSectionSides[5] = section.Chunk.Sections[section.Y + 1]; } else { bestSectionSides[5] = null; } } } if (bestSection != null) { foreach (ChunkSection sectionSide in bestSectionSides) { sectionSide?.DecodeLongs(); } bestSection.DecodeLongs(); bestSection.Rend(true); RenderQueue.Remove(bestSection); } }