Merge branch 'new-netcode' of https://gitlab.com/poe.regalis/barotrauma into new-netcode
This commit is contained in:
@@ -1206,6 +1206,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
|
||||
@@ -1227,6 +1244,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;
|
||||
@@ -1245,7 +1278,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();
|
||||
}
|
||||
|
||||
@@ -1101,6 +1101,27 @@ namespace Barotrauma
|
||||
return closestCharacter;
|
||||
}
|
||||
|
||||
private void TransformCursorPos()
|
||||
{
|
||||
if (Submarine == null)
|
||||
{
|
||||
//character is outside but cursor position inside
|
||||
if (cursorPosition.Y > Level.Loaded.Size.Y)
|
||||
{
|
||||
var sub = Submarine.FindContaining(cursorPosition);
|
||||
if (sub != null) cursorPosition += sub.Position;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//character is inside but cursor position is outside
|
||||
if (cursorPosition.Y < Level.Loaded.Size.Y)
|
||||
{
|
||||
cursorPosition -= Submarine.Position;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void SelectCharacter(Character character)
|
||||
{
|
||||
if (character == null) return;
|
||||
@@ -1315,41 +1336,46 @@ namespace Barotrauma
|
||||
{
|
||||
if (GameMain.Server != null && !(this is AICharacter) && AllowMovement)
|
||||
{
|
||||
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)
|
||||
|
||||
if (AllowMovement) AnimController.Frozen = true;
|
||||
return;
|
||||
}
|
||||
|
||||
AnimController.Frozen = false;
|
||||
prevDequeuedInput = dequeuedInput;
|
||||
|
||||
dequeuedInput = memInput[memInput.Count - 1];
|
||||
memInput.RemoveAt(memInput.Count - 1);
|
||||
|
||||
cursorPosition = memMousePos[memMousePos.Count - 1];
|
||||
memMousePos.RemoveAt(memMousePos.Count - 1);
|
||||
|
||||
TransformCursorPos();
|
||||
|
||||
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;
|
||||
}
|
||||
else
|
||||
{
|
||||
isStillCountdown--;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (AllowMovement) AnimController.Frozen = true;
|
||||
return;
|
||||
}
|
||||
isStillCountdown = 15;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (GameMain.Client != null)
|
||||
@@ -2089,6 +2115,8 @@ namespace Barotrauma
|
||||
if (aiming)
|
||||
{
|
||||
//TODO: write this with less accuracy?
|
||||
|
||||
|
||||
msg.Write(cursorPosition.X);
|
||||
msg.Write(cursorPosition.Y);
|
||||
}
|
||||
@@ -2153,6 +2181,8 @@ namespace Barotrauma
|
||||
cursorPosition = new Vector2(
|
||||
msg.ReadFloat(),
|
||||
msg.ReadFloat());
|
||||
|
||||
TransformCursorPos();
|
||||
}
|
||||
facingRight = msg.ReadBoolean();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user