Faction Test 100.4.0.0

This commit is contained in:
Markus Isberg
2022-11-14 18:28:28 +02:00
parent 87426b68b2
commit c772b61fc1
412 changed files with 16984 additions and 5530 deletions
@@ -97,7 +97,6 @@ namespace Barotrauma
get { return list; }
}
protected Vector2 prevPosition;
protected float prevRotation;
@@ -120,7 +119,9 @@ namespace Barotrauma
}
private Shape bodyShape;
public float height, width, radius;
public float Height { get; private set; }
public float Width { get; private set; }
public float Radius { get; private set; }
private readonly float density;
@@ -344,6 +345,22 @@ namespace Barotrauma
}
}
/// <summary>
/// Ignore rotation calls for the rest of this and the next update. Automatically disabled after that. Used for temporarily suppressing the SmoothRotate calls to prevent conflicting or unitentionally amplified rotations.
/// </summary>
public bool SuppressSmoothRotationCalls
{
get => _suppressSmoothRotationCalls;
set
{
_suppressSmoothRotationCalls = value;
smoothRotationSuppressionCounter = 0;
}
}
private bool _suppressSmoothRotationCalls;
private int smoothRotationSuppressionCounter;
public PhysicsBody(XElement element, float scale = 1.0f, bool findNewContacts = true) : this(element, Vector2.Zero, scale, findNewContacts: findNewContacts) { }
public PhysicsBody(ColliderParams cParams, bool findNewContacts = true) : this(cParams, Vector2.Zero, findNewContacts) { }
public PhysicsBody(LimbParams lParams, bool findNewContacts = true) : this(lParams, Vector2.Zero, findNewContacts) { }
@@ -370,7 +387,7 @@ namespace Barotrauma
float height = ConvertUnits.ToSimUnits(colliderParams.Height) * colliderParams.Ragdoll.LimbScale;
float width = ConvertUnits.ToSimUnits(colliderParams.Width) * colliderParams.Ragdoll.LimbScale;
density = Physics.NeutralDensity;
CreateBody(width, height, radius, density, BodyType.Dynamic,
CreateBody(width, height, radius, density, colliderParams.BodyType,
Physics.CollisionCharacter,
Physics.CollisionWall | Physics.CollisionLevel,
findNewContacts);
@@ -419,9 +436,17 @@ namespace Barotrauma
float width = ConvertUnits.ToSimUnits(element.GetAttributeFloat("width", 0.0f)) * scale;
density = Math.Max(forceDensity ?? element.GetAttributeFloat("density", Physics.NeutralDensity), MinDensity);
Enum.TryParse(element.GetAttributeString("bodytype", "Dynamic"), out BodyType bodyType);
CreateBody(width, height, radius, density, bodyType, collisionCategory, collidesWith, findNewContacts);
_collisionCategories = collisionCategory;
_collidesWith = collidesWith;
if (element.GetAttributeBool("ignorecollision", false))
{
_collisionCategories = Category.None;
_collidesWith = Category.None;
}
else
{
_collisionCategories = collisionCategory;
_collidesWith = collidesWith;
}
CreateBody(width, height, radius, density, bodyType, _collisionCategories, _collidesWith, findNewContacts);
FarseerBody.Friction = element.GetAttributeFloat("friction", 0.5f);
FarseerBody.Restitution = element.GetAttributeFloat("restitution", 0.05f);
FarseerBody.UserData = this;
@@ -457,9 +482,9 @@ namespace Barotrauma
{
DebugConsole.ThrowError("Invalid physics body dimensions (width: " + width + ", height: " + height + ", radius: " + radius + ")");
}
this.width = width;
this.height = height;
this.radius = radius;
Width = width;
Height = height;
Radius = radius;
_collisionCategories = collisionCategory;
_collidesWith = collidesWith;
}
@@ -477,16 +502,16 @@ namespace Barotrauma
switch (bodyShape)
{
case Shape.Capsule:
pos = new Vector2(0.0f, height / 2 + radius);
pos = new Vector2(0.0f, Height / 2 + Radius);
break;
case Shape.HorizontalCapsule:
pos = new Vector2(width / 2 + radius, 0.0f);
pos = new Vector2(Width / 2 + Radius, 0.0f);
break;
case Shape.Circle:
pos = new Vector2(0.0f, radius);
pos = new Vector2(0.0f, Radius);
break;
case Shape.Rectangle:
pos = height > width ? new Vector2(0, height / 2) : new Vector2(width / 2, 0);
pos = Height > Width ? new Vector2(0, Height / 2) : new Vector2(Width / 2, 0);
break;
default:
throw new NotImplementedException();
@@ -499,13 +524,13 @@ namespace Barotrauma
switch (bodyShape)
{
case Shape.Capsule:
return height / 2 + radius;
return Height / 2 + Radius;
case Shape.HorizontalCapsule:
return width / 2 + radius;
return Width / 2 + Radius;
case Shape.Circle:
return radius;
return Radius;
case Shape.Rectangle:
return new Vector2(width * 0.5f, height * 0.5f).Length();
return new Vector2(Width * 0.5f, Height * 0.5f).Length();
default:
throw new NotImplementedException();
}
@@ -516,13 +541,13 @@ namespace Barotrauma
switch (bodyShape)
{
case Shape.Capsule:
return new Vector2(radius * 2, height + radius * 2);
return new Vector2(Radius * 2, Height + Radius * 2);
case Shape.HorizontalCapsule:
return new Vector2(width + radius * 2, radius * 2);
return new Vector2(Width + Radius * 2, Radius * 2);
case Shape.Circle:
return new Vector2(radius * 2);
return new Vector2(Radius * 2);
case Shape.Rectangle:
return new Vector2(width, height);
return new Vector2(Width, Height);
default:
throw new NotImplementedException();
}
@@ -533,24 +558,24 @@ namespace Barotrauma
switch (bodyShape)
{
case Shape.Capsule:
radius = Math.Max(size.X / 2, 0);
height = Math.Max(size.Y - size.X, 0);
width = 0;
Radius = Math.Max(size.X / 2, 0);
Height = Math.Max(size.Y - size.X, 0);
Width = 0;
break;
case Shape.HorizontalCapsule:
radius = Math.Max(size.Y / 2, 0);
width = Math.Max(size.X - size.Y, 0);
height = 0;
Radius = Math.Max(size.Y / 2, 0);
Width = Math.Max(size.X - size.Y, 0);
Height = 0;
break;
case Shape.Circle:
radius = Math.Max(Math.Min(size.X, size.Y) / 2, 0);
width = 0;
height = 0;
Radius = Math.Max(Math.Min(size.X, size.Y) / 2, 0);
Width = 0;
Height = 0;
break;
case Shape.Rectangle:
width = Math.Max(size.X, 0);
height = Math.Max(size.Y, 0);
radius = 0;
Width = Math.Max(size.X, 0);
Height = Math.Max(size.Y, 0);
Radius = 0;
break;
default:
throw new NotImplementedException();
@@ -815,7 +840,7 @@ namespace Barotrauma
Vector2 velDir = LinearVelocity / speed;
float vel = speed * 2.0f;
float drag = vel * vel * Math.Max(height + radius * 2, height);
float drag = vel * vel * Math.Max(Height + Radius * 2, Height);
dragForce = Math.Min(drag, Mass * 500.0f) * -velDir;
}
@@ -831,6 +856,17 @@ namespace Barotrauma
}
drawOffset = NetConfig.InterpolateSimPositionError(drawOffset, PositionSmoothingFactor);
rotationOffset = NetConfig.InterpolateRotationError(rotationOffset);
if (SuppressSmoothRotationCalls)
{
if (smoothRotationSuppressionCounter > 0)
{
SuppressSmoothRotationCalls = false;
}
else
{
smoothRotationSuppressionCounter++;
}
}
}
public void UpdateDrawPosition()
@@ -873,6 +909,7 @@ namespace Barotrauma
/// <param name="wrapAngle">Should the angles be wrapped. Set to false if it makes a difference whether the angle of the body is 0.0f or 360.0f.</param>
public void SmoothRotate(float targetRotation, float force = 10.0f, bool wrapAngle = true)
{
if (SuppressSmoothRotationCalls) { return; }
float nextAngle = FarseerBody.Rotation + FarseerBody.AngularVelocity * (float)Timing.Step;
float angle = wrapAngle ?
MathUtils.GetShortestAngle(nextAngle, targetRotation) :
@@ -881,7 +918,7 @@ namespace Barotrauma
if (FarseerBody.BodyType == BodyType.Kinematic)
{
if (!IsValidValue(torque, "torque")) return;
if (!IsValidValue(torque, "torque")) { return; }
FarseerBody.AngularVelocity = torque;
}
else