From 9d1c4f3efbfa6a5c6f7a44ae8a4ca4bea119e194 Mon Sep 17 00:00:00 2001 From: Joonas Rikkonen Date: Mon, 23 Jul 2018 17:58:28 +0300 Subject: [PATCH] Moved Submarine.ClientRead to the client project --- .../BarotraumaClient/Source/Map/Submarine.cs | 29 +++++++++++++++++++ .../BarotraumaShared/Source/Map/Submarine.cs | 28 ------------------ 2 files changed, 29 insertions(+), 28 deletions(-) diff --git a/Barotrauma/BarotraumaClient/Source/Map/Submarine.cs b/Barotrauma/BarotraumaClient/Source/Map/Submarine.cs index c6c4e786e..44e13dd6b 100644 --- a/Barotrauma/BarotraumaClient/Source/Map/Submarine.cs +++ b/Barotrauma/BarotraumaClient/Source/Map/Submarine.cs @@ -1,5 +1,6 @@ using Barotrauma.Networking; using FarseerPhysics; +using Lidgren.Network; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using System; @@ -216,6 +217,34 @@ namespace Barotrauma } } } + + public void ClientRead(ServerNetObject type, NetBuffer msg, float sendingTime) + { + var newTargetPosition = new Vector2( + msg.ReadFloat(), + msg.ReadFloat()); + + //already interpolating with more up-to-date data -> ignore + if (subBody.MemPos.Count > 1 && subBody.MemPos[0].Timestamp > sendingTime) + { + return; + } + int index = 0; + while (index < subBody.MemPos.Count && sendingTime > subBody.MemPos[index].Timestamp) + { + 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.LastReceivedPositionUpdate = Math.Max(subBody.LastReceivedPositionUpdate, Timing.TotalTime); + subBody.MemPos.Insert(index, new PosInfo(newTargetPosition, 0.0f, sendingTime)); + } } } diff --git a/Barotrauma/BarotraumaShared/Source/Map/Submarine.cs b/Barotrauma/BarotraumaShared/Source/Map/Submarine.cs index 0568cfcd4..ad03b26fc 100644 --- a/Barotrauma/BarotraumaShared/Source/Map/Submarine.cs +++ b/Barotrauma/BarotraumaShared/Source/Map/Submarine.cs @@ -1326,34 +1326,6 @@ namespace Barotrauma msg.Write(PhysicsBody.SimPosition.X); msg.Write(PhysicsBody.SimPosition.Y); } - - public void ClientRead(ServerNetObject type, NetBuffer msg, float sendingTime) - { - var newTargetPosition = new Vector2( - msg.ReadFloat(), - msg.ReadFloat()); - - //already interpolating with more up-to-date data -> ignore - if (subBody.MemPos.Count > 1 && subBody.MemPos[0].Timestamp > sendingTime) - { - return; - } - - int index = 0; - while (index < subBody.MemPos.Count && sendingTime > subBody.MemPos[index].Timestamp) - { - 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, 0.0f, sendingTime)); - } } }