diff --git a/Subsurface/Source/Items/Components/Door.cs b/Subsurface/Source/Items/Components/Door.cs index db75742b3..8998491d6 100644 --- a/Subsurface/Source/Items/Components/Door.cs +++ b/Subsurface/Source/Items/Components/Door.cs @@ -488,26 +488,27 @@ namespace Barotrauma.Items.Components { if (isStuck) return; - bool wasOpen = isOpen; + bool wasOpen = predictedState == null ? isOpen : predictedState.Value; if (connection.Name == "toggle") { - SetState(!isOpen, false, true); + SetState(!wasOpen, false, true); } else if (connection.Name == "set_state") { SetState(signal != "0", false, true); } - if (sender != null && wasOpen != isOpen) + bool newState = predictedState == null ? isOpen : predictedState.Value; + if (sender != null && wasOpen != newState) { - GameServer.Log(sender.Name + (isOpen ? " opened " : " closed ") + item.Name, ServerLog.MessageType.ItemInteraction); + GameServer.Log(sender.Name + (newState ? " opened " : " closed ") + item.Name, ServerLog.MessageType.ItemInteraction); } } public void SetState(bool open, bool isNetworkMessage, bool sendNetworkMessage = false) { - if (isStuck || isOpen == open) return; + if (isStuck || (predictedState == null && isOpen == open) || (predictedState != null && isOpen == predictedState.Value)) return; if (GameMain.Client != null && !isNetworkMessage) { diff --git a/Subsurface/Source/Items/Item.cs b/Subsurface/Source/Items/Item.cs index 5b90e9ecd..29509af1c 100644 --- a/Subsurface/Source/Items/Item.cs +++ b/Subsurface/Source/Items/Item.cs @@ -2133,21 +2133,27 @@ namespace Barotrauma public void ClientReadPosition(ServerNetObject type, NetBuffer msg, float sendingTime) { - Vector2 newPosition = new Vector2( - msg.ReadFloat(), - msg.ReadFloat()); - - float newRotation = msg.ReadRangedSingle(0.0f, MathHelper.TwoPi, 7); - - body.FarseerBody.Awake = msg.ReadBoolean(); - + Vector2 newPosition = new Vector2(msg.ReadFloat(), msg.ReadFloat()); + float newRotation = msg.ReadRangedSingle(0.0f, MathHelper.TwoPi, 7); + bool awake = msg.ReadBoolean(); Vector2 newVelocity = Vector2.Zero; - - if (body.FarseerBody.Awake) + + if (awake) { newVelocity = new Vector2( msg.ReadRangedSingle(-MaxVel, MaxVel, 12), msg.ReadRangedSingle(-MaxVel, MaxVel, 12)); + } + + if (body == null) + { + DebugConsole.ThrowError("Received a position update for an item with no physics body ("+Name+")"); + return; + } + + body.FarseerBody.Awake = awake; + if (body.FarseerBody.Awake) + { if ((newVelocity - body.LinearVelocity).Length() > 8.0f) body.LinearVelocity = newVelocity; } else @@ -2159,29 +2165,6 @@ namespace Barotrauma { body.SetTransform(newPosition,newRotation); } - - //DebugConsole.NewMessage("Received item pos, t: "+sendingTime+ " ("+Name+")", Color.LightGreen); - - /*//already interpolating with more up-to-date data -> ignore - if (MemPos.Count > 1 && MemPos[0].Timestamp > sendingTime) - { - return; - } - - int index = 0; - while (index < MemPos.Count && sendingTime > MemPos[index].Timestamp) - { - index++; - } - - //position with the same timestamp already in the buffer (duplicate packet?) - // -> no need to add again - if (index < MemPos.Count && sendingTime == MemPos[index].Timestamp) - { - return; - } - - MemPos.Insert(index, new PosInfo(newTargetPosition, Direction.None, sendingTime));*/ } public static void Load(XElement element, Submarine submarine)