Cut 5c-2: Godot IClientArenaSession cutover, F9 connect bar, and 2-client Sion verification

This commit is contained in:
Meta Vens 2026-12-05 08:52:40 +01:00
commit 8ab62655d5
9 changed files with 944 additions and 241 deletions

View file

@ -1,8 +1,11 @@
using System;
using System.Collections.Generic;
using System.Net;
using System.Threading.Tasks;
using Godot;
using RustToDust.Core;
using RustToDust.Net;
using RustToDust.Ymir;
namespace RustToDust.Client.Tests;
@ -40,7 +43,7 @@ public partial class Smoke : Node
if (_main.Failure is { } failure)
{
Check(false, "Main failed to initialize ArenaSession: " + failure);
Check(false, "Main failed to initialize IClientArenaSession: " + failure);
}
else
{
@ -62,7 +65,7 @@ public partial class Smoke : Node
Check(!_main.GetWorld3D().Space.IsValid, "Godot should have no active 3D physics space");
Check(_main.Terrain.BakedTileCount == 64, $"Expected 64 baked terrain tiles, got {_main.Terrain.BakedTileCount}");
var player = _main.Session.State.Contenders[0];
var player = _main.Session.ViewState.Contenders[0];
float startX = player.X;
float startZ = player.Z;
@ -98,7 +101,7 @@ public partial class Smoke : Node
bool isHeadless = DisplayServer.GetName() == "headless";
int rebakesBefore = _main.Terrain.DirtyRebakes;
float cpuBefore = _main.Session.State.Terrain.SampleHeight(-96f, -96f);
float cpuBefore = _main.Session.ViewState.Terrain.SampleHeight(-96f, -96f);
float gpuBefore = 0f;
if (!isHeadless)
{
@ -120,11 +123,11 @@ public partial class Smoke : Node
// Verify brushed terrain relief (tallest Mesa/DuneRidge center) so a flat-map bug can never pass
TerrainBrush? reliefBrush = null;
float bestHillCpu = 0f;
foreach (var b in _main.Session.State.Terrain.Brushes)
foreach (var b in _main.Session.ViewState.Terrain.Brushes)
{
if (b.Kind == TerrainBrushKind.Mesa || (b.Kind == TerrainBrushKind.DuneRidge && b.HeightDelta > 0f))
{
float h = _main.Session.State.Terrain.SampleHeight(b.X, b.Z);
float h = _main.Session.ViewState.Terrain.SampleHeight(b.X, b.Z);
if (h > bestHillCpu)
{
bestHillCpu = h;
@ -173,12 +176,12 @@ public partial class Smoke : Node
Check(maxSeamErr < 0.01f, $"Expected tile seam error < 0.01m, got {maxSeamErr:F5}m");
}
_main.Session.State.Terrain.StampCrater(-96f, -96f, radius: 5f, depth: 1.4f);
_main.Terrain.Sync(_main.Session.State.Terrain);
_main.Session.ViewState.Terrain.StampCrater(-96f, -96f, radius: 5f, depth: 1.4f);
_main.Terrain.Sync(_main.Session.ViewState.Terrain);
await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
float cpuAfter = _main.Session.State.Terrain.SampleHeight(-96f, -96f);
float cpuAfter = _main.Session.ViewState.Terrain.SampleHeight(-96f, -96f);
Check(cpuAfter < cpuBefore - 0.8f,
$"Expected CPU terrain height to drop after crater stamp (before {cpuBefore:F2}m, after {cpuAfter:F2}m)");
Check(_main.Terrain.DirtyRebakes == rebakesBefore + 1,
@ -203,9 +206,9 @@ public partial class Smoke : Node
// and passive Track throttling preserves DirtyTileMask until all tiles are baked without skipping via _rebakeCursor.
{
// Flush any lingering track rebakes first so baseline is clean
for (int flush = 0; flush < 32 && _main.Session.State.Terrain.DirtyTileMask != 0UL; flush++)
for (int flush = 0; flush < 32 && _main.Session.ViewState.Terrain.DirtyTileMask != 0UL; flush++)
{
_main.Terrain.Sync(_main.Session.State.Terrain);
_main.Terrain.Sync(_main.Session.ViewState.Terrain);
}
await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
@ -221,11 +224,11 @@ public partial class Smoke : Node
}
int rebakes4Before = _main.Terrain.DirtyRebakes;
_main.Session.State.Terrain.StampCrater(0f, 0f, radius: 6f, depth: 1.4f);
_main.Terrain.Sync(_main.Session.State.Terrain); // Sync#1
_main.Session.ViewState.Terrain.StampCrater(0f, 0f, radius: 6f, depth: 1.4f);
_main.Terrain.Sync(_main.Session.ViewState.Terrain); // Sync#1
Check(_main.Terrain.DirtyRebakes == rebakes4Before + 4,
$"Expected 4-tile boundary crater at (0,0) to bake all 4 tiles on Sync#1, got {_main.Terrain.DirtyRebakes - rebakes4Before}");
Check(_main.Session.State.Terrain.StructuralDirtyTileMask == 0UL,
Check(_main.Session.ViewState.Terrain.StructuralDirtyTileMask == 0UL,
"Expected StructuralDirtyTileMask == 0 after Sync#1 on 4-tile boundary crater");
await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
@ -235,7 +238,7 @@ public partial class Smoke : Node
{
for (int q = 0; q < 4; q++)
{
float qCpu = _main.Session.State.Terrain.SampleHeight(quadrants[q].Qx, quadrants[q].Qz);
float qCpu = _main.Session.ViewState.Terrain.SampleHeight(quadrants[q].Qx, quadrants[q].Qz);
bool ok = _main.Terrain.TrySampleBakedHeight(quadrants[q].Qx, quadrants[q].Qz, out float qGpu);
Check(ok, $"Expected GPU readback on quadrant {q} after 4-tile boundary crater");
if (ok)
@ -250,18 +253,18 @@ public partial class Smoke : Node
// Stamp 3 passive tracks in adjacent tiles so _rebakeCursor must advance across Sync#1 and Sync#2 without skipping
int rebakesTrackBefore = _main.Terrain.DirtyRebakes;
_main.Session.State.Terrain.StampTrack(-480f, -480f, 0f, 2f, 3f);
_main.Session.State.Terrain.StampTrack(-288f, -480f, 0f, 2f, 3f);
_main.Session.State.Terrain.StampTrack(-96f, -480f, 0f, 2f, 3f);
_main.Terrain.Sync(_main.Session.State.Terrain);
_main.Session.ViewState.Terrain.StampTrack(-480f, -480f, 0f, 2f, 3f);
_main.Session.ViewState.Terrain.StampTrack(-288f, -480f, 0f, 2f, 3f);
_main.Session.ViewState.Terrain.StampTrack(-96f, -480f, 0f, 2f, 3f);
_main.Terrain.Sync(_main.Session.ViewState.Terrain);
Check(_main.Terrain.DirtyRebakes == rebakesTrackBefore + 2,
$"Expected Sync#1 to throttle 3 passive tracks to 2 rebakes, got {_main.Terrain.DirtyRebakes - rebakesTrackBefore}");
Check(_main.Session.State.Terrain.DirtyTileMask != 0UL,
Check(_main.Session.ViewState.Terrain.DirtyTileMask != 0UL,
"Expected DirtyTileMask to stay non-zero while 1 passive track tile remains dirty");
_main.Terrain.Sync(_main.Session.State.Terrain);
_main.Terrain.Sync(_main.Session.ViewState.Terrain);
Check(_main.Terrain.DirtyRebakes == rebakesTrackBefore + 3,
$"Expected Sync#2 to bake remaining 3rd passive track tile without _rebakeCursor skip, got {_main.Terrain.DirtyRebakes - rebakesTrackBefore}");
Check(_main.Session.State.Terrain.DirtyTileMask == 0UL,
Check(_main.Session.ViewState.Terrain.DirtyTileMask == 0UL,
"Expected DirtyTileMask == 0 after all passive track tiles baked");
}
@ -287,7 +290,7 @@ public partial class Smoke : Node
Check(mat.Shader is not null && !string.IsNullOrWhiteSpace(mat.Shader.Code),
$"panel_chrome.gdshader failed to load on HUD panel #{chromeCount}");
}
Check(chromeCount == 5, $"Expected 5 ChromePanel materials on HUD, got {chromeCount}");
Check(chromeCount == 6, $"Expected 6 ChromePanel materials on HUD, got {chromeCount}");
// Pack a real Ironclad chassis with mounted modules, thermal gradient, stripped cell, and active hit-pulse
var testGrid = new ChassisGrid(Catalog.Ironclad);
@ -371,6 +374,12 @@ public partial class Smoke : Node
Check(!_main.Hud.HasPanelOverlapOrClip(vpSize), $"Garage HUD panels overlapped or clipped at {vpSize}");
_main.Hud.ToggleGarage();
await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
_main.Hud.ToggleNetworkPanel();
_main.Hud.Sync(_main.Session);
await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
Check(!_main.Hud.HasPanelOverlapOrClip(vpSize), $"F9 Network HUD panel overlapped or clipped at {vpSize}");
_main.Hud.ToggleNetworkPanel();
await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
if (isHeadless)
{
@ -580,7 +589,7 @@ public partial class Smoke : Node
}
// Seed realistic combat telemetry so the preview clearly showcases armor stripping, hit-flash, cargo rack, and thermal heat
var player = _main.Session.State.Contenders[0];
var player = _main.Session.ViewState.Contenders[0];
var grid = player.Grid;
grid.TryAddCargo(Catalog.TouringPlasma);
grid.TryAddCargo(Catalog.GoldRadiator);
@ -594,17 +603,17 @@ public partial class Smoke : Node
float fwdZ = MathF.Cos(_main.CameraYaw);
float rightX = -fwdZ;
float rightZ = fwdX;
if (_main.Session.State.Contenders.Count > 2)
if (_main.Session is LocalArenaSession localPreview && localPreview.Inner.State.Contenders.Count > 2)
{
var r1 = _main.Session.State.Contenders[1];
var r1 = localPreview.Inner.State.Contenders[1];
if (r1.Alive)
{
_main.Session.SetContenderPose(r1.Id, player.X + fwdX * 19f - rightX * 5.5f, player.Z + fwdZ * 19f - rightZ * 5.5f, _main.CameraYaw + MathF.PI * 0.82f);
localPreview.Inner.SetContenderPose(r1.Id, player.X + fwdX * 19f - rightX * 5.5f, player.Z + fwdZ * 19f - rightZ * 5.5f, _main.CameraYaw + MathF.PI * 0.82f);
}
var r2 = _main.Session.State.Contenders[2];
var r2 = localPreview.Inner.State.Contenders[2];
if (r2.Alive)
{
_main.Session.SetContenderPose(r2.Id, player.X + fwdX * 26f + rightX * 8.5f, player.Z + fwdZ * 26f + rightZ * 8.5f, _main.CameraYaw - MathF.PI * 0.72f);
localPreview.Inner.SetContenderPose(r2.Id, player.X + fwdX * 26f + rightX * 8.5f, player.Z + fwdZ * 26f + rightZ * 8.5f, _main.CameraYaw - MathF.PI * 0.72f);
}
}
@ -807,7 +816,7 @@ public partial class Smoke : Node
{
for (int s = 0; s < 25; s++)
{
debris.Step(1f / 60f, _main.Session.State.Terrain);
debris.Step(1f / 60f, _main.Session.ViewState.Terrain);
}
debris.TryGetPiecePosition(0, out Vector3 p1);
float moved = p1.DistanceTo(p0);
@ -853,7 +862,7 @@ public partial class Smoke : Node
// 5. All 15 ChassisDrop salvage wrecks ground within 0.05m of terrain & PickedUp frees drops cleanly
{
var drops = _main.Session.State.GroundDrops;
var drops = _main.Session.ViewState.GroundDrops;
int baseCount = drops.Count;
_main.Arena.Sync(_main.Session, 1.0f, 1f / 60f);
int trackedBefore = _main.Arena.ActiveDropVisualCount;
@ -884,7 +893,7 @@ public partial class Smoke : Node
{
dropVis.SetLodState(useStaticLod: false, castShadows: false);
float minWorldY = dropVis.ComputeMinVertexY();
float terrainY = _main.Session.State.Terrain.SampleHeight(d.X, d.Z);
float terrainY = _main.Session.ViewState.Terrain.SampleHeight(d.X, d.Z);
float err = MathF.Abs(minWorldY - terrainY);
if (err > maxGroundErr) maxGroundErr = err;
Check(err <= 0.05f,
@ -902,7 +911,7 @@ public partial class Smoke : Node
{
dropVis.SetLodState(useStaticLod: true, castShadows: false);
float minFarWorldY = dropVis.ComputeMinVertexY();
float terrainY = _main.Session.State.Terrain.SampleHeight(d.X, d.Z);
float terrainY = _main.Session.ViewState.Terrain.SampleHeight(d.X, d.Z);
float err = MathF.Abs(minFarWorldY - terrainY);
if (err > maxFarGroundErr) maxFarGroundErr = err;
Check(err <= 0.05f,
@ -923,9 +932,11 @@ public partial class Smoke : Node
drops.RemoveRange(baseCount, added.Count);
}
// 6. All 7 walkers (including Kestrel) walk through real ArenaSession + Hybrid B FK snapshot cleanly
// 6. All 7 walkers (including Kestrel) walk through IClientArenaSession (LocalArenaSession) + Hybrid B FK snapshot cleanly
{
using var walkSession = new RustToDust.Ymir.ArenaSession(seed: 42, mapKind: ArenaMapKind.Desert, slot0Human: true);
using var localWalk = new LocalArenaSession(seed: 42, mapKind: ArenaMapKind.Desert);
IClientArenaSession walkIface = localWalk;
var walkSession = localWalk.Inner;
for (int cIdx = 1; cIdx < walkSession.State.Contenders.Count; cIdx++)
{
walkSession.SetContenderPose(cIdx, 450f + cIdx * 18f, 450f);
@ -946,9 +957,9 @@ public partial class Smoke : Node
{
var wSpec = Catalog.ChassisById[wId];
walkSession.SetContenderPose(0, 0f, 0f, 0f);
if (walkSession.State.Contenders[0].Grid.Spec.Id != wId)
if (walkIface.LocalContender.Grid.Spec.Id != wId)
{
walkSession.State.SpawnChassisDrop(0f, 0f, wSpec);
walkIface.ViewState.SpawnChassisDrop(0f, 0f, wSpec);
Check(walkSession.TrySwapNearbyChassis(0), $"Failed to swap walkSession player to '{wId}'");
}
@ -961,24 +972,23 @@ public partial class Smoke : Node
Check(footNode is not null && pelvisNode is not null,
$"Missing FK nodes '{footNodeName}'/'{pelvisNodeName}' on walker '{wId}'");
var player = walkSession.State.Contenders[0];
var player = walkIface.LocalContender;
for (int step = 0; step < 60; step++)
{
walkSession.SetHumanInput(0, new PlayerInput(
walkIface.SubmitLocalInput(new PlayerInput(
Throttle: 1f,
Steer: 0f,
AimWorldX: player.X,
AimWorldZ: player.Z + 50f,
Fire: false,
InteractPickup: false,
Brake: false));
walkSession.Step();
Brake: false), isPhysicsTick: true);
bool hasSnap = walkSession.TrySampleInterpolatedWalkerPose(true, player.Id, 1f, out var walkerSnap);
bool hasSnap = walkIface.TrySampleInterpolatedWalkerPose(true, player.Id, 1f, out var walkerSnap);
Check(hasSnap, $"Missing WalkerVisualSnapshot for '{wId}' at step {step}");
if (!hasSnap) break;
var (interpPos, interpRot, interpVel) = walkSession.GetInterpolatedContenderPose(player.Id, 1f);
var (interpPos, interpRot, interpVel) = walkIface.GetInterpolatedContenderPose(player.Id, 1f);
var q = new Quaternion(interpRot.X, interpRot.Y, interpRot.Z, interpRot.W);
vis.Root.Transform = new Transform3D(new Basis(q), new Vector3(interpPos.X, interpPos.Y, interpPos.Z));
VehicleRigAnimator.Update(
@ -1002,7 +1012,7 @@ public partial class Smoke : Node
Vector3 fInModel = TransformPointToAncestor(footNode, vis.ModelRoot, Vector3.Zero);
Vector3 fWorld = vis.Root.Transform * (vis.ModelRoot.Transform * fInModel);
float groundUnderFoot = walkSession.State.Terrain.SampleHeight(fWorld.X, fWorld.Z);
float groundUnderFoot = walkIface.ViewState.Terrain.SampleHeight(fWorld.X, fWorld.Z);
float relMinY = curMinWorldY - groundUnderFoot;
if (relMinY < worstRelMinY) worstRelMinY = relMinY;
}
@ -1066,7 +1076,7 @@ public partial class Smoke : Node
{
_main.Arena.Sync(_main.Session, 1.5f, 1f / 60f);
bool sawPatron = false;
foreach (var s in _main.Session.State.Spectators.Spectators)
foreach (var s in _main.Session.ViewState.Spectators.Spectators)
{
if (!s.Alive) continue;
var vis = _main.Arena.GetSpectatorVisual(s.Id);
@ -1133,8 +1143,9 @@ public partial class Smoke : Node
// 10. MultiMeshPartPool & PomDecalPool sanity: live arena submits into MultiMeshPartPool and PomDecalPool stamps impacts cleanly
{
var localC = _main.Session.LocalContender;
_main.Arena.PomDecals.StampTestDecal(
new Vector3(_main.Session.State.Contenders[0].X + 2f, _main.Session.State.Terrain.SampleHeight(_main.Session.State.Contenders[0].X + 2f, _main.Session.State.Contenders[0].Z) + 0.03f, _main.Session.State.Contenders[0].Z),
new Vector3(localC.X + 2f, _main.Session.ViewState.Terrain.SampleHeight(localC.X + 2f, localC.Z) + 0.03f, localC.Z),
Vector3.Up, 1.2f, tileIndex: 14);
_main.Arena.Sync(_main.Session, 1.6f, 1f / 60f);
Check(_main.Arena.PartPool.TotalSubmittedInstances > 0,
@ -1142,7 +1153,7 @@ public partial class Smoke : Node
Check(_main.Arena.PomDecals.ActiveCount >= 1,
$"Expected PomDecalPool to hold >= 1 active decal, got {_main.Arena.PomDecals.ActiveCount}");
_main.Hud.PushTestHitArc(_main.Session.State.Contenders[0].X + 20f, _main.Session.State.Contenders[0].Z + 10f, WeaponVisualClass.Explosive);
_main.Hud.PushTestHitArc(localC.X + 20f, localC.Z + 10f, WeaponVisualClass.Explosive);
Check(_main.Hud.ActiveHitArcCount >= 1, "Expected CrosshairOverlay to accept incoming hit arc");
}
@ -1218,13 +1229,14 @@ public partial class Smoke : Node
// 12. Finding 2: Monotonic TracerEvent.Id spawns muzzle flash + recoilless smoke puffs ONCE regardless of TTL or FPS
{
var tracers = _main.Session.State.Tracers;
var tracers = _main.Session.ViewState.Tracers;
tracers.Clear();
_main.Arena.Sync(_main.Session, 1.69f, 0f);
int vfxBefore = _main.Arena.TransientVfxCount;
int tracerId = _main.Session.State.AllocateTracerId();
Vector3 pPos = new(_main.Session.State.Contenders[0].X, _main.Session.State.Contenders[0].Y, _main.Session.State.Contenders[0].Z);
int tracerId = _main.Session.ViewState.AllocateTracerId();
var localC = _main.Session.LocalContender;
Vector3 pPos = new(localC.X, localC.Y, localC.Z);
tracers.Add(new TracerEvent(
pPos.X, pPos.Y + 1f, pPos.Z,
pPos.X + 20f, pPos.Y + 1f, pPos.Z,
@ -1247,6 +1259,30 @@ public partial class Smoke : Node
tracers.Clear();
}
// 13. Loopback IClientArenaSession check: ServerMatchHost + RemoteArenaSession join + snapshot sync
{
using var host = new ServerMatchHost(IPAddress.Loopback, port: 0, seed: 42, mapKind: ArenaMapKind.Desert);
using var remote = new RemoteArenaSession(new IPEndPoint(IPAddress.Loopback, host.BoundPort), "SmokeClient");
IClientArenaSession remoteIface = remote;
long nowMs = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
for (int t = 0; t < 15 && !remote.IsJoined; t++)
{
host.StepOnce(nowMs + t * 16);
remoteIface.BeginRenderFrame(1.0 / 60.0, 1.0f);
}
Check(remote.IsJoined && remoteIface.ConnectionStatus.Connected,
$"Expected RemoteArenaSession loopback connect inside Smoke, label='{remoteIface.ConnectionStatus.StateLabel}'");
for (int t = 0; t < 6; t++)
{
remoteIface.SubmitLocalInput(new PlayerInput(0.5f, 0f, 10f, 10f, false, false, false), isPhysicsTick: true);
host.StepOnce(nowMs + 300 + t * 16);
remoteIface.BeginRenderFrame(1.0 / 60.0, 1.0f);
}
Check(remote.LastSnapshotSeq > 0, $"Expected loopback RemoteArenaSession to receive snapshots, got seq={remote.LastSnapshotSeq}");
Check(remoteIface.LocalContender.Alive, "Expected loopback RemoteArenaSession LocalContender alive");
}
await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
}
@ -1401,7 +1437,7 @@ public partial class Smoke : Node
private async Task VerifyMaxLoadPaladinGarageAsync()
{
var grid = _main.Session.State.Contenders[0].Grid;
var grid = _main.Session.LocalContender.Grid;
grid.SwapChassis(Catalog.Paladin);
Check(grid.TryMount(Catalog.TouringPlasma, "hp.weapon.sh_l"), "Expected TouringPlasma on Paladin hp.weapon.sh_l");
Check(grid.TryMount(Catalog.WeldedPlate, "hp.armor.torso"), "Expected WeldedPlate on Paladin hp.armor.torso");
@ -1459,7 +1495,7 @@ public partial class Smoke : Node
await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
var sionState = _main.Session.State;
var sionState = _main.Session.ViewState;
Check(_main.MapKind == ArenaMapKind.Sion && sionState.MapKind == ArenaMapKind.Sion, "Expected Sion map kind after Reset");
Check(_main.SionMap.Visible && !_main.Terrain.Visible, "Expected SionMapRenderer visible and Desert TerrainRenderer hidden");
Check(_main.SionMap.IsBuilt, "Expected SionMapRenderer.IsBuilt == true");