Submarine position syncing improvements
This commit is contained in:
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace Barotrauma
|
||||
|
||||
public readonly PhysicsBody Body;
|
||||
|
||||
List<PosInfo> memPos = new List<PosInfo>();
|
||||
private List<PosInfo> memPos = new List<PosInfo>();
|
||||
|
||||
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<Submarine> subsToMove = new List<Submarine>() { 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
|
||||
{
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user