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)
|
if (Screen.Selected == GameMain.GameScreen)
|
||||||
{
|
{
|
||||||
var closestSub = Submarine.GetClosest(WorldViewCenter);
|
var closestSub = Submarine.FindClosest(WorldViewCenter);
|
||||||
if (closestSub != null)
|
if (closestSub != null)
|
||||||
{
|
{
|
||||||
moveCam += FarseerPhysics.ConvertUnits.ToDisplayUnits(closestSub.Velocity * deltaTime);
|
moveCam += FarseerPhysics.ConvertUnits.ToDisplayUnits(closestSub.Velocity * deltaTime);
|
||||||
|
|||||||
@@ -1101,6 +1101,27 @@ namespace Barotrauma
|
|||||||
return closestCharacter;
|
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)
|
private void SelectCharacter(Character character)
|
||||||
{
|
{
|
||||||
if (character == null) return;
|
if (character == null) return;
|
||||||
@@ -1315,40 +1336,45 @@ namespace Barotrauma
|
|||||||
{
|
{
|
||||||
if (GameMain.Server != null && !(this is AICharacter) && AllowMovement)
|
if (GameMain.Server != null && !(this is AICharacter) && AllowMovement)
|
||||||
{
|
{
|
||||||
if (memInput.Count > 0)
|
if (memInput.Count == 0)
|
||||||
{
|
{
|
||||||
AnimController.Frozen = false;
|
|
||||||
prevDequeuedInput = dequeuedInput;
|
if (AllowMovement) AnimController.Frozen = true;
|
||||||
dequeuedInput = memInput[memInput.Count - 1];
|
return;
|
||||||
cursorPosition = memMousePos[memMousePos.Count - 1];
|
}
|
||||||
memInput.RemoveAt(memInput.Count - 1);
|
|
||||||
memMousePos.RemoveAt(memMousePos.Count - 1);
|
AnimController.Frozen = false;
|
||||||
if (dequeuedInput == InputNetFlags.None)
|
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
|
||||||
//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;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
isStillCountdown--;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (AllowMovement) AnimController.Frozen = true;
|
isStillCountdown = 15;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2077,6 +2103,8 @@ namespace Barotrauma
|
|||||||
if (aiming)
|
if (aiming)
|
||||||
{
|
{
|
||||||
//TODO: write this with less accuracy?
|
//TODO: write this with less accuracy?
|
||||||
|
|
||||||
|
|
||||||
msg.Write(cursorPosition.X);
|
msg.Write(cursorPosition.X);
|
||||||
msg.Write(cursorPosition.Y);
|
msg.Write(cursorPosition.Y);
|
||||||
}
|
}
|
||||||
@@ -2141,6 +2169,8 @@ namespace Barotrauma
|
|||||||
cursorPosition = new Vector2(
|
cursorPosition = new Vector2(
|
||||||
msg.ReadFloat(),
|
msg.ReadFloat(),
|
||||||
msg.ReadFloat());
|
msg.ReadFloat());
|
||||||
|
|
||||||
|
TransformCursorPos();
|
||||||
}
|
}
|
||||||
facingRight = msg.ReadBoolean();
|
facingRight = msg.ReadBoolean();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -163,7 +163,7 @@ namespace Barotrauma
|
|||||||
return null;
|
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))
|
if (closestSub != null && (closestSub.AtEndPosition || closestSub.AtStartPosition))
|
||||||
{
|
{
|
||||||
return closestSub.DockedTo.Contains(Submarine.MainSub) ? Submarine.MainSub : closestSub;
|
return closestSub.DockedTo.Contains(Submarine.MainSub) ? Submarine.MainSub : closestSub;
|
||||||
|
|||||||
@@ -811,7 +811,7 @@ namespace Barotrauma
|
|||||||
//Level.Loaded.Move(-amount);
|
//Level.Loaded.Move(-amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Submarine GetClosest(Vector2 worldPosition)
|
public static Submarine FindClosest(Vector2 worldPosition)
|
||||||
{
|
{
|
||||||
Submarine closest = null;
|
Submarine closest = null;
|
||||||
float closestDist = 0.0f;
|
float closestDist = 0.0f;
|
||||||
@@ -828,6 +828,24 @@ namespace Barotrauma
|
|||||||
return closest;
|
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 ----------------------------------------------------
|
//saving/loading ----------------------------------------------------
|
||||||
|
|
||||||
public bool Save()
|
public bool Save()
|
||||||
@@ -1056,7 +1074,10 @@ namespace Barotrauma
|
|||||||
|
|
||||||
//place the sub above the top of the level
|
//place the sub above the top of the level
|
||||||
HiddenSubPosition = HiddenSubStartPosition;
|
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)
|
foreach (Submarine sub in Submarine.loaded)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -207,7 +207,7 @@ namespace Barotrauma
|
|||||||
Submarine closestSub = null;
|
Submarine closestSub = null;
|
||||||
if (Character.Controlled == null)
|
if (Character.Controlled == null)
|
||||||
{
|
{
|
||||||
closestSub = Submarine.GetClosest(GameMain.GameScreen.Cam.WorldViewCenter);
|
closestSub = Submarine.FindClosest(GameMain.GameScreen.Cam.WorldViewCenter);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -50,25 +50,11 @@ namespace Barotrauma
|
|||||||
|
|
||||||
public static PosInfo TransformInToOutside(PosInfo posInfo)
|
public static PosInfo TransformInToOutside(PosInfo posInfo)
|
||||||
{
|
{
|
||||||
Submarine closestSub = null;
|
var sub = Submarine.FindContaining(ConvertUnits.ToDisplayUnits(posInfo.Position));
|
||||||
foreach (Submarine sub in Submarine.Loaded)
|
if (sub == null) return posInfo;
|
||||||
{
|
|
||||||
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(
|
return new PosInfo(
|
||||||
posInfo.Position + ConvertUnits.ToSimUnits(closestSub.Position),
|
posInfo.Position + ConvertUnits.ToSimUnits(sub.Position),
|
||||||
posInfo.Direction,
|
posInfo.Direction,
|
||||||
posInfo.ID,
|
posInfo.ID,
|
||||||
posInfo.Timestamp);
|
posInfo.Timestamp);
|
||||||
|
|||||||
@@ -118,7 +118,7 @@ namespace Barotrauma
|
|||||||
if (GameMain.GameSession != null && GameMain.GameSession.Level != null && GameMain.GameSession.Submarine != null &&
|
if (GameMain.GameSession != null && GameMain.GameSession.Level != null && GameMain.GameSession.Submarine != null &&
|
||||||
!DebugConsole.IsOpen)
|
!DebugConsole.IsOpen)
|
||||||
{
|
{
|
||||||
var closestSub = Submarine.GetClosest(cam.WorldViewCenter);
|
var closestSub = Submarine.FindClosest(cam.WorldViewCenter);
|
||||||
if (closestSub == null) closestSub = GameMain.GameSession.Submarine;
|
if (closestSub == null) closestSub = GameMain.GameSession.Submarine;
|
||||||
|
|
||||||
Vector2 targetMovement = Vector2.Zero;
|
Vector2 targetMovement = Vector2.Zero;
|
||||||
|
|||||||
Reference in New Issue
Block a user