diff --git a/Subsurface/Source/Map/Submarine.cs b/Subsurface/Source/Map/Submarine.cs index 060612c36..213c30924 100644 --- a/Subsurface/Source/Map/Submarine.cs +++ b/Subsurface/Source/Map/Submarine.cs @@ -1194,6 +1194,13 @@ namespace Barotrauma index++; } + //position with the same timestamp already in the buffer (duplicate packet?) + // -> no need to add again + if (index < subBody.MemPos.Count && sendingTime == subBody.MemPos[index].Timestamp) + { + return; + } + subBody.MemPos.Insert(index, new PosInfo(newTargetPosition, Direction.Right, sendingTime)); } } diff --git a/Subsurface/Source/Map/SubmarineBody.cs b/Subsurface/Source/Map/SubmarineBody.cs index c9c904ef9..6a0f6906b 100644 --- a/Subsurface/Source/Map/SubmarineBody.cs +++ b/Subsurface/Source/Map/SubmarineBody.cs @@ -35,7 +35,7 @@ namespace Barotrauma public readonly PhysicsBody Body; - List memPos = new List(); + private List memPos = new List(); public Rectangle Borders { @@ -186,22 +186,7 @@ namespace Barotrauma { if (GameMain.Client != null) { - //if (memPos.Count > 1 && Vector2.Distance(memPos[1].Position, Body.SimPosition) > 5.0f) - //{ - // Vector2 moveAmount = ConvertUnits.ToDisplayUnits(memPos[1].Position - Body.SimPosition); - - // ForceTranslate(moveAmount); - // DisplaceCharacters(moveAmount); - - // foreach (Submarine sub in submarine.DockedTo) - // { - // sub.SubBody.ForceTranslate(moveAmount); - // sub.SubBody.DisplaceCharacters(moveAmount); - // } - - // memPos.RemoveRange(0, 2); - //} - //else + if (memPos.Count == 0) return; Vector2 newVelocity = Body.LinearVelocity; Vector2 newPosition = Body.SimPosition; @@ -212,10 +197,17 @@ namespace Barotrauma List subsToMove = new List() { this.submarine }; subsToMove.AddRange(submarine.DockedTo); + foreach (Submarine dockedSub in submarine.DockedTo) + { + //clear the position buffer of the docked sub to prevent unnecessary position corrections + dockedSub.SubBody.memPos.Clear(); + subsToMove.Add(dockedSub); + } + Submarine closestSub = null; if (Character.Controlled == null) { - closestSub= Submarine.GetClosest(GameMain.GameScreen.Cam.WorldViewCenter); + closestSub = Submarine.GetClosest(GameMain.GameScreen.Cam.WorldViewCenter); } else { diff --git a/Subsurface/Source/Networking/NetEntityEvent/NetEntityEventManager.cs b/Subsurface/Source/Networking/NetEntityEvent/NetEntityEventManager.cs index dd136c14e..04aba20e6 100644 --- a/Subsurface/Source/Networking/NetEntityEvent/NetEntityEventManager.cs +++ b/Subsurface/Source/Networking/NetEntityEvent/NetEntityEventManager.cs @@ -68,7 +68,14 @@ namespace Barotrauma.Networking //skip the event if we've already received it or if the entity isn't found if (thisEventID != lastReceivedID + 1 || entity == null) { - DebugConsole.NewMessage("received msg "+thisEventID, Microsoft.Xna.Framework.Color.Red); + if (thisEventID != lastReceivedID + 1) + { + DebugConsole.NewMessage("received msg "+thisEventID, Microsoft.Xna.Framework.Color.Red); + } + else if (entity == null) + { + DebugConsole.NewMessage("received msg " + thisEventID+", entity "+entityID+" not found", Microsoft.Xna.Framework.Color.Red); + } msg.Position += msgLength * 8; } else diff --git a/Subsurface/Source/Physics/PhysicsBody.cs b/Subsurface/Source/Physics/PhysicsBody.cs index dbde6a2db..495b12425 100644 --- a/Subsurface/Source/Physics/PhysicsBody.cs +++ b/Subsurface/Source/Physics/PhysicsBody.cs @@ -511,10 +511,18 @@ namespace Barotrauma float speedMultiplier = 0.9f + (float)Math.Pow((positionBuffer.Count - 2) / 5.0f, 2.0f); netInterpolationState += (deltaTime * speedMultiplier) / (next.Timestamp - prev.Timestamp); - 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); + newPosition = Vector2.Lerp(prev.Position, next.Position, Math.Min(netInterpolationState, 1.0f)); + + if (next.Timestamp == prev.Timestamp) + { + newVelocity = Vector2.Zero; + } + else + { + //override the targetMovement to make the character play the walking/running animation + newVelocity = (next.Position - prev.Position) / (next.Timestamp - prev.Timestamp); + } } else {