AICharacter position syncing

This commit is contained in:
Regalis
2016-12-29 22:01:50 +02:00
parent 98183c47fb
commit 020aac55ea
3 changed files with 47 additions and 43 deletions

View File

@@ -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

View File

@@ -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)

View File

@@ -44,6 +44,7 @@ namespace Barotrauma.Networking
{
if (Data[i] != other.Data[i]) return false;
}
return true;
}
else
{