Merge gravity-fog-precision-and-jitter

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-10-15 19:52:55 +02:00
commit 49e8ea58e1
13 changed files with 129 additions and 22 deletions

View file

@ -45,13 +45,13 @@ public sealed class FireControlTests : IDisposable
// `well` digs the zone one well at the origin (WellFixture), so heights differ across the zone.
private (ItemManager items, Ship ship, EquippedItem[] weapons) BuildShipWithHardpoints(
bool well, (ItemRotation rotation, float firingArc)[] hardpoints)
bool well, (ItemRotation rotation, float firingArc)[] hardpoints, float gridOffset = 0f)
{
var hullShape = new Shape(Math.Max(hardpoints.Length, 3), 3);
foreach (var cell in hullShape.AllCoordinates) hullShape[cell] = true;
// Mass defaults to 0 (ItemData.cs:285), which zeroes ThermalMass (Entity.cs MapEntity) and NaNs
// UpdateTemperature -- author a real mass so the entity's own temperature stays a real number.
var hullData = new HullData { Name = "TestHull", HullType = HullType.Ship, Shape = hullShape, Durability = 1, Mass = 1000 };
var hullData = new HullData { Name = "TestHull", HullType = HullType.Ship, Shape = hullShape, Durability = 1, Mass = 1000, GridOffset = gridOffset };
for (var i = 0; i < hardpoints.Length; i++)
hullData.Hardpoints.Add(new HardpointData
{
@ -380,6 +380,39 @@ public sealed class FireControlTests : IDisposable
// height, so its distance in space is longer than its planar distance. A claim whose Range lies between the two, full
// damage out to the planar distance, is in range on the plane and out of range in space: it (against Slug's 5) is the
// chosen claim. Mutation: Combat measures the three-dimensional distance (the claim then reads 0).
// B32: a ship drawn ahead rides the field at its drawn xz, not at the height of its last step (the per-step height
// staircase that read as jitter on a steep slope). Mutation: DrawAhead's y back to entity.Position.y fails the first
// assertion; reading the height at the last step's xz fails it too.
[Fact]
public void ADrawnShipRidesTheFieldAtItsDrawnPosition()
{
var (items, ship, _) = BuildShipWithHardpoints(true, new[] { (ItemRotation.None, 0f) }, gridOffset: 2.5f);
var zone = ship.Zone;
ship.Position = float3(200, 0, 0);
zone.Update(1f);
ship.Velocity = float2(100, 0); // up the slope, away from the well
const float lead = .1f;
var drawn = DrawAhead.Position(ship, lead);
Assert.Equal(ship.Position.x + 100 * lead, drawn.x, 4);
// The hull rides 2.5 u above the field (authored above): dropping or doubling the offset moves the ship by 2.5.
Assert.Equal(zone.GetHeight(float2(drawn.x, drawn.z)) + 2.5f, drawn.y, 4);
Assert.Equal(zone.GetHeight(float2(ship.Position.x, ship.Position.z)) + 2.5f, ship.Position.y, 4);
Assert.True(abs(drawn.y - ship.Position.y) > .1f, "the slope is real: the drawn height differs from the last step's");
var still = DrawAhead.Position(ship, 0f);
Assert.Equal(ship.Position.x, still.x);
Assert.Equal(ship.Position.y, still.y);
Assert.Equal(ship.Position.z, still.z);
// A child (a docked ship) is drawn where its parent is drawn, whatever its own pose and velocity.
var child = new Ship(items, zone, ship.Hull, new EntitySettings()) { Position = float3(-500, 7, 300), Velocity = float2(-30, 40), Parent = ship };
var carried = DrawAhead.Position(child, lead);
Assert.Equal(drawn.x, carried.x, 4);
Assert.Equal(drawn.y, carried.y, 4);
Assert.Equal(drawn.z, carried.z, 4);
}
[Fact]
public void TheAIMeasuresTheTargetOnTheGroundPlane()
{