Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
evilfactory committed Dec 11, 2024
2 parents b4f264d + 38ca721 commit 6da26ff
Show file tree
Hide file tree
Showing 257 changed files with 4,794 additions and 1,654 deletions.
2 changes: 1 addition & 1 deletion .github/DISCUSSION_TEMPLATE/bug-reports.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ body:
label: Version
description: Which version of the game did the bug happen in? You can see the current version number in the bottom left corner of your screen in the main menu.
options:
- v1.6.19.1 (Unto the Breach Update Hotfix 2)
- v1.7.7.0 (Winter Update)
- Other
validations:
required: true
Expand Down
15 changes: 12 additions & 3 deletions Barotrauma/BarotraumaClient/ClientSource/Camera.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ public float MaxZoom
private float prevZoom;

public float Shake;

/// <summary>
/// Should the camera's transform matrices be automatically updated to match the screen resolution?
/// </summary>
public bool AutoUpdateToScreenResolution = true;

public Vector2 ShakePosition { get; private set; }
private float shakeTimer;

Expand Down Expand Up @@ -198,10 +204,13 @@ public void SetResolution(Point res)

public void UpdateTransform(bool interpolate = true, bool updateListener = true)
{
if (GameMain.GraphicsWidth != Resolution.X ||
GameMain.GraphicsHeight != Resolution.Y)
if (AutoUpdateToScreenResolution)
{
CreateMatrices();
if (GameMain.GraphicsWidth != Resolution.X ||
GameMain.GraphicsHeight != Resolution.Y)
{
CreateMatrices();
}
}

Vector2 interpolatedPosition = interpolate ? Timing.Interpolate(prevPosition, position) : position;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public override void DebugDraw(SpriteBatch spriteBatch)
if (wallTarget != null && !IsCoolDownRunning)
{
Vector2 wallTargetPos = wallTarget.Position;
if (wallTarget.Structure.Submarine != null) { wallTargetPos += wallTarget.Structure.Submarine.Position; }
if (wallTarget.Structure.Submarine != null) { wallTargetPos += wallTarget.Structure.Submarine.DrawPosition; }
wallTargetPos.Y = -wallTargetPos.Y;
GUI.DrawRectangle(spriteBatch, wallTargetPos - new Vector2(10.0f, 10.0f), new Vector2(20.0f, 20.0f), Color.Orange, false);
GUI.DrawLine(spriteBatch, pos, wallTargetPos, Color.Orange * 0.5f, 0, 5);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public override void DebugDraw(Microsoft.Xna.Framework.Graphics.SpriteBatch spri
{
if (Character == Character.Controlled) { return; }
if (!DebugAI) { return; }
Vector2 pos = Character.WorldPosition;
Vector2 pos = Character.DrawPosition;
pos.Y = -pos.Y;
Vector2 textOffset = new Vector2(-40, -160);
textOffset.Y -= Math.Max(ObjectiveManager.CurrentOrders.Count - 1, 0) * 20;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ partial void UpdateNetPlayerPositionProjSpecific(float deltaTime, float lowestSu
character.AnimController.Anim = AnimController.Animation.None;
}

character.AnimController.IgnorePlatforms = character.MemState[0].IgnorePlatforms;
character.AnimController.overrideTargetMovement = character.MemState[0].TargetMovement;

Vector2 newVelocity = Collider.LinearVelocity;
Vector2 newPosition = Collider.SimPosition;
float newRotation = Collider.Rotation;
Expand All @@ -103,16 +106,17 @@ partial void UpdateNetPlayerPositionProjSpecific(float deltaTime, float lowestSu
{
newVelocity = newVelocity.ClampLength(100.0f);
if (!MathUtils.IsValid(newVelocity)) { newVelocity = Vector2.Zero; }
overrideTargetMovement = newVelocity.LengthSquared() > 0.01f ? newVelocity : Vector2.Zero;
Collider.LinearVelocity = newVelocity;
Collider.AngularVelocity = newAngularVelocity;
}

float distSqrd = Vector2.DistanceSquared(newPosition, Collider.SimPosition);
float errorTolerance = character.CanMove && (!character.IsRagdolled || character.AnimController.IsHangingWithRope) ? 0.01f : 0.2f;
float errorTolerance =
ColliderControlsMovement && (!character.IsRagdolled || character.AnimController.IsHangingWithRope) ? 0.01f : 0.2f;
if (distSqrd > errorTolerance)
{
if (distSqrd > 10.0f || !character.CanMove)
character.AnimController.BodyInRest = false;
if (distSqrd > 10.0f)
{
Collider.TargetRotation = newRotation;
if (distSqrd > 10.0f)
Expand All @@ -126,28 +130,31 @@ partial void UpdateNetPlayerPositionProjSpecific(float deltaTime, float lowestSu
}
}
SetPosition(newPosition, lerp: distSqrd < 5.0f, ignorePlatforms: false);
//make sure ragdoll isn't stuck at the wrong side of a platform if the movement is controlled by the ragdoll, and the ragdoll has come to rest server-side
if (!ColliderControlsMovement && newVelocity.LengthSquared() < 0.01f) { TryPlatformCorrection(newPosition); }
}
else
else if (ColliderControlsMovement)
{
Collider.TargetRotation = newRotation;
Collider.TargetPosition = newPosition;
Collider.MoveToTargetPosition(true);
}
}

//immobilized characters can't correct their position using AnimController movement
// -> we need to correct it manually
if (!character.CanMove)
{
float mainLimbDistSqrd = Vector2.DistanceSquared(MainLimb.PullJointWorldAnchorA, Collider.SimPosition);
float mainLimbErrorTolerance = 0.1f;
//if the main limb is roughly at the correct position and the collider isn't moving (much at least),
//don't attempt to correct the position.
if (mainLimbDistSqrd > mainLimbErrorTolerance || Collider.LinearVelocity.LengthSquared() > 0.05f)
else
{
MainLimb.PullJointWorldAnchorB = Collider.SimPosition;
MainLimb.PullJointEnabled = true;
MainLimb.body.LinearVelocity = newVelocity;
float mainLimbDistSqrd = Vector2.DistanceSquared(MainLimb.PullJointWorldAnchorA, newPosition);
float mainLimbErrorTolerance = 0.1f;
//if the main limb is roughly at the correct position and the collider isn't moving (much at least),
//don't attempt to correct the position.
if (mainLimbDistSqrd > mainLimbErrorTolerance)
{
MainLimb.PullJointWorldAnchorB = newPosition;
MainLimb.PullJointEnabled = true;
if (!ColliderControlsMovement && newVelocity.LengthSquared() < 0.01f) { TryPlatformCorrection(newPosition); }
}
else
{
MainLimb.body.LinearVelocity = newVelocity;
}
}
}
}
Expand Down Expand Up @@ -179,9 +186,9 @@ partial void UpdateNetPlayerPositionProjSpecific(float deltaTime, float lowestSu
}
}

if (character.MemState.Count < 1) return;
if (character.MemState.Count < 1) { return; }

overrideTargetMovement = Vector2.Zero;
overrideTargetMovement = null;

CharacterStateInfo serverPos = character.MemState.Last();

Expand Down Expand Up @@ -294,6 +301,38 @@ partial void UpdateNetPlayerPositionProjSpecific(float deltaTime, float lowestSu
character.MemState.Clear();
}
}

/// <summary>
/// Attempts to correct the ragdoll to the correct side of a platform if the server position is above the platform and some of the ragdoll's limbs below it client-side, or vice versa.
/// </summary>
private void TryPlatformCorrection(Vector2 serverPos)
{
float highestPos = limbs.Where(static l => !l.IsSevered).Max(static l => l.SimPosition.Y);
highestPos = Math.Max(serverPos.Y, highestPos);
float lowestPos = limbs.Where(static l => !l.IsSevered).Min(static l => l.SimPosition.Y);
lowestPos = Math.Min(serverPos.Y, lowestPos);

var platform = Submarine.PickBody(new Vector2(serverPos.X, highestPos), new Vector2(serverPos.X, lowestPos), collisionCategory: Physics.CollisionPlatform, allowInsideFixture: true);
if (platform == null) { return; }

int serverDir = Math.Sign(serverPos.Y - platform.Position.Y);
foreach (var limb in limbs)
{
if (limb.IsSevered) { continue; }
int limbDir = Math.Sign(limb.SimPosition.Y - platform.Position.Y);

const float Margin = 0.01f;

if (limbDir != serverDir)
{
limb.body.SetTransformIgnoreContacts(
new Vector2(
limb.SimPosition.X,
serverDir > 0 ? Math.Max(serverPos.Y + Margin + limb.body.GetMaxExtent(), limb.SimPosition.Y) : Math.Min(serverPos.Y - Margin - limb.body.GetMaxExtent(), limb.SimPosition.Y)),
limb.Rotation);
}
}
}

partial void ImpactProjSpecific(float impact, Body body)
{
Expand Down
17 changes: 12 additions & 5 deletions Barotrauma/BarotraumaClient/ClientSource/Characters/Character.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ sealed class SpeechBubble
public Vector2 Position;
public Vector2 DrawPosition;
public float MoveUpAmount;
public readonly string Text;
public readonly RichString Text;
public readonly Character Character;
public readonly Submarine Submarine;
public readonly Vector2 TextSize;
Expand All @@ -260,7 +260,7 @@ sealed class SpeechBubble

public SpeechBubble(Character character, float lifeTime, Color color, string text = "")
{
Text = ToolBox.WrapText(text, GUI.IntScale(300), GUIStyle.SmallFont.GetFontForStr(text));
Text = RichString.Rich(ToolBox.WrapText(text, GUI.IntScale(300), GUIStyle.SmallFont.GetFontForStr(text)));
TextSize = GUIStyle.SmallFont.MeasureString(Text);

Character = character;
Expand Down Expand Up @@ -322,7 +322,6 @@ partial void UpdateLimbLightSource(Limb limb)
/// </summary>
public void ControlLocalPlayer(float deltaTime, Camera cam, bool moveCam = true)
{

if (DisableControls || GUI.InputBlockingMenuOpen)
{
foreach (Key key in keys)
Expand Down Expand Up @@ -417,6 +416,11 @@ void ResetInputIfPrimaryMouse(InputType inputType)

UpdateLocalCursor(cam);

if (IsKeyHit(InputType.ToggleRun))
{
ToggleRun = !ToggleRun;
}

Vector2 mouseSimPos = ConvertUnits.ToSimUnits(cursorPosition);
if (GUI.PauseMenuOpen)
{
Expand Down Expand Up @@ -1189,7 +1193,7 @@ public static void DrawSpeechBubbles(SpriteBatch spriteBatch, Camera cam)
Vector2 bubbleSize = bubble.TextSize + Vector2.One * GUI.IntScale(15);
speechBubbleIconSliced.Draw(spriteBatch, new RectangleF(iconPos - bubbleSize / 2, bubbleSize), bubble.Color * Math.Min(bubble.LifeTime, 1.0f) * alpha);
}
GUI.DrawString(spriteBatch, iconPos - bubble.TextSize / 2, bubble.Text, bubble.Color * Math.Min(bubble.LifeTime, 1.0f) * alpha, font: GUIStyle.SmallFont);
GUI.DrawStringWithColors(spriteBatch, iconPos - bubble.TextSize / 2, bubble.Text.SanitizedValue, bubble.Color * Math.Min(bubble.LifeTime, 1.0f) * alpha, bubble.Text.RichTextData, font: GUIStyle.SmallFont);
}
spriteBatch.End();
}
Expand Down Expand Up @@ -1435,7 +1439,10 @@ partial void OnMoneyChanged(int prevAmount, int newAmount) { }

partial void OnTalentGiven(TalentPrefab talentPrefab)
{
AddMessage(TextManager.Get("talentname." + talentPrefab.Identifier).Value, GUIStyle.Yellow, playSound: this == Controlled);
if (!talentPrefab.IsHiddenExtraTalent)
{
AddMessage(TextManager.Get("talentname." + talentPrefab.Identifier).Value, GUIStyle.Yellow, playSound: this == Controlled);
}
}
}
}
Loading

0 comments on commit 6da26ff

Please sign in to comment.