void BuildChunk(ChunkInfo info, ref int chunkUpdates) { game.ChunkUpdates++; builder.GetDrawInfo(info.CentreX - 8, info.CentreY - 8, info.CentreZ - 8, ref info.NormalParts, ref info.TranslucentParts, ref info.OcclusionFlags); if (info.NormalParts == null && info.TranslucentParts == null) { info.Empty = true; } chunkUpdates++; }
void UpdateChunks(double deltaTime) { int chunksUpdatedThisFrame = 0; int viewDist = game.ViewDistance < 16 ? 16 : game.ViewDistance; int adjViewDistSqr = (viewDist + 24) * (viewDist + 24); chunksTarget += deltaTime < targetTime ? 1 : -1; // build more chunks if 30 FPS or over, otherwise slowdown. Utils.Clamp(ref chunksTarget, 4, 12); for (int i = 0; i < chunks.Length; i++) { ChunkInfo info = chunks[i]; if (info.Empty) { continue; } int distSqr = distances[i]; bool inRange = distSqr <= adjViewDistSqr; if (info.NormalParts == null && info.TranslucentParts == null) { if (inRange && chunksUpdatedThisFrame < chunksTarget) { game.ChunkUpdates++; builder.GetDrawInfo(info.CentreX - 8, info.CentreY - 8, info.CentreZ - 8, ref info.NormalParts, ref info.TranslucentParts, ref info.OcclusionFlags); if (info.NormalParts == null && info.TranslucentParts == null) { info.Empty = true; } chunksUpdatedThisFrame++; } } info.Visible = inRange && game.Culling.SphereInFrustum(info.CentreX, info.CentreY, info.CentreZ, 14); // 14 ~ sqrt(3 * 8^2) } LocalPlayer p = game.LocalPlayer; Vector3 cameraPos = game.CurrentCameraPos; if (chunksUpdatedThisFrame == 0 && cameraPos == lastCamPos && p.YawDegrees == lastYaw && p.PitchDegrees == lastPitch) { return; } lastCamPos = cameraPos; lastYaw = p.YawDegrees; lastPitch = p.PitchDegrees; RecalcBooleans(false); }