From e1296e4a8e7d84e540f19aaff41aa7873c78f1d7 Mon Sep 17 00:00:00 2001 From: juanjp600 Date: Sun, 2 Oct 2016 22:24:31 -0300 Subject: [PATCH] Backported vsync changes from new-netcode, WIP hull visibility culling The hull culling functions are there, they just aren't being used right now because there are some annoying bugs. --- Subsurface/Source/Characters/Character.cs | 7 ++ Subsurface/Source/GUI/GUI.cs | 12 ++- Subsurface/Source/GUI/GUIButton.cs | 67 +++++++++-------- Subsurface/Source/GUI/GUIComponent.cs | 9 ++- Subsurface/Source/GUI/LoadingScreen.cs | 1 + Subsurface/Source/GameMain.cs | 72 +++++++++++------- Subsurface/Source/GameSettings.cs | 18 +++++ Subsurface/Source/Items/Components/Door.cs | 5 ++ .../Source/Items/Components/ItemComponent.cs | 4 +- .../Components/Machines/Deconstructor.cs | 6 +- .../Items/Components/Machines/Engine.cs | 5 ++ .../Items/Components/Machines/Fabricator.cs | 6 +- .../Source/Items/Components/Machines/Pump.cs | 8 +- .../Items/Components/Machines/Reactor.cs | 6 +- .../Items/Components/Machines/Steering.cs | 8 +- .../Items/Components/Power/PowerContainer.cs | 5 ++ .../Items/Components/Power/PowerTransfer.cs | 5 ++ .../Items/Components/Signal/LightComponent.cs | 2 +- Subsurface/Source/Items/FixRequirement.cs | 9 ++- Subsurface/Source/Items/Item.cs | 26 ++++++- Subsurface/Source/Map/Hull.cs | 74 ++++++++++++++++++- Subsurface/Source/Map/Levels/WaterRenderer.cs | 11 ++- Subsurface/Source/Map/Lights/LightManager.cs | 1 + Subsurface/Source/Map/Structure.cs | 5 +- Subsurface/Source/Networking/GameServer.cs | 27 +++---- Subsurface/Source/Screens/GameScreen.cs | 14 +++- Subsurface/Source/Screens/ServerListScreen.cs | 2 +- 27 files changed, 316 insertions(+), 99 deletions(-) diff --git a/Subsurface/Source/Characters/Character.cs b/Subsurface/Source/Characters/Character.cs index d7308bbf8..7808e6797 100644 --- a/Subsurface/Source/Characters/Character.cs +++ b/Subsurface/Source/Characters/Character.cs @@ -58,6 +58,9 @@ namespace Barotrauma } } + public Hull PreviousHull = null; + public Hull CurrentHull = null; + public readonly bool IsNetworkPlayer; private bool networkUpdateSent; @@ -1132,6 +1135,10 @@ namespace Barotrauma { if (!Enabled) return; + PreviousHull = CurrentHull; + CurrentHull = Hull.FindHull(WorldPosition, CurrentHull, true); + //if (PreviousHull != CurrentHull && Character.Controlled == this) Hull.DetectItemVisibility(this); //WIP item culling + speechBubbleTimer = Math.Max(0.0f, speechBubbleTimer - deltaTime); obstructVisionAmount = Math.Max(obstructVisionAmount - deltaTime, 0.0f); diff --git a/Subsurface/Source/GUI/GUI.cs b/Subsurface/Source/GUI/GUI.cs index bfb32ee68..2fb987745 100644 --- a/Subsurface/Source/GUI/GUI.cs +++ b/Subsurface/Source/GUI/GUI.cs @@ -453,13 +453,11 @@ namespace Barotrauma if (pauseMenuOpen) { - pauseMenu.Update(0.016f); pauseMenu.Draw(spriteBatch); } if (settingsMenuOpen) { - GameMain.Config.SettingsFrame.Update(0.016f); GameMain.Config.SettingsFrame.Draw(spriteBatch); } @@ -472,6 +470,16 @@ namespace Barotrauma public static void Update(float deltaTime) { + if (pauseMenuOpen) + { + pauseMenu.Update(0.016f); + } + + if (settingsMenuOpen) + { + GameMain.Config.SettingsFrame.Update(0.016f); + } + if (GUIMessageBox.MessageBoxes.Count > 0) { var messageBox = GUIMessageBox.MessageBoxes.Peek(); diff --git a/Subsurface/Source/GUI/GUIButton.cs b/Subsurface/Source/GUI/GUIButton.cs index 59022491c..8545de791 100644 --- a/Subsurface/Source/GUI/GUIButton.cs +++ b/Subsurface/Source/GUI/GUIButton.cs @@ -162,38 +162,6 @@ namespace Barotrauma { if (!Visible) return; - if (rect.Contains(PlayerInput.MousePosition) && CanBeSelected && Enabled && (MouseOn == null || MouseOn == this || IsParentOf(MouseOn))) - { - state = ComponentState.Hover; - if (PlayerInput.LeftButtonHeld()) - { - if (OnPressed != null) - { - if (OnPressed()) state = ComponentState.Selected; - } - } - else if (PlayerInput.LeftButtonClicked()) - { - GUI.PlayUISound(GUISoundType.Click); - - if (OnClicked != null) - { - if (OnClicked(this, UserData) && CanBeSelected) state = ComponentState.Selected; - } - else - { - Selected = !Selected; - // state = state == ComponentState.Selected ? ComponentState.None : ComponentState.Selected; - } - } - } - else - { - state = Selected ? ComponentState.Selected : ComponentState.None; - } - - frame.State = state; - //Color currColor = color; //if (state == ComponentState.Hover) currColor = hoverColor; //if (state == ComponentState.Selected) currColor = selectedColor; @@ -208,5 +176,40 @@ namespace Barotrauma //if (!Enabled) GUI.DrawRectangle(spriteBatch, rect, Color.Gray*0.5f, true); } + + public override void Update(float deltaTime) + { + if (!Visible) return; + base.Update(deltaTime); + if (rect.Contains(PlayerInput.MousePosition) && CanBeSelected && Enabled && (MouseOn == null || MouseOn == this || IsParentOf(MouseOn))) + { + state = ComponentState.Hover; + if (PlayerInput.LeftButtonHeld()) + { + if (OnPressed != null) + { + if (OnPressed()) state = ComponentState.Selected; + } + } + else if (PlayerInput.LeftButtonClicked()) + { + GUI.PlayUISound(GUISoundType.Click); + if (OnClicked != null) + { + if (OnClicked(this, UserData) && CanBeSelected) state = ComponentState.Selected; + } + else + { + Selected = !Selected; + // state = state == ComponentState.Selected ? ComponentState.None : ComponentState.Selected; + } + } + } + else + { + state = Selected ? ComponentState.Selected : ComponentState.None; + } + frame.State = state; + } } } diff --git a/Subsurface/Source/GUI/GUIComponent.cs b/Subsurface/Source/GUI/GUIComponent.cs index dae94096f..5a61587a9 100644 --- a/Subsurface/Source/GUI/GUIComponent.cs +++ b/Subsurface/Source/GUI/GUIComponent.cs @@ -317,10 +317,13 @@ namespace Barotrauma } - for (int i = 0; i < children.Count; i++) + //use a fixed list since children can change their order in the main children list + //TODO: maybe find a more efficient way of handling changes in list order + List fixedChildren = new List(children); + foreach (GUIComponent c in fixedChildren) { - if (!children[i].Visible) continue; - children[i].Update(deltaTime); + if (!c.Visible) continue; + c.Update(deltaTime); } } diff --git a/Subsurface/Source/GUI/LoadingScreen.cs b/Subsurface/Source/GUI/LoadingScreen.cs index d4ec357a7..cc42b4e91 100644 --- a/Subsurface/Source/GUI/LoadingScreen.cs +++ b/Subsurface/Source/GUI/LoadingScreen.cs @@ -101,6 +101,7 @@ namespace Barotrauma if (Hull.renderer != null) { + Hull.renderer.ScrollWater(deltaTime); Hull.renderer.RenderBack(spriteBatch, renderTarget, 0.0f); } diff --git a/Subsurface/Source/GameMain.cs b/Subsurface/Source/GameMain.cs index a9c236791..28b995303 100644 --- a/Subsurface/Source/GameMain.cs +++ b/Subsurface/Source/GameMain.cs @@ -71,12 +71,15 @@ namespace Barotrauma private bool hasLoaded; + private GameTime fixedTime; + private double updatesToMake; + //public static Random localRandom; //public static Random random; //private Stopwatch renderTimer; //public static int renderTimeElapsed; - + public Camera Cam { get { return GameScreen.Cam; } @@ -120,6 +123,7 @@ namespace Barotrauma graphicsWidth = Config.GraphicsWidth; graphicsHeight = Config.GraphicsHeight; + Graphics.SynchronizeWithVerticalRetrace = Config.VSyncEnabled; Graphics.HardwareModeSwitch = Config.WindowMode != WindowMode.BorderlessWindowed; @@ -138,11 +142,16 @@ namespace Barotrauma IsFixedTimeStep = false; //TargetElapsedTime = new TimeSpan(0, 0, 0, 0, 55); + updatesToMake = 0.0; + fixedTime = new GameTime(); + World = new World(new Vector2(0, -9.82f)); FarseerPhysics.Settings.AllowSleep = true; FarseerPhysics.Settings.ContinuousPhysics = false; FarseerPhysics.Settings.VelocityIterations = 1; FarseerPhysics.Settings.PositionIterations = 1; + + Graphics.ApplyChanges(); } /// @@ -282,40 +291,51 @@ namespace Barotrauma /// Provides a snapshot of timing values. protected override void Update(GameTime gameTime) { - base.Update(gameTime); + double realDeltaTime = gameTime.ElapsedGameTime.TotalSeconds; + double deltaTime = 0.016; + updatesToMake += realDeltaTime; - double deltaTime = gameTime.ElapsedGameTime.TotalSeconds; - PlayerInput.Update(deltaTime); - - bool paused = false; - - if (hasLoaded && !titleScreenOpen) + while (updatesToMake > 0.0) { - SoundPlayer.Update(); + fixedTime.IsRunningSlowly = gameTime.IsRunningSlowly; + TimeSpan addTime = new TimeSpan(0, 0, 0, 0, 16); + fixedTime.ElapsedGameTime = addTime; + fixedTime.TotalGameTime.Add(addTime); + base.Update(fixedTime); + + PlayerInput.Update(deltaTime); - if (PlayerInput.KeyHit(Keys.Escape)) GUI.TogglePauseMenu(); + bool paused = false; - DebugConsole.Update(this, (float)deltaTime); - - paused = (DebugConsole.IsOpen || GUI.PauseMenuOpen || GUI.SettingsMenuOpen) && - (NetworkMember == null || !NetworkMember.GameStarted); - - if (!paused) Screen.Selected.Update(deltaTime); - - if (NetworkMember != null) + if (hasLoaded && !titleScreenOpen) { - NetworkMember.Update((float)deltaTime); - } - else - { - NetworkEvent.Events.Clear(); + SoundPlayer.Update(); + + if (PlayerInput.KeyHit(Keys.Escape)) GUI.TogglePauseMenu(); + + DebugConsole.Update(this, (float)deltaTime); + + paused = (DebugConsole.IsOpen || GUI.PauseMenuOpen || GUI.SettingsMenuOpen) && + (NetworkMember == null || !NetworkMember.GameStarted); + + if (!paused) Screen.Selected.Update(deltaTime); + + if (NetworkMember != null) + { + NetworkMember.Update((float)deltaTime); + } + else + { + NetworkEvent.Events.Clear(); + } + + GUI.Update((float)deltaTime); } - GUI.Update((float)deltaTime); + CoroutineManager.Update((float)deltaTime, paused ? 0.0f : (float)deltaTime); + updatesToMake -= deltaTime; } - - CoroutineManager.Update((float)deltaTime, paused ? 0.0f : (float)deltaTime); } diff --git a/Subsurface/Source/GameSettings.cs b/Subsurface/Source/GameSettings.cs index 23a784404..c459724af 100644 --- a/Subsurface/Source/GameSettings.cs +++ b/Subsurface/Source/GameSettings.cs @@ -44,6 +44,8 @@ namespace Barotrauma public int GraphicsWidth { get; set; } public int GraphicsHeight { get; set; } + public bool VSyncEnabled { get; set; } + //public bool FullScreenEnabled { get; set; } public WindowMode WindowMode @@ -126,6 +128,7 @@ namespace Barotrauma XElement graphicsMode = doc.Root.Element("graphicsmode"); GraphicsWidth = ToolBox.GetAttributeInt(graphicsMode, "width", 0); GraphicsHeight = ToolBox.GetAttributeInt(graphicsMode, "height", 0); + VSyncEnabled = ToolBox.GetAttributeBool(graphicsMode, "vsync", true); if (GraphicsWidth==0 || GraphicsHeight==0) { @@ -253,6 +256,7 @@ namespace Barotrauma gMode.ReplaceAttributes( new XAttribute("width", GraphicsWidth), new XAttribute("height", GraphicsHeight), + new XAttribute("vsync", VSyncEnabled), new XAttribute("displaymode", windowMode)); } @@ -349,6 +353,20 @@ namespace Barotrauma y += 70; + GUITickBox vsyncTickBox = new GUITickBox(new Rectangle(0, y, 20, 20), "Enable vertical sync", Alignment.CenterY | Alignment.Left, settingsFrame); + vsyncTickBox.OnSelected = (GUITickBox box) => + { + VSyncEnabled = !VSyncEnabled; + GameMain.Graphics.SynchronizeWithVerticalRetrace = VSyncEnabled; + GameMain.Graphics.ApplyChanges(); + UnsavedSettings = true; + + return true; + }; + vsyncTickBox.Selected = VSyncEnabled; + + y += 70; + new GUITextBlock(new Rectangle(0, y, 100, 20), "Sound volume:", GUI.Style, settingsFrame); GUIScrollBar soundScrollBar = new GUIScrollBar(new Rectangle(0, y + 20, 150, 20), GUI.Style, 0.1f, settingsFrame); soundScrollBar.BarScroll = SoundVolume; diff --git a/Subsurface/Source/Items/Components/Door.cs b/Subsurface/Source/Items/Components/Door.cs index 3181677b9..3ed69e783 100644 --- a/Subsurface/Source/Items/Components/Door.cs +++ b/Subsurface/Source/Items/Components/Door.cs @@ -95,6 +95,11 @@ namespace Barotrauma.Items.Components } } + public Rectangle WindowRect + { + get { return window; } + } + [Editable, HasDefaultValue(false, true)] public bool IsOpen { diff --git a/Subsurface/Source/Items/Components/ItemComponent.cs b/Subsurface/Source/Items/Components/ItemComponent.cs index bd9c9af23..a10d499dc 100644 --- a/Subsurface/Source/Items/Components/ItemComponent.cs +++ b/Subsurface/Source/Items/Components/ItemComponent.cs @@ -463,7 +463,9 @@ namespace Barotrauma.Items.Components //} public virtual void DrawHUD(SpriteBatch spriteBatch, Character character) { } - + + public virtual void UpdateHUD(Character character) { } + /// true if the operation was completed public virtual bool AIOperate(float deltaTime, Character character, AIObjectiveOperateItem objective) { diff --git a/Subsurface/Source/Items/Components/Machines/Deconstructor.cs b/Subsurface/Source/Items/Components/Machines/Deconstructor.cs index 89b4d0643..c8dc22eab 100644 --- a/Subsurface/Source/Items/Components/Machines/Deconstructor.cs +++ b/Subsurface/Source/Items/Components/Machines/Deconstructor.cs @@ -82,10 +82,14 @@ namespace Barotrauma.Items.Components public override void DrawHUD(SpriteBatch spriteBatch, Character character) { - GuiFrame.Update((float)Physics.step); GuiFrame.Draw(spriteBatch); } + public override void UpdateHUD(Character character) + { + GuiFrame.Update((float)Physics.step); + } + private bool ToggleActive(GUIButton button, object obj) { SetActive(!IsActive); diff --git a/Subsurface/Source/Items/Components/Machines/Engine.cs b/Subsurface/Source/Items/Components/Machines/Engine.cs index 7300050ad..297d72165 100644 --- a/Subsurface/Source/Items/Components/Machines/Engine.cs +++ b/Subsurface/Source/Items/Components/Machines/Engine.cs @@ -119,6 +119,11 @@ namespace Barotrauma.Items.Components } + public override void UpdateHUD(Character character) + { + GuiFrame.Update(1.0f / 60.0f); + } + public override void UpdateBroken(float deltaTime, Camera cam) { force = MathHelper.Lerp(force, 0.0f, 0.1f); diff --git a/Subsurface/Source/Items/Components/Machines/Fabricator.cs b/Subsurface/Source/Items/Components/Machines/Fabricator.cs index 3a6ae872e..1f690c678 100644 --- a/Subsurface/Source/Items/Components/Machines/Fabricator.cs +++ b/Subsurface/Source/Items/Components/Machines/Fabricator.cs @@ -338,6 +338,11 @@ namespace Barotrauma.Items.Components } public override void DrawHUD(SpriteBatch spriteBatch, Character character) + { + GuiFrame.Draw(spriteBatch); + } + + public override void UpdateHUD(Character character) { FabricableItem targetItem = itemList.SelectedData as FabricableItem; if (targetItem != null) @@ -346,7 +351,6 @@ namespace Barotrauma.Items.Components } GuiFrame.Update((float)Physics.step); - GuiFrame.Draw(spriteBatch); } private bool CanBeFabricated(FabricableItem fabricableItem, Character user) diff --git a/Subsurface/Source/Items/Components/Machines/Pump.cs b/Subsurface/Source/Items/Components/Machines/Pump.cs index 3c1a243fa..f45e3ab25 100644 --- a/Subsurface/Source/Items/Components/Machines/Pump.cs +++ b/Subsurface/Source/Items/Components/Machines/Pump.cs @@ -155,14 +155,18 @@ namespace Barotrauma.Items.Components { int x = GuiFrame.Rect.X; int y = GuiFrame.Rect.Y; - - GuiFrame.Update(1.0f / 60.0f); + GuiFrame.Draw(spriteBatch); spriteBatch.DrawString(GUI.Font, "Pumping speed: " + (int)flowPercentage + " %", new Vector2(x + 40, y + 85), Color.White); } + public override void UpdateHUD(Character character) + { + GuiFrame.Update(1.0f / 60.0f); + } + public override void ReceiveSignal(int stepsTaken, string signal, Connection connection, Item sender, float power=0.0f) { base.ReceiveSignal(stepsTaken, signal, connection, sender, power); diff --git a/Subsurface/Source/Items/Components/Machines/Reactor.cs b/Subsurface/Source/Items/Components/Machines/Reactor.cs index 82f409c2a..1dda50849 100644 --- a/Subsurface/Source/Items/Components/Machines/Reactor.cs +++ b/Subsurface/Source/Items/Components/Machines/Reactor.cs @@ -438,7 +438,6 @@ namespace Barotrauma.Items.Components int x = GuiFrame.Rect.X; int y = GuiFrame.Rect.Y; - GuiFrame.Update(1.0f / 60.0f); GuiFrame.Draw(spriteBatch); float xOffset = (graphTimer / (float)updateGraphInterval); @@ -481,6 +480,11 @@ namespace Barotrauma.Items.Components //y = y - 260; } + public override void UpdateHUD(Character character) + { + GuiFrame.Update(1.0f / 60.0f); + } + private bool ToggleAutoTemp(GUITickBox tickBox) { unsentChanges = true; diff --git a/Subsurface/Source/Items/Components/Machines/Steering.cs b/Subsurface/Source/Items/Components/Machines/Steering.cs index b2c0553bb..56bcd1f13 100644 --- a/Subsurface/Source/Items/Components/Machines/Steering.cs +++ b/Subsurface/Source/Items/Components/Machines/Steering.cs @@ -160,8 +160,7 @@ namespace Barotrauma.Items.Components int width = GuiFrame.Rect.Width, height = GuiFrame.Rect.Height; int x = GuiFrame.Rect.X; int y = GuiFrame.Rect.Y; - - GuiFrame.Update(1.0f / 60.0f); + GuiFrame.Draw(spriteBatch); if (voltage < minVoltage && powerConsumption > 0.0f) return; @@ -210,6 +209,11 @@ namespace Barotrauma.Items.Components } } + public override void UpdateHUD(Character character) + { + GuiFrame.Update(1.0f / 60.0f); + } + private void UpdateAutoPilot(float deltaTime) { if (posToMaintain != null) diff --git a/Subsurface/Source/Items/Components/Power/PowerContainer.cs b/Subsurface/Source/Items/Components/Power/PowerContainer.cs index 1fcf4a172..cf34a92f6 100644 --- a/Subsurface/Source/Items/Components/Power/PowerContainer.cs +++ b/Subsurface/Source/Items/Components/Power/PowerContainer.cs @@ -246,6 +246,11 @@ namespace Barotrauma.Items.Components spriteBatch.DrawString(GUI.Font, "Recharge rate: " + (int)((rechargeSpeed / maxRechargeSpeed) * 100.0f) + " %", new Vector2(x + 30, y + 95), Color.White); } + public override void UpdateHUD(Character character) + { + GuiFrame.Update(1.0f / 60.0f); + } + public override bool FillNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetBuffer message) { message.WriteRangedSingle(MathHelper.Clamp(rechargeSpeed / MaxRechargeSpeed, 0.0f, 1.0f), 0.0f, 1.0f, 8); diff --git a/Subsurface/Source/Items/Components/Power/PowerTransfer.cs b/Subsurface/Source/Items/Components/Power/PowerTransfer.cs index 4b3366829..6e10aae51 100644 --- a/Subsurface/Source/Items/Components/Power/PowerTransfer.cs +++ b/Subsurface/Source/Items/Components/Power/PowerTransfer.cs @@ -186,6 +186,11 @@ namespace Barotrauma.Items.Components spriteBatch.DrawString(GUI.Font, "Load: " + (int)powerLoad + " kW", new Vector2(x + 30, y + 100), Color.White); } + public override void UpdateHUD(Character character) + { + GuiFrame.Update(1.0f / 60.0f); + } + public override void ReceiveSignal(int stepsTaken, string signal, Connection connection, Item sender, float power) { base.ReceiveSignal(stepsTaken, signal, connection, sender, power); diff --git a/Subsurface/Source/Items/Components/Signal/LightComponent.cs b/Subsurface/Source/Items/Components/Signal/LightComponent.cs index a761383d3..bb51c0353 100644 --- a/Subsurface/Source/Items/Components/Signal/LightComponent.cs +++ b/Subsurface/Source/Items/Components/Signal/LightComponent.cs @@ -122,7 +122,7 @@ namespace Barotrauma.Items.Components base.Update(deltaTime, cam); light.ParentSub = item.Submarine; - + ApplyStatusEffects(ActionType.OnActive, deltaTime); if (item.Container != null) diff --git a/Subsurface/Source/Items/FixRequirement.cs b/Subsurface/Source/Items/FixRequirement.cs index e0884310a..70d5644f6 100644 --- a/Subsurface/Source/Items/FixRequirement.cs +++ b/Subsurface/Source/Items/FixRequirement.cs @@ -186,18 +186,23 @@ namespace Barotrauma } public static void DrawHud(SpriteBatch spriteBatch, Item item, Character character) + { + if (frame == null) return; + + frame.Draw(spriteBatch); + } + + public static void UpdateHud(Item item, Character character) { if (frame == null || frame.UserData != item) { CreateGUIFrame(item); - } UpdateGUIFrame(item, character); if (frame == null) return; frame.Update((float)Physics.step); - frame.Draw(spriteBatch); } } } diff --git a/Subsurface/Source/Items/Item.cs b/Subsurface/Source/Items/Item.cs index 2ee92427d..440d69459 100644 --- a/Subsurface/Source/Items/Item.cs +++ b/Subsurface/Source/Items/Item.cs @@ -40,6 +40,8 @@ namespace Barotrauma public Hull CurrentHull; + public bool Visible = true; + public SpriteEffects SpriteEffects = SpriteEffects.None; //components that determine the functionality of the item @@ -806,9 +808,9 @@ namespace Barotrauma { base.FlipX(); - if (prefab.CanSpriteFlipX) - { - SpriteEffects ^= SpriteEffects.FlipHorizontally; + if (prefab.CanSpriteFlipX) + { + SpriteEffects ^= SpriteEffects.FlipHorizontally; } foreach (ItemComponent component in components) @@ -819,10 +821,11 @@ namespace Barotrauma public override void Draw(SpriteBatch spriteBatch, bool editing, bool back = true) { + if (!Visible) return; Color color = (isSelected && editing) ? color = Color.Red : spriteColor; if (isHighlighted) color = Color.Orange; - SpriteEffects oldEffects = prefab.sprite.effects; + SpriteEffects oldEffects = prefab.sprite.effects; prefab.sprite.effects ^= SpriteEffects; if (prefab.sprite != null) @@ -1076,6 +1079,21 @@ namespace Barotrauma } } + public virtual void UpdateHUD(Character character) + { + if (condition <= 0.0f) + { + FixRequirement.UpdateHud(this, character); + return; + } + + + foreach (ItemComponent ic in components) + { + ic.UpdateHUD(character); + } + } + public List GetConnectedComponents(bool recursive = false) { List connectedComponents = new List(); diff --git a/Subsurface/Source/Map/Hull.cs b/Subsurface/Source/Map/Hull.cs index ee3a09295..8a69404e5 100644 --- a/Subsurface/Source/Map/Hull.cs +++ b/Subsurface/Source/Map/Hull.cs @@ -60,6 +60,8 @@ namespace Barotrauma private bool update; + public bool Visible = true; + private Sound currentFlowSound; private int soundIndex; private float soundVolume; @@ -559,6 +561,17 @@ namespace Barotrauma public override void Draw(SpriteBatch spriteBatch, bool editing, bool back = true) { //if (back) return; + Rectangle drawRect; + if (!Visible) + { + drawRect = + 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), + new Vector2(rect.Width, rect.Height), + Color.Black,true); + } if (!ShowHulls && !GameMain.DebugDraw) return; @@ -566,7 +579,7 @@ namespace Barotrauma if (aiTarget != null) aiTarget.Draw(spriteBatch); - Rectangle drawRect = + drawRect = Submarine == null ? rect : new Rectangle((int)(Submarine.DrawPosition.X + rect.X), (int)(Submarine.DrawPosition.Y + rect.Y), rect.Width, rect.Height); GUI.DrawRectangle(spriteBatch, @@ -746,6 +759,65 @@ namespace Barotrauma return null; } + public static void DetectItemVisibility(Character c=null) + { + if (c==null) + { + foreach (Item it in Item.ItemList) + { + it.Visible = true; + } + } + else + { + Hull h = c.CurrentHull; + hullList.ForEach(j => j.Visible = false); + List visibleHulls; + if (h == null || c.Submarine == null) + { + visibleHulls = hullList.FindAll(j => j.CanSeeOther(null, false)); + } + else + { + visibleHulls = hullList.FindAll(j => h.CanSeeOther(j, true)); + } + visibleHulls.ForEach(j => j.Visible = true); + foreach (Item it in Item.ItemList) + { + if (it.CurrentHull == null || visibleHulls.Contains(it.CurrentHull)) it.Visible = true; + else it.Visible = false; + } + } + } + + private bool CanSeeOther(Hull other,bool allowIndirect=true) + { + if (other == this) return true; + + if (other != null && other.Submarine==Submarine) + { + bool retVal = false; + foreach (Gap g in ConnectedGaps) + { + if (g.ConnectedWall != null && g.ConnectedWall.CastShadow) continue; + List otherHulls = Hull.hullList.FindAll(h => h.ConnectedGaps.Contains(g) && h!=this); + retVal = otherHulls.Any(h => h == other); + if (!retVal && allowIndirect) retVal = otherHulls.Any(h => h.CanSeeOther(other, false)); + if (retVal) return true; + } + } + else + { + foreach (Gap g in ConnectedGaps) + { + if (g.ConnectedDoor != null && !hullList.Any(h => h.ConnectedGaps.Contains(g) && h!=this)) return true; + } + List structures = MapEntity.mapEntityList.FindAll(me => me is Structure && me.Rect.Intersects(Rect)); + return structures.Any(st => !(st as Structure).CastShadow); + } + return false; + } + //public List FindGaps() //{ // List gaps = new List(); diff --git a/Subsurface/Source/Map/Levels/WaterRenderer.cs b/Subsurface/Source/Map/Levels/WaterRenderer.cs index 828255172..e897f8b45 100644 --- a/Subsurface/Source/Map/Levels/WaterRenderer.cs +++ b/Subsurface/Source/Map/Levels/WaterRenderer.cs @@ -63,10 +63,7 @@ namespace Barotrauma waterEffect.Parameters["xWavePos"].SetValue(wavePos); waterEffect.Parameters["xBlurDistance"].SetValue(blurAmount); //waterEffect.CurrentTechnique.Passes[0].Apply(); - - wavePos.X += 0.0001f; - wavePos.Y += 0.0001f; - + #if WINDOWS waterEffect.Parameters["xTexture"].SetValue(texture); spriteBatch.Draw(waterTexture, new Rectangle(0, 0, GameMain.GraphicsWidth, GameMain.GraphicsHeight), Color.White); @@ -77,6 +74,12 @@ namespace Barotrauma spriteBatch.End(); } + public void ScrollWater(float deltaTime) + { + wavePos.X += 0.006f * deltaTime; + wavePos.Y += 0.006f * deltaTime; + } + public void Render(GraphicsDevice graphicsDevice, Camera cam, RenderTarget2D texture, Matrix transform) { if (vertices == null) return; diff --git a/Subsurface/Source/Map/Lights/LightManager.cs b/Subsurface/Source/Map/Lights/LightManager.cs index 25d86b263..3095465a7 100644 --- a/Subsurface/Source/Map/Lights/LightManager.cs +++ b/Subsurface/Source/Map/Lights/LightManager.cs @@ -136,6 +136,7 @@ namespace Barotrauma.Lights { if (Character.Controlled.ClosestItem != null) { + Character.Controlled.ClosestItem.IsHighlighted = true; Character.Controlled.ClosestItem.Draw(spriteBatch, false, true); Character.Controlled.ClosestItem.IsHighlighted = true; } diff --git a/Subsurface/Source/Map/Structure.cs b/Subsurface/Source/Map/Structure.cs index 18c789cfe..bfc3f0b4b 100644 --- a/Subsurface/Source/Map/Structure.cs +++ b/Subsurface/Source/Map/Structure.cs @@ -52,7 +52,10 @@ namespace Barotrauma List bodies; //sections of the wall that are supposed to be rendered - private WallSection[] sections; + public WallSection[] sections { + get; + private set; + } bool isHorizontal; diff --git a/Subsurface/Source/Networking/GameServer.cs b/Subsurface/Source/Networking/GameServer.cs index a3d6e438b..802ef7dfb 100644 --- a/Subsurface/Source/Networking/GameServer.cs +++ b/Subsurface/Source/Networking/GameServer.cs @@ -197,22 +197,23 @@ namespace Barotrauma.Networking request.AddParameter("password", string.IsNullOrWhiteSpace(password) ? 0 : 1); // execute the request - RestResponse response = (RestResponse)restClient.Execute(request); - - if (response.StatusCode != System.Net.HttpStatusCode.OK) + restClient.ExecuteAsync(request, response => { - DebugConsole.ThrowError("Error while connecting to master server (" +response.StatusCode+": "+response.StatusDescription+")"); - return; - } + if (response.StatusCode != System.Net.HttpStatusCode.OK) + { + DebugConsole.ThrowError("Error while connecting to master server (" + response.StatusCode + ": " + response.StatusDescription + ")"); + return; + } - if (response != null && !string.IsNullOrWhiteSpace(response.Content)) - { - DebugConsole.ThrowError("Error while connecting to master server (" +response.Content+")"); - return; - } + if (response != null && !string.IsNullOrWhiteSpace(response.Content)) + { + DebugConsole.ThrowError("Error while connecting to master server (" + response.Content + ")"); + return; + } - registeredToMaster = true; - refreshMasterTimer = DateTime.Now + refreshMasterInterval; + registeredToMaster = true; + refreshMasterTimer = DateTime.Now + refreshMasterInterval; + }); } private IEnumerable RefreshMaster() diff --git a/Subsurface/Source/Screens/GameScreen.cs b/Subsurface/Source/Screens/GameScreen.cs index e85d1d26d..577988788 100644 --- a/Subsurface/Source/Screens/GameScreen.cs +++ b/Subsurface/Source/Screens/GameScreen.cs @@ -114,6 +114,14 @@ namespace Barotrauma Character.UpdateAll(cam, (float)deltaTime); + if (Character.Controlled != null && Character.Controlled.SelectedConstruction != null) + { + if (Character.Controlled.SelectedConstruction == Character.Controlled.ClosestItem) + { + Character.Controlled.SelectedConstruction.UpdateHUD(Character.Controlled); + } + } + Physics.accumulator = Math.Min(Physics.accumulator, Physics.step * 6); //Physics.accumulator = Physics.step; while (Physics.accumulator >= Physics.step) @@ -168,9 +176,13 @@ 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(); diff --git a/Subsurface/Source/Screens/ServerListScreen.cs b/Subsurface/Source/Screens/ServerListScreen.cs index 71d03dfc2..268824155 100644 --- a/Subsurface/Source/Screens/ServerListScreen.cs +++ b/Subsurface/Source/Screens/ServerListScreen.cs @@ -370,7 +370,7 @@ namespace Barotrauma { menu.Update((float)deltaTime); - GUI.Update((float)deltaTime); + //GUI.Update((float)deltaTime); } } }