Optimization: FindHull spatial hashing, itemcomponent sounds in a dictionary, got rid of Item.Updated, rendering fixes, disposing shadow vertex buffers

This commit is contained in:
Regalis11
2015-12-21 11:01:35 +02:00
parent a62c6d6711
commit 2ff8643c02
16 changed files with 354 additions and 136 deletions
+4 -3
View File
@@ -314,8 +314,8 @@ namespace Barotrauma
wrappingWalls[side, i] = new WrappingWall(pathCells, cells, borders.Height * 0.5f,
(side == 0 ? -1 : 1) * (i == 0 ? 1 : 2));
wrappingWalls[side, i].BodyVertices = GeneratePolygons(wrappingWalls[side, i].Cells, new List<VoronoiCell>(), false);
wrappingWalls[side, i].WallVertices = GenerateWallShapes(wrappingWalls[side, i].Cells);
wrappingWalls[side, i].SetBodyVertices(GeneratePolygons(wrappingWalls[side, i].Cells, new List<VoronoiCell>(), false));
wrappingWalls[side, i].SetWallVertices(GenerateWallShapes(wrappingWalls[side, i].Cells));
//wrappingWalls[side, i].Cells[0].edges[1].isSolid = false;
//wrappingWalls[side, i].Cells[0].edges[3].isSolid = false;
@@ -1091,10 +1091,11 @@ namespace Barotrauma
private void Unload()
{
renderer.Dispose();
renderer = null;
cells = null;
bodies.Clear();
bodies = null;
+42 -23
View File
@@ -8,7 +8,7 @@ using System.Text;
namespace Barotrauma
{
class LevelRenderer
class LevelRenderer : IDisposable
{
private static BasicEffect basicEffect;
@@ -182,16 +182,18 @@ namespace Barotrauma
graphicsDevice.DrawPrimitives(PrimitiveType.TriangleList, 0, (int)Math.Floor(bodyVertices.VertexCount / 3.0f));
//for (int side = 0; side < 2; side++)
//{
// for (int i = 0; i < 2; i++)
// {
// graphicsDevice.DrawUserPrimitives(
// PrimitiveType.TriangleList, level.WrappingWalls[side, i].BodyVertices, 0,
// (int)Math.Floor(level.WrappingWalls[side, i].BodyVertices.Length / 3.0f));
for (int side = 0; side < 2; side++)
{
for (int i = 0; i < 2; i++)
{
graphicsDevice.SetVertexBuffer(level.WrappingWalls[side, i].BodyVertices);
// }
//}
graphicsDevice.DrawPrimitives(
PrimitiveType.TriangleList, 0,
(int)Math.Floor(level.WrappingWalls[side, i].BodyVertices.VertexCount / 3.0f));
}
}
graphicsDevice.SetVertexBuffer(wallVertices);
@@ -201,25 +203,42 @@ namespace Barotrauma
basicEffect.CurrentTechnique.Passes[0].Apply();
graphicsDevice.DrawPrimitives(PrimitiveType.TriangleList, 0, (int)Math.Floor(wallVertices.VertexCount / 3.0f));
//for (int side = 0; side < 2; side++)
//{
// for (int i = 0; i < 2; i++)
// {
// basicEffect.VertexColorEnabled = false;
// basicEffect.TextureEnabled = true;
// basicEffect.CurrentTechnique = basicEffect.Techniques["BasicEffect_Texture"];
// basicEffect.CurrentTechnique.Passes[0].Apply();
// graphicsDevice.DrawUserPrimitives(
// PrimitiveType.TriangleList, level.WrappingWalls[side, i].WallVertices, 0,
// (int)Math.Floor(level.WrappingWalls[side, i].WallVertices.Length / 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++)
{
graphicsDevice.SetVertexBuffer(level.WrappingWalls[side, i].WallVertices);
graphicsDevice.DrawPrimitives(
PrimitiveType.TriangleList, 0,
(int)Math.Floor(level.WrappingWalls[side, i].WallVertices.VertexCount / 3.0f));
}
}
sw.Stop();
Debug.WriteLine("level render: "+sw.ElapsedTicks);
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
wallVertices.Dispose();
bodyVertices.Dispose();
}
}
}
+23 -3
View File
@@ -15,9 +15,7 @@ namespace Barotrauma
public const float WallWidth = 20000.0f;
public VertexPositionTexture[] WallVertices;
public VertexPositionColor[] BodyVertices;
private VertexBuffer wallVertices, bodyVertices;
private Vector2 midPos;
private int slot;
@@ -26,6 +24,16 @@ namespace Barotrauma
private List<VoronoiCell> cells;
public VertexBuffer WallVertices
{
get { return wallVertices; }
}
public VertexBuffer BodyVertices
{
get { return bodyVertices; }
}
public Vector2 Offset
{
get { return offset; }
@@ -116,6 +124,18 @@ namespace Barotrauma
}
}
public void SetWallVertices(VertexPositionTexture[] vertices)
{
wallVertices = new VertexBuffer(GameMain.CurrGraphicsDevice, VertexPositionTexture.VertexDeclaration, vertices.Length, BufferUsage.WriteOnly);
wallVertices.SetData(vertices);
}
public void SetBodyVertices(VertexPositionColor[] vertices)
{
bodyVertices = new VertexBuffer(GameMain.CurrGraphicsDevice, VertexPositionColor.VertexDeclaration, vertices.Length, BufferUsage.WriteOnly);
bodyVertices.SetData(vertices);
}
public static void UpdateWallShift(Vector2 pos, WrappingWall[,] walls)
{