Cut 6c: fix remote pod stepping, Sion PVS ghost pods, Wave 1/2 respawn sync, alley/roof surface guards, and petal impulse

This commit is contained in:
Meta Vens 2026-12-05 12:11:51 +01:00
commit 43da8fdf81
8 changed files with 969 additions and 132 deletions

View file

@ -554,6 +554,382 @@ namespace RustToDust.Tests
_output.WriteLine($"Network orbital drop: maxUdpBytes={maxUdpBytes}B (cap {SnapshotCodec.MaxLatestDatagramBytes}B), packets={latestPacketsSeen}, podEvents={simEvents.OfType<DropPodEvent>().Count()}");
}
[Fact]
public void RemoteArenaSession_Wave0Pods_AdvanceSmoothlyAndZeroGhostPodsAfterTouchdown()
{
using var host = new ServerMatchHost(IPAddress.Loopback, 0, seed: 42, ArenaMapKind.Sion, maxHumans: 12, autoRestartSec: 0);
var ep = new IPEndPoint(IPAddress.Loopback, host.BoundPort);
using var client = new RemoteArenaSession(ep, "SionDropPilot");
IClientArenaSession clientIface = client;
long nowMs = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
var deadline = DateTimeOffset.UtcNow.AddSeconds(4);
while (DateTimeOffset.UtcNow < deadline && !client.IsJoined)
{
nowMs += 16;
host.StepOnce(nowMs);
client.PumpNetwork(nowMs);
Thread.Sleep(2);
}
Assert.True(client.IsJoined);
Assert.True(clientIface.LocalContender.IsInDropPod);
var initialLocalPod = clientIface.ActivePods.FirstOrDefault(
p => p.PodKind == OrbitalPodKind.Contender && p.ContenderId == clientIface.LocalContenderId);
var initialGearPod = clientIface.ActivePods.FirstOrDefault(p => p.PodKind != OrbitalPodKind.Contender);
Assert.NotNull(initialLocalPod);
Assert.NotNull(initialGearPod);
float localY0 = initialLocalPod!.Y;
float localAgl0 = initialLocalPod.LastAgl;
int trackedGearId = initialGearPod!.PodId;
float gearY0 = initialGearPod.Y;
float gearAgl0 = initialGearPod.LastAgl;
Assert.True(localAgl0 > 50f, $"Expected initialized local LastAgl > 50m, got {localAgl0:F2}");
Assert.True(gearAgl0 > 50f, $"Expected initialized gear LastAgl > 50m, got {gearAgl0:F2}");
// Step 60 ticks (1.0s) and verify BOTH local pod and replicated gear pods descend smoothly and update LastAgl
for (int t = 0; t < 60; t++)
{
nowMs += 16;
clientIface.SubmitLocalInput(new PlayerInput(
Throttle: 0.4f,
Steer: 0f,
AimWorldX: clientIface.LocalContender.X,
AimWorldZ: clientIface.LocalContender.Z + 50f,
Fire: false,
InteractPickup: false,
Brake: false), isPhysicsTick: true);
host.StepOnce(nowMs);
client.PumpNetwork(nowMs);
clientIface.BeginRenderFrame(ArenaSession.FixedDt, 1.0f);
}
var midLocalPod = clientIface.ActivePods.FirstOrDefault(
p => p.PodKind == OrbitalPodKind.Contender && p.ContenderId == clientIface.LocalContenderId);
var midGearPod = clientIface.ActivePods.FirstOrDefault(p => p.PodId == trackedGearId);
Assert.NotNull(midLocalPod);
Assert.NotNull(midGearPod);
Assert.True(midLocalPod!.Y < localY0 - 15f, $"Local pod froze on client: {localY0:F2} -> {midLocalPod.Y:F2}");
Assert.True(midLocalPod.LastAgl < localAgl0 - 15f && midLocalPod.LastAgl > 0f,
$"Local pod LastAgl failed to update: {localAgl0:F2} -> {midLocalPod.LastAgl:F2}");
Assert.True(midGearPod!.Y < gearY0 - 20f, $"Gear pod froze on client: {gearY0:F2} -> {midGearPod.Y:F2}");
Assert.True(midGearPod.LastAgl < gearAgl0 - 20f && midGearPod.LastAgl > 0f,
$"Gear pod LastAgl failed to update: {gearAgl0:F2} -> {midGearPod.LastAgl:F2}");
// Step through remainder of Wave 0 + 30 settle ticks so all pods touch down across Sion PVS
var simEvents = new List<ISimEvent>();
for (int t = 0; t < 560; t++)
{
nowMs += 16;
clientIface.SubmitLocalInput(new PlayerInput(
Throttle: 0f,
Steer: 0f,
AimWorldX: clientIface.LocalContender.X,
AimWorldZ: clientIface.LocalContender.Z + 50f,
Fire: false,
InteractPickup: false,
Brake: false), isPhysicsTick: true);
host.StepOnce(nowMs);
client.PumpNetwork(nowMs);
clientIface.BeginRenderFrame(ArenaSession.FixedDt, 1.0f);
clientIface.DrainSimEvents(simEvents);
}
Assert.True(clientIface.LocalContender.IsGroundedActive,
$"Expected LocalContender grounded after Wave 0, lifecycle={clientIface.LocalContender.Lifecycle}");
Assert.Empty(host.Session.State.OrbitalDrop.ActivePods);
Assert.Empty(clientIface.ActivePods);
_output.WriteLine($"Sion net Wave 0: local {localY0:F1}->{midLocalPod.Y:F1}, gear {gearY0:F1}->{midGearPod.Y:F1}, final ActivePods={clientIface.ActivePods.Count}");
}
[Fact]
public void RemoteArenaSession_Wave1Respawn_ReplicatesResetJackalChassisToLocalClient()
{
using var host = new ServerMatchHost(IPAddress.Loopback, 0, seed: 42, ArenaMapKind.Desert, maxHumans: 12, autoRestartSec: 0);
var ep = new IPEndPoint(IPAddress.Loopback, host.BoundPort);
using var client = new RemoteArenaSession(ep, "RespawnPilot");
IClientArenaSession clientIface = client;
long nowMs = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
var deadline = DateTimeOffset.UtcNow.AddSeconds(4);
while (DateTimeOffset.UtcNow < deadline && !client.IsJoined)
{
nowMs += 16;
host.StepOnce(nowMs);
client.PumpNetwork(nowMs);
Thread.Sleep(2);
}
Assert.True(client.IsJoined);
int localId = clientIface.LocalContenderId;
void PumpStep(int ticks)
{
var evs = new List<ISimEvent>();
for (int t = 0; t < ticks; t++)
{
nowMs += 16;
clientIface.SubmitLocalInput(new PlayerInput(
Throttle: 0f,
Steer: 0f,
AimWorldX: clientIface.LocalContender.X,
AimWorldZ: clientIface.LocalContender.Z + 50f,
Fire: false,
InteractPickup: false,
Brake: false), isPhysicsTick: true);
host.StepOnce(nowMs);
client.PumpNetwork(nowMs);
clientIface.BeginRenderFrame(ArenaSession.FixedDt, 1.0f);
clientIface.DrainSimEvents(evs);
}
}
// 1. Land Wave 0
for (int i = 0; i < 480 && !clientIface.LocalContender.IsGroundedActive; i++)
{
PumpStep(1);
}
Assert.True(clientIface.LocalContender.IsGroundedActive);
// 2. Swap local player to Paladin on server and replicate to client
var serverLocal = host.Session.State.Contenders[localId];
host.Session.State.SpawnChassisDrop(serverLocal.X, serverLocal.Z, Catalog.Paladin);
Assert.True(host.Session.TrySwapNearbyChassis(localId));
PumpStep(12);
Assert.Equal(Catalog.Paladin.Id, clientIface.LocalContender.Grid.Spec.Id);
// 3. Eliminate local player -> WaitingForRespawnWave
host.Session.ForceEliminateContender(localId);
PumpStep(12);
Assert.Equal(ContenderLifecycle.WaitingForRespawnWave, clientIface.LocalContender.Lifecycle);
// 4. Advance past Wave 1 (75.0s) -> server resets local player to Jackal (256/256) and launches Wave 1 pod
host.Session.State.Time = 74.85f;
PumpStep(30);
Assert.Equal(ContenderLifecycle.Deploying, clientIface.LocalContender.Lifecycle);
Assert.Equal(Catalog.Jackal.Id, clientIface.LocalContender.Grid.Spec.Id);
Assert.Equal(256f, clientIface.LocalContender.Grid.MaxCoreHp);
Assert.Equal(256f, clientIface.LocalContender.Grid.CoreHp);
_output.WriteLine($"Wave 1 respawn replicated: chassis={clientIface.LocalContender.Grid.Spec.Id}, core={clientIface.LocalContender.Grid.CoreHp}/{clientIface.LocalContender.Grid.MaxCoreHp}");
}
[Fact]
public void SionQueryDropSurface_1mOutsideBuildingWall_DoesNotReturnPhantomRoofAbovePod()
{
using var session = new ArenaSession(seed: 42, ArenaMapKind.Sion, slot0Human: true);
var sion = session.State.SionMap!;
var alleySpots = new List<(SionBuildingAabb Bldg, float X, float Z)>();
for (int i = 0; i < sion.Buildings.Count && alleySpots.Count < 10; i++)
{
var b = sion.Buildings[i];
if ((b.RoofY - b.GroundY) < 8f || MathF.Abs(b.CenterX) > 1000f || MathF.Abs(b.CenterZ) > 1000f)
{
continue;
}
float px = b.CenterX;
float pz = b.CenterZ - b.HalfZ - 1.0f;
if (!sion.IsInsideAnyBuildingXz(px, pz, 0f))
{
alleySpots.Add((b, px, pz));
}
}
Assert.Equal(10, alleySpots.Count);
for (int i = 0; i < alleySpots.Count; i++)
{
var (b, px, pz) = alleySpots[i];
float terrainY = session.State.Terrain.SampleHeight(px, pz);
float midWallY = terrainY + (b.RoofY - terrainY) * 0.5f;
var simSample = session.QueryDropSurface(px, pz, OrbitalPodPreset.Contender.PodFootRadius, midWallY + 1.0f);
var coreSample = session.State.DefaultDropSurfaceQuery(px, pz, OrbitalPodPreset.Contender.PodFootRadius, midWallY + 1.0f);
Assert.False(simSample.IsBuildingRoof, $"Point {i} 1.0m outside {b.Id} returned IsBuildingRoof=true!");
Assert.True(simSample.SurfaceY <= midWallY,
$"Point {i} 1.0m outside {b.Id}: QueryDropSurface returned phantom SurfaceY={simSample.SurfaceY:F2} > midWallY={midWallY:F2} (roof={b.RoofY:F2})");
Assert.False(coreSample.IsBuildingRoof);
Assert.True(coreSample.SurfaceY <= midWallY,
$"Point {i} 1.0m outside {b.Id}: DefaultDropSurfaceQuery returned phantom SurfaceY={coreSample.SurfaceY:F2} > midWallY={midWallY:F2}");
// Verify a descending pod 1.0m outside the wall does NOT mid-air instant-pop at 33.67 m/s
var pod = new OrbitalPod
{
PodId = 9000 + i,
PodKind = OrbitalPodKind.Contender,
Phase = OrbitalPodPhase.Freefall,
X = px,
Y = midWallY + 18f,
Z = pz,
VelY = -33.67f,
AllowFlatRoofLanding = true
};
bool touched = false;
for (int t = 0; t < 360; t++)
{
if (OrbitalDropKinematics.StepPod(
pod,
ArenaSession.FixedDt,
session.State.Terrain,
session.QueryDropSurface,
session.State.FindClearDropPoint,
out _,
out _))
{
touched = true;
break;
}
}
Assert.True(touched, $"Pod {i} outside {b.Id} failed to land");
float finalTerrain = session.State.Terrain.SampleHeight(pod.X, pod.Z);
Assert.True(pod.Y <= finalTerrain + 0.5f,
$"Pod {i} outside {b.Id} popped in mid-air at Y={pod.Y:F2} vs terrain={finalTerrain:F2}");
Assert.InRange(pod.TouchdownSpeed, 0.5f, 2.99f);
}
}
[Fact]
public void SionRoofEdgeAndSteppedRoof_HorizontalSteering_AlwaysLandsUnder3MsWithoutWarp()
{
using var session = new ArenaSession(seed: 42, ArenaMapKind.Sion, slot0Human: true);
var sion = session.State.SionMap!;
// 1. Test horizontal entry onto flat Sion roofs (including sion_0146, sion_0665) at 1..3m above roof edge during RetroBurn
var targetRoofs = new List<SionBuildingAabb>();
foreach (var targetId in new[] { "sion_0146", "sion_0665" })
{
var found = sion.Buildings.FirstOrDefault(b => b.Id == targetId);
Assert.Equal(targetId, found.Id);
targetRoofs.Add(found);
}
foreach (var b in targetRoofs)
{
// Find a clear approach side 1.0m outside the building AABB and sample actual roof height inside the edge
float probeInX = b.CenterX;
float probeInZ = b.CenterZ - b.HalfZ + 4.0f;
var roofSample = session.QueryDropSurface(probeInX, probeInZ, 1.65f, b.RoofY + 20f);
float edgeRoofY = roofSample.IsBuildingRoof ? roofSample.SurfaceY : b.RoofY;
float startX = b.CenterX;
float startZ = b.CenterZ - b.HalfZ - 0.8f;
if (sion.IsInsideAnyBuildingXz(startX, startZ, 0f)) continue;
foreach (float hAboveEdge in new[] { 1.0f, 2.0f, 3.0f })
{
foreach (float vyDown in new[] { 12f, 22f, 35f })
{
var pod = new OrbitalPod
{
PodId = 9100,
PodKind = OrbitalPodKind.Contender,
Phase = OrbitalPodPhase.RetroBurn,
AllowFlatRoofLanding = true,
X = startX,
Y = edgeRoofY + hAboveEdge,
Z = startZ,
VelX = 0f,
VelY = -vyDown,
VelZ = 18f
};
bool landed = false;
float maxStepDeltaY = 0f;
for (int t = 0; t < 360; t++)
{
float prevY = pod.Y;
bool touched = OrbitalDropKinematics.StepPod(
pod,
ArenaSession.FixedDt,
session.State.Terrain,
session.QueryDropSurface,
session.State.FindClearDropPoint,
out _,
out _);
maxStepDeltaY = MathF.Max(maxStepDeltaY, MathF.Abs(pod.Y - prevY));
if (touched)
{
landed = true;
break;
}
}
Assert.True(landed, $"Pod near {b.Id} (h={hAboveEdge}m, vy={vyDown}) failed to land");
Assert.InRange(pod.TouchdownSpeed, 0.5f, 2.99f);
Assert.True(maxStepDeltaY <= 2.0f,
$"Pod near {b.Id} (h={hAboveEdge}m, vy={vyDown}) warped vertically by {maxStepDeltaY:F2}m");
}
}
}
// 2. Test AllowFlatRoofLanding = false near stepped Old Town roofs -> never warps > 2m and always < 3.0 m/s
int steppedTested = 0;
for (int i = 0; i < sion.Buildings.Count && steppedTested < 12; i++)
{
var b = sion.Buildings[(i * 53) % sion.Buildings.Count];
if ((b.RoofY - b.GroundY) < 10f || MathF.Abs(b.CenterX) > 900f || MathF.Abs(b.CenterZ) > 900f)
{
continue;
}
float startX = b.CenterX;
float startZ = b.CenterZ - b.HalfZ - 1.2f;
if (sion.IsInsideAnyBuildingXz(startX, startZ, 0f)) continue;
foreach (float startOffset in new[] { 2.0f, 18.0f, 55.0f })
{
var pod = new OrbitalPod
{
PodId = 9200 + steppedTested,
PodKind = OrbitalPodKind.Contender,
Phase = startOffset < 10f ? OrbitalPodPhase.RetroBurn : OrbitalPodPhase.Freefall,
AllowFlatRoofLanding = false,
X = startX,
Y = b.RoofY + startOffset,
Z = startZ,
VelX = 0f,
VelY = -28f,
VelZ = 16f,
LookForwardX = 0f,
LookForwardZ = 1f,
SteerForwardCmd = 1f
};
bool landed = false;
float maxStepDeltaY = 0f;
for (int t = 0; t < 480; t++)
{
float prevY = pod.Y;
bool touched = OrbitalDropKinematics.StepPod(
pod,
ArenaSession.FixedDt,
session.State.Terrain,
session.QueryDropSurface,
session.State.FindClearDropPoint,
out _,
out var touchSample);
maxStepDeltaY = MathF.Max(maxStepDeltaY, MathF.Abs(pod.Y - prevY));
if (touched)
{
landed = true;
Assert.False(touchSample.IsBuildingRoof, $"AllowFlatRoofLanding=false pod landed on roof of {b.Id}");
Assert.False(sion.IsInsideAnyBuildingXz(pod.X, pod.Z, 0f), $"Pod landed inside {b.Id}");
break;
}
}
Assert.True(landed, $"AllowFlatRoofLanding=false pod near {b.Id} failed to land");
Assert.InRange(pod.TouchdownSpeed, 0.5f, 2.99f);
Assert.True(maxStepDeltaY <= 2.0f,
$"AllowFlatRoofLanding=false pod near {b.Id} (offset={startOffset}m) warped by {maxStepDeltaY:F2}m");
}
steppedTested++;
}
Assert.Equal(12, steppedTested);
}
private static void AssertZeroChassisPenetration(MatchState state, ContenderState c)
{
var spec = c.Grid.Spec;