Better logic for determining which convex hulls are in the range of a lightsource (separate convexhull lists for each sub)

This commit is contained in:
Regalis
2016-06-30 17:50:02 +03:00
parent 38c5251005
commit aae24b2b2c
6 changed files with 218 additions and 67 deletions
+36 -10
View File
@@ -42,9 +42,21 @@ namespace Barotrauma.Lights
}
}
class ConvexHullList
{
public readonly Submarine Submarine;
public List<ConvexHull> List;
public ConvexHullList(Submarine submarine)
{
Submarine = submarine;
List = new List<ConvexHull>();
}
}
class ConvexHull
{
public static List<ConvexHull> list = new List<ConvexHull>();
public static List<ConvexHullList> HullLists = new List<ConvexHullList>();
static BasicEffect shadowEffect;
static BasicEffect penumbraEffect;
@@ -116,15 +128,20 @@ namespace Barotrauma.Lights
Enabled = true;
foreach (ConvexHull ch in list)
var chList = HullLists.Find(x => x.Submarine == parent.Submarine);
if (chList == null)
{
chList = new ConvexHullList(parent.Submarine);
HullLists.Add(chList);
}
foreach (ConvexHull ch in chList.List)
{
UpdateIgnoredEdges(ch);
ch.UpdateIgnoredEdges(this);
}
list.Add(this);
chList.List.Add(this);
}
private void UpdateIgnoredEdges(ConvexHull ch)
@@ -219,7 +236,7 @@ namespace Barotrauma.Lights
{
foreach (KeyValuePair<LightSource, CachedShadow> cachedShadow in cachedShadows)
{
cachedShadow.Key.NeedsHullUpdate();
cachedShadow.Key.NeedsHullUpdate = true;
cachedShadow.Value.Dispose();
}
cachedShadows.Clear();
@@ -377,13 +394,13 @@ namespace Barotrauma.Lights
if (parentEntity != null && parentEntity.Submarine != null)
{
if (light.Submarine == null)
if (light.ParentSub == null)
{
lightSourcePos -= parentEntity.Submarine.Position;
}
else if (light.Submarine != parentEntity.Submarine)
else if (light.ParentSub != parentEntity.Submarine)
{
lightSourcePos += (light.Submarine.Position-parentEntity.Submarine.Position);
lightSourcePos += (light.ParentSub.Position-parentEntity.Submarine.Position);
}
}
@@ -467,7 +484,16 @@ namespace Barotrauma.Lights
{
ClearCachedShadows();
list.Remove(this);
var chList = HullLists.Find(x => x.Submarine == parentEntity.Submarine);
if (chList != null)
{
chList.List.Remove(this);
if (chList.List.Count == 0)
{
HullLists.Remove(chList);
}
}
}