From 39c31b10f50d30175494e32a21bfbc4b5d0773c5 Mon Sep 17 00:00:00 2001 From: Regalis Date: Sun, 9 Oct 2016 14:17:22 +0300 Subject: [PATCH 1/9] Fixed child rects not being updated when modifying GUIButton or GUITickBox rects --- Subsurface/Source/GUI/GUIButton.cs | 3 ++- Subsurface/Source/GUI/GUITickBox.cs | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Subsurface/Source/GUI/GUIButton.cs b/Subsurface/Source/GUI/GUIButton.cs index f755578f7..c96f149bd 100644 --- a/Subsurface/Source/GUI/GUIButton.cs +++ b/Subsurface/Source/GUI/GUIButton.cs @@ -124,9 +124,10 @@ namespace Barotrauma } set { + base.Rect = value; + frame.Rect = new Rectangle(value.X, value.Y, frame.Rect.Width, frame.Rect.Height); textBlock.Rect = value; - rect = value; } } diff --git a/Subsurface/Source/GUI/GUITickBox.cs b/Subsurface/Source/GUI/GUITickBox.cs index 6a4417250..4421ef9c9 100644 --- a/Subsurface/Source/GUI/GUITickBox.cs +++ b/Subsurface/Source/GUI/GUITickBox.cs @@ -48,9 +48,10 @@ namespace Barotrauma } set { + base.Rect = value; + box.Rect = new Rectangle(value.X,value.Y,box.Rect.Width,box.Rect.Height); text.Rect = new Rectangle(box.Rect.Right + 10, box.Rect.Y + 2, 20, box.Rect.Height); - rect = value; } } From e720fa366c2451bee7dc30d657537df1fe4ddad3 Mon Sep 17 00:00:00 2001 From: Regalis Date: Sun, 9 Oct 2016 15:12:57 +0300 Subject: [PATCH 2/9] Timing.Alpha isn't updated when the game is paused (-> no "twitching" when the pause menu is open), moved water scrolling and surface lerping from draw method to update --- Subsurface/Source/GameMain.cs | 6 ++--- Subsurface/Source/Map/Hull.cs | 30 +++++-------------------- Subsurface/Source/Map/Levels/Level.cs | 5 +++++ Subsurface/Source/Screens/GameScreen.cs | 7 ------ 4 files changed, 13 insertions(+), 35 deletions(-) diff --git a/Subsurface/Source/GameMain.cs b/Subsurface/Source/GameMain.cs index d11b0f9a2..b9ad84ce6 100644 --- a/Subsurface/Source/GameMain.cs +++ b/Subsurface/Source/GameMain.cs @@ -292,6 +292,8 @@ namespace Barotrauma { Timing.Accumulator += gameTime.ElapsedGameTime.TotalSeconds; + bool paused = false; + while (Timing.Accumulator >= Timing.Step) { fixedTime.IsRunningSlowly = gameTime.IsRunningSlowly; @@ -302,8 +304,6 @@ namespace Barotrauma PlayerInput.Update(Timing.Step); - bool paused = false; - if (titleScreenOpen) { if (TitleScreen.LoadState >= 100.0f && @@ -342,7 +342,7 @@ namespace Barotrauma Timing.Accumulator -= Timing.Step; } - Timing.Alpha = Timing.Accumulator / Timing.Step; + if (!paused) Timing.Alpha = Timing.Accumulator / Timing.Step; } diff --git a/Subsurface/Source/Map/Hull.cs b/Subsurface/Source/Map/Hull.cs index 62f5ddcdd..9474d9430 100644 --- a/Subsurface/Source/Map/Hull.cs +++ b/Subsurface/Source/Map/Hull.cs @@ -403,17 +403,7 @@ namespace Barotrauma foreach (Gap gap in ConnectedGaps) { float gapFlow = gap.LerpedFlowForce.Length(); - -#if DEBUG - var asd = MapEntity.FindEntityByID(gap.ID); - - if (asd != gap) - { - int adslkmfdlasfk = 9; - } -#endif - - + if (gapFlow > strongestFlow) { strongestFlow = gapFlow; @@ -492,11 +482,9 @@ namespace Barotrauma waveVel[i] = waveVel[i] * -0.5f; } - //acceleration float a = -WaveStiffness * waveY[i] - waveVel[i] * WaveDampening; waveVel[i] = waveVel[i] + a; - } for (int j = 0; j < 2; j++) @@ -517,6 +505,9 @@ namespace Barotrauma } } + //interpolate the position of the rendered surface towards the "target surface" + surface = MathHelper.Lerp(surface, surfaceY, deltaTime*10.0f); + if (volume < FullVolume) { LethalPressure -= 10.0f * deltaTime; @@ -608,15 +599,7 @@ namespace Barotrauma isHighlighted ? Color.LightBlue*0.5f : Color.Red*0.5f, true,0, (int)Math.Max((1.5f / GameScreen.Selected.Cam.Zoom), 1.0f)); } } - - private float GetSurfaceY() - { - float top = rect.Y + Submarine.DrawPosition.Y; - float bottom = top - rect.Height; - - return bottom + Volume / rect.Width; - } - + public void Render(GraphicsDevice graphicsDevice, Camera cam) { if (renderer.PositionInBuffer > renderer.vertices.Length - 6) return; @@ -626,10 +609,7 @@ namespace Barotrauma //calculate where the surface should be based on the water volume float top = rect.Y + submarinePos.Y; float bottom = top - rect.Height; - float surfaceY = bottom + Volume / rect.Width; - //interpolate the position of the rendered surface towards the "target surface" - surface = surface + ((surfaceY - submarinePos.Y) - surface) / 10.0f; float drawSurface = surface + submarinePos.Y; Matrix transform = cam.Transform * Matrix.CreateOrthographic(GameMain.GraphicsWidth, GameMain.GraphicsHeight, -1, 1) * 0.5f; diff --git a/Subsurface/Source/Map/Levels/Level.cs b/Subsurface/Source/Map/Levels/Level.cs index f5ae51cea..c3adb7194 100644 --- a/Subsurface/Source/Map/Levels/Level.cs +++ b/Subsurface/Source/Map/Levels/Level.cs @@ -814,6 +814,11 @@ namespace Barotrauma WrappingWall.UpdateWallShift(Submarine.MainSub.WorldPosition, wrappingWalls); } + if (Hull.renderer != null) + { + Hull.renderer.ScrollWater((float)deltaTime); + } + renderer.Update(deltaTime); } diff --git a/Subsurface/Source/Screens/GameScreen.cs b/Subsurface/Source/Screens/GameScreen.cs index 3dfcc9889..aa1bd038d 100644 --- a/Subsurface/Source/Screens/GameScreen.cs +++ b/Subsurface/Source/Screens/GameScreen.cs @@ -166,13 +166,6 @@ namespace Barotrauma { cam.UpdateTransform(true); - if (Hull.renderer != null) - { - Hull.renderer.ScrollWater((float)deltaTime); - } - - //damageStencil = TextureLoader.FromFile("Content/Map/background.png"); - DrawMap(graphics, spriteBatch); spriteBatch.Begin(); From f4c5c5e542b40d7207b628225eb609844e6e0a88 Mon Sep 17 00:00:00 2001 From: Regalis Date: Sun, 9 Oct 2016 15:13:41 +0300 Subject: [PATCH 3/9] Added a particle trail to railgun shells --- Subsurface/Content/Items/Weapons/railgun.xml | 9 +++++++++ .../Source/Items/Components/Projectile.cs | 6 ++++++ Subsurface/Source/Map/Map/Map.cs | 5 +++++ .../Source/Particles/ParticleEmitter.cs | 20 ++++++++++++++++++- 4 files changed, 39 insertions(+), 1 deletion(-) diff --git a/Subsurface/Content/Items/Weapons/railgun.xml b/Subsurface/Content/Items/Weapons/railgun.xml index 3540372e6..5d5922029 100644 --- a/Subsurface/Content/Items/Weapons/railgun.xml +++ b/Subsurface/Content/Items/Weapons/railgun.xml @@ -82,6 +82,10 @@ + + + + @@ -110,9 +114,14 @@ + + + + + diff --git a/Subsurface/Source/Items/Components/Projectile.cs b/Subsurface/Source/Items/Components/Projectile.cs index b9a173a0a..06571e940 100644 --- a/Subsurface/Source/Items/Components/Projectile.cs +++ b/Subsurface/Source/Items/Components/Projectile.cs @@ -88,6 +88,8 @@ namespace Barotrauma.Items.Components item.body.CollisionCategories = Physics.CollisionProjectile; item.body.CollidesWith = Physics.CollisionCharacter | Physics.CollisionWall | Physics.CollisionLevel; + IsActive = true; + if (stickJoint == null || !doesStick) return; if (stickTarget != null) @@ -111,6 +113,8 @@ namespace Barotrauma.Items.Components public override void Update(float deltaTime, Camera cam) { + ApplyStatusEffects(ActionType.OnActive, deltaTime, null); + if (stickJoint != null && stickJoint.JointTranslation < 0.01f) { if (stickTarget != null) @@ -174,6 +178,8 @@ namespace Barotrauma.Items.Components ApplyStatusEffects(ActionType.OnUse, 1.0f); ApplyStatusEffects(ActionType.OnImpact, 1.0f); + IsActive = false; + item.body.FarseerBody.OnCollision -= OnProjectileCollision; item.body.FarseerBody.IsBullet = false; diff --git a/Subsurface/Source/Map/Map/Map.cs b/Subsurface/Source/Map/Map/Map.cs index a15b19bea..64eae3e71 100644 --- a/Subsurface/Source/Map/Map/Map.cs +++ b/Subsurface/Source/Map/Map/Map.cs @@ -309,6 +309,11 @@ namespace Barotrauma { crackColor = Color.Red; } + else if (highlightedLocation != currentLocation && + (connection.Locations.Contains(highlightedLocation) && connection.Locations.Contains(currentLocation))) + { + crackColor = Color.Red * 0.5f; + } else if (!connection.Passed) { crackColor *= 0.2f; diff --git a/Subsurface/Source/Particles/ParticleEmitter.cs b/Subsurface/Source/Particles/ParticleEmitter.cs index 593f9abc5..3defc25f0 100644 --- a/Subsurface/Source/Particles/ParticleEmitter.cs +++ b/Subsurface/Source/Particles/ParticleEmitter.cs @@ -15,6 +15,8 @@ namespace Barotrauma.Particles public readonly float VelocityMin, VelocityMax; + public readonly float ScaleMin, ScaleMax; + public readonly float ParticleAmount; public ParticleEmitterPrefab(XElement element) @@ -37,6 +39,17 @@ namespace Barotrauma.Particles AngleMin = MathHelper.ToRadians(AngleMin); AngleMax = MathHelper.ToRadians(AngleMax); + if (element.Attribute("scalemin")==null) + { + ScaleMin = 1.0f; + ScaleMax = 1.0f; + } + else + { + ScaleMin = ToolBox.GetAttributeFloat(element,"scalemin",1.0f); + ScaleMax = Math.Max(ScaleMin, ToolBox.GetAttributeFloat(element, "scalemax", 1.0f)); + } + if (element.Attribute("velocity") == null) { VelocityMin = ToolBox.GetAttributeFloat(element, "velocitymin", 0.0f); @@ -58,7 +71,12 @@ namespace Barotrauma.Particles float angle = Rand.Range(AngleMin, AngleMax); Vector2 velocity = new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle)) * Rand.Range(VelocityMin, VelocityMax); - GameMain.ParticleManager.CreateParticle(particlePrefab, position, velocity, 0.0f, hullGuess); + var particle = GameMain.ParticleManager.CreateParticle(particlePrefab, position, velocity, 0.0f, hullGuess); + + if (particle!=null) + { + particle.Size *= Rand.Range(ScaleMin, ScaleMax); + } } } } From f7e98ee6a8a853aa98e986af3bae60411e9c368e Mon Sep 17 00:00:00 2001 From: Regalis Date: Sun, 9 Oct 2016 17:33:51 +0300 Subject: [PATCH 4/9] Cargo spawning fix again: items are spawned slightly above the bottom of the cargo room (because the item is only inside the hull if pos.Y > hull.rect.bottom) --- Subsurface/Source/Events/Missions/CargoMission.cs | 2 +- Subsurface/Source/GameSession/CargoManager.cs | 10 +++++----- Subsurface/Source/Networking/GameServer.cs | 2 +- Subsurface/Source/Screens/LobbyScreen.cs | 6 +++--- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Subsurface/Source/Events/Missions/CargoMission.cs b/Subsurface/Source/Events/Missions/CargoMission.cs index a0b8a5629..b52797ad2 100644 --- a/Subsurface/Source/Events/Missions/CargoMission.cs +++ b/Subsurface/Source/Events/Missions/CargoMission.cs @@ -70,7 +70,7 @@ namespace Barotrauma Vector2 position = new Vector2( cargoSpawnPos.Position.X + Rand.Range(-20.0f, 20.0f, false), - cargoRoom.Rect.Y - cargoRoom.Rect.Height); + cargoRoom.Rect.Y - cargoRoom.Rect.Height + itemPrefab.Size.Y / 2); var item = new Item(itemPrefab, position, cargoRoom.Submarine); item.FindHull(); diff --git a/Subsurface/Source/GameSession/CargoManager.cs b/Subsurface/Source/GameSession/CargoManager.cs index ec66319d1..c6292c27a 100644 --- a/Subsurface/Source/GameSession/CargoManager.cs +++ b/Subsurface/Source/GameSession/CargoManager.cs @@ -5,14 +5,14 @@ namespace Barotrauma { class CargoManager { - private List purchasedItems; + private List purchasedItems; public CargoManager() { - purchasedItems = new List(); + purchasedItems = new List(); } - public void AddItem(MapEntityPrefab item) + public void AddItem(ItemPrefab item) { purchasedItems.Add(item); } @@ -35,11 +35,11 @@ namespace Barotrauma return; } - foreach (MapEntityPrefab prefab in purchasedItems) + foreach (ItemPrefab prefab in purchasedItems) { Vector2 position = new Vector2( Rand.Range(cargoRoom.Rect.X + 20, cargoRoom.Rect.Right - 20), - Rand.Range(cargoRoom.Rect.Y - cargoRoom.Rect.Height, cargoRoom.Rect.Y)); + cargoRoom.Rect.Y - cargoRoom.Rect.Height + prefab.Size.Y/2); new Item(prefab as ItemPrefab, position, wp.Submarine); } diff --git a/Subsurface/Source/Networking/GameServer.cs b/Subsurface/Source/Networking/GameServer.cs index 86109cbb3..4c31efeb0 100644 --- a/Subsurface/Source/Networking/GameServer.cs +++ b/Subsurface/Source/Networking/GameServer.cs @@ -987,7 +987,7 @@ namespace Barotrauma.Networking for (int i = 0; i < extraCargo[s]; i++) { - Item.Spawner.QueueItem(itemPrefab, position, sub, false); + Item.Spawner.QueueItem(itemPrefab, position + (Vector2.UnitX * itemPrefab.Size.Y/2), sub, false); } } } diff --git a/Subsurface/Source/Screens/LobbyScreen.cs b/Subsurface/Source/Screens/LobbyScreen.cs index 96336860a..6052ae1d8 100644 --- a/Subsurface/Source/Screens/LobbyScreen.cs +++ b/Subsurface/Source/Screens/LobbyScreen.cs @@ -330,10 +330,10 @@ namespace Barotrauma { GUIComponent child = selectedItemList.children[i]; - MapEntityPrefab ep = child.UserData as MapEntityPrefab; - if (ep == null) continue; + ItemPrefab ip = child.UserData as ItemPrefab; + if (ip == null) continue; - gameMode.CargoManager.AddItem(ep); + gameMode.CargoManager.AddItem(ip); selectedItemList.RemoveChild(child); } From f64743a57ce9385996bc9514574e7de0050a4749 Mon Sep 17 00:00:00 2001 From: Regalis Date: Sun, 9 Oct 2016 17:36:11 +0300 Subject: [PATCH 5/9] SubInventories return "back to normal" if removed from the parent inventory (e.g. crate inventories aren't drawn above the hand slots after dropping the crate) --- Subsurface/Source/Items/CharacterInventory.cs | 2 +- Subsurface/Source/Items/Inventory.cs | 52 ++++++++++++------- 2 files changed, 33 insertions(+), 21 deletions(-) diff --git a/Subsurface/Source/Items/CharacterInventory.cs b/Subsurface/Source/Items/CharacterInventory.cs index 62aee8a8b..6b24f62ed 100644 --- a/Subsurface/Source/Items/CharacterInventory.cs +++ b/Subsurface/Source/Items/CharacterInventory.cs @@ -311,7 +311,7 @@ namespace Barotrauma MergeSlots(); } - public override void Update(float deltaTime) + public override void Update(float deltaTime, bool subInventory = false) { base.Update(deltaTime); diff --git a/Subsurface/Source/Items/Inventory.cs b/Subsurface/Source/Items/Inventory.cs index bf0616918..0dbd5bcd3 100644 --- a/Subsurface/Source/Items/Inventory.cs +++ b/Subsurface/Source/Items/Inventory.cs @@ -63,9 +63,10 @@ namespace Barotrauma protected int selectedSlot = -1; protected InventorySlot[] slots; - public Item[] Items; + private bool isSubInventory; + public bool Locked; public Vector2 CenterPos @@ -234,9 +235,13 @@ namespace Barotrauma } } - public virtual void Update(float deltaTime) + public virtual void Update(float deltaTime, bool subInventory = false) { - if (slots == null) CreateSlots(); + if (slots == null || isSubInventory != subInventory) + { + CreateSlots(); + isSubInventory = subInventory; + } for (int i = 0; i < capacity; i++) { @@ -261,17 +266,17 @@ namespace Barotrauma } - public virtual void Draw(SpriteBatch spriteBatch) + public virtual void Draw(SpriteBatch spriteBatch, bool subInventory = false) { string toolTip = ""; - if (slots == null) CreateSlots(); + if (slots == null || isSubInventory != subInventory) return; for (int i = 0; i < capacity; i++) { if (slots[i].Disabled) continue; - //don't draw the slot if dragged an item out of it + //don't draw the item if it's being dragged out of the slot bool drawItem = draggingItem == null || draggingItem != Items[i] || slots[i].IsHighlighted; DrawSlot(spriteBatch, slots[i], Items[i], drawItem); @@ -373,9 +378,26 @@ namespace Barotrauma if (container.Inventory.slots == null) container.Inventory.CreateSlots(); + int itemCapacity = container.Capacity; + + var slot = slots[slotIndex]; + Rectangle containerRect = new Rectangle(slot.Rect.X - 5, slot.Rect.Y - (40 + 10) * itemCapacity - 5, + slot.Rect.Width + 10, slot.Rect.Height + (40 + 10) * itemCapacity + 10); + + Rectangle subRect = slot.Rect; + subRect.Height = 40; + + for (int i = 0; i < itemCapacity; i++) + { + subRect.Y = subRect.Y - subRect.Height - 10; + container.Inventory.slots[i].Rect = subRect; + } + + container.Inventory.isSubInventory = true; + slots[slotIndex].State = GUIComponent.ComponentState.Hover; - container.Inventory.Update(deltaTime); + container.Inventory.Update(deltaTime, true); } public void DrawSubInventory(SpriteBatch spriteBatch, int slotIndex) @@ -386,8 +408,7 @@ namespace Barotrauma var container = item.GetComponent(); if (container == null) return; - if (container.Inventory.slots == null) container.Inventory.CreateSlots(); - + if (container.Inventory.slots == null || !container.Inventory.isSubInventory) return; int itemCapacity = container.Capacity; @@ -400,20 +421,11 @@ namespace Barotrauma var slot = slots[slotIndex]; Rectangle containerRect = new Rectangle(slot.Rect.X - 5, slot.Rect.Y - (40 + 10) * itemCapacity - 5, slot.Rect.Width + 10, slot.Rect.Height + (40 + 10) * itemCapacity + 10); - - Rectangle subRect = slot.Rect; - subRect.Height = 40; - + GUI.DrawRectangle(spriteBatch, new Rectangle(containerRect.X, containerRect.Y, containerRect.Width, containerRect.Height - slot.Rect.Height - 5), Color.Black * 0.8f, true); GUI.DrawRectangle(spriteBatch, containerRect, Color.White); - for (int i = 0; i < itemCapacity; i++) - { - subRect.Y = subRect.Y - subRect.Height - 10; - container.Inventory.slots[i].Rect = subRect; - } - - container.Inventory.Draw(spriteBatch); + container.Inventory.Draw(spriteBatch, true); if (!containerRect.Contains(PlayerInput.MousePosition)) { From e7e51fbe0cbac0b79c04ab800b9dcdabe0df7042 Mon Sep 17 00:00:00 2001 From: Regalis Date: Sun, 9 Oct 2016 17:38:01 +0300 Subject: [PATCH 6/9] Saving times and map seeds are displayed correctly in the "load game" menu --- Subsurface/Source/GameSession/GameSession.cs | 4 +++- Subsurface/Source/Screens/MainMenuScreen.cs | 11 +---------- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/Subsurface/Source/GameSession/GameSession.cs b/Subsurface/Source/GameSession/GameSession.cs index cc5fb63ea..dc3842065 100644 --- a/Subsurface/Source/GameSession/GameSession.cs +++ b/Subsurface/Source/GameSession/GameSession.cs @@ -334,10 +334,12 @@ namespace Barotrauma new XElement("Gamesession")); var now = DateTime.Now; - doc.Root.Add(new XAttribute("savetime", now.Hour + ":" + now.Minute + ", " + now.ToShortDateString())); + doc.Root.Add(new XAttribute("savetime", now.ToShortTimeString() + ", " + now.ToShortDateString())); doc.Root.Add(new XAttribute("submarine", submarine==null ? "" : submarine.Name)); + doc.Root.Add(new XAttribute("mapseed", Map.Seed)); + ((SinglePlayerMode)gameMode).Save(doc.Root); try diff --git a/Subsurface/Source/Screens/MainMenuScreen.cs b/Subsurface/Source/Screens/MainMenuScreen.cs index beb4d6e17..9625cd33c 100644 --- a/Subsurface/Source/Screens/MainMenuScreen.cs +++ b/Subsurface/Source/Screens/MainMenuScreen.cs @@ -417,16 +417,7 @@ namespace Barotrauma string saveTime = ToolBox.GetAttributeString(doc.Root, "savetime", "unknown"); - XElement modeElement = null; - foreach (XElement element in doc.Root.Elements()) - { - if (element.Name.ToString().ToLowerInvariant() != "gamemode") continue; - - modeElement = element; - break; - } - - string mapseed = ToolBox.GetAttributeString(modeElement, "mapseed", "unknown"); + string mapseed = ToolBox.GetAttributeString(doc.Root, "mapseed", "unknown"); GUIFrame saveFileFrame = new GUIFrame(new Rectangle((int)(saveList.Rect.Width + 20), 0, 200, 230), Color.Black*0.4f, GUI.Style, menuTabs[(int)Tab.LoadGame]); saveFileFrame.UserData = "savefileframe"; From ef9dce9a0d4d252334d1674c0afabcc582d6134d Mon Sep 17 00:00:00 2001 From: Regalis Date: Sun, 9 Oct 2016 18:20:32 +0300 Subject: [PATCH 7/9] - fixed exception in GetSubsToLeaveBehind if the round ends when none of the subs is at an exit - water surface is clamped above the bottom of the hull - character names don't overlap with health bars --- Subsurface/Source/Characters/Character.cs | 2 +- .../GameSession/GameModes/SinglePlayerMode.cs | 22 ++++++++++--------- Subsurface/Source/Map/Hull.cs | 12 +++++----- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/Subsurface/Source/Characters/Character.cs b/Subsurface/Source/Characters/Character.cs index 7808e6797..d69420376 100644 --- a/Subsurface/Source/Characters/Character.cs +++ b/Subsurface/Source/Characters/Character.cs @@ -1328,7 +1328,7 @@ namespace Barotrauma if (info != null) { - Vector2 namePos = new Vector2(pos.X, pos.Y - 80.0f - (5.0f/cam.Zoom)) - GUI.Font.MeasureString(Info.Name) * 0.5f / cam.Zoom; + Vector2 namePos = new Vector2(pos.X, pos.Y - 110.0f - (5.0f/cam.Zoom)) - GUI.Font.MeasureString(Info.Name) * 0.5f / cam.Zoom; Color nameColor = Color.White; if (Character.Controlled != null && TeamID!=Character.Controlled.TeamID) diff --git a/Subsurface/Source/GameSession/GameModes/SinglePlayerMode.cs b/Subsurface/Source/GameSession/GameModes/SinglePlayerMode.cs index f76525739..ce1b6ea64 100644 --- a/Subsurface/Source/GameSession/GameModes/SinglePlayerMode.cs +++ b/Subsurface/Source/GameSession/GameModes/SinglePlayerMode.cs @@ -241,17 +241,19 @@ namespace Barotrauma { isRunning = false; - if (subsToLeaveBehind == null || leavingSub == null) - { - DebugConsole.ThrowError("Leaving submarine not selected -> selecting the closest one"); - - leavingSub = GetLeavingSub(); - - subsToLeaveBehind = GetSubsToLeaveBehind(leavingSub); - } - - bool success = CrewManager.characters.Any(c => !c.IsDead); + + if (success) + { + if (subsToLeaveBehind == null || leavingSub == null) + { + DebugConsole.ThrowError("Leaving submarine not selected -> selecting the closest one"); + + leavingSub = GetLeavingSub(); + + subsToLeaveBehind = GetSubsToLeaveBehind(leavingSub); + } + } GameMain.GameSession.EndShift(""); diff --git a/Subsurface/Source/Map/Hull.cs b/Subsurface/Source/Map/Hull.cs index 9474d9430..ff306401f 100644 --- a/Subsurface/Source/Map/Hull.cs +++ b/Subsurface/Source/Map/Hull.cs @@ -100,6 +100,8 @@ namespace Barotrauma Item.UpdateHulls(); Gap.UpdateHulls(); } + + surface = rect.Y - rect.Height + Volume / rect.Width; } } @@ -506,7 +508,7 @@ namespace Barotrauma } //interpolate the position of the rendered surface towards the "target surface" - surface = MathHelper.Lerp(surface, surfaceY, deltaTime*10.0f); + surface = Math.Max(MathHelper.Lerp(surface, surfaceY, deltaTime*10.0f), rect.Y - rect.Height); if (volume < FullVolume) { @@ -556,7 +558,7 @@ namespace Barotrauma if (!Visible) { drawRect = - Submarine == null ? rect : new Rectangle((int)(Submarine.DrawPosition.X + rect.X), (int)(Submarine.DrawPosition.Y + rect.Y), rect.Width, rect.Height); + Submarine == null ? rect : new Rectangle((int)(Submarine.DrawPosition.X + rect.X), (int)(Submarine.DrawPosition.Y + rect.Y), rect.Width, rect.Height); GUI.DrawRectangle(spriteBatch, new Vector2(drawRect.X, -drawRect.Y), @@ -577,11 +579,11 @@ namespace Barotrauma GUI.DrawRectangle(spriteBatch, new Vector2(drawRect.X, -drawRect.Y), new Vector2(rect.Width, rect.Height), - Color.Blue,false,0, (int)Math.Max((1.5f / Screen.Selected.Cam.Zoom), 1.0f)); + Color.Blue, false, 0, (int)Math.Max((1.5f / Screen.Selected.Cam.Zoom), 1.0f)); GUI.DrawRectangle(spriteBatch, new Rectangle(drawRect.X, -drawRect.Y, rect.Width, rect.Height), - Color.Red*((100.0f-OxygenPercentage)/400.0f), true,0, (int)Math.Max((1.5f / GameScreen.Selected.Cam.Zoom), 1.0f)); + Color.Red * ((100.0f - OxygenPercentage) / 400.0f), true, 0, (int)Math.Max((1.5f / GameScreen.Selected.Cam.Zoom), 1.0f)); if (GameMain.DebugDraw) { @@ -596,7 +598,7 @@ namespace Barotrauma GUI.DrawRectangle(spriteBatch, new Vector2(drawRect.X + 5, -drawRect.Y + 5), new Vector2(rect.Width - 10, rect.Height - 10), - isHighlighted ? Color.LightBlue*0.5f : Color.Red*0.5f, true,0, (int)Math.Max((1.5f / GameScreen.Selected.Cam.Zoom), 1.0f)); + isHighlighted ? Color.LightBlue * 0.5f : Color.Red * 0.5f, true, 0, (int)Math.Max((1.5f / GameScreen.Selected.Cam.Zoom), 1.0f)); } } From d4e9116b0f5708b7d142e37479945d9abaec1ee4 Mon Sep 17 00:00:00 2001 From: Regalis Date: Sun, 9 Oct 2016 19:25:14 +0300 Subject: [PATCH 8/9] Audio channel states visible in debug view + some sound fixes: - a short "cooldown" after each footstep sound (prevents the sound playing multiple times during one footstep) - water flow sounds are only played by one of the hulls a gap is between - flow rate affects the range of the flow sound --- .../Source/Characters/Animation/Ragdoll.cs | 6 +- Subsurface/Source/GUI/GUI.cs | 27 ++++ Subsurface/Source/Map/Hull.cs | 23 ++- Subsurface/Source/Sounds/SoundManager.cs | 153 ++++-------------- 4 files changed, 77 insertions(+), 132 deletions(-) diff --git a/Subsurface/Source/Characters/Animation/Ragdoll.cs b/Subsurface/Source/Characters/Animation/Ragdoll.cs index 75b26d98f..d46ace6d9 100644 --- a/Subsurface/Source/Characters/Animation/Ragdoll.cs +++ b/Subsurface/Source/Characters/Animation/Ragdoll.cs @@ -422,7 +422,11 @@ namespace Barotrauma float volume = stairs == null ? impact / 5.0f : impact; volume = Math.Min(impact, 1.0f); - if (impact > 0.8f && l.HitSound != null && l.soundTimer <= 0.0f) l.HitSound.Play(volume, impact * 100.0f, l.WorldPosition); + if (impact > 0.5f && l.HitSound != null && l.soundTimer <= 0.0f) + { + l.soundTimer = Limb.SoundInterval; + l.HitSound.Play(volume, impact * 250.0f, l.WorldPosition); + } if (impact > l.impactTolerance) { diff --git a/Subsurface/Source/GUI/GUI.cs b/Subsurface/Source/GUI/GUI.cs index 5ec7a82d4..d2392e6e7 100644 --- a/Subsurface/Source/GUI/GUI.cs +++ b/Subsurface/Source/GUI/GUI.cs @@ -449,6 +449,33 @@ namespace Barotrauma "Sub pos: " + Submarine.MainSub.Position.ToPoint(), new Vector2(10, 50), Color.White); } + + for (int i = 1; i < Sounds.SoundManager.DefaultSourceCount; i++) + { + Color clr = Color.White; + + string soundStr = i+": "; + + var playingSound = Sounds.SoundManager.GetPlayingSound(i); + + if (playingSound == null) + { + soundStr+= "none"; + clr *= 0.5f; + } + else + { + soundStr += System.IO.Path.GetFileNameWithoutExtension(playingSound.FilePath); + + if (Sounds.SoundManager.IsLooping(i)) + { + soundStr += " (looping)"; + clr = Color.Yellow; + } + } + + GUI.DrawString(spriteBatch, new Vector2(200, i * 15), soundStr, clr, Color.Black * 0.5f, 0, GUI.SmallFont); + } } if (GameMain.NetworkMember != null) GameMain.NetworkMember.Draw(spriteBatch); diff --git a/Subsurface/Source/Map/Hull.cs b/Subsurface/Source/Map/Hull.cs index ff306401f..83693d7da 100644 --- a/Subsurface/Source/Map/Hull.cs +++ b/Subsurface/Source/Map/Hull.cs @@ -102,6 +102,7 @@ namespace Barotrauma } surface = rect.Y - rect.Height + Volume / rect.Width; + Pressure = surface; } } @@ -259,7 +260,7 @@ namespace Barotrauma return rect; } - + public static EntityGrid GenerateEntityGrid(Submarine submarine) { var newGrid = new EntityGrid(submarine, 200.0f); @@ -318,6 +319,9 @@ namespace Barotrauma Item.UpdateHulls(); Gap.UpdateHulls(); } + + surface = rect.Y - rect.Height + Volume / rect.Width; + Pressure = surface; } public override void Remove() @@ -404,6 +408,12 @@ namespace Barotrauma float strongestFlow = 0.0f; foreach (Gap gap in ConnectedGaps) { + if (gap.IsRoomToRoom) + { + //only the first linked hull plays the flow sound + if (gap.linkedTo[1] == this) continue; + } + float gapFlow = gap.LerpedFlowForce.Length(); if (gapFlow > strongestFlow) @@ -411,9 +421,8 @@ namespace Barotrauma strongestFlow = gapFlow; } } - - - if (strongestFlow>0.1f) + + if (strongestFlow > 1.0f) { soundVolume = soundVolume + ((strongestFlow < 100.0f) ? -deltaTime * 0.5f : deltaTime * 0.5f); soundVolume = MathHelper.Clamp(soundVolume, 0.0f, 1.0f); @@ -430,8 +439,7 @@ namespace Barotrauma } currentFlowSound = flowSound; - - soundIndex = currentFlowSound.Loop(soundIndex, soundVolume, WorldPosition, 2000.0f); + soundIndex = currentFlowSound.Loop(soundIndex, soundVolume, WorldPosition, Math.Min(strongestFlow*5.0f, 2000.0f)); } else { @@ -515,10 +523,13 @@ namespace Barotrauma LethalPressure -= 10.0f * deltaTime; if (Volume == 0.0f) { + //wait for the surface to be lerped back to bottom and the waves to settle until disabling update + if (surface > rect.Y - rect.Height + 1) return; for (int i = 1; i < waveY.Length - 1; i++) { if (waveY[i] > 0.1f) return; } + update = false; } } diff --git a/Subsurface/Source/Sounds/SoundManager.cs b/Subsurface/Source/Sounds/SoundManager.cs index 80a073bc9..3c28bc280 100644 --- a/Subsurface/Source/Sounds/SoundManager.cs +++ b/Subsurface/Source/Sounds/SoundManager.cs @@ -14,6 +14,8 @@ namespace Barotrauma.Sounds private static readonly List alSources = new List(); private static readonly int[] alBuffers = new int[DefaultSourceCount]; private static int lowpassFilterId; + + private static readonly Sound[] soundsPlaying = new Sound[DefaultSourceCount]; private static AudioContext AC; @@ -47,112 +49,33 @@ namespace Barotrauma.Sounds LowPassHFGain = 1.0f; } - - } - - //public SoundManager(int bufferCount = DefaultSourceCount) - //{ - // Stopwatch sw = new Stopwatch(); - // sw.Start(); - - // alSourceId = AL.GenSource(); - // //AL.Source(alSourceId, ALSourcei.Buffer, alBufferId); - - // Volume = 1; - - // if (ALHelper.Efx.IsInitialized) - // { - // alFilterId = ALHelper.Efx.GenFilter(); - // ALHelper.Efx.Filter(alFilterId, EfxFilteri.FilterType, (int)EfxFilterType.Lowpass); - // ALHelper.Efx.Filter(alFilterId, EfxFilterf.LowpassGain, 1); - // LowPassHFGain = 1; - // } - - // sw.Stop(); - // System.Diagnostics.Debug.WriteLine("oggsource: "+sw.ElapsedMilliseconds); - - //} - - // public static int Play(Sound sound, float volume = 1.0f) - // { - // return Play(sound, volume, new Vector2(0.0f, 0.0f)); - //} public static int Play(Sound sound, float volume = 1.0f) { return Play(sound, Vector2.Zero, volume, 0.0f); - //for (int i = 2; i < DefaultSourceCount; i++) - //{ - // AL.SourceStop(alSources[i]); - // AL.Source(alSources[i], ALSourceb.Looping, false); - // System.Diagnostics.Debug.WriteLine(i + ": " + AL.GetSourceState(alSources[i])); - // System.Diagnostics.Debug.WriteLine(AL.GetSourceType(alSources[i])); - //} - - //for (int i = 1; i < DefaultSourceCount; i++) - //{ - // //find a source that's free to use (not playing or paused) - // if (AL.GetSourceState(alSources[i]) == ALSourceState.Playing - // || AL.GetSourceState(alSources[i]) == ALSourceState.Paused) continue; - - // //if (position!=Vector2.Zero) - // // position /= 1000.0f; - - // alBuffers[i]=sound.AlBufferId; - // AL.Source(alSources[i], ALSourceb.Looping, false); - // AL.Source(alSources[i], ALSource3f.Position, 0.0f, 0.0f, 0.0f); - // AL.Source(alSources[i], ALSourcei.Buffer, sound.AlBufferId); - // AL.Source(alSources[i], ALSourcef.Gain, volume); - // //AL.Source(alSources[i], ALSource3f.Position, position.X, position.Y, 0.0f); - // AL.SourcePlay(alSources[i]); - - // //sound.sourceIndex = i; - - // return i; - //} - - //return -1; } public static int Play(Sound sound, Vector2 position, float volume = 1.0f, float lowPassGain = 0.0f, bool loop=false) { - //for (int i = 2; i < DefaultSourceCount; i++) - //{ - // AL.SourceStop(alSources[i]); - // AL.Source(alSources[i], ALSourceb.Looping, false); - // System.Diagnostics.Debug.WriteLine(i + ": " + AL.GetSourceState(alSources[i])); - // System.Diagnostics.Debug.WriteLine(AL.GetSourceType(alSources[i])); - //} - - - for (int i = 1; i < DefaultSourceCount; i++) { //find a source that's free to use (not playing or paused) if (OpenTK.Audio.OpenAL.AL.GetSourceState(alSources[i]) == OpenTK.Audio.OpenAL.ALSourceState.Playing || OpenTK.Audio.OpenAL.AL.GetSourceState(alSources[i]) == OpenTK.Audio.OpenAL.ALSourceState.Paused) continue; - //if (position!=Vector2.Zero) - // position /= 1000.0f; + soundsPlaying[i] = sound; alBuffers[i] = sound.AlBufferId; OpenTK.Audio.OpenAL.AL.Source(alSources[i], OpenTK.Audio.OpenAL.ALSourceb.Looping, loop); OpenTK.Audio.OpenAL.AL.Source(alSources[i], OpenTK.Audio.OpenAL.ALSourcei.Buffer, sound.AlBufferId); - - + UpdateSoundPosition(i, position, volume); - //AL.Source(alSources[i], ALSource3f.Position, position.X, position.Y, 0.0f); OpenTK.Audio.OpenAL.AL.SourcePlay(alSources[i]); - - - - //sound.sourceIndex = i; - return i; } @@ -174,44 +97,17 @@ namespace Barotrauma.Sounds if (sourceIndex<1) { sourceIndex = Play(sound, position, volume, 0.0f, true); - //if (sourceIndex>0) - //{ - // AL.Source(alSources[sourceIndex], ALSourceb.Looping, true); - // AL.Source(alSources[sourceIndex], ALSourcef.Gain, volume); - //} } else { UpdateSoundPosition(sourceIndex, position, volume); - - //position /= 1000.0f; - - //OpenTK.Audio.OpenAL.AL.Source(alSources[sourceIndex], OpenTK.Audio.OpenAL.ALSource3f.Position, position.X, position.Y, 0.0f); AL.Source(alSources[sourceIndex], ALSourceb.Looping, true); - //AL.Source(alSources[sourceIndex], ALSourcef.Gain, volume); - } ALHelper.Check(); return sourceIndex; } - //public static int Loop(int sourceIndex, float volume = 1.0f) - //{ - - // if (sourceIndex > 0 && alSources[sourceIndex]>0) - // { - // ALSourceState state = AL.GetSourceState(alSources[sourceIndex]); - // ALHelper.Check(); - // if (state == ALSourceState.Playing) return sourceIndex; - // } - - // int newSourceIndex = Play(sound, volume); - // AL.Source(alSources[sourceIndex], ALSourceb.Looping, true); - - // return sourceIndex; - //} - public static void Pause(int sourceIndex) { if (AL.GetSourceState(alSources[sourceIndex]) != ALSourceState.Playing) @@ -239,9 +135,21 @@ namespace Barotrauma.Sounds { AL.SourceStop(alSources[sourceIndex]); AL.Source(alSources[sourceIndex], ALSourceb.Looping, false); + + soundsPlaying[sourceIndex] = null; } } + public static Sound GetPlayingSound(int sourceIndex) + { + if (sourceIndex < 1 || sourceIndex>alSources.Count-1) return null; + + if (AL.GetSourceState(alSources[sourceIndex]) != ALSourceState.Playing) return null; + + return soundsPlaying[sourceIndex]; + } + + public static bool IsPlaying(int sourceIndex) { if (sourceIndex < 1 || sourceIndex>alSources.Count-1) return false; @@ -249,14 +157,23 @@ namespace Barotrauma.Sounds return (state == ALSourceState.Playing); } + public static bool IsLooping(int sourceIndex) + { + if (sourceIndex < 1 || sourceIndex > alSources.Count - 1) return false; + + bool isLooping; + + OpenTK.Audio.OpenAL.AL.GetSource(alSources[sourceIndex], OpenTK.Audio.OpenAL.ALSourceb.Looping, out isLooping); + + return isLooping; + } + public static void Volume(int sourceIndex, float volume) { AL.Source(alSources[sourceIndex], ALSourcef.Gain, volume * MasterVolume); ALHelper.Check(); } - //int alFilterId; - static float lowPassHfGain; public static float LowPassHFGain { @@ -281,16 +198,6 @@ namespace Barotrauma.Sounds } } - //float volume; - //public float Volume - //{ - // get { return volume; } - // set - // { - // AL.Source(alSourceId, ALSourcef.Gain, volume = value); - // ALHelper.Check(); - // } - //} public static void UpdateSoundPosition(int sourceIndex, Vector2 position, float baseVolume = 1.0f) { @@ -301,9 +208,7 @@ namespace Barotrauma.Sounds position = Vector2.Zero; } - //Resume(sourceIndex); - - position/= 1000.0f; + position /= 1000.0f; OpenTK.Audio.OpenAL.AL.Source(alSources[sourceIndex], OpenTK.Audio.OpenAL.ALSourcef.Gain, baseVolume * MasterVolume); OpenTK.Audio.OpenAL.AL.Source(alSources[sourceIndex], OpenTK.Audio.OpenAL.ALSource3f.Position, position.X, position.Y, 0.0f); @@ -313,8 +218,6 @@ namespace Barotrauma.Sounds ALHelper.Efx.Filter(lowpassFilterId, OpenTK.Audio.OpenAL.EfxFilterf.LowpassGainHF, lowPassGain); ALHelper.Efx.BindFilterToSource(alSources[sourceIndex], lowpassFilterId); ALHelper.Check(); - - } public static OggStream StartStream(string file, float volume = 1.0f) From 74a94536762fb68bb602c539701e3cb78523950b Mon Sep 17 00:00:00 2001 From: Regalis Date: Sun, 9 Oct 2016 20:45:28 +0300 Subject: [PATCH 9/9] Upper limit to water drag force, fixed highlighted items "flickering" --- Subsurface/Source/Characters/Limb.cs | 4 ++-- Subsurface/Source/Items/Item.cs | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Subsurface/Source/Characters/Limb.cs b/Subsurface/Source/Characters/Limb.cs index 1adbca15d..8a86cc5a6 100644 --- a/Subsurface/Source/Characters/Limb.cs +++ b/Subsurface/Source/Characters/Limb.cs @@ -462,14 +462,14 @@ namespace Barotrauma Vector2 normal = new Vector2(-line.Y, line.X); normal = Vector2.Normalize(-normal); - float dragDot = Vector2.Dot(normal, velDir); + float dragDot = Math.Abs(Vector2.Dot(normal, velDir)); Vector2 dragForce = Vector2.Zero; if (dragDot > 0) { float vel = LinearVelocity.Length()*2.0f; float drag = dragDot * vel * vel * ConvertUnits.ToSimUnits(sprite.size.Y); - dragForce = drag * -velDir; + dragForce = Math.Min(drag, Mass*1000.0f) * -velDir; //if (dragForce.Length() > 100.0f) { } } diff --git a/Subsurface/Source/Items/Item.cs b/Subsurface/Source/Items/Item.cs index 9b4ffe5b7..5495caaec 100644 --- a/Subsurface/Source/Items/Item.cs +++ b/Subsurface/Source/Items/Item.cs @@ -703,6 +703,8 @@ namespace Barotrauma inWater = IsInWater(); if (inWater) ApplyStatusEffects(ActionType.InWater, deltaTime); + isHighlighted = false; + if (body == null || !body.Enabled) return; if (Math.Abs(body.LinearVelocity.X) > 0.01f || Math.Abs(body.LinearVelocity.Y) > 0.01f) @@ -881,7 +883,6 @@ namespace Barotrauma if (!editing || (body != null && !body.Enabled)) { - isHighlighted = false; return; }