- a WIP attempt to correct the position of the controlled character based on updates from the server
- fixed server not being able to move character controllers - renamed IsNetworkPlayer -> IsRemotePlayer
This commit is contained in:
@@ -113,7 +113,7 @@ namespace Barotrauma
|
||||
|
||||
if (mirror || !inWater)
|
||||
{
|
||||
if (!character.IsNetworkPlayer)
|
||||
if (!character.IsRemotePlayer)
|
||||
{
|
||||
//targetDir = (movement.X > 0.0f) ? Direction.Right : Direction.Left;
|
||||
if (targetMovement.X > 0.1f && targetMovement.X > Math.Abs(targetMovement.Y) * 0.5f)
|
||||
@@ -153,7 +153,7 @@ namespace Barotrauma
|
||||
|
||||
if (TargetDir != dir)
|
||||
{
|
||||
if (flipTimer>1.0f || character.IsNetworkPlayer)
|
||||
if (flipTimer>1.0f || character.IsRemotePlayer)
|
||||
{
|
||||
Flip();
|
||||
if (mirror || !inWater) Mirror();
|
||||
|
||||
@@ -84,7 +84,7 @@ namespace Barotrauma
|
||||
}
|
||||
|
||||
|
||||
if (!character.IsNetworkPlayer || true)
|
||||
if (!character.IsRemotePlayer || true)
|
||||
{
|
||||
//re-enable collider
|
||||
if (!collider.FarseerBody.Enabled)
|
||||
@@ -215,7 +215,7 @@ namespace Barotrauma
|
||||
}
|
||||
|
||||
aiming = false;
|
||||
if (character.IsNetworkPlayer) collider.LinearVelocity = Vector2.Zero;
|
||||
if (character.IsRemotePlayer && GameMain.Server == null) collider.LinearVelocity = Vector2.Zero;
|
||||
}
|
||||
|
||||
|
||||
@@ -312,7 +312,7 @@ namespace Barotrauma
|
||||
|
||||
//if (LowestLimb == null) return;
|
||||
|
||||
if (onGround && !character.IsNetworkPlayer)
|
||||
if (onGround && (!character.IsRemotePlayer || GameMain.Server != null))
|
||||
{
|
||||
collider.LinearVelocity = new Vector2(
|
||||
movement.X,
|
||||
@@ -535,7 +535,7 @@ namespace Barotrauma
|
||||
rotation = MathHelper.ToDegrees(rotation);
|
||||
if (rotation < 0.0f) rotation += 360;
|
||||
|
||||
if (!character.IsNetworkPlayer && !aiming)
|
||||
if (!character.IsRemotePlayer && !aiming)
|
||||
{
|
||||
if (rotation > 20 && rotation < 170)
|
||||
TargetDir = Direction.Left;
|
||||
@@ -608,7 +608,7 @@ namespace Barotrauma
|
||||
movement.Y = movement.Y - (surfaceLimiter - 1.0f) * 0.01f;
|
||||
}
|
||||
|
||||
if (!character.IsNetworkPlayer)
|
||||
if (!character.IsRemotePlayer || GameMain.Server != null)
|
||||
{
|
||||
collider.LinearVelocity = Vector2.Lerp(collider.LinearVelocity, movement * swimSpeed, movementLerp);
|
||||
}
|
||||
@@ -730,7 +730,7 @@ namespace Barotrauma
|
||||
MoveLimb(torso, new Vector2(ladderSimPos.X - 0.27f * Dir, collider.SimPosition.Y+0.5f), 10.5f);
|
||||
MoveLimb(waist, new Vector2(ladderSimPos.X - 0.35f * Dir, collider.SimPosition.Y+0.4f), 10.5f);
|
||||
|
||||
if (!character.IsNetworkPlayer)
|
||||
if (!character.IsRemotePlayer)
|
||||
{
|
||||
collider.MoveToPos(new Vector2(ladderSimPos.X - 0.2f * Dir, collider.SimPosition.Y), 10.5f);
|
||||
}
|
||||
@@ -802,7 +802,7 @@ namespace Barotrauma
|
||||
trigger = character.SelectedConstruction.TransformTrigger(trigger);
|
||||
|
||||
bool notClimbing = false;
|
||||
if (character.IsNetworkPlayer)
|
||||
if (character.IsRemotePlayer)
|
||||
{
|
||||
notClimbing = character.IsKeyDown(InputType.Left) || character.IsKeyDown(InputType.Right);
|
||||
}
|
||||
|
||||
@@ -458,7 +458,7 @@ namespace Barotrauma
|
||||
}
|
||||
else if (f1.Body == collider.FarseerBody)
|
||||
{
|
||||
if (!character.IsNetworkPlayer || GameMain.Server != null)
|
||||
if (!character.IsRemotePlayer || GameMain.Server != null)
|
||||
{
|
||||
if (impact > 8.0f)
|
||||
{
|
||||
@@ -1050,6 +1050,47 @@ namespace Barotrauma
|
||||
private void UpdateNetPlayerPosition(float deltaTime)
|
||||
{
|
||||
if (character.MemPos.Count < 2) return;
|
||||
|
||||
if (character == GameMain.NetworkMember.Character)
|
||||
{
|
||||
PosInfo serverPos = character.MemPos.Last();
|
||||
|
||||
//this doesn't work correctly, because the delay caused by the 150ms update interval isn't taken into account
|
||||
//and the server may have unprocessed inputs in memInput (causing a 0-1s delay)
|
||||
float localizedTimestamp = serverPos.Timestamp - GameMain.Client.ServerConnection.AverageRoundtripTime / 2;
|
||||
|
||||
int index = 0;
|
||||
for (index = 0; index < character.MemLocalPos.Count; index++)
|
||||
{
|
||||
if (character.MemLocalPos[index].Timestamp > localizedTimestamp)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (index > character.MemLocalPos.Count-1 || index < 1) return;
|
||||
|
||||
//local positions before and after the timestamp
|
||||
PosInfo prevLocalPos = character.MemLocalPos[index - 1];
|
||||
PosInfo nextLocalPos = character.MemLocalPos[index];
|
||||
|
||||
Vector2 localPos = Vector2.Lerp(
|
||||
prevLocalPos.Position,
|
||||
nextLocalPos.Position,
|
||||
(localizedTimestamp - prevLocalPos.Timestamp) / (nextLocalPos.Timestamp - prevLocalPos.Timestamp));
|
||||
|
||||
|
||||
if (Vector2.Distance(localPos, serverPos.Position) > 0.5f)
|
||||
{
|
||||
//collider.SetTransform(collider.SimPosition + (pos.Position - remotePos), collider.Rotation);
|
||||
collider.SetTransform(serverPos.Position, collider.Rotation);
|
||||
}
|
||||
|
||||
if (character.MemLocalPos.Count > 120) character.MemLocalPos.RemoveRange(0, character.MemLocalPos.Count - 120);
|
||||
character.MemPos.Clear();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
PosInfo prev = character.MemPos[0];
|
||||
PosInfo next = character.MemPos[1];
|
||||
@@ -1082,89 +1123,6 @@ namespace Barotrauma
|
||||
t = 0.0f;
|
||||
character.MemPos.RemoveAt(0);
|
||||
}
|
||||
|
||||
//if (refLimb.body.TargetPosition == Vector2.Zero)
|
||||
//{
|
||||
// correctionMovement = Vector2.Zero;
|
||||
// return;
|
||||
//}
|
||||
|
||||
////if the limb is closer than alloweddistance, just ignore the difference
|
||||
//float allowedDistance = NetConfig.AllowedRagdollDistance * ((inWater) ? 2.0f : 1.0f);
|
||||
|
||||
//if (currentHull == null)
|
||||
//{
|
||||
// var overLappingHull = Hull.FindHull(ConvertUnits.ToDisplayUnits(refLimb.body.TargetPosition), null, true);
|
||||
|
||||
// if (overLappingHull != null)
|
||||
// {
|
||||
// Submarine.PickBody(refLimb.SimPosition, refLimb.body.TargetPosition, null, Physics.CollisionWall);
|
||||
|
||||
// refLimb.body.TargetPosition = refLimb.SimPosition + (refLimb.body.TargetPosition - refLimb.SimPosition) * Submarine.LastPickedFraction * 0.9f;
|
||||
// }
|
||||
//}
|
||||
|
||||
|
||||
//float dist = Vector2.Distance(collider.SimPosition, character.MemPos[0].Position);
|
||||
|
||||
////if the limb is further away than resetdistance, all limbs are immediately snapped to their targetpositions
|
||||
//bool resetAll = dist > NetConfig.ResetRagdollDistance;
|
||||
|
||||
//Vector2 diff = (refLimb.body.TargetPosition - refLimb.body.SimPosition);
|
||||
|
||||
//if (diff == Vector2.Zero || diff.Length() < allowedDistance)
|
||||
//{
|
||||
// refLimb.body.TargetPosition = Vector2.Zero;
|
||||
// foreach (Limb limb in Limbs)
|
||||
// {
|
||||
// limb.body.TargetPosition = Vector2.Zero;
|
||||
// }
|
||||
|
||||
// correctionMovement = Vector2.Zero;
|
||||
// return;
|
||||
//}
|
||||
|
||||
//if (resetAll)
|
||||
//{
|
||||
// System.Diagnostics.Debug.WriteLine("reset ragdoll limb positions");
|
||||
|
||||
// SetPosition(refLimb.body.TargetPosition, dist < 10.0f);
|
||||
|
||||
// return;
|
||||
//}
|
||||
|
||||
//if (inWater)
|
||||
//{
|
||||
// if (targetMovement.LengthSquared() > 0.01f)
|
||||
// {
|
||||
// correctionMovement =
|
||||
// Vector2.Lerp(targetMovement, Vector2.Normalize(diff) * MathHelper.Clamp(dist * 5.0f, 0.1f, 5.0f), 0.2f);
|
||||
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// refLimb.body.LinearVelocity = Vector2.Lerp(
|
||||
// refLimb.LinearVelocity,
|
||||
// Vector2.Normalize(diff) * MathHelper.Clamp(dist, 0.0f, 5.0f),
|
||||
// 0.2f);
|
||||
// }
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// //clamp the magnitude of the correction movement between 0.5f - 5.0f
|
||||
// Vector2 newCorrectionMovement = Vector2.Normalize(diff) * MathHelper.Clamp(dist * 2.0f, 0.5f, 5.0f);
|
||||
|
||||
// //heading in the right direction -> use the \"normal\" movement if it's faster than correctionMovement
|
||||
// //i.e. the character is close to the targetposition but the character is still running
|
||||
// if (Math.Sign(targetMovement.X) == Math.Sign(newCorrectionMovement.X))
|
||||
// {
|
||||
// newCorrectionMovement.X = Math.Max(Math.Abs(targetMovement.X), Math.Abs(newCorrectionMovement.X)) * Math.Sign(targetMovement.X);
|
||||
// }
|
||||
|
||||
// correctionMovement = Vector2.Lerp(correctionMovement, newCorrectionMovement, 0.5f);
|
||||
|
||||
// if (Math.Abs(correctionMovement.Y) < 0.1f) correctionMovement.Y = 0.0f;
|
||||
//}
|
||||
}
|
||||
|
||||
public virtual Vector2 EstimateCurrPosition(Vector2 prevPosition, float timePassed)
|
||||
|
||||
Reference in New Issue
Block a user