AICharacter position syncing
This commit is contained in:
@@ -1309,46 +1309,43 @@ namespace Barotrauma
|
|||||||
|
|
||||||
if (this != Character.Controlled)
|
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;
|
if (isStillCountdown<=0)
|
||||||
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)
|
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
|
||||||
//remove inputs where the player is not moving at all
|
memInput.RemoveAt(memInput.Count - 1);
|
||||||
//helps the server catch up, shouldn't affect final position
|
memMousePos.RemoveAt(memMousePos.Count - 1);
|
||||||
memInput.RemoveAt(memInput.Count - 1);
|
|
||||||
memMousePos.RemoveAt(memMousePos.Count - 1);
|
|
||||||
}
|
|
||||||
isStillCountdown = 15;
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
isStillCountdown--;
|
|
||||||
}
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
isStillCountdown = 15;
|
isStillCountdown = 15;
|
||||||
}
|
}
|
||||||
//DebugConsole.NewMessage(Convert.ToString(memInput.Count), Color.Lime);
|
else
|
||||||
}
|
{
|
||||||
else
|
isStillCountdown--;
|
||||||
|
}
|
||||||
|
} else
|
||||||
{
|
{
|
||||||
AnimController.Frozen = true;
|
isStillCountdown = 15;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
//DebugConsole.NewMessage(Convert.ToString(memInput.Count), Color.Lime);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
AnimController.Frozen = true;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -664,15 +664,12 @@ namespace Barotrauma.Networking
|
|||||||
|
|
||||||
foreach (GUIComponent gc in GameMain.NetLobbyScreen.ChatBox.children)
|
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;
|
cMsg.ServerWrite(outmsg, c);
|
||||||
if (cMsg.NetStateID > c.lastRecvChatMsgID)
|
|
||||||
{
|
|
||||||
cMsg.ServerWrite(outmsg, c);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -686,11 +683,20 @@ namespace Barotrauma.Networking
|
|||||||
|
|
||||||
foreach (Character character in Character.CharacterList)
|
foreach (Character character in Character.CharacterList)
|
||||||
{
|
{
|
||||||
if (character is AICharacter) continue;
|
if (character is AICharacter)
|
||||||
|
{
|
||||||
outmsg.Write((byte)ServerNetObject.ENTITY_POSITION);
|
//TODO: don't send if the ai character is far from the client
|
||||||
character.ServerWrite(outmsg, c);
|
//(some sort of distance-based culling might be a good idea for player-controlled characters as well)
|
||||||
outmsg.WritePadBits();
|
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)
|
foreach (Submarine sub in Submarine.Loaded)
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ namespace Barotrauma.Networking
|
|||||||
{
|
{
|
||||||
if (Data[i] != other.Data[i]) return false;
|
if (Data[i] != other.Data[i]) return false;
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user