/// <summary> /// Adds an octant of light. /// </summary> /// <param name="range">The range of the light.</param> /// <param name="octant">The octant to scan.</param> /// <returns>This object, for call chaining.</returns> public OctantBuilder AddOctant(int range, Octant octant) { var points = ListPool <int, OctantBuilder> .Allocate(); OCTANT_SCAN?.Invoke(null, new object[] { Grid.CellToXY(SourceCell), range, 1, octant, 1.0, 0.0, points }); // Transfer to our array using: foreach (int cell in points) { float intensity; if (SmoothLight) { // Better, not rounded falloff intensity = PLightShape.GetSmoothFalloff(Falloff, cell, SourceCell); } else { // Default falloff intensity = PLightShape.GetDefaultFalloff(Falloff, cell, SourceCell); } destination[cell] = intensity; } points.Recycle(); return(this); }
/// <summary> /// Gets the brightness at a given cell for the specified light source. /// </summary> /// <param name="source">The source of the light.</param> /// <param name="location">The location to check.</param> /// <param name="state">The lighting state.</param> /// <param name="result">The brightness there.</param> /// <returns>true if that brightness is valid, or false otherwise.</returns> internal bool GetBrightness(LightGridEmitter source, int location, LightGridEmitter.State state, out int result) { bool valid; CacheEntry cacheEntry; var shape = state.shape; if (shape != LightShape.Cone && shape != LightShape.Circle) { lock (brightCache) { // Shared access to the cache valid = brightCache.TryGetValue(source, out cacheEntry); } if (valid) { valid = cacheEntry.Intensity.TryGetValue(location, out float ratio); if (valid) { result = Mathf.RoundToInt(cacheEntry.BaseLux * ratio); } else { #if DEBUG PUtil.LogDebug("GetBrightness for invalid cell at {0:D}".F(location)); #endif result = 0; } } else { #if DEBUG PUtil.LogDebug("GetBrightness for invalid emitter at {0:D}".F(location)); #endif result = 0; valid = false; } } else if (ForceSmoothLight) { // Use smooth light even for vanilla Cone and Circle result = Mathf.RoundToInt(state.intensity * PLightShape.GetSmoothFalloff( state.falloffRate, location, state.origin)); valid = true; } else { // Stock result = 0; valid = false; } return(valid); }