Update content vectors to numerics (#17759)

This commit is contained in:
metalgearsloth
2023-07-08 14:08:32 +10:00
committed by GitHub
parent 15772478c9
commit 68480af109
383 changed files with 978 additions and 575 deletions

View File

@@ -1,3 +1,4 @@
using System.Numerics;
using Content.Server.Cargo.Components;
using Content.Server.Shuttle.Components;
using Content.Server.Shuttles.Components;
@@ -309,7 +310,7 @@ namespace Content.Server.Physics.Controllers
brakeInput += pilotInput.Brakes;
}
if (pilotInput.Strafe.Length > 0f)
if (pilotInput.Strafe.Length() > 0f)
{
var offsetRotation = consoleXform.LocalRotation;
linearInput += offsetRotation.RotateVec(pilotInput.Strafe);
@@ -329,7 +330,7 @@ namespace Content.Server.Physics.Controllers
// Handle shuttle movement
if (brakeInput > 0f)
{
if (body.LinearVelocity.Length > 0f)
if (body.LinearVelocity.Length() > 0f)
{
// Minimum brake velocity for a direction to show its thrust appearance.
const float appearanceThreshold = 0.1f;
@@ -383,11 +384,11 @@ namespace Content.Server.Physics.Controllers
var impulse = force * brakeInput * ShuttleComponent.BrakeCoefficient;
impulse = shuttleNorthAngle.RotateVec(impulse);
var forceMul = frameTime * body.InvMass;
var maxVelocity = (-body.LinearVelocity).Length / forceMul;
var maxVelocity = (-body.LinearVelocity).Length() / forceMul;
// Don't overshoot
if (impulse.Length > maxVelocity)
impulse = impulse.Normalized * maxVelocity;
if (impulse.Length() > maxVelocity)
impulse = impulse.Normalized() * maxVelocity;
PhysicsSystem.ApplyForce(shuttle.Owner, impulse, body: body);
}
@@ -422,7 +423,7 @@ namespace Content.Server.Physics.Controllers
}
}
if (linearInput.Length.Equals(0f))
if (linearInput.Length().Equals(0f))
{
PhysicsSystem.SetSleepingAllowed(shuttle.Owner, body, true);
@@ -481,20 +482,20 @@ namespace Content.Server.Physics.Controllers
}
_thruster.EnableLinearThrustDirection(shuttle, dir);
var impulse = force * linearInput.Length;
var impulse = force * linearInput.Length();
totalForce += impulse;
}
totalForce = shuttleNorthAngle.RotateVec(totalForce);
var forceMul = frameTime * body.InvMass;
var maxVelocity = (ShuttleComponent.MaxLinearVelocity - body.LinearVelocity.Length) / forceMul;
var maxVelocity = (ShuttleComponent.MaxLinearVelocity - body.LinearVelocity.Length()) / forceMul;
if (maxVelocity != 0f)
{
// Don't overshoot
if (totalForce.Length > maxVelocity)
totalForce = totalForce.Normalized * maxVelocity;
if (totalForce.Length() > maxVelocity)
totalForce = totalForce.Normalized() * maxVelocity;
PhysicsSystem.ApplyForce(shuttle.Owner, totalForce, body: body);
}

View File

@@ -1,4 +1,5 @@
using Content.Shared.Gravity;
using System.Numerics;
using Content.Shared.Gravity;
using Content.Shared.Pulling;
using Content.Shared.Pulling.Components;
using Content.Shared.Rotatable;
@@ -72,7 +73,7 @@ namespace Content.Server.Physics.Controllers
UpdatePulledRotation(uid, pullable);
if (args.NewPosition.EntityId == args.OldPosition.EntityId &&
(args.NewPosition.Position - args.OldPosition.Position).LengthSquared < MinimumMovementDistance * MinimumMovementDistance)
(args.NewPosition.Position - args.OldPosition.Position).LengthSquared() < MinimumMovementDistance * MinimumMovementDistance)
return;
if (TryComp<PhysicsComponent>(pullable, out var physics))
@@ -98,7 +99,7 @@ namespace Content.Server.Physics.Controllers
var pulledData = TransformSystem.GetWorldPositionRotation(pulledXform, xforms);
var dir = pullerData.WorldPosition - pulledData.WorldPosition;
if (dir.LengthSquared > ThresholdRotDistance * ThresholdRotDistance)
if (dir.LengthSquared() > ThresholdRotDistance * ThresholdRotDistance)
{
var oldAngle = pulledData.WorldRotation;
var newAngle = Angle.FromWorldVec(dir);
@@ -163,9 +164,9 @@ namespace Content.Server.Physics.Controllers
var ownerPosition = pullableXform.MapPosition.Position;
var diff = movingPosition - ownerPosition;
var diffLength = diff.Length;
var diffLength = diff.Length();
if (diffLength < MaximumSettleDistance && physics.LinearVelocity.Length < MaximumSettleVelocity)
if (diffLength < MaximumSettleDistance && physics.LinearVelocity.Length() < MaximumSettleVelocity)
{
PhysicsSystem.SetLinearVelocity(pullableEnt, Vector2.Zero, body: physics);
_pullableSystem.StopMoveTo(pullable);
@@ -176,9 +177,9 @@ namespace Content.Server.Physics.Controllers
var impulseModifier = MathHelper.Lerp(AccelModifierLow, AccelModifierHigh, impulseModifierLerp);
var multiplier = diffLength < 1 ? impulseModifier * diffLength : impulseModifier;
// Note the implication that the real rules of physics don't apply to pulling control.
var accel = diff.Normalized * multiplier;
var accel = diff.Normalized() * multiplier;
// Now for the part where velocity gets shutdown...
if (diffLength < SettleShutdownDistance && physics.LinearVelocity.Length >= SettleMinimumShutdownVelocity)
if (diffLength < SettleShutdownDistance && physics.LinearVelocity.Length() >= SettleMinimumShutdownVelocity)
{
// Shutdown velocity increases as we get closer to centre
var scaling = (SettleShutdownDistance - diffLength) / SettleShutdownDistance;