Submarine position syncing
This commit is contained in:
@@ -1111,6 +1111,10 @@ namespace Barotrauma
|
||||
|
||||
public void ServerWrite(NetOutgoingMessage msg, Client c)
|
||||
{
|
||||
msg.Write(ID);
|
||||
//length in bytes
|
||||
msg.Write((byte)(4 + 4));
|
||||
|
||||
msg.Write(PhysicsBody.SimPosition.X);
|
||||
msg.Write(PhysicsBody.SimPosition.Y);
|
||||
}
|
||||
@@ -1119,8 +1123,7 @@ namespace Barotrauma
|
||||
{
|
||||
var newTargetPosition = new Vector2(
|
||||
msg.ReadFloat(),
|
||||
msg.ReadFloat());
|
||||
|
||||
msg.ReadFloat());
|
||||
|
||||
//already interpolating with more up-to-date data -> ignore
|
||||
if (subBody.MemPos.Count > 1 && subBody.MemPos[0].Timestamp > sendingTime)
|
||||
|
||||
@@ -121,7 +121,7 @@ namespace Barotrauma.Networking
|
||||
config.SimulatedLoss = 0.05f;
|
||||
config.SimulatedDuplicatesChance = 0.05f;
|
||||
config.SimulatedMinimumLatency = 0.1f;
|
||||
config.SimulatedRandomLatency = 0.2f;
|
||||
config.SimulatedRandomLatency = 0.05f;
|
||||
#endif
|
||||
|
||||
config.DisableMessageType(NetIncomingMessageType.DebugMessage | NetIncomingMessageType.WarningMessage | NetIncomingMessageType.Receipt
|
||||
@@ -706,19 +706,19 @@ namespace Barotrauma.Networking
|
||||
case ServerNetObject.SYNC_IDS:
|
||||
lastSentChatMsgID = inc.ReadUInt32();
|
||||
break;
|
||||
case ServerNetObject.CHARACTER_POSITION:
|
||||
case ServerNetObject.ENTITY_POSITION:
|
||||
UInt16 id = inc.ReadUInt16();
|
||||
byte msgLength = inc.ReadByte();
|
||||
|
||||
var character = Entity.FindEntityByID(id) as Character;
|
||||
if (character == null)
|
||||
var entity = Entity.FindEntityByID(id) as IServerSerializable;
|
||||
if (entity == null)
|
||||
{
|
||||
//skip through the rest of the message
|
||||
inc.Position += msgLength * 8;
|
||||
}
|
||||
else
|
||||
{
|
||||
character.ClientRead(inc, sendingTime);
|
||||
entity.ClientRead(inc, sendingTime);
|
||||
}
|
||||
|
||||
inc.ReadPadBits();
|
||||
|
||||
@@ -69,7 +69,7 @@ namespace Barotrauma.Networking
|
||||
|
||||
#if DEBUG
|
||||
config.SimulatedLoss = 0.05f;
|
||||
config.SimulatedRandomLatency = 0.2f;
|
||||
config.SimulatedRandomLatency = 0.05f;
|
||||
config.SimulatedDuplicatesChance = 0.05f;
|
||||
config.SimulatedMinimumLatency = 0.1f;
|
||||
#endif
|
||||
@@ -664,11 +664,22 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
if (character is AICharacter) continue;
|
||||
|
||||
outmsg.Write((byte)ServerNetObject.CHARACTER_POSITION);
|
||||
outmsg.Write((byte)ServerNetObject.ENTITY_POSITION);
|
||||
character.ServerWrite(outmsg, c);
|
||||
outmsg.WritePadBits();
|
||||
}
|
||||
|
||||
foreach (Submarine sub in Submarine.Loaded)
|
||||
{
|
||||
//if docked to a sub with a smaller ID, don't send an update
|
||||
// (= update is only sent for the docked sub that has the smallest ID, doesn't matter if it's the main sub or a shuttle)
|
||||
if (sub.DockedTo.Any(s => s.ID < sub.ID)) continue;
|
||||
|
||||
outmsg.Write((byte)ServerNetObject.ENTITY_POSITION);
|
||||
sub.ServerWrite(outmsg, c);
|
||||
outmsg.WritePadBits();
|
||||
}
|
||||
|
||||
outmsg.Write((byte)ServerNetObject.END_OF_MESSAGE);
|
||||
server.SendMessage(outmsg, c.Connection, NetDeliveryMethod.Unreliable);
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ namespace Barotrauma.Networking
|
||||
SYNC_IDS,
|
||||
CHAT_MESSAGE,
|
||||
VOTE,
|
||||
CHARACTER_POSITION,
|
||||
ENTITY_POSITION,
|
||||
ITEM_STATE,
|
||||
|
||||
ENTITY_SPAWN,
|
||||
|
||||
@@ -503,7 +503,7 @@ namespace Barotrauma
|
||||
{
|
||||
//if there are more than 2 positions in the buffer,
|
||||
//increase the interpolation speed to catch up with the server
|
||||
float speedMultiplier = 1.0f + (float)Math.Pow((positionBuffer.Count - 2) / 2.0f, 2.0f);
|
||||
float speedMultiplier = 0.9f + (float)Math.Pow((positionBuffer.Count - 2) / 5.0f, 2.0f);
|
||||
|
||||
netInterpolationState += (deltaTime * speedMultiplier) / (next.Timestamp - prev.Timestamp);
|
||||
newPosition = Vector2.Lerp(prev.Position, next.Position, netInterpolationState);
|
||||
|
||||
Reference in New Issue
Block a user