Vastly improved item syncing + Crouch syncing

Using SetTransform instead of TargetPosition + a larger margin seems to make the item syncing near-perfect.
This commit is contained in:
juanjp600
2017-03-09 20:18:19 -03:00
parent 6a31d56175
commit c55c1b6d0e
3 changed files with 25 additions and 19 deletions
+8 -3
View File
@@ -670,13 +670,16 @@ namespace Barotrauma
//break; //break;
case InputType.Down: case InputType.Down:
return !(dequeuedInput.HasFlag(InputNetFlags.Down)) && (prevDequeuedInput.HasFlag(InputNetFlags.Down)); return !(dequeuedInput.HasFlag(InputNetFlags.Down)) && (prevDequeuedInput.HasFlag(InputNetFlags.Down));
//break; //break;
case InputType.Run: case InputType.Run:
return !(dequeuedInput.HasFlag(InputNetFlags.Run)) && (prevDequeuedInput.HasFlag(InputNetFlags.Run)); return !(dequeuedInput.HasFlag(InputNetFlags.Run)) && (prevDequeuedInput.HasFlag(InputNetFlags.Run));
//break; //break;
case InputType.Crouch:
return !(dequeuedInput.HasFlag(InputNetFlags.Crouch)) && (prevDequeuedInput.HasFlag(InputNetFlags.Crouch));
//break;
case InputType.Select: case InputType.Select:
return dequeuedInput.HasFlag(InputNetFlags.Select); //TODO: clean up the way this input is registered return dequeuedInput.HasFlag(InputNetFlags.Select); //TODO: clean up the way this input is registered
//break; //break;
default: default:
return false; return false;
//break; //break;
@@ -702,6 +705,8 @@ namespace Barotrauma
return dequeuedInput.HasFlag(InputNetFlags.Down); return dequeuedInput.HasFlag(InputNetFlags.Down);
case InputType.Run: case InputType.Run:
return dequeuedInput.HasFlag(InputNetFlags.Run); return dequeuedInput.HasFlag(InputNetFlags.Run);
case InputType.Crouch:
return dequeuedInput.HasFlag(InputNetFlags.Crouch);
case InputType.Select: case InputType.Select:
return false; //TODO: clean up the way this input is registered return false; //TODO: clean up the way this input is registered
case InputType.Aim: case InputType.Aim:
@@ -21,12 +21,13 @@ namespace Barotrauma
Down = 0x8, Down = 0x8,
FacingLeft = 0x10, FacingLeft = 0x10,
Run = 0x20, Run = 0x20,
Select = 0x40, Crouch = 0x40,
Use = 0x80, Select = 0x80,
Aim = 0x100, Use = 0x100,
Attack = 0x200, Aim = 0x200,
Attack = 0x400,
MaxVal = 0x3FF MaxVal = 0x7FF
} }
private InputNetFlags dequeuedInput = 0; private InputNetFlags dequeuedInput = 0;
private InputNetFlags prevDequeuedInput = 0; private InputNetFlags prevDequeuedInput = 0;
@@ -134,6 +135,7 @@ namespace Barotrauma
if (IsKeyDown(InputType.Up)) newInput |= InputNetFlags.Up; if (IsKeyDown(InputType.Up)) newInput |= InputNetFlags.Up;
if (IsKeyDown(InputType.Down)) newInput |= InputNetFlags.Down; if (IsKeyDown(InputType.Down)) newInput |= InputNetFlags.Down;
if (IsKeyDown(InputType.Run)) newInput |= InputNetFlags.Run; if (IsKeyDown(InputType.Run)) newInput |= InputNetFlags.Run;
if (IsKeyDown(InputType.Crouch)) newInput |= InputNetFlags.Crouch;
if (IsKeyHit(InputType.Select)) newInput |= InputNetFlags.Select; //TODO: clean up the way this input is registered if (IsKeyHit(InputType.Select)) newInput |= InputNetFlags.Select; //TODO: clean up the way this input is registered
if (IsKeyDown(InputType.Use)) newInput |= InputNetFlags.Use; if (IsKeyDown(InputType.Use)) newInput |= InputNetFlags.Use;
if (IsKeyDown(InputType.Aim)) newInput |= InputNetFlags.Aim; if (IsKeyDown(InputType.Aim)) newInput |= InputNetFlags.Aim;
+7 -8
View File
@@ -1543,7 +1543,11 @@ namespace Barotrauma
if (Container != null) if (Container != null)
{ {
if (body != null) body.Enabled = true; if (body != null)
{
body.Enabled = true;
body.LinearVelocity = Vector2.Zero;
}
SetTransform(Container.SimPosition, 0.0f); SetTransform(Container.SimPosition, 0.0f);
Container.RemoveContained(this); Container.RemoveContained(this);
@@ -2110,9 +2114,6 @@ namespace Barotrauma
Vector2 newVelocity = Vector2.Zero; Vector2 newVelocity = Vector2.Zero;
//TODO: this code should take previous positions and velocities into account,
//rather than use the current values for the comparisons.
if (body.FarseerBody.Awake) if (body.FarseerBody.Awake)
{ {
newVelocity = new Vector2( newVelocity = new Vector2(
@@ -2125,11 +2126,9 @@ namespace Barotrauma
body.FarseerBody.Enabled = false; body.FarseerBody.Enabled = false;
} }
if (body.TargetPosition==null || (newPosition - (Vector2)body.TargetPosition).Length() > body.LinearVelocity.Length() * 3.0f) if ((newPosition - SimPosition).Length() > body.LinearVelocity.Length() * 3.0f + 24.0f)
{ {
body.TargetPosition = newPosition; body.SetTransform(newPosition,newRotation);
body.FarseerBody.Rotation = newRotation;
} }
DebugConsole.NewMessage("Received item pos, t: "+sendingTime+ " ("+Name+")", Color.LightGreen); DebugConsole.NewMessage("Received item pos, t: "+sendingTime+ " ("+Name+")", Color.LightGreen);