Merge remote-tracking branch 'upstream/master' into develop

This commit is contained in:
EvilFactory
2024-12-11 10:44:53 -03:00
257 changed files with 4793 additions and 1653 deletions
@@ -112,7 +112,7 @@ namespace Barotrauma
//a movement vector that overrides targetmovement if trying to steer
//a Character to the position sent by server in multiplayer mode
protected Vector2 overrideTargetMovement;
protected Vector2? overrideTargetMovement;
protected float floorY, standOnFloorY;
protected Fixture floorFixture;
@@ -142,6 +142,12 @@ namespace Barotrauma
private Category prevCollisionCategory = Category.None;
/// <summary>
/// When the character is alive/conscious, the collider drives the character's movement and is used to sync the character's position in MP.
/// When unconscious, the ragdoll controls the movement and the collider just sticks to the main limb.
/// </summary>
public bool ColliderControlsMovement => character.CanMove;
public bool IsStuck => Limbs.Any(l => l.IsStuck);
public PhysicsBody Collider
@@ -189,7 +195,7 @@ namespace Barotrauma
Vector2 pos = collider[colliderIndex].SimPosition;
pos.Y -= collider[colliderIndex].Height * 0.5f;
pos.Y += collider[value].Height * 0.5f;
collider[value].SetTransform(pos, collider[colliderIndex].Rotation);
collider[value].SetTransformIgnoreContacts(pos, collider[colliderIndex].Rotation);
collider[value].LinearVelocity = collider[colliderIndex].LinearVelocity;
collider[value].AngularVelocity = collider[colliderIndex].AngularVelocity;
@@ -286,7 +292,7 @@ namespace Barotrauma
foreach (Limb limb in Limbs)
{
if (limb.IsSevered || !limb.body.PhysEnabled) { continue; }
limb.body.SetTransform(Collider.SimPosition, Collider.Rotation);
limb.body.SetTransformIgnoreContacts(Collider.SimPosition, Collider.Rotation);
//reset pull joints (they may be somewhere far away if the character has moved from the position where animations were last updated)
limb.PullJointEnabled = false;
limb.PullJointWorldAnchorB = limb.SimPosition;
@@ -301,11 +307,11 @@ namespace Barotrauma
{
get
{
return (overrideTargetMovement == Vector2.Zero) ? targetMovement : overrideTargetMovement;
return overrideTargetMovement ?? targetMovement;
}
set
{
if (!MathUtils.IsValid(value)) return;
if (!MathUtils.IsValid(value)) { return; }
targetMovement.X = MathHelper.Clamp(value.X, -MAX_SPEED, MAX_SPEED);
targetMovement.Y = MathHelper.Clamp(value.Y, -MAX_SPEED, MAX_SPEED);
}
@@ -1307,6 +1313,11 @@ namespace Barotrauma
}
}
float MaxVel = NetConfig.MaxPhysicsBodyVelocity;
Collider.LinearVelocity = new Vector2(
NetConfig.Quantize(Collider.LinearVelocity.X, -MaxVel, MaxVel, 12),
NetConfig.Quantize(Collider.LinearVelocity.Y, -MaxVel, MaxVel, 12));
if (forceStanding)
{
inWater = false;
@@ -1451,7 +1462,7 @@ namespace Barotrauma
else
{
// Falling -> ragdoll briefly if we are not moving at all, because we are probably stuck.
if (Collider.LinearVelocity == Vector2.Zero)
if (Collider.LinearVelocity == Vector2.Zero && !character.IsRemotePlayer)
{
character.IsRagdolled = true;
if (character.IsBot)
@@ -1466,6 +1477,30 @@ namespace Barotrauma
forceNotStanding = false;
}
/// <summary>
/// Update the logic that needs to run when the ragdoll is what controls the character's movement instead of the collider <see cref="ColliderControlsMovement"/>
/// (making the collider stick to the ragdoll's main limb).
/// </summary>
protected void UpdateRagdollControlsMovement()
{
levitatingCollider = false;
Collider.FarseerBody.FixedRotation = false;
if (Collider.Enabled)
{
//deactivating the collider -> make the main limb inherit the collider's velocity because it'll control the movement now
MainLimb.body.LinearVelocity = Collider.LinearVelocity;
Collider.Enabled = false;
}
Collider.LinearVelocity = MainLimb.LinearVelocity;
Collider.SetTransformIgnoreContacts(MainLimb.SimPosition, MainLimb.Rotation);
//reset pull joints to prevent the character from "hanging" mid-air if pull joints had been active when the character was still moving
//(except when dragging, then we need the pull joints)
if (!Draggable || character.SelectedBy == null)
{
ResetPullJoints();
}
}
private void CheckBodyInRest(float deltaTime)
{
if (SimplePhysicsEnabled) { return; }
@@ -2102,7 +2137,7 @@ namespace Barotrauma
partial void UpdateNetPlayerPositionProjSpecific(float deltaTime, float lowestSubPos);
private void UpdateNetPlayerPosition(float deltaTime)
{
if (GameMain.NetworkMember == null) return;
if (GameMain.NetworkMember == null) { return; }
float lowestSubPos = float.MaxValue;
if (Submarine.Loaded.Any())