diff --git a/Subsurface/Source/Characters/Animation/Ragdoll.cs b/Subsurface/Source/Characters/Animation/Ragdoll.cs index 4aed729b1..df15807d7 100644 --- a/Subsurface/Source/Characters/Animation/Ragdoll.cs +++ b/Subsurface/Source/Characters/Animation/Ragdoll.cs @@ -1053,6 +1053,8 @@ namespace Barotrauma private void UpdateNetPlayerPosition(float deltaTime) { + if (GameMain.NetworkMember == null) return; + if (character == GameMain.NetworkMember.Character) { if (character.MemPos.Count < 2) return; diff --git a/Subsurface/Source/Characters/CharacterHUD.cs b/Subsurface/Source/Characters/CharacterHUD.cs index 37e0a3319..179d1fbea 100644 --- a/Subsurface/Source/Characters/CharacterHUD.cs +++ b/Subsurface/Source/Characters/CharacterHUD.cs @@ -18,7 +18,7 @@ namespace Barotrauma private static GUIProgressBar drowningBar, healthBar; - private static float damageOverlayTimer; + public static float damageOverlayTimer { get; private set; } public static void Reset() { @@ -49,9 +49,24 @@ namespace Barotrauma if (!character.IsUnconscious && character.Stun <= 0.0f) { - if (character.Inventory != null && !character.LockHands && character.Stun >= -0.1f) + + if (character.Inventory != null) { - character.Inventory.Update(deltaTime); + if (!character.LockHands && character.Stun >= -0.1f) + { + character.Inventory.Update(deltaTime); + } + + for (int i = 0; i < character.Inventory.Items.Length - 1; i++) + { + var item = character.Inventory.Items[i]; + if (item == null || CharacterInventory.limbSlots[i] == InvSlotType.Any) continue; + + foreach (ItemComponent ic in item.components) + { + if (ic.DrawHudWhenEquipped) ic.UpdateHUD(character); + } + } } if (character.SelectedCharacter != null && character.SelectedCharacter.Inventory != null) @@ -80,12 +95,11 @@ namespace Barotrauma if (character.Inventory != null) { - for (int i = 0; i< character.Inventory.Items.Length-1; i++) + for (int i = 0; i < character.Inventory.Items.Length - 1; i++) { var item = character.Inventory.Items[i]; - if (item == null || CharacterInventory.limbSlots[i]==InvSlotType.Any) continue; - //var statusHUD = item.GetComponent(); - //if (statusHUD == null) continue; + if (item == null || CharacterInventory.limbSlots[i] == InvSlotType.Any) continue; + foreach (ItemComponent ic in item.components) { if (ic.DrawHudWhenEquipped) ic.DrawHUD(spriteBatch, character); diff --git a/Subsurface/Source/Items/Item.cs b/Subsurface/Source/Items/Item.cs index 29caafe50..856681e8a 100644 --- a/Subsurface/Source/Items/Item.cs +++ b/Subsurface/Source/Items/Item.cs @@ -872,13 +872,12 @@ namespace Barotrauma prefab.sprite.effects = oldEffects; - for (int i = 0; i < drawableComponents.Count; i++ ) + List staticDrawableComponents = new List(drawableComponents); //static list to compensate for drawable toggling + for (int i = 0; i < staticDrawableComponents.Count; i++) { - drawableComponents[i].Draw(spriteBatch, editing); + staticDrawableComponents[i].Draw(spriteBatch, editing); } - //foreach (ItemComponent component in components) component.Draw(spriteBatch, editing); - if (GameMain.DebugDraw && aiTarget!=null) aiTarget.Draw(spriteBatch); if (!editing || (body != null && !body.Enabled)) diff --git a/Subsurface/Source/Map/Levels/CaveGenerator.cs b/Subsurface/Source/Map/Levels/CaveGenerator.cs index 7f68a6a0a..539cb595c 100644 --- a/Subsurface/Source/Map/Levels/CaveGenerator.cs +++ b/Subsurface/Source/Map/Levels/CaveGenerator.cs @@ -419,9 +419,12 @@ namespace Barotrauma for (int i = 0; i < triangles.Count; i++) { - if (triangles[i][0].Y == triangles[i][1].Y && triangles[i][0].Y == triangles[i][2].Y) continue; - if (triangles[i][0].X == triangles[i][1].X && triangles[i][0].X == triangles[i][2].X) continue; - + //don't create a triangle if any of the vertices are too close to each other + //(apparently Farseer doesn't like polygons with a very small area, see Shape.ComputeProperties) + if (Vector2.Distance(triangles[i][0], triangles[i][1]) < 0.05f || + Vector2.Distance(triangles[i][0], triangles[i][2]) < 0.05f || + Vector2.Distance(triangles[i][1], triangles[i][2]) < 0.05f) continue; + Vertices bodyVertices = new Vertices(triangles[i]); FixtureFactory.AttachPolygon(bodyVertices, 5.0f, cellBody); } diff --git a/Subsurface/Source/Map/Lights/LightManager.cs b/Subsurface/Source/Map/Lights/LightManager.cs index 71d658f7b..3fd45ac65 100644 --- a/Subsurface/Source/Map/Lights/LightManager.cs +++ b/Subsurface/Source/Map/Lights/LightManager.cs @@ -366,15 +366,15 @@ namespace Barotrauma.Lights spriteBatch.End(); } - public void DrawLOS(SpriteBatch spriteBatch, Effect effect) + public void DrawLOS(SpriteBatch spriteBatch, Effect effect,bool renderingBackground) { if (!LosEnabled || ViewTarget == null) return; - - spriteBatch.Begin(SpriteSortMode.Deferred, CustomBlendStates.Multiplicative, null, null, null, effect); + + spriteBatch.Begin(SpriteSortMode.Deferred, renderingBackground ? CustomBlendStates.LOS : CustomBlendStates.Multiplicative, null, null, null, effect); spriteBatch.Draw(losTexture, Vector2.Zero, Color.White); spriteBatch.End(); - ObstructVision = false; + if (!renderingBackground) ObstructVision = false; } public void ClearLights() @@ -399,10 +399,16 @@ namespace Barotrauma.Lights MultiplyWithAlpha = new BlendState(); MultiplyWithAlpha.ColorDestinationBlend = MultiplyWithAlpha.AlphaDestinationBlend = Blend.One; MultiplyWithAlpha.ColorSourceBlend = MultiplyWithAlpha.AlphaSourceBlend = Blend.DestinationAlpha; + + LOS = new BlendState(); + LOS.ColorSourceBlend = LOS.AlphaSourceBlend = Blend.Zero; + LOS.ColorDestinationBlend = LOS.AlphaDestinationBlend = Blend.InverseSourceColor; + LOS.ColorBlendFunction = LOS.AlphaBlendFunction = BlendFunction.Add; } public static BlendState Multiplicative { get; private set; } public static BlendState WriteToAlpha { get; private set; } public static BlendState MultiplyWithAlpha { get; private set; } + public static BlendState LOS { get; private set; } } } diff --git a/Subsurface/Source/Map/MapEntityPrefab.cs b/Subsurface/Source/Map/MapEntityPrefab.cs index d3f12afdc..7f6dacd67 100644 --- a/Subsurface/Source/Map/MapEntityPrefab.cs +++ b/Subsurface/Source/Map/MapEntityPrefab.cs @@ -31,9 +31,9 @@ namespace Barotrauma protected ConstructorInfo constructor; //is it possible to stretch the entity horizontally/vertically - protected bool resizeHorizontal; - protected bool resizeVertical; - + public bool resizeHorizontal { get; protected set; } + public bool resizeVertical { get; protected set; } + //which prefab has been selected for placing protected static MapEntityPrefab selected; diff --git a/Subsurface/Source/Map/Structure.cs b/Subsurface/Source/Map/Structure.cs index 6bb331613..8ac9d3862 100644 --- a/Subsurface/Source/Map/Structure.cs +++ b/Subsurface/Source/Map/Structure.cs @@ -67,6 +67,16 @@ namespace Barotrauma public SpriteEffects SpriteEffects = SpriteEffects.None; + public bool resizeHorizontal + { + get { return prefab.resizeHorizontal; } + } + + public bool resizeVertical + { + get { return prefab.resizeVertical; } + } + private bool flippedX; public override Sprite Sprite diff --git a/Subsurface/Source/Map/Submarine.cs b/Subsurface/Source/Map/Submarine.cs index b5ea26be9..66c154c22 100644 --- a/Subsurface/Source/Map/Submarine.cs +++ b/Subsurface/Source/Map/Submarine.cs @@ -317,15 +317,23 @@ namespace Barotrauma if (MapEntity.mapEntityList[i].DrawDamageEffect) MapEntity.mapEntityList[i].DrawDamage(spriteBatch, damageEffect); } - damageEffect.Parameters["aCutoff"].SetValue(0.0f); - damageEffect.Parameters["cCutoff"].SetValue(0.0f); + if (damageEffect != null) + { + damageEffect.Parameters["aCutoff"].SetValue(0.0f); + damageEffect.Parameters["cCutoff"].SetValue(0.0f); + } } - public static void DrawBack(SpriteBatch spriteBatch, bool editing = false) + public static void DrawBack(SpriteBatch spriteBatch, bool editing = false, Predicate predicate = null) { for (int i = 0; i < MapEntity.mapEntityList.Count; i++) { + if (predicate != null) + { + if (!predicate(MapEntity.mapEntityList[i])) continue; + } + if (MapEntity.mapEntityList[i].DrawBelowWater) MapEntity.mapEntityList[i].Draw(spriteBatch, editing, true); } diff --git a/Subsurface/Source/Screens/GameScreen.cs b/Subsurface/Source/Screens/GameScreen.cs index c91b2ea56..33a18eb87 100644 --- a/Subsurface/Source/Screens/GameScreen.cs +++ b/Subsurface/Source/Screens/GameScreen.cs @@ -12,6 +12,7 @@ namespace Barotrauma { Camera cam; + readonly RenderTarget2D renderTargetBackground; readonly RenderTarget2D renderTarget; readonly RenderTarget2D renderTargetWater; readonly RenderTarget2D renderTargetAir; @@ -33,7 +34,8 @@ namespace Barotrauma { cam = new Camera(); cam.Translate(new Vector2(-10.0f, 50.0f)); - + + renderTargetBackground = new RenderTarget2D(graphics, GameMain.GraphicsWidth, GameMain.GraphicsHeight); renderTarget = new RenderTarget2D(graphics, GameMain.GraphicsWidth, GameMain.GraphicsHeight); renderTargetWater = new RenderTarget2D(graphics, GameMain.GraphicsWidth, GameMain.GraphicsHeight); renderTargetAir = new RenderTarget2D(graphics, GameMain.GraphicsWidth, GameMain.GraphicsHeight); @@ -223,7 +225,7 @@ namespace Barotrauma //1. draw the background, characters and the parts of the submarine that are behind them //---------------------------------------------------------------------------------------- - graphics.SetRenderTarget(renderTarget); + graphics.SetRenderTarget(renderTargetBackground); if (Level.Loaded == null) { @@ -239,7 +241,23 @@ namespace Barotrauma null, null, null, null, cam.Transform); - Submarine.DrawBack(spriteBatch); + Submarine.DrawBack(spriteBatch,false,s => s is Structure && ((s as Structure).resizeHorizontal || (s as Structure).resizeVertical)); + + spriteBatch.End(); + + graphics.SetRenderTarget(renderTarget); + + spriteBatch.Begin(SpriteSortMode.Deferred, + BlendState.Opaque); + spriteBatch.Draw(renderTargetBackground, new Rectangle(0, 0, GameMain.GraphicsWidth, GameMain.GraphicsHeight), Color.White); + spriteBatch.End(); + + spriteBatch.Begin(SpriteSortMode.BackToFront, + BlendState.AlphaBlend, + null, null, null, null, + cam.Transform); + + Submarine.DrawBack(spriteBatch, false, s => (!(s is Structure)) || (!(s as Structure).resizeHorizontal && !(s as Structure).resizeHorizontal)); foreach (Character c in Character.CharacterList) c.Draw(spriteBatch); @@ -305,6 +323,25 @@ namespace Barotrauma GameMain.ParticleManager.Draw(spriteBatch, false, Particles.ParticleBlendState.Additive); spriteBatch.End(); + if (Character.Controlled != null && GameMain.LightManager.LosEnabled) + { + graphics.SetRenderTarget(renderTarget); + spriteBatch.Begin(SpriteSortMode.Deferred, + BlendState.Opaque, null, null, null, lightBlur.Effect); + spriteBatch.Draw(renderTargetBackground, new Rectangle(0, 0, GameMain.GraphicsWidth, GameMain.GraphicsHeight), Color.White); + spriteBatch.End(); + + spriteBatch.Begin(SpriteSortMode.BackToFront, + BlendState.AlphaBlend, SamplerState.LinearWrap, + null, null, null, + cam.Transform); + Submarine.DrawDamageable(spriteBatch, null); + spriteBatch.End(); + + GameMain.LightManager.DrawLightMap(spriteBatch, lightBlur.Effect); + + GameMain.LightManager.DrawLOS(spriteBatch, lightBlur.Effect, true); + } graphics.SetRenderTarget(null); @@ -359,9 +396,17 @@ namespace Barotrauma spriteBatch.End(); - if (Character.Controlled != null) + if (Character.Controlled != null && GameMain.LightManager.LosEnabled) { - GameMain.LightManager.DrawLOS(spriteBatch, lightBlur.Effect); + GameMain.LightManager.DrawLOS(spriteBatch, lightBlur.Effect,false); + + spriteBatch.Begin(SpriteSortMode.Immediate, + BlendState.AlphaBlend); + float r = Math.Min(CharacterHUD.damageOverlayTimer * 0.5f, 0.5f); + spriteBatch.Draw(renderTarget, new Rectangle(0, 0, GameMain.GraphicsWidth, GameMain.GraphicsHeight), + Color.Lerp(new Color(0.1f, 0.1f, 0.1f), Color.Red, r)); + + spriteBatch.End(); } }