Fixed some inconsistencies and oddities in physics-handling code

I'm not sure if this fixes or breaks anything, but it's worth a shot.
This commit is contained in:
juanjp600
2017-12-15 18:11:00 -03:00
parent 9ad9a65f1e
commit 1cb39f7fd5
7 changed files with 16 additions and 8 deletions
@@ -470,7 +470,7 @@ namespace Barotrauma
} }
else else
{ {
body.FarseerBody.Enabled = false; body.Enabled = false;
} }
if ((newPosition - SimPosition).Length() > body.LinearVelocity.Length() * 2.0f) if ((newPosition - SimPosition).Length() > body.LinearVelocity.Length() * 2.0f)
@@ -78,7 +78,7 @@ namespace Barotrauma
} }
//re-enable collider //re-enable collider
if (!Collider.FarseerBody.Enabled) if (!Collider.Enabled)
{ {
var lowestLimb = FindLowestLimb(); var lowestLimb = FindLowestLimb();
@@ -87,7 +87,7 @@ namespace Barotrauma
Math.Max(lowestLimb.SimPosition.Y + (Collider.radius + Collider.height / 2), Collider.SimPosition.Y)), Math.Max(lowestLimb.SimPosition.Y + (Collider.radius + Collider.height / 2), Collider.SimPosition.Y)),
0.0f); 0.0f);
Collider.FarseerBody.Enabled = true; Collider.Enabled = true;
} }
ResetPullJoints(); ResetPullJoints();
@@ -104,7 +104,7 @@ namespace Barotrauma
//re-enable collider //re-enable collider
if (!Collider.FarseerBody.Enabled) if (!Collider.Enabled)
{ {
var lowestLimb = FindLowestLimb(); var lowestLimb = FindLowestLimb();
@@ -114,7 +114,7 @@ namespace Barotrauma
Collider.Rotation); Collider.Rotation);
Collider.FarseerBody.ResetDynamics(); Collider.FarseerBody.ResetDynamics();
Collider.FarseerBody.Enabled = true; Collider.Enabled = true;
} }
if (swimming) if (swimming)
@@ -1469,5 +1469,12 @@ namespace Barotrauma
list.Remove(this); list.Remove(this);
} }
public static void RemoveAll()
{
for (int i = list.Count - 1; i >= 0; i--)
{
list[i].Remove();
}
}
} }
} }
@@ -1605,7 +1605,7 @@ namespace Barotrauma
msg.Write(body.FarseerBody.Awake); msg.Write(body.FarseerBody.Awake);
if (body.FarseerBody.Awake) if (body.FarseerBody.Awake)
{ {
body.FarseerBody.Enabled = true; body.Enabled = true;
msg.WriteRangedSingle(MathHelper.Clamp(body.LinearVelocity.X, -MaxVel, MaxVel), -MaxVel, MaxVel, 12); msg.WriteRangedSingle(MathHelper.Clamp(body.LinearVelocity.X, -MaxVel, MaxVel), -MaxVel, MaxVel, 12);
msg.WriteRangedSingle(MathHelper.Clamp(body.LinearVelocity.Y, -MaxVel, MaxVel), -MaxVel, MaxVel, 12); msg.WriteRangedSingle(MathHelper.Clamp(body.LinearVelocity.Y, -MaxVel, MaxVel), -MaxVel, MaxVel, 12);
} }
@@ -835,6 +835,7 @@ namespace Barotrauma
{ {
StairDirection = StairDirection == Direction.Left ? Direction.Right : Direction.Left; StairDirection = StairDirection == Direction.Left ? Direction.Right : Direction.Left;
bodies.ForEach(b => GameMain.World.RemoveBody(b)); bodies.ForEach(b => GameMain.World.RemoveBody(b));
bodies.Clear();
CreateStairBodies(); CreateStairBodies();
} }
@@ -1208,9 +1208,9 @@ namespace Barotrauma
Item.ItemList.Clear(); Item.ItemList.Clear();
} }
PhysicsBody.RemoveAll(); Ragdoll.RemoveAll();
Ragdoll.list.Clear(); PhysicsBody.RemoveAll();
GameMain.World.Clear(); GameMain.World.Clear();