diff --git a/.vs/Subsurface_Solution/v14/.suo b/.vs/Subsurface_Solution/v14/.suo index 7133c7cba..1f2cb3603 100644 Binary files a/.vs/Subsurface_Solution/v14/.suo and b/.vs/Subsurface_Solution/v14/.suo differ diff --git a/Farseer Physics Engine 3.5/Collision/Shapes/ChainShape.cs b/Farseer Physics Engine 3.5/Collision/Shapes/ChainShape.cs index cd41b43ff..46750381b 100644 --- a/Farseer Physics Engine 3.5/Collision/Shapes/ChainShape.cs +++ b/Farseer Physics Engine 3.5/Collision/Shapes/ChainShape.cs @@ -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); } diff --git a/Subsurface/Barotrauma.csproj b/Subsurface/Barotrauma.csproj index 20f9cf499..6e0167f44 100644 --- a/Subsurface/Barotrauma.csproj +++ b/Subsurface/Barotrauma.csproj @@ -114,6 +114,7 @@ + diff --git a/Subsurface/Source/Items/Components/ItemComponent.cs b/Subsurface/Source/Items/Components/ItemComponent.cs index 90658eb4a..4d16074e7 100644 --- a/Subsurface/Source/Items/Components/ItemComponent.cs +++ b/Subsurface/Source/Items/Components/ItemComponent.cs @@ -61,7 +61,7 @@ namespace Barotrauma.Items.Components public List requiredSkills; - private List sounds; + private Dictionary> sounds; private GUIFrame guiFrame; @@ -175,7 +175,7 @@ namespace Barotrauma.Items.Components requiredSkills = new List(); - sounds = new List(); + sounds = new Dictionary>(); statusEffects = new List(); @@ -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 soundList = null; + if (!sounds.TryGetValue(itemSound.Type, out soundList)) + { + soundList = new List(); + 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 matchingSounds = sounds.FindAll(x => x.Type == type); - if (matchingSounds.Count == 0) return; + + List matchingSounds = null; + if (!sounds.TryGetValue(type, out matchingSounds)) return; ItemSound itemSound = null; if (!Sounds.SoundManager.IsPlaying(loopingSoundIndex)) diff --git a/Subsurface/Source/Items/Components/Power/PowerTransfer.cs b/Subsurface/Source/Items/Components/Power/PowerTransfer.cs index c011bb4c6..6e9db3461 100644 --- a/Subsurface/Source/Items/Components/Power/PowerTransfer.cs +++ b/Subsurface/Source/Items/Components/Power/PowerTransfer.cs @@ -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(); - 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; diff --git a/Subsurface/Source/Items/Inventory.cs b/Subsurface/Source/Items/Inventory.cs index d492816ec..40e1a6f8a 100644 --- a/Subsurface/Source/Items/Inventory.cs +++ b/Subsurface/Source/Items/Inventory.cs @@ -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, diff --git a/Subsurface/Source/Items/Item.cs b/Subsurface/Source/Items/Item.cs index 571049dd7..3dc2cb2c3 100644 --- a/Subsurface/Source/Items/Item.cs +++ b/Subsurface/Source/Items/Item.cs @@ -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; } diff --git a/Subsurface/Source/Map/EntityGrid.cs b/Subsurface/Source/Map/EntityGrid.cs new file mode 100644 index 000000000..0f433902a --- /dev/null +++ b/Subsurface/Source/Map/EntityGrid.cs @@ -0,0 +1,115 @@ +using Microsoft.Xna.Framework; +using System; +using System.Collections.Generic; + +namespace Barotrauma +{ + class EntityGrid + { + private List[,] entities; + + private Rectangle limits; + + private float cellSize; + + public EntityGrid(Rectangle limits, float cellSize) + { + this.limits = limits; + this.cellSize = cellSize; + + entities = new List[(int)Math.Ceiling(limits.Width / cellSize),(int)Math.Ceiling(limits.Height / cellSize)]; + for (int x = 0; x(); + } + } + } + + 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 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(); + } + + 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)); + } + } +} diff --git a/Subsurface/Source/Map/Hull.cs b/Subsurface/Source/Map/Hull.cs index ef7ce7eb7..af0969fc0 100644 --- a/Subsurface/Source/Map/Hull.cs +++ b/Subsurface/Source/Map/Hull.cs @@ -14,6 +14,7 @@ namespace Barotrauma class Hull : MapEntity { public static List hullList = new List(); + 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 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 hulls, Hull guess = null, bool useWorldCoordinates = true) { if (guess != null && hulls.Contains(guess)) { diff --git a/Subsurface/Source/Map/Levels/Level.cs b/Subsurface/Source/Map/Levels/Level.cs index dface1f80..632c7257f 100644 --- a/Subsurface/Source/Map/Levels/Level.cs +++ b/Subsurface/Source/Map/Levels/Level.cs @@ -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(), false); - wrappingWalls[side, i].WallVertices = GenerateWallShapes(wrappingWalls[side, i].Cells); + wrappingWalls[side, i].SetBodyVertices(GeneratePolygons(wrappingWalls[side, i].Cells, new List(), 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; diff --git a/Subsurface/Source/Map/Levels/LevelRenderer.cs b/Subsurface/Source/Map/Levels/LevelRenderer.cs index c50a12918..d58ecafa9 100644 --- a/Subsurface/Source/Map/Levels/LevelRenderer.cs +++ b/Subsurface/Source/Map/Levels/LevelRenderer.cs @@ -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(); + } + } } diff --git a/Subsurface/Source/Map/Levels/WrappingWall.cs b/Subsurface/Source/Map/Levels/WrappingWall.cs index 5a8db2df9..e4e2fa020 100644 --- a/Subsurface/Source/Map/Levels/WrappingWall.cs +++ b/Subsurface/Source/Map/Levels/WrappingWall.cs @@ -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 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) { diff --git a/Subsurface/Source/Map/Lights/ConvexHull.cs b/Subsurface/Source/Map/Lights/ConvexHull.cs index 79c02e66d..f009f7f9d 100644 --- a/Subsurface/Source/Map/Lights/ConvexHull.cs +++ b/Subsurface/Source/Map/Lights/ConvexHull.cs @@ -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 cachedShadow in cachedShadows) + { + cachedShadow.Value.Dispose(); + } + cachedShadows.Clear(); + list.Remove(this); } diff --git a/Subsurface/Source/Map/Lights/LightSource.cs b/Subsurface/Source/Map/Lights/LightSource.cs index b3818648f..5bf53393c 100644 --- a/Subsurface/Source/Map/Lights/LightSource.cs +++ b/Subsurface/Source/Map/Lights/LightSource.cs @@ -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(); } } diff --git a/Subsurface/Source/Map/MapEntity.cs b/Subsurface/Source/Map/MapEntity.cs index eada87ff6..a8ef403dd 100644 --- a/Subsurface/Source/Map/MapEntity.cs +++ b/Subsurface/Source/Map/MapEntity.cs @@ -16,7 +16,7 @@ namespace Barotrauma //which entities have been selected for editing protected static List selectedList = new List(); - + protected static GUIComponent editingHUD; protected static Vector2 selectionPos = Vector2.Zero; @@ -206,11 +206,6 @@ namespace Barotrauma /// 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); diff --git a/Subsurface/Source/Screens/GameScreen.cs b/Subsurface/Source/Screens/GameScreen.cs index c1b7e4855..1c1bb5bb2 100644 --- a/Subsurface/Source/Screens/GameScreen.cs +++ b/Subsurface/Source/Screens/GameScreen.cs @@ -51,9 +51,7 @@ namespace Barotrauma Sounds.SoundManager.LowPassHFGain = 1.0f; } - - int rendc; - + /// /// 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 /// Provides a snapshot of timing values. 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;