private bool CheckLightPropagation(ChunkLightPropagInfo info) { return(CheckLightPropagation(info.pos, info.propagationFlag, info.recursionDepth)); }
// Checks if neighbor chunks should have light propagated // MUST BE USED AFTER THE CalculateLightMap FUNCTION // Returns true if should update current chunk and false if not public bool CheckLightPropagation(ChunkPos pos, byte flag = 255, int recursionDepth = 0) { byte propagationFlag; ChunkPos neighbor; bool updateCurrent = false; byte updateCode = 0; if (recursionDepth >= 5) { return(false); } if (flag == 255) { propagationFlag = this.chunks[pos].data.GetPropagationFlag(); } else { propagationFlag = flag; } // None if (propagationFlag == 0) { return(false); } // xm if ((propagationFlag & 1) != 0) { neighbor = new ChunkPos(pos.x - 1, pos.z); if (this.chunks.ContainsKey(neighbor)) { updateCode = VoxelData.PropagateLight(this.chunks[pos].data, this.chunks[neighbor].data, 0); if ((updateCode & 4) == 4) { AddToUpdate(neighbor, noLight: false); } if (((updateCode & 7) == 2 || (updateCode & 7) == 3) && (updateCode & 4) != 4) { AddToUpdate(neighbor, noLight: true); } if ((updateCode & 7) == 1 || (updateCode & 7) == 3) { AddToUpdate(pos, noLight: true); } if (updateCode >= 8) { toCallLightCascade.Add(new ChunkLightPropagInfo(neighbor, (byte)(updateCode >> 3), recursionDepth + 1)); } } } // xp if ((propagationFlag & 2) != 0) { neighbor = new ChunkPos(pos.x + 1, pos.z); if (this.chunks.ContainsKey(neighbor)) { updateCode = VoxelData.PropagateLight(this.chunks[pos].data, this.chunks[neighbor].data, 1); if ((updateCode & 4) == 4) { AddToUpdate(neighbor, noLight: false); } if (((updateCode & 7) == 2 || (updateCode & 7) == 3) && (updateCode & 4) != 4) { AddToUpdate(neighbor, noLight: true); } if ((updateCode & 7) == 1 || (updateCode & 7) == 3) { AddToUpdate(pos, noLight: true); } if (updateCode >= 8) { toCallLightCascade.Add(new ChunkLightPropagInfo(neighbor, (byte)(updateCode >> 3), recursionDepth + 1)); } } } // zm if ((propagationFlag & 4) != 0) { neighbor = new ChunkPos(pos.x, pos.z - 1); if (this.chunks.ContainsKey(neighbor)) { updateCode = VoxelData.PropagateLight(this.chunks[pos].data, this.chunks[neighbor].data, 2); if ((updateCode & 4) == 4) { AddToUpdate(neighbor, noLight: false); } if (((updateCode & 7) == 2 || (updateCode & 7) == 3) && (updateCode & 4) != 4) { AddToUpdate(neighbor, noLight: true); } if ((updateCode & 7) == 1 || (updateCode & 7) == 3) { AddToUpdate(pos, noLight: true); } if (updateCode >= 8) { toCallLightCascade.Add(new ChunkLightPropagInfo(neighbor, (byte)(updateCode >> 3), recursionDepth + 1)); } } } // zp if ((propagationFlag & 8) != 0) { neighbor = new ChunkPos(pos.x, pos.z + 1); if (this.chunks.ContainsKey(neighbor)) { updateCode = VoxelData.PropagateLight(this.chunks[pos].data, this.chunks[neighbor].data, 3); if ((updateCode & 4) == 4) { AddToUpdate(neighbor, noLight: false); } if (((updateCode & 7) == 2 || (updateCode & 7) == 3) && (updateCode & 4) != 4) { AddToUpdate(neighbor, noLight: true); } if ((updateCode & 7) == 1 || (updateCode & 7) == 3) { AddToUpdate(pos, noLight: true); } if (updateCode >= 8) { toCallLightCascade.Add(new ChunkLightPropagInfo(neighbor, (byte)(updateCode >> 3), recursionDepth + 1)); } } } while (toCallLightCascade.Count > 0) { ChunkLightPropagInfo info = toCallLightCascade[0]; toCallLightCascade.RemoveAt(0); CheckLightPropagation(info); } return(updateCurrent); }