Transforming received in-sub mouse coordinates to outside coordinates if the character is outside and vice versa, HiddenSubPosition fix (can't use Level.Loaded to find the top of the level because the level isn't loaded yet)
This commit is contained in:
@@ -188,7 +188,7 @@ namespace Barotrauma
|
||||
|
||||
if (Screen.Selected == GameMain.GameScreen)
|
||||
{
|
||||
var closestSub = Submarine.GetClosest(WorldViewCenter);
|
||||
var closestSub = Submarine.FindClosest(WorldViewCenter);
|
||||
if (closestSub != null)
|
||||
{
|
||||
moveCam += FarseerPhysics.ConvertUnits.ToDisplayUnits(closestSub.Velocity * deltaTime);
|
||||
|
||||
@@ -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)
|
||||
@@ -2077,6 +2103,8 @@ namespace Barotrauma
|
||||
if (aiming)
|
||||
{
|
||||
//TODO: write this with less accuracy?
|
||||
|
||||
|
||||
msg.Write(cursorPosition.X);
|
||||
msg.Write(cursorPosition.Y);
|
||||
}
|
||||
@@ -2141,6 +2169,8 @@ namespace Barotrauma
|
||||
cursorPosition = new Vector2(
|
||||
msg.ReadFloat(),
|
||||
msg.ReadFloat());
|
||||
|
||||
TransformCursorPos();
|
||||
}
|
||||
facingRight = msg.ReadBoolean();
|
||||
}
|
||||
|
||||
@@ -163,7 +163,7 @@ namespace Barotrauma
|
||||
return null;
|
||||
}
|
||||
|
||||
Submarine closestSub = Submarine.GetClosest(GameMain.GameScreen.Cam.WorldViewCenter);
|
||||
Submarine closestSub = Submarine.FindClosest(GameMain.GameScreen.Cam.WorldViewCenter);
|
||||
if (closestSub != null && (closestSub.AtEndPosition || closestSub.AtStartPosition))
|
||||
{
|
||||
return closestSub.DockedTo.Contains(Submarine.MainSub) ? Submarine.MainSub : closestSub;
|
||||
|
||||
@@ -811,7 +811,7 @@ namespace Barotrauma
|
||||
//Level.Loaded.Move(-amount);
|
||||
}
|
||||
|
||||
public static Submarine GetClosest(Vector2 worldPosition)
|
||||
public static Submarine FindClosest(Vector2 worldPosition)
|
||||
{
|
||||
Submarine closest = null;
|
||||
float closestDist = 0.0f;
|
||||
@@ -828,6 +828,24 @@ namespace Barotrauma
|
||||
return closest;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Finds the sub whose borders contain the position
|
||||
/// </summary>
|
||||
public static Submarine FindContaining(Vector2 position)
|
||||
{
|
||||
foreach (Submarine sub in Submarine.Loaded)
|
||||
{
|
||||
Rectangle subBorders = sub.Borders;
|
||||
subBorders.Location += sub.HiddenSubPosition.ToPoint() - new Microsoft.Xna.Framework.Point(0, sub.Borders.Height);
|
||||
|
||||
subBorders.Inflate(500.0f, 500.0f);
|
||||
|
||||
if (subBorders.Contains(position)) return sub;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
//saving/loading ----------------------------------------------------
|
||||
|
||||
public bool Save()
|
||||
@@ -1056,7 +1074,10 @@ namespace Barotrauma
|
||||
|
||||
//place the sub above the top of the level
|
||||
HiddenSubPosition = HiddenSubStartPosition;
|
||||
if (Level.Loaded != null) HiddenSubPosition += Vector2.UnitY * Level.Loaded.Size.Y;
|
||||
if (GameMain.GameSession != null && GameMain.GameSession.Level != null)
|
||||
{
|
||||
HiddenSubPosition += Vector2.UnitY * GameMain.GameSession.Level.Size.Y;
|
||||
}
|
||||
|
||||
foreach (Submarine sub in Submarine.loaded)
|
||||
{
|
||||
|
||||
@@ -207,7 +207,7 @@ namespace Barotrauma
|
||||
Submarine closestSub = null;
|
||||
if (Character.Controlled == null)
|
||||
{
|
||||
closestSub = Submarine.GetClosest(GameMain.GameScreen.Cam.WorldViewCenter);
|
||||
closestSub = Submarine.FindClosest(GameMain.GameScreen.Cam.WorldViewCenter);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -50,25 +50,11 @@ namespace Barotrauma
|
||||
|
||||
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;
|
||||
var sub = Submarine.FindContaining(ConvertUnits.ToDisplayUnits(posInfo.Position));
|
||||
if (sub == null) return posInfo;
|
||||
|
||||
return new PosInfo(
|
||||
posInfo.Position + ConvertUnits.ToSimUnits(closestSub.Position),
|
||||
posInfo.Position + ConvertUnits.ToSimUnits(sub.Position),
|
||||
posInfo.Direction,
|
||||
posInfo.ID,
|
||||
posInfo.Timestamp);
|
||||
|
||||
@@ -118,7 +118,7 @@ namespace Barotrauma
|
||||
if (GameMain.GameSession != null && GameMain.GameSession.Level != null && GameMain.GameSession.Submarine != null &&
|
||||
!DebugConsole.IsOpen)
|
||||
{
|
||||
var closestSub = Submarine.GetClosest(cam.WorldViewCenter);
|
||||
var closestSub = Submarine.FindClosest(cam.WorldViewCenter);
|
||||
if (closestSub == null) closestSub = GameMain.GameSession.Submarine;
|
||||
|
||||
Vector2 targetMovement = Vector2.Zero;
|
||||
|
||||
Reference in New Issue
Block a user