From e7e7d321236155f3a8bd0a7085872709edf67919 Mon Sep 17 00:00:00 2001 From: Joonas Rikkonen Date: Wed, 20 Jun 2018 15:55:23 +0300 Subject: [PATCH] Cherry-picked 0ff9a3d (more ragdoll optimization) --- .../Source/Characters/Animation/Ragdoll.cs | 38 ++++++++----------- .../BarotraumaShared/Source/Items/Item.cs | 12 +++--- 2 files changed, 21 insertions(+), 29 deletions(-) diff --git a/Barotrauma/BarotraumaShared/Source/Characters/Animation/Ragdoll.cs b/Barotrauma/BarotraumaShared/Source/Characters/Animation/Ragdoll.cs index 869180621..273a83788 100644 --- a/Barotrauma/BarotraumaShared/Source/Characters/Animation/Ragdoll.cs +++ b/Barotrauma/BarotraumaShared/Source/Characters/Animation/Ragdoll.cs @@ -1101,22 +1101,19 @@ namespace Barotrauma float tfloorY = rayStart.Y + (rayEnd.Y - rayStart.Y) * closestFraction; float targetY = tfloorY + Collider.height * 0.5f + Collider.radius + colliderHeightFromFloor; - - if (Math.Abs(Collider.SimPosition.Y - targetY) > 0.01f && Collider.SimPosition.Y 0.01f) { - Vector2 newSpeed = Collider.LinearVelocity; - newSpeed.Y = (targetY - Collider.SimPosition.Y)*5.0f; - Collider.LinearVelocity = newSpeed; - } - else - { - Vector2 newSpeed = Collider.LinearVelocity; - newSpeed.Y = 0.0f; - Collider.LinearVelocity = newSpeed; - Vector2 newPos = Collider.SimPosition; - newPos.Y = targetY; - Collider.SetTransform(newPos, Collider.Rotation); - } + if (forceImmediate) + { + Collider.LinearVelocity = new Vector2(Collider.LinearVelocity.X, 0); + Collider.SetTransform(new Vector2(Collider.SimPosition.X, targetY), Collider.Rotation); + } + else + { + Collider.LinearVelocity = new Vector2(Collider.LinearVelocity.X, (targetY - Collider.SimPosition.Y) * 5.0f); + } + } } } } @@ -1465,22 +1462,17 @@ namespace Barotrauma private Vector2 GetFlowForce() { - Vector2 limbPos = ConvertUnits.ToDisplayUnits(Limbs[0].SimPosition); + Vector2 limbPos = Limbs[0].Position; Vector2 force = Vector2.Zero; - foreach (MapEntity e in MapEntity.mapEntityList) + foreach (Gap gap in Gap.GapList) { - Gap gap = e as Gap; - if (gap == null || gap.FlowTargetHull != currentHull || gap.LerpedFlowForce == Vector2.Zero) continue; + if (gap.Open <= 0.0f || gap.FlowTargetHull != currentHull || gap.LerpedFlowForce == Vector2.Zero) continue; Vector2 gapPos = gap.SimPosition; - float dist = Vector2.Distance(limbPos, gapPos); - force += Vector2.Normalize(gap.LerpedFlowForce) * (Math.Max(gap.LerpedFlowForce.Length() - dist, 0.0f) / 500.0f); } - - if (force.Length() > 20.0f) return force; return force; } diff --git a/Barotrauma/BarotraumaShared/Source/Items/Item.cs b/Barotrauma/BarotraumaShared/Source/Items/Item.cs index 32da8efeb..5fe179479 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Item.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Item.cs @@ -783,12 +783,6 @@ namespace Barotrauma public override void Update(float deltaTime, Camera cam) { - if (Level.Loaded != null && WorldPosition.Y < Level.MaxEntityDepth) - { - Spawner.AddToRemoveQueue(this); - return; - } - ApplyStatusEffects(ActionType.Always, deltaTime, null); foreach (ItemComponent ic in components) @@ -851,6 +845,12 @@ namespace Barotrauma MathHelper.Clamp(body.LinearVelocity.X, -MaxVel, MaxVel), MathHelper.Clamp(body.LinearVelocity.Y, -MaxVel, MaxVel)); } + + if (CurrentHull == null && body.SimPosition.Y < ConvertUnits.ToSimUnits(Level.MaxEntityDepth)) + { + Spawner.AddToRemoveQueue(this); + return; + } } UpdateNetPosition();