Transforming in-sub MemPos/MemLocalPos coordinates to outside coordinates if the character is outside and vice versa, server doesn't start sending ingame updates until they receive the first ingame update message from the client (no need to send updates while the client is loading or if they fail to start the round)
This commit is contained in:
@@ -1205,6 +1205,23 @@ namespace Barotrauma
|
||||
{
|
||||
if (GameMain.NetworkMember == null) return;
|
||||
|
||||
for (int i = 0; i < character.MemPos.Count; i++ )
|
||||
{
|
||||
if (character.Submarine == null)
|
||||
{
|
||||
//transform in-sub coordinates to outside coordinates
|
||||
if (character.MemPos[i].Position.Y > ConvertUnits.ToSimUnits(Level.Loaded.Size.Y))
|
||||
character.MemPos[i] = PosInfo.TransformInToOutside(character.MemPos[i]);
|
||||
}
|
||||
else if (currentHull != null)
|
||||
{
|
||||
//transform outside coordinates to in-sub coordinates
|
||||
if (character.MemPos[i].Position.Y < ConvertUnits.ToSimUnits(Level.Loaded.Size.Y))
|
||||
character.MemPos[i] = PosInfo.TransformOutToInside(character.MemPos[i], currentHull.Submarine);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (character != GameMain.NetworkMember.Character || !character.AllowMovement)
|
||||
{
|
||||
//use simple interpolation for other players' characters and characters that can't move
|
||||
@@ -1226,6 +1243,22 @@ namespace Barotrauma
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < character.MemLocalPos.Count; i++)
|
||||
{
|
||||
if (character.Submarine == null)
|
||||
{
|
||||
//transform in-sub coordinates to outside coordinates
|
||||
if (character.MemLocalPos[i].Position.Y > ConvertUnits.ToSimUnits(Level.Loaded.Size.Y))
|
||||
character.MemLocalPos[i] = PosInfo.TransformInToOutside(character.MemLocalPos[i]);
|
||||
}
|
||||
else if (currentHull != null)
|
||||
{
|
||||
//transform outside coordinates to in-sub coordinates
|
||||
if (character.MemLocalPos[i].Position.Y < ConvertUnits.ToSimUnits(Level.Loaded.Size.Y))
|
||||
character.MemLocalPos[i] = PosInfo.TransformOutToInside(character.MemLocalPos[i], currentHull.Submarine);
|
||||
}
|
||||
}
|
||||
|
||||
if (character.MemPos.Count < 1) return;
|
||||
|
||||
overrideTargetMovement = Vector2.Zero;
|
||||
@@ -1244,7 +1277,7 @@ namespace Barotrauma
|
||||
if (errorMagnitude > 2.0f)
|
||||
{
|
||||
//predicted position was way off, reset completely
|
||||
Collider.SetTransform(serverPos.Position, Collider.Rotation);
|
||||
SetPosition(serverPos.Position, false);
|
||||
//local positions are incorrect now -> just clear the list
|
||||
character.MemLocalPos.Clear();
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ namespace Barotrauma
|
||||
{
|
||||
public static string SavePath = "Submarines";
|
||||
|
||||
public static readonly Vector2 HiddenSubStartPosition = new Vector2(-50000.0f, 80000.0f);
|
||||
public static readonly Vector2 HiddenSubStartPosition = new Vector2(-50000.0f, 10000.0f);
|
||||
//position of the "actual submarine" which is rendered wherever the SubmarineBody is
|
||||
//should be in an unreachable place
|
||||
public Vector2 HiddenSubPosition
|
||||
@@ -1054,7 +1054,10 @@ namespace Barotrauma
|
||||
Description = ToolBox.GetAttributeString(submarineElement, "description", "");
|
||||
Enum.TryParse(ToolBox.GetAttributeString(submarineElement, "tags", ""), out tags);
|
||||
|
||||
//place the sub above the top of the level
|
||||
HiddenSubPosition = HiddenSubStartPosition;
|
||||
if (Level.Loaded != null) HiddenSubPosition += Vector2.UnitY * Level.Loaded.Size.Y;
|
||||
|
||||
foreach (Submarine sub in Submarine.loaded)
|
||||
{
|
||||
HiddenSubPosition += Vector2.UnitY * (sub.Borders.Height + 5000.0f);
|
||||
|
||||
@@ -128,6 +128,8 @@ namespace Barotrauma.Networking
|
||||
config.SimulatedDuplicatesChance = 0.05f;
|
||||
config.SimulatedMinimumLatency = 0.1f;
|
||||
config.SimulatedRandomLatency = 0.05f;
|
||||
|
||||
config.ConnectionTimeout = 600.0f;
|
||||
#endif
|
||||
|
||||
config.DisableMessageType(NetIncomingMessageType.DebugMessage | NetIncomingMessageType.WarningMessage | NetIncomingMessageType.Receipt
|
||||
|
||||
@@ -76,6 +76,8 @@ namespace Barotrauma.Networking
|
||||
config.SimulatedRandomLatency = 0.05f;
|
||||
config.SimulatedDuplicatesChance = 0.05f;
|
||||
config.SimulatedMinimumLatency = 0.1f;
|
||||
|
||||
config.ConnectionTimeout = 600.0f;
|
||||
#endif
|
||||
config.Port = port;
|
||||
Port = port;
|
||||
@@ -472,16 +474,9 @@ namespace Barotrauma.Networking
|
||||
|
||||
foreach (Client c in ConnectedClients)
|
||||
{
|
||||
if (gameStarted)
|
||||
if (gameStarted && c.inGame)
|
||||
{
|
||||
if (c.inGame)
|
||||
{
|
||||
ClientWriteIngame(c);
|
||||
}
|
||||
else
|
||||
{
|
||||
ClientWriteLobby(c);
|
||||
}
|
||||
ClientWriteIngame(c);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -606,7 +601,6 @@ namespace Barotrauma.Networking
|
||||
//break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void ClientReadIngame(NetIncomingMessage inc)
|
||||
@@ -617,6 +611,8 @@ namespace Barotrauma.Networking
|
||||
inc.SenderConnection.Disconnect("You're not a connected client.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (gameStarted) c.inGame = true;
|
||||
|
||||
ClientNetObject objHeader;
|
||||
while ((objHeader = (ClientNetObject)inc.ReadByte()) != ClientNetObject.END_OF_MESSAGE)
|
||||
@@ -924,7 +920,6 @@ namespace Barotrauma.Networking
|
||||
List<CharacterInfo> characterInfos = new List<CharacterInfo>();
|
||||
foreach (Client client in connectedClients)
|
||||
{
|
||||
client.inGame = true;
|
||||
if (client.characterInfo == null)
|
||||
{
|
||||
client.characterInfo = new CharacterInfo(Character.HumanConfigFile, client.name);
|
||||
|
||||
@@ -37,6 +37,42 @@ namespace Barotrauma
|
||||
|
||||
Timestamp = time;
|
||||
}
|
||||
|
||||
public static PosInfo TransformOutToInside(PosInfo posInfo, Submarine submarine)
|
||||
{
|
||||
//transform outside coordinates to in-sub coordinates
|
||||
return new PosInfo(
|
||||
posInfo.Position - ConvertUnits.ToSimUnits(submarine.Position),
|
||||
posInfo.Direction,
|
||||
posInfo.ID,
|
||||
posInfo.Timestamp);
|
||||
}
|
||||
|
||||
public static PosInfo TransformInToOutside(PosInfo posInfo)
|
||||
{
|
||||
Submarine closestSub = null;
|
||||
foreach (Submarine sub in Submarine.Loaded)
|
||||
{
|
||||
Rectangle subBorders = sub.Borders;
|
||||
subBorders.Location += sub.HiddenSubPosition.ToPoint() - new Point(0, sub.Borders.Height);
|
||||
|
||||
subBorders.Inflate(500.0f, 500.0f);
|
||||
|
||||
if (subBorders.Contains(ConvertUnits.ToDisplayUnits(posInfo.Position)))
|
||||
{
|
||||
closestSub = sub;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (closestSub == null) return posInfo;
|
||||
|
||||
return new PosInfo(
|
||||
posInfo.Position + ConvertUnits.ToSimUnits(closestSub.Position),
|
||||
posInfo.Direction,
|
||||
posInfo.ID,
|
||||
posInfo.Timestamp);
|
||||
}
|
||||
}
|
||||
|
||||
class PhysicsBody
|
||||
|
||||
Reference in New Issue
Block a user