Merge branch 'master' into animcontroller-overhaul
Conflicts: Subsurface/Content/Characters/Crawler/crawler.xml Subsurface/Source/Characters/AICharacter.cs Subsurface/Source/Characters/Animation/FishAnimController.cs Subsurface/Source/Characters/Animation/Ragdoll.cs Subsurface/Source/Characters/Character.cs Subsurface/Source/Map/Submarine.cs Subsurface/Source/Map/SubmarineBody.cs Subsurface/Source/Networking/GameClient.cs Subsurface/Source/Networking/GameServer.cs Subsurface/Source/Physics/PhysicsBody.cs
This commit is contained in:
@@ -11,9 +11,35 @@ using System;
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
struct PosInfo
|
||||
{
|
||||
public readonly Vector2 Position;
|
||||
public readonly Direction Direction;
|
||||
|
||||
public readonly float Timestamp;
|
||||
public readonly UInt32 ID;
|
||||
|
||||
public PosInfo(Vector2 pos, Direction dir, float time)
|
||||
{
|
||||
Position = pos;
|
||||
Direction = dir;
|
||||
Timestamp = time;
|
||||
|
||||
ID = 0;
|
||||
}
|
||||
|
||||
public PosInfo(Vector2 pos, Direction dir, UInt32 ID)
|
||||
{
|
||||
Position = pos;
|
||||
Direction = dir;
|
||||
this.ID = ID;
|
||||
|
||||
Timestamp = 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
class PhysicsBody
|
||||
{
|
||||
|
||||
public enum Shape
|
||||
{
|
||||
Circle, Rectangle, Capsule
|
||||
@@ -70,18 +96,7 @@ namespace Barotrauma
|
||||
targetPosition.Y = MathHelper.Clamp(value.Y, -10000.0f, 10000.0f);
|
||||
}
|
||||
}
|
||||
|
||||
//public Vector2 TargetVelocity
|
||||
//{
|
||||
// get { return targetVelocity; }
|
||||
// set
|
||||
// {
|
||||
// if (!MathUtils.IsValid(value)) return;
|
||||
// targetVelocity.X = MathHelper.Clamp(value.X, -100.0f, 100.0f);
|
||||
// targetVelocity.Y = MathHelper.Clamp(value.Y, -100.0f, 100.0f);
|
||||
// }
|
||||
//}
|
||||
|
||||
|
||||
public float TargetRotation
|
||||
{
|
||||
get { return targetRotation; }
|
||||
@@ -92,16 +107,6 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
//public float TargetAngularVelocity
|
||||
//{
|
||||
// get { return targetAngularVelocity; }
|
||||
// set
|
||||
// {
|
||||
// if (!MathUtils.IsValid(value)) return;
|
||||
// targetAngularVelocity = value;
|
||||
// }
|
||||
//}
|
||||
|
||||
public Vector2 DrawPosition
|
||||
{
|
||||
get { return Submarine == null ? drawPosition : drawPosition + Submarine.DrawPosition; }
|
||||
@@ -225,6 +230,16 @@ namespace Barotrauma
|
||||
list.Add(this);
|
||||
}
|
||||
|
||||
public PhysicsBody(Body farseerBody)
|
||||
{
|
||||
body = farseerBody;
|
||||
body.UserData = this;
|
||||
|
||||
LastSentPosition = body.Position;
|
||||
|
||||
list.Add(this);
|
||||
}
|
||||
|
||||
public PhysicsBody(XElement element, Vector2 position, float scale=1.0f)
|
||||
{
|
||||
float radius = ConvertUnits.ToSimUnits(ToolBox.GetAttributeFloat(element, "radius", 0.0f)) * scale;
|
||||
@@ -466,14 +481,23 @@ namespace Barotrauma
|
||||
|
||||
public void CorrectPosition(List<PosInfo> positionBuffer, float deltaTime, out Vector2 newVelocity)
|
||||
{
|
||||
newVelocity = Vector2.Zero;
|
||||
if (positionBuffer.Count < 2) return;
|
||||
Vector2 newPosition = SimPosition;
|
||||
CorrectPosition(positionBuffer, deltaTime, out newVelocity, out newPosition);
|
||||
|
||||
SetTransform(newPosition, Rotation);
|
||||
}
|
||||
|
||||
|
||||
public void CorrectPosition(List<PosInfo> positionBuffer, float deltaTime, out Vector2 newVelocity, out Vector2 newPosition)
|
||||
{
|
||||
newVelocity = Vector2.Zero;
|
||||
newPosition = SimPosition;
|
||||
|
||||
if (positionBuffer.Count < 2) return;
|
||||
|
||||
PosInfo prev = positionBuffer[0];
|
||||
PosInfo next = positionBuffer[1];
|
||||
|
||||
Vector2 currPos = SimPosition;
|
||||
|
||||
|
||||
//interpolate the position of the collider from the first position in the buffer towards the second
|
||||
if (prev.Timestamp < next.Timestamp)
|
||||
{
|
||||
@@ -482,28 +506,24 @@ namespace Barotrauma
|
||||
float speedMultiplier = 1.0f + (float)Math.Pow((positionBuffer.Count - 2) / 2.0f, 2.0f);
|
||||
|
||||
netInterpolationState += (deltaTime * speedMultiplier) / (next.Timestamp - prev.Timestamp);
|
||||
currPos = Vector2.Lerp(prev.Position, next.Position, netInterpolationState);
|
||||
newPosition = Vector2.Lerp(prev.Position, next.Position, netInterpolationState);
|
||||
|
||||
//override the targetMovement to make the character play the walking/running animation
|
||||
newVelocity = (next.Position - prev.Position) / (next.Timestamp - prev.Timestamp);
|
||||
}
|
||||
else
|
||||
{
|
||||
currPos = next.Position;
|
||||
newPosition = next.Position;
|
||||
netInterpolationState = 1.0f;
|
||||
}
|
||||
|
||||
SetTransform(currPos, Rotation);
|
||||
|
||||
if (netInterpolationState >= 1.0f)
|
||||
{
|
||||
netInterpolationState = 0.0f;
|
||||
positionBuffer.RemoveAt(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// rotate the body towards the target rotation in the "shortest direction"
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user