From f3c58a24948d616fbc918954275f6ea229f7bdc2 Mon Sep 17 00:00:00 2001 From: juanjp600 Date: Sat, 25 Feb 2017 12:22:38 -0300 Subject: [PATCH] Made item syncing look slightly less erratic on client's side Still kinda glitchy, we might need a more elaborate approach later --- Subsurface/Source/Items/Item.cs | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/Subsurface/Source/Items/Item.cs b/Subsurface/Source/Items/Item.cs index 6b6146157..fdd50dfbe 100644 --- a/Subsurface/Source/Items/Item.cs +++ b/Subsurface/Source/Items/Item.cs @@ -2106,26 +2106,38 @@ namespace Barotrauma public void ClientReadPosition(ServerNetObject type, NetBuffer msg, float sendingTime) { - - body.TargetPosition = new Vector2( + Vector2 newPosition = new Vector2( msg.ReadFloat(), msg.ReadFloat()); - body.FarseerBody.Rotation = msg.ReadRangedSingle(0.0f, MathHelper.TwoPi, 7); - + float newRotation = msg.ReadRangedSingle(0.0f, MathHelper.TwoPi, 7); + body.FarseerBody.Awake = msg.ReadBoolean(); + 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) { - body.LinearVelocity = new Vector2( + newVelocity = new Vector2( msg.ReadRangedSingle(-32.0f, 32.0f, 12), msg.ReadRangedSingle(-32.0f, 32.0f, 12)); + if ((newVelocity-body.LinearVelocity).Length()>8.0f) body.LinearVelocity = newVelocity; } else { body.FarseerBody.Enabled = false; } + if (body.TargetPosition==null || (newPosition - (Vector2)body.TargetPosition).Length() > body.LinearVelocity.Length() * 3.0f) + { + body.TargetPosition = newPosition; + + body.FarseerBody.Rotation = newRotation; + } + DebugConsole.NewMessage("Received item pos, t: "+sendingTime+ " ("+Name+")", Color.LightGreen); /* //already interpolating with more up-to-date data -> ignore