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

Binary file not shown.

View File

@@ -78,12 +78,7 @@ namespace FarseerPhysics.Collision.Shapes
Vector2 v2 = vertices[i];
// If the code crashes here, it means your vertices are too close together.
if (Vector2.DistanceSquared(v1, v2) < Settings.LinearSlop * Settings.LinearSlop)
{
int asldmfk = 1;
}
Debug.Assert(Vector2.DistanceSquared(v1, v2) > Settings.LinearSlop * Settings.LinearSlop);
}

View File

@@ -114,6 +114,7 @@
<Compile Include="Source\Items\Components\ItemLabel.cs" />
<Compile Include="Source\Items\FixRequirement.cs" />
<Compile Include="Source\Items\ItemSpawner.cs" />
<Compile Include="Source\Map\EntityGrid.cs" />
<Compile Include="Source\Map\FireSource.cs" />
<Compile Include="Source\Map\Levels\LevelRenderer.cs" />
<Compile Include="Source\Map\Levels\WrappingWall.cs" />

View File

@@ -61,7 +61,7 @@ namespace Barotrauma.Items.Components
public List<Skill> requiredSkills;
private List<ItemSound> sounds;
private Dictionary<ActionType,List<ItemSound>> sounds;
private GUIFrame guiFrame;
@@ -175,7 +175,7 @@ namespace Barotrauma.Items.Components
requiredSkills = new List<Skill>();
sounds = new List<ItemSound>();
sounds = new Dictionary<ActionType, List<ItemSound>>();
statusEffects = new List<StatusEffect>();
@@ -283,7 +283,15 @@ namespace Barotrauma.Items.Components
ItemSound itemSound = new ItemSound(sound, type, range, loop);
itemSound.VolumeProperty = ToolBox.GetAttributeString(subElement, "volume", "");
itemSound.VolumeMultiplier = ToolBox.GetAttributeFloat(subElement, "volumemultiplier", 1.0f);
sounds.Add(itemSound);
List<ItemSound> soundList = null;
if (!sounds.TryGetValue(itemSound.Type, out soundList))
{
soundList = new List<ItemSound>();
sounds.Add(itemSound.Type, soundList);
}
soundList.Add(itemSound);
break;
default:
ItemComponent ic = ItemComponent.Load(subElement, item, item.ConfigFile, false);
@@ -306,9 +314,9 @@ namespace Barotrauma.Items.Components
loopingSoundIndex = loopingSound.Sound.Loop(loopingSoundIndex, GetSoundVolume(loopingSound), position, loopingSound.Range);
return;
}
List<ItemSound> matchingSounds = sounds.FindAll(x => x.Type == type);
if (matchingSounds.Count == 0) return;
List<ItemSound> matchingSounds = null;
if (!sounds.TryGetValue(type, out matchingSounds)) return;
ItemSound itemSound = null;
if (!Sounds.SoundManager.IsPlaying(loopingSoundIndex))

View File

@@ -12,6 +12,10 @@ namespace Barotrauma.Items.Components
static float fullPower;
static float fullLoad;
//private bool updated;
private int updateTimer;
const float FireProbability = 0.15f;
//affects how fast changes in power/load are carried over the grid
@@ -40,9 +44,14 @@ namespace Barotrauma.Items.Components
fullLoad = 0.0f;
connectedList.Clear();
if (updated) return;
if (updateTimer > 0)
{
updateTimer--;
return;
}
CheckJunctions(deltaTime);
updateTimer = 0;
foreach (Powered p in connectedList)
{
@@ -54,51 +63,43 @@ namespace Barotrauma.Items.Components
pt.Item.SendSignal("", "power", fullPower / Math.Max(fullLoad, 1.0f));
//damage the item if voltage is too high
if (-pt.currPowerConsumption > Math.Max(pt.powerLoad * 2.0f, 200.0f))
if (-pt.currPowerConsumption < Math.Max(pt.powerLoad * 2.0f, 200.0f)) continue;
float prevCondition = pt.item.Condition;
pt.item.Condition -= deltaTime * 10.0f;
if (pt.item.Condition <= 0.0f && prevCondition > 0.0f)
{
sparkSounds[Rand.Int(sparkSounds.Length)].Play(1.0f, 600.0f, pt.item.WorldPosition);
float prevCondition = pt.item.Condition;
pt.item.Condition -= deltaTime * 10.0f;
if (pt.item.Condition<=0.0f && prevCondition > 0.0f)
Vector2 baseVel = Rand.Vector(300.0f);
for (int i = 0; i < 10; i++)
{
sparkSounds[Rand.Int(sparkSounds.Length)].Play(1.0f, 600.0f, pt.item.WorldPosition);
var particle = GameMain.ParticleManager.CreateParticle("spark", pt.item.WorldPosition,
baseVel + Rand.Vector(100.0f), 0.0f, item.CurrentHull);
Vector2 baseVel = Rand.Vector(300.0f);
for (int i = 0; i < 10; i++)
{
var particle = GameMain.ParticleManager.CreateParticle("spark", pt.item.WorldPosition,
baseVel + Rand.Vector(100.0f), 0.0f, item.CurrentHull);
if (particle != null) particle.Size *= Rand.Range(0.5f, 1.0f);
}
if (particle != null) particle.Size *= Rand.Range(0.5f, 1.0f);
}
if (FireProbability > 0.0f && Rand.Int((int)(1.0f / FireProbability)) == 1)
{
new FireSource(pt.item.WorldPosition);
}
if (FireProbability > 0.0f && Rand.Int((int)(1.0f / FireProbability)) == 1)
{
new FireSource(pt.item.WorldPosition);
}
}
}
}
public override bool Pick(Character picker)
{
if (picker == null) return false;
//picker.SelectedConstruction = (picker.SelectedConstruction == item) ? null : item;
return true;
return picker != null;
}
//a recursive function that goes through all the junctions and adds up
//all the generated/consumed power of the constructions connected to the grid
private void CheckJunctions(float deltaTime)
{
updated = true;
updateTimer = 1;
connectedList.Add(this);
ApplyStatusEffects(ActionType.OnActive, deltaTime, null);
@@ -119,11 +120,12 @@ namespace Barotrauma.Items.Components
//if (it.Updated) continue;
Powered powered = it.GetComponent<Powered>();
if (powered == null || powered.Updated) continue;
if (powered == null) continue;
PowerTransfer powerTransfer = powered as PowerTransfer;
if (powerTransfer != null)
{
if (powerTransfer.updateTimer>0) continue;
powerTransfer.CheckJunctions(deltaTime);
}
else
@@ -143,9 +145,8 @@ namespace Barotrauma.Items.Components
}
}
}
}
public override void DrawHUD(SpriteBatch spriteBatch, Character character)
{
int x = GuiFrame.Rect.X;

View File

@@ -284,7 +284,7 @@ namespace Barotrauma
#if DEBUG
System.Diagnostics.Debug.Assert(slotIndex >= 0 && slotIndex < Items.Length);
#else
if (slotIndex<0 || slotIndex>=items.Length) return;
if (slotIndex<0 || slotIndex>=Items.Length) return;
#endif
Rectangle containerRect = new Rectangle(rect.X - 5, rect.Y - (40 + 10) * itemCapacity - 5,

View File

@@ -111,7 +111,7 @@ namespace Barotrauma
get { return condition; }
set
{
if (float.IsNaN(value)) return;
if (!MathUtils.IsValid(value)) return;
float prev = condition;
condition = MathHelper.Clamp(value, 0.0f, 100.0f);
@@ -166,15 +166,7 @@ namespace Barotrauma
return IsInWater();
}
}
public bool Updated
{
set
{
foreach (ItemComponent ic in components) ic.Updated = value;
}
}
public ItemPrefab Prefab
{
get { return prefab; }

View File

@@ -0,0 +1,115 @@
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
namespace Barotrauma
{
class EntityGrid
{
private List<MapEntity>[,] entities;
private Rectangle limits;
private float cellSize;
public EntityGrid(Rectangle limits, float cellSize)
{
this.limits = limits;
this.cellSize = cellSize;
entities = new List<MapEntity>[(int)Math.Ceiling(limits.Width / cellSize),(int)Math.Ceiling(limits.Height / cellSize)];
for (int x = 0; x<entities.GetLength(0); x++)
{
for (int y=0; y<entities.GetLength(1); y++)
{
entities[x, y] = new List<MapEntity>();
}
}
}
public void InsertEntity(MapEntity entity)
{
Rectangle rect = entity.Rect;
//if (Submarine.Loaded != null) rect.Offset(-Submarine.HiddenSubPosition);
Rectangle indices = GetIndices(rect);
if (indices.X<0 || indices.Width>=entities.GetLength(0) ||
indices.Y<0 || indices.Height>=entities.GetLength(1))
{
DebugConsole.ThrowError("Error in EntityGrid.InsertEntity: "+entity+" is outside the grid");
return;
}
for (int x=indices.X; x<=indices.Width; x++)
{
for (int y = indices.Y; y<=indices.Height; y++)
{
entities[x, y].Add(entity);
}
}
}
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))
{
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++)
{
entities[x, y].Remove(entity);
}
}
}
public void Clear()
{
for (int x = 0; x < entities.GetLength(0); x++)
{
for (int y = 0; y < entities.GetLength(1); y++)
{
entities[x, y].Clear();
}
}
}
public List<MapEntity> GetEntities(Vector2 position)
{
if (Submarine.Loaded != null) position -= Submarine.HiddenSubPosition;
if (position.X < limits.X || position.Y > limits.Y ||
position.X > limits.Right || position.Y < limits.Y - limits.Height)
{
return new List<MapEntity>();
}
Point indices = GetIndices(position);
return entities[indices.X, indices.Y];
}
public Rectangle GetIndices(Rectangle rect)
{
Rectangle indices = Rectangle.Empty;
indices.X = (int)Math.Floor((rect.X - limits.X) / cellSize);
indices.Y = (int)Math.Floor((limits.Y - rect.Y)/cellSize);
indices.Width = (int)Math.Floor((rect.Right - limits.X) / cellSize);
indices.Height = (int)Math.Floor((limits.Y - (rect.Y-rect.Height)) / cellSize);
return indices;
}
public Point GetIndices(Vector2 position)
{
return new Point(
(int)Math.Floor((position.X - limits.X) / cellSize),
(int)Math.Floor((limits.Y - position.Y) / cellSize));
}
}
}

View File

@@ -14,6 +14,7 @@ namespace Barotrauma
class Hull : MapEntity
{
public static List<Hull> hullList = new List<Hull>();
private static EntityGrid entityGrid;
public static bool EditWater, EditFire;
@@ -165,9 +166,21 @@ namespace Barotrauma
Volume = 0.0f;
InsertToList();
}
public override void OnMapLoaded()
{
if (entityGrid == null)
{
entityGrid = new EntityGrid(Submarine.Borders, 200.0f);
}
entityGrid.InsertEntity(this);
}
public override bool Contains(Vector2 position)
{
return (Submarine.RectContains(WorldRect, position) &&
@@ -210,6 +223,8 @@ namespace Barotrauma
//renderer.Dispose();
entityGrid.RemoveEntity(this);
hullList.Remove(this);
}
@@ -481,10 +496,30 @@ namespace Barotrauma
//returns the water block which contains the point (or null if it isn't inside any)
public static Hull FindHull(Vector2 position, Hull guess = null, bool useWorldCoordinates = true)
{
return FindHull(position, hullList, guess, useWorldCoordinates);
if (entityGrid == null) return null;
if (guess != null)
{
if (Submarine.RectContains(useWorldCoordinates ? guess.WorldRect : guess.rect, position)) return guess;
}
var entities = entityGrid.GetEntities(useWorldCoordinates ? position-Submarine.Loaded.Position : position);
foreach (Hull hull in entities)
{
if (Submarine.RectContains(useWorldCoordinates ? hull.WorldRect : hull.rect, position)) return hull;
}
return null;
}
public static Hull FindHull(Vector2 position, List<Hull> hulls, Hull guess = null, bool useWorldCoordinates = true)
//returns the water block which contains the point (or null if it isn't inside any)
public static Hull FindHullOld(Vector2 position, Hull guess = null, bool useWorldCoordinates = true)
{
return FindHullOld(position, hullList, guess, useWorldCoordinates);
}
public static Hull FindHullOld(Vector2 position, List<Hull> hulls, Hull guess = null, bool useWorldCoordinates = true)
{
if (guess != null && hulls.Contains(guess))
{

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;

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();
}
}
}

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)
{

View File

@@ -1,16 +1,19 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
namespace Barotrauma.Lights
{
class CachedShadow
class CachedShadow : IDisposable
{
public VertexPositionColor[] ShadowVertices;
public VertexPositionTexture[] PenumbraVertices;
//public VertexPositionColor[] ShadowVertices;
//public VertexPositionTexture[] PenumbraVertices;
public VertexBuffer ShadowBuffer;
public Vector2 LightPos;
@@ -18,14 +21,29 @@ namespace Barotrauma.Lights
public CachedShadow(VertexPositionColor[] shadowVertices, VertexPositionTexture[] penumbraVertices, Vector2 lightPos, int shadowVertexCount, int penumbraVertexCount)
{
ShadowVertices = shadowVertices;
PenumbraVertices = penumbraVertices;
//var ShadowVertices = new VertexPositionColor [shadowVertices.Count()];
//shadowVertices.CopyTo(ShadowVertices, 0);
ShadowBuffer = new VertexBuffer(GameMain.CurrGraphicsDevice, VertexPositionColor.VertexDeclaration, 6*2, BufferUsage.None);
ShadowBuffer.SetData(shadowVertices, 0, shadowVertices.Length);
ShadowVertexCount = shadowVertexCount;
PenumbraVertexCount = penumbraVertexCount;
LightPos = lightPos;
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
ShadowBuffer.Dispose();
}
}
class ConvexHull
@@ -43,9 +61,7 @@ namespace Barotrauma.Lights
private VertexPositionColor[] shadowVertices;
private VertexPositionTexture[] penumbraVertices;
private VertexBuffer shadowBuffer, penumbraBuffer;
int shadowVertexCount;
private Entity parentEntity;
@@ -85,9 +101,6 @@ namespace Barotrauma.Lights
shadowVertices = new VertexPositionColor[6 * 2];
penumbraVertices = new VertexPositionTexture[6];
shadowBuffer = new VertexBuffer(GameMain.CurrGraphicsDevice, VertexPositionColor.VertexDeclaration, 6*2, BufferUsage.WriteOnly);
vertices = points;
primitiveCount = vertices.Length;
@@ -100,7 +113,7 @@ namespace Barotrauma.Lights
list.Add(this);
}
private void CalculateDimensions()
{
Vector2 center = Vector2.Zero;
@@ -225,10 +238,6 @@ namespace Barotrauma.Lights
{
CalculatePenumbraVertices(startingIndex, endingIndex, lightSourcePos, los);
}
else
{
shadowBuffer.SetData(shadowVertices);
}
}
private void CalculatePenumbraVertices(int startingIndex, int endingIndex, Vector2 lightSourcePos, bool los)
@@ -283,21 +292,9 @@ namespace Barotrauma.Lights
(light.Position == cachedShadow.LightPos || Vector2.DistanceSquared(light.Position, cachedShadow.LightPos) < 1.0f))
{
//{
shadowVertices = cachedShadow.ShadowVertices;
penumbraVertices = cachedShadow.PenumbraVertices;
graphicsDevice.SetVertexBuffer(cachedShadow.ShadowBuffer);
shadowVertexCount = cachedShadow.ShadowVertexCount;
//}
//else
//CalculateShadowVertices(light.Position, los);
//cachedShadow.LightPos = light.Position;
//cachedShadow.ShadowVertices = shadowVertices;
//cachedShadow.PenumbraVertices = penumbraVertices;
}
else
{
@@ -309,7 +306,11 @@ namespace Barotrauma.Lights
CalculateShadowVertices(lightPos, los);
if (cachedShadows.ContainsKey(light)) cachedShadows.Remove(light);
if (cachedShadow != null)
{
cachedShadow.Dispose();
cachedShadows.Remove(light);
}
cachedShadow = new CachedShadow(shadowVertices, penumbraVertices, light.Position, shadowVertexCount, 0);
cachedShadows.Add(light, cachedShadow);
}
@@ -339,20 +340,17 @@ namespace Barotrauma.Lights
}
if (shadowVertexCount>0)
{
{
shadowEffect.World = Matrix.CreateTranslation(offset) * transform;
shadowEffect.World = Matrix.CreateTranslation(offset) * transform;
shadowEffect.CurrentTechnique.Passes[0].Apply();
if (los || true)
if (los)
{
shadowEffect.CurrentTechnique.Passes[0].Apply();
graphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleStrip, shadowVertices, 0, shadowVertexCount * 2 - 2);
}
else
{
graphicsDevice.SetVertexBuffer(shadowBuffer);
{
shadowEffect.CurrentTechnique.Passes[0].Apply();
graphicsDevice.DrawPrimitives(PrimitiveType.TriangleStrip, 0, shadowVertexCount);
}
@@ -373,6 +371,12 @@ namespace Barotrauma.Lights
public void Remove()
{
foreach (KeyValuePair<LightSource, CachedShadow> cachedShadow in cachedShadows)
{
cachedShadow.Value.Dispose();
}
cachedShadows.Clear();
list.Remove(this);
}

View File

@@ -63,10 +63,11 @@ namespace Barotrauma.Lights
get { return range; }
set
{
float newRange = MathHelper.Clamp(value, 0.0f, 2048.0f);
if (range == newRange) return;
range = newRange;
float prevRange = range;
range = MathHelper.Clamp(value, 0.0f, 2048.0f);
if (Math.Abs(prevRange - range)<5.0f) return;
UpdateHullsInRange();
}
}

View File

@@ -16,7 +16,7 @@ namespace Barotrauma
//which entities have been selected for editing
protected static List<MapEntity> selectedList = new List<MapEntity>();
protected static GUIComponent editingHUD;
protected static Vector2 selectionPos = Vector2.Zero;
@@ -206,11 +206,6 @@ namespace Barotrauma
/// </summary>
public static void UpdateAll(Camera cam, float deltaTime)
{
foreach (Item item in Item.ItemList)
{
item.Updated = false;
}
foreach (Hull hull in Hull.hullList)
{
hull.Update(cam, deltaTime);

View File

@@ -51,9 +51,7 @@ namespace Barotrauma
Sounds.SoundManager.LowPassHFGain = 1.0f;
}
int rendc;
/// <summary>
/// Allows the game to run logic such as updating the world,
/// checking for collisions, gathering input, and playing audio.
@@ -61,6 +59,39 @@ namespace Barotrauma
/// <param name="gameTime">Provides a snapshot of timing values.</param>
public override void Update(double deltaTime)
{
//if (PlayerInput.KeyHit(Keys.T))
//{
// Stopwatch sw = new Stopwatch();
// sw.Start();
// Rand.SetSyncedSeed(123);
// for (int i = 0; i<10000; i++)
// {
// Hull.FindHull(new Vector2(
// Rand.Range(Submarine.Borders.X, Submarine.Borders.Right, false),
// Rand.Range(Submarine.Borders.Y - Submarine.Borders.Height, Submarine.Borders.Y, false)),
// Hull.hullList[Rand.Int(Hull.hullList.Count-1)], false);
// }
// sw.Stop();
// Debug.WriteLine("FindHull1: "+sw.ElapsedMilliseconds);
// sw.Restart();
// Rand.SetSyncedSeed(123);
// for (int i = 0; i < 10000; i++)
// {
// Hull.FindHull2(new Vector2(
// Rand.Range(Submarine.Borders.X, Submarine.Borders.Right, false),
// Rand.Range(Submarine.Borders.Y - Submarine.Borders.Height, Submarine.Borders.Y, false)),
// Hull.hullList[Rand.Int(Hull.hullList.Count - 1)], false);
// }
// sw.Stop();
// Debug.WriteLine("FindHull2: " + sw.ElapsedMilliseconds);
// var askdnkjd = 1;
//}
//the accumulator code is based on this article:
//http://gafferongames.com/game-physics/fix-your-timestep/
Physics.accumulator += deltaTime;