LightSource vertices are recalculated if another submarine within the range of the light has moved relative to the sub the light is in
This commit is contained in:
@@ -40,6 +40,8 @@ namespace Barotrauma.Lights
|
||||
//when were the vertices of the light volume last calculated
|
||||
private float lastRecalculationTime;
|
||||
|
||||
private Dictionary<Submarine, Vector2> diffToSub;
|
||||
|
||||
private DynamicVertexBuffer lightVolumeBuffer;
|
||||
private DynamicIndexBuffer lightVolumeIndexBuffer;
|
||||
private int vertexCount;
|
||||
@@ -151,6 +153,8 @@ namespace Barotrauma.Lights
|
||||
|
||||
texture = LightTexture;
|
||||
|
||||
diffToSub = new Dictionary<Submarine, Vector2>();
|
||||
|
||||
GameMain.LightManager.AddLight(this);
|
||||
}
|
||||
|
||||
@@ -275,7 +279,7 @@ namespace Barotrauma.Lights
|
||||
Rectangle subBorders = sub.Borders;
|
||||
subBorders.Location += sub.HiddenSubPosition.ToPoint() - new Point(0, sub.Borders.Height);
|
||||
|
||||
//only draw if the light overlaps with the sub
|
||||
//don't draw any shadows if the light doesn't overlap with the borders of the sub
|
||||
if (!MathUtils.CircleIntersectsRectangle(lightPos, range, subBorders))
|
||||
{
|
||||
if (chList.List.Count > 0) NeedsRecalculation = true;
|
||||
@@ -283,6 +287,20 @@ namespace Barotrauma.Lights
|
||||
continue;
|
||||
}
|
||||
|
||||
//recalculate vertices if the subs have moved > 5 px relative to each other
|
||||
Vector2 diff = ParentSub.WorldPosition - sub.WorldPosition;
|
||||
Vector2 prevDiff;
|
||||
if (!diffToSub.TryGetValue(sub, out prevDiff))
|
||||
{
|
||||
diffToSub.Add(sub, diff);
|
||||
NeedsRecalculation = true;
|
||||
}
|
||||
else if (Vector2.DistanceSquared(diff, prevDiff) > 5.0f*5.0f)
|
||||
{
|
||||
diffToSub[sub] = diff;
|
||||
NeedsRecalculation = true;
|
||||
}
|
||||
|
||||
RefreshConvexHullList(chList, lightPos, sub);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user