From c33a4ba5e5e69f72d9d18881f9fd159ee584ad79 Mon Sep 17 00:00:00 2001 From: Regalis Date: Tue, 25 Oct 2016 15:40:19 +0300 Subject: [PATCH] AmbientLightHulls optimization (only spread to adjacent hulls once, not once per every gap between the hulls) --- Subsurface/Source/Map/Lights/LightManager.cs | 26 ++++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/Subsurface/Source/Map/Lights/LightManager.cs b/Subsurface/Source/Map/Lights/LightManager.cs index 3fd45ac65..b3d4c8382 100644 --- a/Subsurface/Source/Map/Lights/LightManager.cs +++ b/Subsurface/Source/Map/Lights/LightManager.cs @@ -328,22 +328,22 @@ namespace Barotrauma.Lights hullAmbientLight.Add(hull, currColor); } + Color nextHullLight = currColor * AmbientLightFalloff; + //light getting too dark to notice -> no need to spread further + if (nextHullLight.A < 20) return hullAmbientLight; + + //use hashset to make sure that each hull is only included once + HashSet hulls = new HashSet(); foreach (Gap g in hull.ConnectedGaps) { - for (int i = 0; i < g.linkedTo.Count;i++ ) - { - if (g.linkedTo[i] is Hull) - { - if (g.linkedTo[i] == hull) continue; + if (!g.IsRoomToRoom || !g.PassAmbientLight || g.Open < 0.5f) continue; + + hulls.Add((g.linkedTo[0] == hull ? g.linkedTo[1] : g.linkedTo[0]) as Hull); + } - Color nextHullLight = currColor * AmbientLightFalloff; - if (!g.PassAmbientLight) nextHullLight *= g.Open; - - if (nextHullLight.A < 10) continue; - - hullAmbientLight = AmbientLightHulls((Hull)g.linkedTo[i], hullAmbientLight, nextHullLight); - } - } + foreach (Hull h in hulls) + { + hullAmbientLight = AmbientLightHulls(h, hullAmbientLight, nextHullLight); } return hullAmbientLight;