From 020aac55ea6a23a271a60d7e3132857a46b731ae Mon Sep 17 00:00:00 2001 From: Regalis Date: Thu, 29 Dec 2016 22:01:50 +0200 Subject: [PATCH] AICharacter position syncing --- Subsurface/Source/Characters/Character.cs | 57 +++++++++---------- Subsurface/Source/Networking/GameServer.cs | 32 ++++++----- .../NetEntityEvent/NetEntityEvent.cs | 1 + 3 files changed, 47 insertions(+), 43 deletions(-) diff --git a/Subsurface/Source/Characters/Character.cs b/Subsurface/Source/Characters/Character.cs index 48fd6721d..994dad171 100644 --- a/Subsurface/Source/Characters/Character.cs +++ b/Subsurface/Source/Characters/Character.cs @@ -1309,47 +1309,44 @@ namespace Barotrauma if (this != Character.Controlled) { - if (GameMain.Server != null) + if (GameMain.Server != null && !(this is AICharacter)) { - if (!IsDead) + if (memInput.Count > 0) { - if (memInput.Count > 0) + AnimController.Frozen = false; + prevDequeuedInput = dequeuedInput; + dequeuedInput = memInput[memInput.Count - 1]; + cursorPosition = memMousePos[memMousePos.Count - 1]; + memInput.RemoveAt(memInput.Count - 1); + memMousePos.RemoveAt(memMousePos.Count - 1); + if (dequeuedInput == InputNetFlags.None) { - AnimController.Frozen = false; - prevDequeuedInput = dequeuedInput; - dequeuedInput = memInput[memInput.Count - 1]; - cursorPosition = memMousePos[memMousePos.Count - 1]; - memInput.RemoveAt(memInput.Count - 1); - memMousePos.RemoveAt(memMousePos.Count - 1); - if (dequeuedInput == InputNetFlags.None) + if (isStillCountdown<=0) { - if (isStillCountdown<=0) + while (memInput.Count>5 && memInput[memInput.Count-1]==0) { - while (memInput.Count>5 && memInput[memInput.Count-1]==0) - { - //remove inputs where the player is not moving at all - //helps the server catch up, shouldn't affect final position - memInput.RemoveAt(memInput.Count - 1); - memMousePos.RemoveAt(memMousePos.Count - 1); - } - isStillCountdown = 15; + //remove inputs where the player is not moving at all + //helps the server catch up, shouldn't affect final position + memInput.RemoveAt(memInput.Count - 1); + memMousePos.RemoveAt(memMousePos.Count - 1); } - else - { - isStillCountdown--; - } - } else - { isStillCountdown = 15; } - //DebugConsole.NewMessage(Convert.ToString(memInput.Count), Color.Lime); - } - else + else + { + isStillCountdown--; + } + } else { - AnimController.Frozen = true; - return; + isStillCountdown = 15; } + //DebugConsole.NewMessage(Convert.ToString(memInput.Count), Color.Lime); } + else + { + AnimController.Frozen = true; + return; + } } } else diff --git a/Subsurface/Source/Networking/GameServer.cs b/Subsurface/Source/Networking/GameServer.cs index 3a2860e97..06e419976 100644 --- a/Subsurface/Source/Networking/GameServer.cs +++ b/Subsurface/Source/Networking/GameServer.cs @@ -664,16 +664,13 @@ namespace Barotrauma.Networking foreach (GUIComponent gc in GameMain.NetLobbyScreen.ChatBox.children) { - if (gc is GUITextBlock) + if (gc is GUITextBlock && gc.UserData is ChatMessage) { - if (gc.UserData is ChatMessage) + ChatMessage cMsg = (ChatMessage)gc.UserData; + if (cMsg.NetStateID > c.lastRecvChatMsgID) { - ChatMessage cMsg = (ChatMessage)gc.UserData; - if (cMsg.NetStateID > c.lastRecvChatMsgID) - { - cMsg.ServerWrite(outmsg, c); - } - } + cMsg.ServerWrite(outmsg, c); + } } } @@ -686,11 +683,20 @@ namespace Barotrauma.Networking foreach (Character character in Character.CharacterList) { - if (character is AICharacter) continue; - - outmsg.Write((byte)ServerNetObject.ENTITY_POSITION); - character.ServerWrite(outmsg, c); - outmsg.WritePadBits(); + if (character is AICharacter) + { + //TODO: don't send if the ai character is far from the client + //(some sort of distance-based culling might be a good idea for player-controlled characters as well) + outmsg.Write((byte)ServerNetObject.ENTITY_POSITION); + character.ServerWrite(outmsg, c); + outmsg.WritePadBits(); + } + else + { + outmsg.Write((byte)ServerNetObject.ENTITY_POSITION); + character.ServerWrite(outmsg, c); + outmsg.WritePadBits(); + } } foreach (Submarine sub in Submarine.Loaded) diff --git a/Subsurface/Source/Networking/NetEntityEvent/NetEntityEvent.cs b/Subsurface/Source/Networking/NetEntityEvent/NetEntityEvent.cs index 6e5a43e86..fadf657a8 100644 --- a/Subsurface/Source/Networking/NetEntityEvent/NetEntityEvent.cs +++ b/Subsurface/Source/Networking/NetEntityEvent/NetEntityEvent.cs @@ -44,6 +44,7 @@ namespace Barotrauma.Networking { if (Data[i] != other.Data[i]) return false; } + return true; } else {