public static void Recompute(Vector3i pos, Queue <Vector3i> nodes) { int oldSunHeight = MapLight.GetRay(pos.x, pos.z); ComputeRayAtPosition(pos.x, pos.z); int newSunHeight = MapLight.GetRay(pos.x, pos.z); if (newSunHeight < oldSunHeight) { for (int ty = newSunHeight; ty <= oldSunHeight; ty++) { pos.y = ty; if (ty < Map.Height) { MapLight.SetSunlight(pos.x, pos.y, pos.z, LightUtils.MinLight); } nodes.Enqueue(pos); } ScatterNodes(nodes, false); return; } if (newSunHeight > oldSunHeight) { for (int ty = oldSunHeight; ty <= newSunHeight; ty++) { pos.y = ty; if (ty < Map.Height) { MapLight.SetSunlight(pos.x, pos.y, pos.z, LightUtils.MaxLight); } nodes.Enqueue(pos); } RemoveNodes(nodes); return; } if (newSunHeight == oldSunHeight) { if (Map.GetBlock(pos.x, pos.y, pos.z).IsTransparent()) { Update(pos, nodes); } else { Remove(pos, nodes); } } }
private static void RemoveNodes(Queue <Vector3i> nodes) { Queue <Vector3i> newNodes = new Queue <Vector3i>(); while (nodes.Count > 0) { Vector3i pos = nodes.Dequeue(); if (pos.y < 0 || pos.y >= Map.Height) { continue; } if (pos.y >= MapLight.GetRay(pos.x, pos.z)) { newNodes.Enqueue(pos); continue; } byte light = (byte)(MapLight.GetSunlight(pos.x, pos.y, pos.z) - 1); MapLight.SetSunlight(pos.x, pos.y, pos.z, LightUtils.MinLight); if (light <= LightUtils.MinLight) { continue; } for (int i = 0; i < 6; i++) { Vector3i nextPos = pos + Vector3i.directions[i]; if (Map.InBounds(nextPos.x, nextPos.z)) { Block block = Map.GetBlock(nextPos.x, nextPos.y, nextPos.z); if (block.IsTransparent()) { if (MapLight.GetSunlight(nextPos.x, nextPos.y, nextPos.z) <= light) { nodes.Enqueue(nextPos); Map.FlagChunkForUpdate(nextPos.x, nextPos.y, nextPos.z); } else { newNodes.Enqueue(nextPos); } } } } } ScatterNodes(newNodes, false); }
private static bool SetMax(byte light, int x, int y, int z) { if (y >= MapLight.GetRay(x, z)) { return(false); } byte oldLight = MapLight.GetSunlight(x, y, z); if (oldLight < light) { MapLight.SetSunlight(x, y, z, light); return(true); } return(false); }
private static void Remove(Vector3i pos, Queue <Vector3i> nodes) { MapLight.SetSunlight(pos.x, pos.y, pos.z, LightUtils.MaxLight); nodes.Enqueue(pos); RemoveNodes(nodes); }