Optimization: Connection recipient caching, resetting cachedshadow data instead of creating a new one
This commit is contained in:
@@ -50,19 +50,11 @@ namespace Barotrauma
|
||||
|
||||
public void RemoveEntity(MapEntity entity)
|
||||
{
|
||||
Rectangle indices = GetIndices(entity.Rect);
|
||||
if (indices.X < 0 || indices.Width >= entities.GetLength(0) ||
|
||||
indices.Y < 0 || indices.Height >= entities.GetLength(1))
|
||||
for (int x = 0; x <= entities.GetLength(0); x++)
|
||||
{
|
||||
DebugConsole.ThrowError("Error in EntityGrid.RemoveEntity: " + entity + " is outside the grid");
|
||||
return;
|
||||
}
|
||||
|
||||
for (int x = indices.X; x <= indices.Width; x++)
|
||||
{
|
||||
for (int y = indices.Y; y <= indices.Height; y++)
|
||||
for (int y = 0; y <= entities.GetLength(1); y++)
|
||||
{
|
||||
entities[x, y].Remove(entity);
|
||||
if (entities[x,y].Contains(entity)) entities[x, y].Remove(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,7 +129,7 @@ namespace Barotrauma
|
||||
viewRect.Y = -viewRect.Y;
|
||||
|
||||
float multiplier = 0.8f;
|
||||
for (int i = 1; i < 5; i++)
|
||||
for (int i = 1; i < 4; i++)
|
||||
{
|
||||
spriteBatch.Draw(dustParticles, new Rectangle(0,0,GameMain.GraphicsWidth,GameMain.GraphicsHeight),
|
||||
new Rectangle((int)((backgroundPos.X * multiplier)), (int)((-backgroundPos.Y * multiplier)), cam.WorldView.Width*2, cam.WorldView.Height*2),
|
||||
@@ -164,10 +164,7 @@ namespace Barotrauma
|
||||
public void RenderWalls(GraphicsDevice graphicsDevice, Camera cam)
|
||||
{
|
||||
if (wallVertices == null) return;
|
||||
|
||||
Stopwatch sw = new Stopwatch();
|
||||
sw.Start();
|
||||
|
||||
|
||||
basicEffect.World = cam.ShaderTransform
|
||||
* Matrix.CreateOrthographic(GameMain.GraphicsWidth, GameMain.GraphicsHeight, -1, 1) * 0.5f;
|
||||
|
||||
@@ -202,12 +199,7 @@ namespace Barotrauma
|
||||
basicEffect.CurrentTechnique = basicEffect.Techniques["BasicEffect_Texture"];
|
||||
basicEffect.CurrentTechnique.Passes[0].Apply();
|
||||
graphicsDevice.DrawPrimitives(PrimitiveType.TriangleList, 0, (int)Math.Floor(wallVertices.VertexCount / 3.0f));
|
||||
|
||||
basicEffect.VertexColorEnabled = false;
|
||||
basicEffect.TextureEnabled = true;
|
||||
basicEffect.CurrentTechnique = basicEffect.Techniques["BasicEffect_Texture"];
|
||||
basicEffect.CurrentTechnique.Passes[0].Apply();
|
||||
|
||||
|
||||
for (int side = 0; side < 2; side++)
|
||||
{
|
||||
for (int i = 0; i < 2; i++)
|
||||
@@ -221,10 +213,7 @@ namespace Barotrauma
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
sw.Stop();
|
||||
|
||||
Debug.WriteLine("level render: "+sw.ElapsedTicks);
|
||||
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
|
||||
@@ -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