From 067fc1c1c73d56f2ee64dbd03125a5c19100b2de Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sat, 5 Dec 2026 12:28:35 +0100 Subject: [PATCH] Cut 6 Soul Pass #2 fixes: wall breach block, slopeRiseRate clamp, mid-drop PVS pod sync --- src/RustToDust.Core/OrbitalDropSystem.cs | 103 ++++++++++- src/RustToDust.Net/RemoteArenaSession.cs | 74 +++++--- src/RustToDust.Net/ServerMatchHost.cs | 50 +++++ tests/RustToDust.Tests/OrbitalDropTests.cs | 201 +++++++++++++++++++++ 4 files changed, 398 insertions(+), 30 deletions(-) diff --git a/src/RustToDust.Core/OrbitalDropSystem.cs b/src/RustToDust.Core/OrbitalDropSystem.cs index 8c5a721..9fac090 100644 --- a/src/RustToDust.Core/OrbitalDropSystem.cs +++ b/src/RustToDust.Core/OrbitalDropSystem.cs @@ -336,7 +336,9 @@ namespace RustToDust.Core float surfSlopeRise = (sampleNow.IsBuildingRoof && sampleNext.IsBuildingRoof && MathF.Abs(surfaceNext - surfaceNow) <= 1.0f) ? MathF.Max(0f, (surfaceNext - surfaceNow) / dt) : 0f; - float slopeRiseRate = MathF.Max(MathF.Max(0f, (terrainNext - terrainNow) / dt), surfSlopeRise); + float horizSpeed = MathF.Sqrt(pod.VelX * pod.VelX + pod.VelZ * pod.VelZ); + float maxPhysicalRise = MathF.Min(32f, MathF.Max(4.0f, horizSpeed * 1.15f)); + float slopeRiseRate = MathF.Min(maxPhysicalRise, MathF.Max(MathF.Max(0f, (terrainNext - terrainNow) / dt), surfSlopeRise)); float vClose = vDown + slopeRiseRate; float hBurn = MathF.Max( 8.0f, @@ -474,6 +476,13 @@ namespace RustToDust.Core return true; } + if (!sampleNow.IsInsideBuildingFootprint && + sampleNext.IsInsideBuildingFootprint && + (!sampleNext.IsBuildingRoof || !pod.AllowFlatRoofLanding)) + { + return true; + } + if (!pod.AllowFlatRoofLanding && sampleNext.IsBuildingRoof && (!sampleNow.IsBuildingRoof || sampleNext.SurfaceY > surfaceNow + 0.25f)) @@ -1317,6 +1326,72 @@ namespace RustToDust.Core return null; } + private OrbitalPod? FindContenderPod(int contenderId) + { + for (int i = 0; i < _activePods.Count; i++) + { + if (_activePods[i].PodKind == OrbitalPodKind.Contender && _activePods[i].ContenderId == contenderId) + { + return _activePods[i]; + } + } + return null; + } + + public OrbitalPod SynthesizeReplicatedContenderPod( + int contenderId, + float x, + float y, + float z, + float velX, + float velY, + float velZ, + Quaternion rot, + float yaw, + OrbitalPodPhase phase, + float lastAgl) + { + var existing = FindContenderPod(contenderId); + if (existing is not null) + { + return existing; + } + + int podId = _nextPodId++; + var pod = new OrbitalPod + { + PodId = podId, + PodKind = OrbitalPodKind.Contender, + Phase = phase, + WaveIndex = _currentWaveIndex, + ContenderId = contenderId, + AllowFlatRoofLanding = false, + TargetX = x, + TargetZ = z, + X = x, + Y = y, + Z = z, + VelX = velX, + VelY = velY, + VelZ = velZ, + Yaw = yaw, + CurrRotX = rot.X, + CurrRotY = rot.Y, + CurrRotZ = rot.Z, + CurrRotW = rot.W, + LookForwardX = MathF.Sin(yaw), + LookForwardZ = MathF.Cos(yaw), + LastAgl = lastAgl + }; + pod.SnapPreviousPose(); + _activePods.Add(pod); + if (contenderId >= 0 && contenderId < _state.Contenders.Count) + { + _state.Contenders[contenderId].ActivePodId = podId; + } + return pod; + } + private void EmitLifecycleEvent( DropPodEventKind kind, int waveIndex, @@ -1450,6 +1525,19 @@ namespace RustToDust.Core var q = Quaternion.CreateFromAxisAngle(Vector3.UnitY, yaw); var existing = FindPodById(ev.PodId); + if (existing is null && podKind == OrbitalPodKind.Contender && ev.ContenderId >= 0) + { + existing = FindContenderPod(ev.ContenderId); + if (existing is not null) + { + existing.PodId = ev.PodId; + if (ev.PodId >= _nextPodId) _nextPodId = ev.PodId + 1; + if (ev.ContenderId < _state.Contenders.Count) + { + _state.Contenders[ev.ContenderId].ActivePodId = ev.PodId; + } + } + } if (existing is null) { var pod = new OrbitalPod @@ -1497,6 +1585,19 @@ namespace RustToDust.Core case DropPodEventKind.PodRetroBurnStart: { var pod = FindPodById(ev.PodId); + if (pod is null && (OrbitalPodKind)ev.PodKind == OrbitalPodKind.Contender && ev.ContenderId >= 0) + { + pod = FindContenderPod(ev.ContenderId); + if (pod is not null) + { + pod.PodId = ev.PodId; + if (ev.PodId >= _nextPodId) _nextPodId = ev.PodId + 1; + if (ev.ContenderId < _state.Contenders.Count) + { + _state.Contenders[ev.ContenderId].ActivePodId = ev.PodId; + } + } + } if (pod is not null) { var preset = OrbitalDropKinematics.GetPreset(pod.PodKind); diff --git a/src/RustToDust.Net/RemoteArenaSession.cs b/src/RustToDust.Net/RemoteArenaSession.cs index a1e01a8..d62693e 100644 --- a/src/RustToDust.Net/RemoteArenaSession.cs +++ b/src/RustToDust.Net/RemoteArenaSession.cs @@ -973,7 +973,7 @@ namespace RustToDust.Net var pod = pods[i]; if (pod.PodKind == OrbitalPodKind.Contender && pod.ContenderId == _localContenderId) { - if (pod.FlightTime > 12f) + if (pod.FlightTime > 25f) { _viewState.OrbitalDrop.RemoveActivePodAt(i); } @@ -990,7 +990,7 @@ namespace RustToDust.Net _viewState.FindClearDropPoint, out _, out _); - if (touched || pod.FlightTime > 12f) + if (touched || pod.FlightTime > 25f) { _viewState.OrbitalDrop.RemoveActivePodAt(i); } @@ -1255,41 +1255,57 @@ namespace RustToDust.Net } else { + OrbitalPod? pod = null; var pods = _viewState.OrbitalDrop.ActivePods; for (int p = 0; p < pods.Count; p++) { if (pods[p].PodKind == OrbitalPodKind.Contender && pods[p].ContenderId == c.Id) { - var pod = pods[p]; - float targetY = nc.Pos.Y - c.Grid.Spec.HalfHeight; - float errSq = (pod.X - nc.Pos.X) * (pod.X - nc.Pos.X) - + (pod.Y - targetY) * (pod.Y - targetY) - + (pod.Z - nc.Pos.Z) * (pod.Z - nc.Pos.Z); - var qRemote = NormalizeQuat(nc.Rot); - var fwdRemote = Vector3.Transform(Vector3.UnitZ, qRemote); - pod.X = nc.Pos.X; - pod.Y = targetY; - pod.Z = nc.Pos.Z; - pod.VelX = nc.Vel.X; - pod.VelY = nc.Vel.Y; - pod.VelZ = nc.Vel.Z; - pod.CurrRotX = qRemote.X; - pod.CurrRotY = qRemote.Y; - pod.CurrRotZ = qRemote.Z; - pod.CurrRotW = qRemote.W; - pod.Yaw = MathF.Atan2(fwdRemote.X, fwdRemote.Z); - pod.Phase = nc.PodRetroBurn ? OrbitalPodPhase.RetroBurn : OrbitalPodPhase.Freefall; - var surf = QueryLocalDropSurface(pod.X, pod.Z, OrbitalPodPreset.Contender.PodFootRadius, pod.Y + 1.0f); - float ty = _viewState.Terrain.SampleHeight(pod.X, pod.Z); - float sy = surf.IsBuildingRoof ? MathF.Max(ty, surf.SurfaceY) : ty; - pod.LastAgl = MathF.Max(0f, pod.Y - sy); - if (nc.Snap || errSq > HardSnapThresholdM * HardSnapThresholdM) - { - pod.SnapPreviousPose(); - } + pod = pods[p]; break; } } + + float targetY = nc.Pos.Y - c.Grid.Spec.HalfHeight; + var qRemote = NormalizeQuat(nc.Rot); + var fwdRemote = Vector3.Transform(Vector3.UnitZ, qRemote); + float yaw = MathF.Atan2(fwdRemote.X, fwdRemote.Z); + var phase = nc.PodRetroBurn ? OrbitalPodPhase.RetroBurn : OrbitalPodPhase.Freefall; + var surf = QueryLocalDropSurface(nc.Pos.X, nc.Pos.Z, OrbitalPodPreset.Contender.PodFootRadius, targetY + 1.0f); + float ty = _viewState.Terrain.SampleHeight(nc.Pos.X, nc.Pos.Z); + float sy = surf.IsBuildingRoof ? MathF.Max(ty, surf.SurfaceY) : ty; + float agl = MathF.Max(0f, targetY - sy); + + if (pod is null) + { + _viewState.OrbitalDrop.SynthesizeReplicatedContenderPod( + c.Id, nc.Pos.X, targetY, nc.Pos.Z, + nc.Vel.X, nc.Vel.Y, nc.Vel.Z, + qRemote, yaw, phase, agl); + } + else + { + float errSq = (pod.X - nc.Pos.X) * (pod.X - nc.Pos.X) + + (pod.Y - targetY) * (pod.Y - targetY) + + (pod.Z - nc.Pos.Z) * (pod.Z - nc.Pos.Z); + pod.X = nc.Pos.X; + pod.Y = targetY; + pod.Z = nc.Pos.Z; + pod.VelX = nc.Vel.X; + pod.VelY = nc.Vel.Y; + pod.VelZ = nc.Vel.Z; + pod.CurrRotX = qRemote.X; + pod.CurrRotY = qRemote.Y; + pod.CurrRotZ = qRemote.Z; + pod.CurrRotW = qRemote.W; + pod.Yaw = yaw; + pod.Phase = phase; + pod.LastAgl = agl; + if (nc.Snap || errSq > HardSnapThresholdM * HardSnapThresholdM) + { + pod.SnapPreviousPose(); + } + } } c.FireCmd = nc.Fire; c.BrakeCmd = nc.Brake; diff --git a/src/RustToDust.Net/ServerMatchHost.cs b/src/RustToDust.Net/ServerMatchHost.cs index 4f3ea1e..bebe38e 100644 --- a/src/RustToDust.Net/ServerMatchHost.cs +++ b/src/RustToDust.Net/ServerMatchHost.cs @@ -603,6 +603,7 @@ namespace RustToDust.Net int obsId = peer.AssignedContenderId; // Track PVS transitions & lifecycle snaps + uint enteredPvsMask = 0; for (int i = 0; i < _session.State.Contenders.Count; i++) { var c = _session.State.Contenders[i]; @@ -616,6 +617,10 @@ namespace RustToDust.Net if (inPvs && !tracker.InPvs) { tracker.SnapNext = true; + if (c.Lifecycle == ContenderLifecycle.Deploying && i < 32) + { + enteredPvsMask |= (1u << i); + } } tracker.InPvs = inPvs; } @@ -829,6 +834,51 @@ namespace RustToDust.Net } } + if (enteredPvsMask != 0) + { + var activePods = _session.State.OrbitalDrop.ActivePods; + for (int i = 0; i < _session.State.Contenders.Count && i < 32; i++) + { + if ((enteredPvsMask & (1u << i)) == 0) continue; + var c = _session.State.Contenders[i]; + if (c.Lifecycle != ContenderLifecycle.Deploying) continue; + for (int p = 0; p < activePods.Count; p++) + { + var pod = activePods[p]; + if (pod.PodKind == OrbitalPodKind.Contender && + pod.ContenderId == c.Id && + peer.SentPodIds.Add(pod.PodId)) + { + filtered.Add(new DropPodEvent + { + EventId = _session.State.OrbitalDrop.AllocatePodEventId(), + Kind = (byte)(pod.Phase == OrbitalPodPhase.RetroBurn + ? DropPodEventKind.PodRetroBurnStart + : DropPodEventKind.PodLaunched), + WaveIndex = pod.WaveIndex, + PodId = pod.PodId, + PodKind = (byte)pod.PodKind, + ContenderId = pod.ContenderId, + X = pod.X, + Y = pod.Y, + Z = pod.Z, + VelX = pod.VelX, + VelY = pod.VelY, + VelZ = pod.VelZ, + NormalX = 0f, + NormalY = 1f, + NormalZ = 0f, + ChassisId = pod.Chassis?.Id, + ModuleId = pod.Module?.Id, + DropId = pod.GroundDropId, + RespawnsClosed = _session.State.OrbitalDrop.RespawnCutoffReached + }); + break; + } + } + } + } + // Sync any PVS-visible contender (including local player!) whose loadout/damage version still differs for (int i = 0; i < _session.State.Contenders.Count; i++) { diff --git a/tests/RustToDust.Tests/OrbitalDropTests.cs b/tests/RustToDust.Tests/OrbitalDropTests.cs index 46e7f86..012f15b 100644 --- a/tests/RustToDust.Tests/OrbitalDropTests.cs +++ b/tests/RustToDust.Tests/OrbitalDropTests.cs @@ -930,6 +930,207 @@ namespace RustToDust.Tests Assert.Equal(12, steppedTested); } + [Fact] + public void Sion410mDrop_SteeringIntoTallWallAndSteepTerrain_NeverBreachesWallOrIgnitesStratosphericRetro() + { + using var session = new ArenaSession(seed: 42, ArenaMapKind.Sion, slot0Human: true); + var sion = session.State.SionMap!; + var tall = sion.Buildings.First(b => b.Id == "sion_1365"); + Assert.True((tall.RoofY - tall.GroundY) > 60f, $"Expected sion_1365 H>60m, got {tall.RoofY - tall.GroundY:F1}m"); + + // 1. 410m AGL human drop outside sion_1365 steering straight toward sion_1365 center, plus low wall-approach & roof-edge sweeps + var approachStarts = new (float X, float Z, float StartAgl, float Vy0)[] + { + (tall.CenterX, tall.CenterZ - tall.HalfZ - 18f, 410f, OrbitalPodPreset.Contender.InitialVelY), + (tall.CenterX - tall.HalfX - 18f, tall.CenterZ, 410f, OrbitalPodPreset.Contender.InitialVelY), + (tall.CenterX, tall.CenterZ + tall.HalfZ + 4.5f, 35f, -35f), + (tall.CenterX + tall.HalfX + 1.2f, tall.CenterZ, tall.RoofY - session.State.Terrain.SampleHeight(tall.CenterX + tall.HalfX + 1.2f, tall.CenterZ) + 2.0f, -22f), + }; + + for (int c = 0; c < approachStarts.Length; c++) + { + var (sx, sz, agl0, vy0) = approachStarts[c]; + float terrain0 = session.State.Terrain.SampleHeight(sx, sz); + float dx = tall.CenterX - sx; + float dz = tall.CenterZ - sz; + float len = MathF.Sqrt(dx * dx + dz * dz); + float dirX = dx / len; + float dirZ = dz / len; + + var pod = new OrbitalPod + { + PodId = 9500 + c, + PodKind = OrbitalPodKind.Contender, + Phase = OrbitalPodPhase.Freefall, + AllowFlatRoofLanding = true, + X = sx, + Y = terrain0 + agl0, + Z = sz, + VelY = vy0, + LookForwardX = dirX, + LookForwardZ = dirZ, + SteerForwardCmd = 1f, + Yaw = MathF.Atan2(dirX, dirZ) + }; + + bool landed = false; + float maxStepDeltaY = 0f; + for (int t = 0; t < 720; t++) + { + float prevY = pod.Y; + bool touched = OrbitalDropKinematics.StepPod( + pod, + ArenaSession.FixedDt, + session.State.Terrain, + session.QueryDropSurface, + session.State.FindClearDropPoint, + out bool retroStarted, + out _); + maxStepDeltaY = MathF.Max(maxStepDeltaY, MathF.Abs(pod.Y - prevY)); + + if (retroStarted) + { + float surfY = session.QueryDropSurface(pod.X, pod.Z, OrbitalPodPreset.Contender.PodFootRadius, pod.Y + 1.0f).SurfaceY; + float startAgl = pod.Y - MathF.Max(session.State.Terrain.SampleHeight(pod.X, pod.Z), surfY); + Assert.True(startAgl <= 160f, $"Case {c}: RetroBurn ignited in stratosphere at {startAgl:F1}m AGL"); + } + + if (sion.TryGetBuildingAt(pod.X, pod.Z, 0f, out var bInside)) + { + Assert.True(pod.Y >= bInside.RoofY - 0.1f, + $"Case {c} tick {t}: pod breached wall of {bInside.Id} at Y={pod.Y:F2} < RoofY={bInside.RoofY:F2}"); + } + + if (touched) + { + landed = true; + break; + } + } + + Assert.True(landed, $"Case {c} pod near sion_1365 failed to land"); + Assert.True(pod.FlightTime <= 10.5f, $"Case {c} exceeded 10.5s flight time: {pod.FlightTime:F2}s"); + Assert.True(maxStepDeltaY <= 2.0f, $"Case {c} had vertical teleport step {maxStepDeltaY:F2}m"); + Assert.InRange(pod.TouchdownSpeed, 0.5f, 2.99f); + } + + // 2. Full Sion Wave 0 drop steering human toward sion_1365 + steep Sion terrain checks across all 12 contenders + var maxBurnStartAgl = new Dictionary(); + for (int t = 0; t < 700; t++) + { + var p0 = session.State.Contenders[0]; + session.SetHumanInput(0, new PlayerInput( + Throttle: 1f, + Steer: 0f, + AimWorldX: tall.CenterX, + AimWorldZ: tall.CenterZ, + Fire: false, + InteractPickup: false, + Brake: false)); + session.Step(); + + foreach (var pod in session.State.OrbitalDrop.ActivePods) + { + if (sion.TryGetBuildingAt(pod.X, pod.Z, 0f, out var bHit)) + { + Assert.True(pod.Y >= bHit.RoofY - 0.1f, + $"Wave 0 pod {pod.PodId} breached {bHit.Id} wall at Y={pod.Y:F2} < RoofY={bHit.RoofY:F2}"); + } + if (pod.Phase == OrbitalPodPhase.RetroBurn && !maxBurnStartAgl.ContainsKey(pod.PodId)) + { + maxBurnStartAgl[pod.PodId] = pod.LastAgl; + Assert.True(pod.LastAgl <= 160f, $"Wave 0 pod {pod.PodId} ignited RetroBurn at {pod.LastAgl:F1}m AGL"); + } + Assert.True(pod.FlightTime <= 10.5f, $"Wave 0 pod {pod.PodId} exceeded 10.5s flight time: {pod.FlightTime:F2}s"); + } + + if (session.State.OrbitalDrop.ActivePods.Count == 0 && p0.IsGroundedActive) + { + break; + } + } + + Assert.Empty(session.State.OrbitalDrop.ActivePods); + Assert.True(session.State.Contenders[0].IsGroundedActive); + } + + [Fact] + public void RemoteArenaSession_RivalEntersPvsMidDrop_BecomesVisibleWithActivePod() + { + 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, "PvsObserver"); + 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; + int rivalId = localId == 0 ? 1 : 0; + + void PumpStep(int ticks) + { + var evs = new List(); + 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); + } + } + + // Land Wave 0 immediately and place observer far away from rival's Wave 1 drop + host.Session.State.OrbitalDrop.DeployAllPodsImmediately(host.Session.QueryDropSurface); + PumpStep(5); + Assert.True(clientIface.LocalContender.IsGroundedActive); + + // Eliminate rival -> WaitingForRespawnWave, then move observer far away (-900, -900) + host.Session.ForceEliminateContender(rivalId); + host.Session.SetContenderPose(localId, -900f, -900f, 0f); + PumpStep(5); + + // Trigger Wave 1 (75.0s) so rival launches its drop pod out of observer PVS + host.Session.State.Time = 74.9f; + for (int i = 0; i < 20 && host.Session.State.Contenders[rivalId].Lifecycle != ContenderLifecycle.Deploying; i++) + { + PumpStep(1); + } + Assert.Equal(ContenderLifecycle.Deploying, host.Session.State.Contenders[rivalId].Lifecycle); + PumpStep(5); + + var rivalPod = host.Session.State.OrbitalDrop.ActivePods.FirstOrDefault( + p => p.PodKind == OrbitalPodKind.Contender && p.ContenderId == rivalId); + Assert.NotNull(rivalPod); + Assert.False(host.Session.IsEntityInPeerPvs(localId, true, rivalId), "Rival should start out of observer PVS"); + Assert.False(clientIface.IsContenderVisible(rivalId), "Rival should not be visible on client before entering PVS"); + + // Move observer within 20m of rival's pod mid-drop, then step 15 ticks + host.Session.SetContenderPose(localId, rivalPod!.X + 18f, rivalPod.Z, 0f); + PumpStep(15); + + Assert.True(clientIface.IsContenderVisible(rivalId), "Rival should become visible on client after entering PVS mid-drop"); + Assert.Contains(clientIface.ActivePods, + p => p.PodKind == OrbitalPodKind.Contender && p.ContenderId == rivalId); + } + private static void AssertZeroChassisPenetration(MatchState state, ContenderState c) { var spec = c.Grid.Spec;