diff --git a/.vs/Subsurface_Solution/v14/.suo b/.vs/Subsurface_Solution/v14/.suo index 26232258c..37658a661 100644 Binary files a/.vs/Subsurface_Solution/v14/.suo and b/.vs/Subsurface_Solution/v14/.suo differ diff --git a/Subsurface/Source/Items/Components/Signal/Connection.cs b/Subsurface/Source/Items/Components/Signal/Connection.cs index 1f41d7b6a..60bde8f79 100644 --- a/Subsurface/Source/Items/Components/Signal/Connection.cs +++ b/Subsurface/Source/Items/Components/Signal/Connection.cs @@ -30,6 +30,8 @@ namespace Barotrauma.Items.Components public readonly ushort[] wireId; + private List recipients; + public bool IsPower { get; @@ -38,17 +40,7 @@ namespace Barotrauma.Items.Components public List Recipients { - get - { - List recipients = new List(); - for (int i = 0; i(); + IsOutput = (element.Name.ToString() == "output"); Name = ToolBox.GetAttributeString(element, "name", (IsOutput) ? "output" : "input"); @@ -140,6 +134,18 @@ namespace Barotrauma.Items.Components //linked[index] = connectedItem; //recipient[index] = otherConnection; Wires[index] = wire; + UpdateRecipients(); + } + + public void UpdateRecipients() + { + recipients.Clear(); + for (int i = 0; i < MaxLinked; i++) + { + if (Wires[i] == null) continue; + Connection recipient = Wires[i].OtherConnection(this); + if (recipient != null) recipients.Add(recipient); + } } public void SendSignal(string signal, Item sender, float power) @@ -175,6 +181,8 @@ namespace Barotrauma.Items.Components Wires[i].RemoveConnection(this); Wires[i] = null; } + + recipients.Clear(); } @@ -460,6 +468,8 @@ namespace Barotrauma.Items.Components } } + UpdateRecipients(); + //wireId = null; } diff --git a/Subsurface/Source/Items/Components/Signal/ConnectionPanel.cs b/Subsurface/Source/Items/Components/Signal/ConnectionPanel.cs index 06a5cb5cb..4f1b81a86 100644 --- a/Subsurface/Source/Items/Components/Signal/ConnectionPanel.cs +++ b/Subsurface/Source/Items/Components/Signal/ConnectionPanel.cs @@ -162,6 +162,7 @@ namespace Barotrauma.Items.Components c.Wires[i] = wireComponent; wireComponent.Connect(c, false); } + c.UpdateRecipients(); } } } diff --git a/Subsurface/Source/Items/Components/Signal/Wire.cs b/Subsurface/Source/Items/Components/Signal/Wire.cs index eb0fb6f54..593668fbd 100644 --- a/Subsurface/Source/Items/Components/Signal/Wire.cs +++ b/Subsurface/Source/Items/Components/Signal/Wire.cs @@ -41,10 +41,10 @@ namespace Barotrauma.Items.Components public override void Move(Vector2 amount) { - for (int i = 0; i < Nodes.Count; i++) - { - Nodes[i] += amount; - } + //for (int i = 0; i < Nodes.Count; i++) + //{ + // Nodes[i] += amount; + //} } public Connection OtherConnection(Connection connection) @@ -64,7 +64,10 @@ namespace Barotrauma.Items.Components for (int n = 0; n< connections[i].Wires.Length; n++) { - if (connections[i].Wires[n] == this) connections[i].Wires[n] = null; + if (connections[i].Wires[n] != this) continue; + + connections[i].Wires[n] = null; + connections[i].UpdateRecipients(); } connections[i] = null; } @@ -290,7 +293,7 @@ namespace Barotrauma.Items.Components } - public override void Draw(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch, bool editing) + public override void Draw(SpriteBatch spriteBatch, bool editing) { if (Nodes.Count == 0) return; @@ -369,8 +372,8 @@ namespace Barotrauma.Items.Components { if (item.Submarine!=null) { - start += item.Submarine.DrawPosition; - end += item.Submarine.DrawPosition; + start += item.Submarine.DrawPosition+Submarine.HiddenSubPosition; + end += item.Submarine.DrawPosition+Submarine.HiddenSubPosition; } start.Y = -start.Y; diff --git a/Subsurface/Source/Map/EntityGrid.cs b/Subsurface/Source/Map/EntityGrid.cs index 0f433902a..679ee9098 100644 --- a/Subsurface/Source/Map/EntityGrid.cs +++ b/Subsurface/Source/Map/EntityGrid.cs @@ -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); } } } diff --git a/Subsurface/Source/Map/Levels/LevelRenderer.cs b/Subsurface/Source/Map/Levels/LevelRenderer.cs index d58ecafa9..7e07bc8d3 100644 --- a/Subsurface/Source/Map/Levels/LevelRenderer.cs +++ b/Subsurface/Source/Map/Levels/LevelRenderer.cs @@ -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() diff --git a/Subsurface/Source/Map/Lights/ConvexHull.cs b/Subsurface/Source/Map/Lights/ConvexHull.cs index f009f7f9d..adba60532 100644 --- a/Subsurface/Source/Map/Lights/ConvexHull.cs +++ b/Subsurface/Source/Map/Lights/ConvexHull.cs @@ -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); } diff --git a/Subsurface/Source/Map/Lights/LightManager.cs b/Subsurface/Source/Map/Lights/LightManager.cs index 5dd00f0ce..f69cff20c 100644 --- a/Subsurface/Source/Map/Lights/LightManager.cs +++ b/Subsurface/Source/Map/Lights/LightManager.cs @@ -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;