From edab86f7300e82e6f1fdd78e810d006f2f060eec Mon Sep 17 00:00:00 2001 From: juanjp600 Date: Wed, 21 Sep 2016 16:46:12 -0300 Subject: [PATCH] Character freezing + Misc fixes --- .../Animation/HumanoidAnimController.cs | 1 + .../Source/Characters/Animation/Ragdoll.cs | 27 ++++++++++++++++++- Subsurface/Source/Characters/Character.cs | 13 ++++++--- Subsurface/Source/DebugConsole.cs | 3 +++ Subsurface/Source/GUI/GUI.cs | 4 +-- Subsurface/Source/GameMain.cs | 1 + Subsurface/Source/Map/Lights/LightManager.cs | 1 + Subsurface/Source/Physics/PhysicsBody.cs | 13 +++++++-- Subsurface/Source/PlayerInput.cs | 16 ++++++++++- 9 files changed, 70 insertions(+), 9 deletions(-) diff --git a/Subsurface/Source/Characters/Animation/HumanoidAnimController.cs b/Subsurface/Source/Characters/Animation/HumanoidAnimController.cs index 76ec4a25b..116766d36 100644 --- a/Subsurface/Source/Characters/Animation/HumanoidAnimController.cs +++ b/Subsurface/Source/Characters/Animation/HumanoidAnimController.cs @@ -62,6 +62,7 @@ namespace Barotrauma public override void UpdateAnim(float deltaTime) { if (character.IsDead) return; + if (Frozen) return; Vector2 colliderPos = GetLimb(LimbType.Torso).SimPosition; diff --git a/Subsurface/Source/Characters/Animation/Ragdoll.cs b/Subsurface/Source/Characters/Animation/Ragdoll.cs index c74734916..2976cdfe4 100644 --- a/Subsurface/Source/Characters/Animation/Ragdoll.cs +++ b/Subsurface/Source/Characters/Animation/Ragdoll.cs @@ -19,6 +19,10 @@ namespace Barotrauma protected Hull currentHull; public Limb[] Limbs; + + private bool isFrozen = false; + public bool Frozen = false; + private Dictionary limbDictionary; public RevoluteJoint[] limbJoints; @@ -320,7 +324,7 @@ namespace Barotrauma public void AddLimb(Limb limb) { limb.body.FarseerBody.OnCollision += OnLimbCollision; - + Array.Resize(ref Limbs, Limbs.Length + 1); Limbs[Limbs.Length-1] = limb; @@ -684,6 +688,27 @@ namespace Barotrauma { if (!character.Enabled) return; + if (Frozen) + { + if (!isFrozen) + { + foreach (Limb l in Limbs) + { + l.body.PhysEnabled = false; + } + isFrozen = true; + } + return; + } + if (isFrozen) + { + for (int i=0;i < Limbs.Length;i++) + { + Limbs[i].body.PhysEnabled = true; + } + isFrozen = false; + } + UpdateNetPlayerPosition(); Vector2 flowForce = Vector2.Zero; diff --git a/Subsurface/Source/Characters/Character.cs b/Subsurface/Source/Characters/Character.cs index 30061000b..202a899d0 100644 --- a/Subsurface/Source/Characters/Character.cs +++ b/Subsurface/Source/Characters/Character.cs @@ -27,7 +27,7 @@ namespace Barotrauma get { return netStateID; } } - List memInput = new List(); + List memInput = new List(); List memMouseX = new List(); List memMouseY = new List(); @@ -1142,7 +1142,14 @@ namespace Barotrauma if (isDead) return; - if (networkUpdateSent) + if (this != Character.Controlled) + { + if (GameMain.Server != null) + { + + } + } + /*if (networkUpdateSent) { foreach (Key key in keys) { @@ -1151,7 +1158,7 @@ namespace Barotrauma } networkUpdateSent = false; - } + }*/ DisableImpactDamageTimer -= deltaTime; diff --git a/Subsurface/Source/DebugConsole.cs b/Subsurface/Source/DebugConsole.cs index c8e5a00b2..01e192a1f 100644 --- a/Subsurface/Source/DebugConsole.cs +++ b/Subsurface/Source/DebugConsole.cs @@ -479,6 +479,9 @@ namespace Barotrauma Character.Controlled.Revive(false); } break; + case "freeze": + if (Character.Controlled != null) Character.Controlled.AnimController.Frozen = !Character.Controlled.AnimController.Frozen; + break; case "freecamera": case "freecam": Character.Controlled = null; diff --git a/Subsurface/Source/GUI/GUI.cs b/Subsurface/Source/GUI/GUI.cs index 9cd7cb2ee..60e2dbc12 100644 --- a/Subsurface/Source/GUI/GUI.cs +++ b/Subsurface/Source/GUI/GUI.cs @@ -461,8 +461,8 @@ namespace Barotrauma DebugConsole.Draw(spriteBatch); if (GUIComponent.MouseOn != null && !string.IsNullOrWhiteSpace(GUIComponent.MouseOn.ToolTip)) GUIComponent.MouseOn.DrawToolTip(spriteBatch); - - cursor.Draw(spriteBatch, PlayerInput.MousePosition); + + cursor.Draw(spriteBatch, PlayerInput.LatestMousePosition); } public static void Update(float deltaTime) diff --git a/Subsurface/Source/GameMain.cs b/Subsurface/Source/GameMain.cs index 6d77ff4a1..9c5221308 100644 --- a/Subsurface/Source/GameMain.cs +++ b/Subsurface/Source/GameMain.cs @@ -295,6 +295,7 @@ namespace Barotrauma double realDeltaTime = gameTime.ElapsedGameTime.TotalSeconds; double deltaTime = 0.016; updatesToMake += realDeltaTime; + PlayerInput.UpdateVariable(); while (updatesToMake > 0.0) { 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/Physics/PhysicsBody.cs b/Subsurface/Source/Physics/PhysicsBody.cs index 185768bea..adedc8af7 100644 --- a/Subsurface/Source/Physics/PhysicsBody.cs +++ b/Subsurface/Source/Physics/PhysicsBody.cs @@ -118,10 +118,19 @@ namespace Barotrauma set { dir = value; } } + private bool isEnabled = true; + private bool isPhysEnabled = true; + public bool Enabled + { + get { return isEnabled; } + set { isEnabled = value; if (isEnabled) body.Enabled = isPhysEnabled; else body.Enabled = false; } + } + + public bool PhysEnabled { get { return body.Enabled; } - set { body.Enabled = value; } + set { isPhysEnabled = value; if (Enabled) body.Enabled = value; } } public Vector2 SimPosition @@ -350,7 +359,7 @@ namespace Barotrauma public void Draw(SpriteBatch spriteBatch, Sprite sprite, Color color, float? depth = null, float scale = 1.0f) { - if (!body.Enabled) return; + if (!Enabled) return; UpdateDrawPosition(); diff --git a/Subsurface/Source/PlayerInput.cs b/Subsurface/Source/PlayerInput.cs index 99d54c936..330be3604 100644 --- a/Subsurface/Source/PlayerInput.cs +++ b/Subsurface/Source/PlayerInput.cs @@ -204,6 +204,7 @@ namespace Barotrauma public static class PlayerInput { static MouseState mouseState, oldMouseState; + static MouseState latestMouseState; //the absolute latest state, do NOT use for player interaction static KeyboardState keyboardState, oldKeyboardState; static double timeSinceClick; @@ -219,6 +220,11 @@ namespace Barotrauma get { return new Vector2(mouseState.Position.X, mouseState.Position.Y); } } + public static Vector2 LatestMousePosition + { + get { return new Vector2(latestMouseState.Position.X, latestMouseState.Position.Y); } + } + //public static MouseState GetMouseState //{ // get { return mouseState; } @@ -334,7 +340,8 @@ namespace Barotrauma timeSinceClick += deltaTime; oldMouseState = mouseState; - mouseState = Mouse.GetState(); + mouseState = latestMouseState; + UpdateVariable(); oldKeyboardState = keyboardState; keyboardState = Keyboard.GetState(); @@ -346,5 +353,12 @@ namespace Barotrauma timeSinceClick = 0.0; } } + + public static void UpdateVariable() + { + //do NOT use this for actual interaction with the game, this is to be used for debugging and rendering ONLY + + latestMouseState = Mouse.GetState(); + } } }