Fixed a server-side off-by-one error in the player input IDs
I'm guessing this one comes from the player's position not being updated immediately after the input is processed, so that's where most of the remaining error came from. Also added some rounding to the horizontal velocity when approaching 0, and changed something that depended on the head limb to use the collider instead, which should hopefully further reduce the chance of syncing errors.
This commit is contained in:
@@ -489,6 +489,10 @@ namespace Barotrauma
|
|||||||
{
|
{
|
||||||
movement = Vector2.Normalize(movement);
|
movement = Vector2.Normalize(movement);
|
||||||
}
|
}
|
||||||
|
if (Math.Abs(movement.X)<0.005f)
|
||||||
|
{
|
||||||
|
movement.X = 0.0f;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ClimbOverObstacles()
|
private void ClimbOverObstacles()
|
||||||
|
|||||||
@@ -571,6 +571,7 @@ namespace Barotrauma
|
|||||||
}
|
}
|
||||||
|
|
||||||
Collider.DebugDraw(spriteBatch, frozen ? Color.Red : (inWater ? Color.SkyBlue : Color.Gray));
|
Collider.DebugDraw(spriteBatch, frozen ? Color.Red : (inWater ? Color.SkyBlue : Color.Gray));
|
||||||
|
spriteBatch.DrawString(GUI.Font, Collider.LinearVelocity.X.ToString(), new Vector2(Collider.DrawPosition.X, -Collider.DrawPosition.Y), Color.Orange);
|
||||||
|
|
||||||
foreach (RevoluteJoint joint in limbJoints)
|
foreach (RevoluteJoint joint in limbJoints)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -839,13 +839,13 @@ namespace Barotrauma
|
|||||||
AnimController.Anim != AnimController.Animation.UsingConstruction &&
|
AnimController.Anim != AnimController.Animation.UsingConstruction &&
|
||||||
AnimController.Anim != AnimController.Animation.CPR)
|
AnimController.Anim != AnimController.Animation.CPR)
|
||||||
{
|
{
|
||||||
Limb head = AnimController.GetLimb(LimbType.Head);
|
//Limb head = AnimController.GetLimb(LimbType.Head);
|
||||||
|
|
||||||
if (cursorPosition.X < head.Position.X - 10.0f)
|
if (cursorPosition.X < AnimController.Collider.Position.X - 10.0f)
|
||||||
{
|
{
|
||||||
AnimController.TargetDir = Direction.Left;
|
AnimController.TargetDir = Direction.Left;
|
||||||
}
|
}
|
||||||
else if (cursorPosition.X > head.Position.X + 10.0f)
|
else if (cursorPosition.X > AnimController.Collider.Position.X + 10.0f)
|
||||||
{
|
{
|
||||||
AnimController.TargetDir = Direction.Right;
|
AnimController.TargetDir = Direction.Right;
|
||||||
}
|
}
|
||||||
@@ -1249,7 +1249,7 @@ namespace Barotrauma
|
|||||||
{
|
{
|
||||||
foreach (Character c in CharacterList)
|
foreach (Character c in CharacterList)
|
||||||
{
|
{
|
||||||
if (!c.Enabled) continue;
|
if (!c.Enabled || c.AnimController.Frozen) continue;
|
||||||
|
|
||||||
c.AnimController.UpdateAnim(deltaTime);
|
c.AnimController.UpdateAnim(deltaTime);
|
||||||
}
|
}
|
||||||
@@ -1610,25 +1610,37 @@ namespace Barotrauma
|
|||||||
if (aiTarget != null) aiTarget.Draw(spriteBatch);
|
if (aiTarget != null) aiTarget.Draw(spriteBatch);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (memPos != null && memPos.Count > 0)
|
if (memPos != null && memPos.Count > 0 && controlled == this)
|
||||||
{
|
{
|
||||||
PosInfo serverPos = memPos.Last();
|
PosInfo serverPos = memPos.Last();
|
||||||
Vector2 remoteVec = ConvertUnits.ToDisplayUnits(serverPos.Position);
|
Vector2 remoteVec = ConvertUnits.ToDisplayUnits(serverPos.Position);
|
||||||
if (Submarine!=null)
|
if (Submarine != null)
|
||||||
{
|
{
|
||||||
remoteVec += Submarine.DrawPosition;
|
remoteVec += Submarine.DrawPosition;
|
||||||
}
|
}
|
||||||
remoteVec.Y = -remoteVec.Y;
|
remoteVec.Y = -remoteVec.Y;
|
||||||
|
|
||||||
PosInfo localPos = memLocalPos.Find(m => m.ID == serverPos.ID);
|
PosInfo localPos = memLocalPos.Find(m => m.ID == serverPos.ID);
|
||||||
|
int mpind = memLocalPos.FindIndex(lp => lp.ID == localPos.ID);
|
||||||
|
PosInfo? localPos1 = mpind > 0 ? memLocalPos[mpind - 1] : (PosInfo?)null;
|
||||||
|
PosInfo? localPos2 = mpind < memLocalPos.Count-1 ? memLocalPos[mpind + 1] : (PosInfo?)null;
|
||||||
|
|
||||||
Vector2 localVec = ConvertUnits.ToDisplayUnits(localPos.Position);
|
Vector2 localVec = ConvertUnits.ToDisplayUnits(localPos.Position);
|
||||||
|
Vector2 localVec1 = localPos1 != null ? ConvertUnits.ToDisplayUnits(((PosInfo)localPos1).Position) : Vector2.Zero;
|
||||||
|
Vector2 localVec2 = localPos2 != null ? ConvertUnits.ToDisplayUnits(((PosInfo)localPos2).Position) : Vector2.Zero;
|
||||||
if (Submarine != null)
|
if (Submarine != null)
|
||||||
{
|
{
|
||||||
localVec += Submarine.DrawPosition;
|
localVec += Submarine.DrawPosition;
|
||||||
|
localVec1 += Submarine.DrawPosition;
|
||||||
|
localVec2 += Submarine.DrawPosition;
|
||||||
}
|
}
|
||||||
localVec.Y = -localVec.Y;
|
localVec.Y = -localVec.Y;
|
||||||
|
localVec1.Y = -localVec1.Y;
|
||||||
|
localVec2.Y = -localVec2.Y;
|
||||||
|
|
||||||
GUI.DrawLine(spriteBatch, remoteVec, localVec, Color.Yellow,0,10);
|
GUI.DrawLine(spriteBatch, remoteVec, localVec, Color.Yellow, 0, 10);
|
||||||
|
if (localPos1 != null) GUI.DrawLine(spriteBatch, remoteVec, localVec1, Color.Lime, 0, 6);
|
||||||
|
if (localPos2 != null) GUI.DrawLine(spriteBatch, remoteVec, localVec2, Color.Red, 0, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2 mouseDrawPos = CursorWorldPosition;
|
Vector2 mouseDrawPos = CursorWorldPosition;
|
||||||
@@ -2037,7 +2049,7 @@ namespace Barotrauma
|
|||||||
//length of the message
|
//length of the message
|
||||||
msg.Write((byte)(4+4+4));
|
msg.Write((byte)(4+4+4));
|
||||||
msg.Write(true);
|
msg.Write(true);
|
||||||
msg.Write((UInt32)(LastNetworkUpdateID - memInput.Count));
|
msg.Write((UInt32)(LastNetworkUpdateID - memInput.Count - 1));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -146,6 +146,11 @@ namespace Barotrauma
|
|||||||
get { return body.Position; }
|
get { return body.Position; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Vector2 Position
|
||||||
|
{
|
||||||
|
get { return ConvertUnits.ToDisplayUnits(body.Position); }
|
||||||
|
}
|
||||||
|
|
||||||
public Vector2 PrevPosition
|
public Vector2 PrevPosition
|
||||||
{
|
{
|
||||||
get { return prevPosition; }
|
get { return prevPosition; }
|
||||||
|
|||||||
Reference in New Issue
Block a user