Optimization: Connection recipient caching, resetting cachedshadow data instead of creating a new one
This commit is contained in:
@@ -9,10 +9,6 @@ namespace Barotrauma.Lights
|
||||
{
|
||||
class CachedShadow : IDisposable
|
||||
{
|
||||
|
||||
//public VertexPositionColor[] ShadowVertices;
|
||||
//public VertexPositionTexture[] PenumbraVertices;
|
||||
|
||||
public VertexBuffer ShadowBuffer;
|
||||
|
||||
public Vector2 LightPos;
|
||||
@@ -291,30 +287,33 @@ namespace Barotrauma.Lights
|
||||
if (cachedShadows.TryGetValue(light, out cachedShadow) &&
|
||||
(light.Position == cachedShadow.LightPos || Vector2.DistanceSquared(light.Position, cachedShadow.LightPos) < 1.0f))
|
||||
{
|
||||
//{
|
||||
graphicsDevice.SetVertexBuffer(cachedShadow.ShadowBuffer);
|
||||
shadowVertexCount = cachedShadow.ShadowVertexCount;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
Vector2 lightPos = light.Position;
|
||||
//if (light.Submarine!=null && parentEntity != null && parentEntity.Submarine == light.Submarine)
|
||||
//{
|
||||
// lightPos = light.Position;
|
||||
//}
|
||||
|
||||
CalculateShadowVertices(lightPos, los);
|
||||
CalculateShadowVertices(light.Position, los);
|
||||
|
||||
if (cachedShadow != null)
|
||||
{
|
||||
cachedShadow.Dispose();
|
||||
cachedShadows.Remove(light);
|
||||
cachedShadow.LightPos = light.Position;
|
||||
cachedShadow.ShadowBuffer.SetData(shadowVertices, 0, shadowVertices.Length);
|
||||
cachedShadow.ShadowVertexCount = shadowVertexCount;
|
||||
}
|
||||
else
|
||||
{
|
||||
cachedShadow = new CachedShadow(shadowVertices, penumbraVertices, light.Position, shadowVertexCount, 0);
|
||||
cachedShadows.Add(light, cachedShadow);
|
||||
}
|
||||
cachedShadow = new CachedShadow(shadowVertices, penumbraVertices, light.Position, shadowVertexCount, 0);
|
||||
cachedShadows.Add(light, cachedShadow);
|
||||
}
|
||||
|
||||
graphicsDevice.SetVertexBuffer(cachedShadow.ShadowBuffer);
|
||||
shadowVertexCount = cachedShadow.ShadowVertexCount;
|
||||
|
||||
DrawShadows(graphicsDevice, cam, transform, los);
|
||||
}
|
||||
|
||||
|
||||
@@ -59,11 +59,7 @@ namespace Barotrauma.Lights
|
||||
}
|
||||
|
||||
public void DrawLOS(GraphicsDevice graphics, SpriteBatch spriteBatch, Camera cam, Vector2 pos)
|
||||
{
|
||||
|
||||
Stopwatch sw = new Stopwatch();
|
||||
sw.Start();
|
||||
|
||||
{
|
||||
if (!LosEnabled) return;
|
||||
|
||||
Rectangle camView = new Rectangle(cam.WorldView.X, cam.WorldView.Y - cam.WorldView.Height, cam.WorldView.Width, cam.WorldView.Height);
|
||||
@@ -78,10 +74,7 @@ namespace Barotrauma.Lights
|
||||
|
||||
convexHull.DrawShadows(graphics, cam, pos, shadowTransform);
|
||||
}
|
||||
|
||||
sw.Stop();
|
||||
|
||||
Debug.WriteLine("drawlos: " + sw.ElapsedTicks + " (" + sw.ElapsedMilliseconds + ")");
|
||||
|
||||
if (!ObstructVision) return;
|
||||
|
||||
spriteBatch.Begin(SpriteSortMode.Deferred, CustomBlendStates.Multiplicative);
|
||||
@@ -102,10 +95,6 @@ namespace Barotrauma.Lights
|
||||
|
||||
public void UpdateLightMap(GraphicsDevice graphics, SpriteBatch spriteBatch, Camera cam)
|
||||
{
|
||||
|
||||
Stopwatch sw = new Stopwatch();
|
||||
sw.Start();
|
||||
|
||||
if (!LightingEnabled) return;
|
||||
|
||||
Matrix shadowTransform = cam.ShaderTransform
|
||||
@@ -162,9 +151,7 @@ namespace Barotrauma.Lights
|
||||
//clear alpha, to avoid messing stuff up later
|
||||
ClearAlphaToOne(graphics, spriteBatch);
|
||||
graphics.SetRenderTarget(null);
|
||||
|
||||
|
||||
Debug.WriteLine("lights: " + sw.ElapsedTicks + " (" + sw.ElapsedMilliseconds + ")");
|
||||
|
||||
if (!ObstructVision) return;
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user