public void EditDensity(Func <Vector3, float, float> editor) { // Do a breadth-first search through the graph for chunks that changed // as a result of applying the editor. var queue = new Queue <Chunk>(); var visited = new Dictionary <ChunkPosition, Chunk>(); // Keep track of points where the solidity flipped. var flippedPoints = new HashSet <GlobalPoint>(); queue.Enqueue(this); visited.Add(position, this); while (queue.Count > 0) { var current = queue.Dequeue(); var neighbourMask = current.EditDensityLocally(editor, ref flippedPoints); for (int n = 0; n < 6; n++) { var bit = 0x1 << n; if ((neighbourMask & bit) != 0) { var neighbour = current.neighbours[n]; if (neighbour != null) { if (!visited.ContainsKey(neighbour.position)) { queue.Enqueue(neighbour); visited.Add(neighbour.position, neighbour); } } } } } // Update the luminance in affected points if (flippedPoints.Count >= 1) { luminance.UpdateAt(ref flippedPoints); } }