From 63ca7254b2069bba54b3eb7d04570762dae232da Mon Sep 17 00:00:00 2001 From: Regalis Date: Fri, 9 Dec 2016 17:42:52 +0200 Subject: [PATCH] Fixed steering syncing --- .../Items/Components/Machines/Steering.cs | 117 +++++++++++------- 1 file changed, 75 insertions(+), 42 deletions(-) diff --git a/Subsurface/Source/Items/Components/Machines/Steering.cs b/Subsurface/Source/Items/Components/Machines/Steering.cs index e34a28b4c..4b856330a 100644 --- a/Subsurface/Source/Items/Components/Machines/Steering.cs +++ b/Subsurface/Source/Items/Components/Machines/Steering.cs @@ -488,7 +488,30 @@ namespace Barotrauma.Items.Components public void ServerRead(Lidgren.Network.NetIncomingMessage msg, Barotrauma.Networking.Client c) { - bool autoPilot = msg.ReadBoolean(); + bool autoPilot = msg.ReadBoolean(); + Vector2 newTargetVelocity = targetVelocity; + bool maintainPos = false; + Vector2? newPosToMaintain = null; + bool headingToStart = false; + + if (autoPilot) + { + maintainPos = msg.ReadBoolean(); + if (maintainPos) + { + newPosToMaintain = new Vector2( + msg.ReadFloat(), + msg.ReadFloat()); + } + else + { + headingToStart = msg.ReadBoolean(); + } + } + else + { + newTargetVelocity = new Vector2(msg.ReadFloat(), msg.ReadFloat()); + } if (!item.CanClientAccess(c)) return; @@ -496,31 +519,24 @@ namespace Barotrauma.Items.Components if (!AutoPilot) { - targetVelocity = new Vector2(msg.ReadFloat(), msg.ReadFloat()); + targetVelocity = newTargetVelocity; } else { - bool maintainPos = msg.ReadBoolean(); - if (posToMaintain == null && maintainPos) + + maintainPosTickBox.Selected = newPosToMaintain != null; + posToMaintain = newPosToMaintain; + + if (posToMaintain == null) { - posToMaintain = item.Submarine.WorldPosition; - maintainPosTickBox.Selected = true; + levelStartTickBox.Selected = headingToStart; + levelEndTickBox.Selected = !headingToStart; + UpdatePath(); } else { - posToMaintain = null; - maintainPosTickBox.Selected = false; - bool maintainPoss = msg.ReadBoolean(); - if (maintainPoss) - { - Vector2 newPosToMaintain = new Vector2( - msg.ReadFloat(), - msg.ReadFloat()); - } - else - { - bool headingToStart = msg.ReadBoolean(); - } + levelStartTickBox.Selected = false; + levelEndTickBox.Selected = false; } } @@ -546,47 +562,64 @@ namespace Barotrauma.Items.Components msg.Write(((Vector2)posToMaintain).X); msg.Write(((Vector2)posToMaintain).Y); } + else + { + msg.Write(levelStartTickBox.Selected); + } } } public void ClientRead(Lidgren.Network.NetIncomingMessage msg, float sendingTime) { - AutoPilot = msg.ReadBoolean(); + bool autoPilot = msg.ReadBoolean(); + Vector2 newTargetVelocity = targetVelocity; + bool maintainPos = false; + Vector2? newPosToMaintain = null; + bool headingToStart = false; - if (!AutoPilot) + if (autoPilot) { - targetVelocity = new Vector2(msg.ReadFloat(), msg.ReadFloat()); - } - else - { - bool maintainPos = msg.ReadBoolean(); + maintainPos = msg.ReadBoolean(); if (maintainPos) { - posToMaintain = new Vector2(msg.ReadSingle(), msg.ReadSingle()); - maintainPosTickBox.Selected = true; + newPosToMaintain = new Vector2( + msg.ReadFloat(), + msg.ReadFloat()); } else { - posToMaintain = null; - maintainPosTickBox.Selected = false; + headingToStart = msg.ReadBoolean(); } } - maintainPosTickBox.Selected = posToMaintain != null; - //posToMaintain = newPosToMaintain; - - if (posToMaintain == null && autoPilot) - { - levelStartTickBox.Selected = false;//headingToStart; - levelEndTickBox.Selected = true;//!headingToStart; - - UpdatePath(); - } else { - levelStartTickBox.Selected = false; - levelEndTickBox.Selected = false; + newTargetVelocity = new Vector2(msg.ReadFloat(), msg.ReadFloat()); } + AutoPilot = autoPilot; + + if (!AutoPilot) + { + targetVelocity = newTargetVelocity; + } + else + { + + maintainPosTickBox.Selected = newPosToMaintain != null; + posToMaintain = newPosToMaintain; + + if (posToMaintain == null) + { + levelStartTickBox.Selected = headingToStart; + levelEndTickBox.Selected = !headingToStart; + UpdatePath(); + } + else + { + levelStartTickBox.Selected = false; + levelEndTickBox.Selected = false; + } + } } } }