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:
@@ -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;
|
||||||
@@ -699,9 +702,11 @@ namespace Barotrauma
|
|||||||
case InputType.Up:
|
case InputType.Up:
|
||||||
return dequeuedInput.HasFlag(InputNetFlags.Up);
|
return dequeuedInput.HasFlag(InputNetFlags.Up);
|
||||||
case InputType.Down:
|
case InputType.Down:
|
||||||
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;
|
||||||
|
|||||||
@@ -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);
|
||||||
@@ -2109,10 +2113,7 @@ namespace Barotrauma
|
|||||||
body.FarseerBody.Awake = msg.ReadBoolean();
|
body.FarseerBody.Awake = msg.ReadBoolean();
|
||||||
|
|
||||||
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);
|
||||||
|
|||||||
Reference in New Issue
Block a user