diff --git a/Assets/Scripts/ServerShared/FireControl.cs b/Assets/Scripts/ServerShared/FireControl.cs index 5f01188b9..261e1a4f3 100644 --- a/Assets/Scripts/ServerShared/FireControl.cs +++ b/Assets/Scripts/ServerShared/FireControl.cs @@ -2089,8 +2089,9 @@ public struct FireControlDiagnostic } // What a ship can do at this instant, in its own frame: acceleration along each body axis (m/s^2) and the kinematic -// turn rate each way (rad/s; turning toward the ship's right is Clockwise). Each propulsor reports its share with -// its own Execute arithmetic and Ship sums them; nothing stores it. Zero is the envelope of anything that is not a Ship. +// turn rate each way (rad/s; turning toward the ship's right is Clockwise). Ship derives it each update as the box +// extremes of its thrusters' columns (Ship.RecalculateEnvelope); nothing stores it. Zero is the envelope of anything +// that is not a Ship. public readonly struct ManoeuvreEnvelope { public readonly float Forward, Reverse, Left, Right, Clockwise, CounterClockwise; @@ -2104,10 +2105,6 @@ public readonly struct ManoeuvreEnvelope Clockwise = clockwise; CounterClockwise = counterClockwise; } - - public static ManoeuvreEnvelope operator +(ManoeuvreEnvelope a, ManoeuvreEnvelope b) => new ManoeuvreEnvelope( - a.Forward + b.Forward, a.Reverse + b.Reverse, a.Left + b.Left, a.Right + b.Right, - a.Clockwise + b.Clockwise, a.CounterClockwise + b.CounterClockwise); } // How unpredictably an entity is changing its motion, observed from its measured acceleration. The trend is an diff --git a/Assets/Scripts/ServerShared/Ship.cs b/Assets/Scripts/ServerShared/Ship.cs index 00e77b4f3..e5759f4cc 100644 --- a/Assets/Scripts/ServerShared/Ship.cs +++ b/Assets/Scripts/ServerShared/Ship.cs @@ -85,8 +85,10 @@ public class Ship : Entity #region ThrustCalculation // What this ship can do at this instant (see ManoeuvreEnvelope): the box extremes of the thrusters' columns at their - // live, granted thrust (zero when unpowered or not Active), the same columns the allocator solves with. Derived each - // update, never saved. + // live thrust (zero when unpowered or not Active), because it reports what the ship can do now. The allocator solves + // with Column(NominalThrust), the full-grant column, because a column promises what a thruster does at a full grant + // and the allocator must not reshape its answer as the grant moves. Same geometry (Thruster.Column), different thrust. + // Derived each update, never saved. public ManoeuvreEnvelope Envelope { get; private set; } private void RecalculateEnvelope() diff --git a/tests/Aetheria.Shared.Tests/EvasionTermTests.cs b/tests/Aetheria.Shared.Tests/EvasionTermTests.cs index cf70946c6..3b558a90e 100644 --- a/tests/Aetheria.Shared.Tests/EvasionTermTests.cs +++ b/tests/Aetheria.Shared.Tests/EvasionTermTests.cs @@ -431,6 +431,37 @@ public sealed partial class RunStartTests Assert.True(djinni.Acceleration.x < -1f, "it still strafes left"); } + // Each side of the envelope is the sum of what every thruster pushing that way contributes, never the largest one: + // the Djinni has several thrusters on a side, so its Left and Right are the sums of the positive and negative + // x of its live columns (Thruster.Column at live thrust, the owner of that geometry). + [Fact] + public void EachSideOfTheEnvelopeSumsTheThrustersPushingThatWay() + { + var (_, _, djinni) = EvFleet(); + EvSettle(djinni); + foreach (var (move, look) in new[] { (float2(1, 0), float3(0, 0, 1)), (float2(-1, 0), float3(0, 0, 1)), (float2(0, 1), float3(0, 0, 1)), + (float2(0, -1), float3(0, 0, 1)) }) + { + djinni.MovementDirection = move; + for (var step = 0; step < 20; step++) + { + EvFace(djinni, look); + djinni.Update(EvDt); + } + } + EvSettle(djinni); + djinni.Update(EvDt); + var columns = djinni.GetBehaviors().Where(t => t.Item.Active.Value).Select(t => t.Column(t.Thrust)).ToList(); + var rightPushers = columns.Where(c => c.x > 0f).ToList(); + var leftPushers = columns.Where(c => c.x < 0f).ToList(); + Assert.True(rightPushers.Count >= 2 && leftPushers.Count >= 2, "fixture: each side has more than one thruster"); + var right = rightPushers.Sum(c => c.x); + var left = leftPushers.Sum(c => -c.x); + Assert.True(right > 1.2f * rightPushers.Max(c => c.x) && left > 1.2f * leftPushers.Max(c => -c.x), "fixture: the sum exceeds the largest column"); + Assert.InRange(djinni.Envelope.Right, right * .99f, right * 1.01f); + Assert.InRange(djinni.Envelope.Left, left * .99f, left * 1.01f); + } + // The reach and the evasion read each side of the envelope for themselves: a forward-only ship that turns clockwise // fast and counter-clockwise slowly reaches further to its right than its left in the window, and its evasion // across a line of sight is the average of what it reaches to either side, capped by the spread it is observed to