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:
parent
5af5d87e06
commit
43da8fdf81
8 changed files with 969 additions and 132 deletions
|
|
@ -1157,7 +1157,7 @@ public partial class ArenaRenderer : Node3D
|
|||
float roleIdx = ResolvePodRoleIndex((OrbitalPodKind)dpe.PodKind, dpe.ContenderId, localId, dpe.WaveIndex, isImperial);
|
||||
|
||||
Vector3 blastOrigin = pos + normal * (isContender ? 1.4f : 1.0f);
|
||||
float impulseScale = isContender ? 2.15f : 1.65f;
|
||||
float impulseScale = isContender ? 1.15f : 1.65f;
|
||||
float petalLife = isContender ? 8.0f : 4.5f;
|
||||
|
||||
for (int p = 0; p < 4; p++)
|
||||
|
|
|
|||
|
|
@ -1289,28 +1289,30 @@ namespace RustToDust.Core
|
|||
if (normal.LengthSquared() < 1e-4f) normal = Vector3.UnitY;
|
||||
else normal = Vector3.Normalize(normal);
|
||||
|
||||
if (SionMap is not null && SionMap.TryGetBuildingAt(x, z, footRadius, out var bldg))
|
||||
if (SionMap is not null)
|
||||
{
|
||||
bool insideExact = SionMap.TryGetBuildingAt(x, z, 0f, out var exactBldg);
|
||||
float roofY = insideExact ? exactBldg.RoofY : bldg.RoofY;
|
||||
if (roofY <= referenceMaxY && roofY > terrainY + 0.25f)
|
||||
bool centerOverBuilding = SionMap.TryGetBuildingAt(x, z, 0f, out var centerBldg);
|
||||
bool lateralWallOverlap = centerOverBuilding || SionMap.TryGetBuildingAt(x, z, footRadius, out _);
|
||||
|
||||
if (centerOverBuilding && centerBldg.RoofY > terrainY + 0.25f && centerBldg.RoofY <= referenceMaxY)
|
||||
{
|
||||
bool flat = bldg.Class == "Gebaeude Einzelhaus"
|
||||
? (bldg.HalfX >= footRadius + 2.2f && bldg.HalfZ >= footRadius + 2.2f)
|
||||
: false;
|
||||
bool flat = centerBldg.Class == "Gebaeude Einzelhaus"
|
||||
&& centerBldg.HalfX >= footRadius + 2.2f
|
||||
&& centerBldg.HalfZ >= footRadius + 2.2f;
|
||||
return new DropSurfaceSample(
|
||||
roofY,
|
||||
centerBldg.RoofY,
|
||||
Vector3.UnitY,
|
||||
IsBuildingRoof: true,
|
||||
IsFlatRoofValid: flat,
|
||||
IsInsideBuildingFootprint: true);
|
||||
}
|
||||
|
||||
return new DropSurfaceSample(
|
||||
MathF.Max(terrainY, bldg.RoofY),
|
||||
terrainY,
|
||||
normal,
|
||||
IsBuildingRoof: true,
|
||||
IsBuildingRoof: false,
|
||||
IsFlatRoofValid: false,
|
||||
IsInsideBuildingFootprint: true);
|
||||
IsInsideBuildingFootprint: lateralWallOverlap);
|
||||
}
|
||||
|
||||
if (ArenaCoverBoxes.Count > 0)
|
||||
|
|
|
|||
|
|
@ -182,6 +182,8 @@ namespace RustToDust.Core
|
|||
|
||||
public static class OrbitalDropKinematics
|
||||
{
|
||||
private const float MaxRetroAccel = 380f;
|
||||
|
||||
public static OrbitalPodPreset GetPreset(OrbitalPodKind kind) =>
|
||||
kind == OrbitalPodKind.Contender ? OrbitalPodPreset.Contender : OrbitalPodPreset.Gear;
|
||||
|
||||
|
|
@ -206,6 +208,7 @@ namespace RustToDust.Core
|
|||
float maxBound = MathF.Max(16f, terrain.MapHalfExtent - 10f);
|
||||
float g = DropWaveConfig.Gravity;
|
||||
float aNetNom = MathF.Max(10f, preset.NominalRetroAccel - g);
|
||||
float aMax = MathF.Max(aNetNom, MaxRetroAccel - g);
|
||||
float vTouch = preset.TargetTouchdownSpeed;
|
||||
|
||||
pod.FlightTime += dt;
|
||||
|
|
@ -213,18 +216,16 @@ namespace RustToDust.Core
|
|||
// 1. Surface & slope query
|
||||
DropSurfaceSample sampleNow = surfaceQuery(pod.X, pod.Z, preset.PodFootRadius, pod.Y + 1.0f);
|
||||
float terrainNow = terrain.SampleHeight(pod.X, pod.Z);
|
||||
float terrainAhead = MathF.Max(
|
||||
terrainNow,
|
||||
terrain.SampleHeight(pod.X + pod.VelX * 0.28f, pod.Z + pod.VelZ * 0.28f));
|
||||
|
||||
float surfaceNow = sampleNow.IsBuildingRoof
|
||||
? MathF.Max(terrainNow, sampleNow.SurfaceY)
|
||||
: terrainNow;
|
||||
|
||||
float hAgl = pod.Y - surfaceNow;
|
||||
float hEff = pod.Y - MathF.Max(surfaceNow, terrainAhead);
|
||||
pod.LastAgl = MathF.Max(0f, hAgl);
|
||||
|
||||
float vyDown = MathF.Max(0f, -pod.VelY);
|
||||
float hStop = vyDown > vTouch ? (vyDown * vyDown - vTouch * vTouch) / (2f * aMax) : 0f;
|
||||
|
||||
// 2. Horizontal steering & building wall/roof safety (computed first so surfaceRiseRate sees horizontal motion)
|
||||
float vxNext = pod.VelX;
|
||||
float vzNext = pod.VelZ;
|
||||
|
|
@ -279,19 +280,19 @@ namespace RustToDust.Core
|
|||
float xCand = Math.Clamp(pod.X + vxNext * dt, -maxBound, maxBound);
|
||||
float zCand = Math.Clamp(pod.Z + vzNext * dt, -maxBound, maxBound);
|
||||
|
||||
// Lateral Building Wall Guard: prevent horizontal entry into building walls during descent
|
||||
// Lateral Building Wall & Stepped-Roof Guard: reject/slide horizontal moves that violate stopping altitude or disallowed roof entry
|
||||
DropSurfaceSample sampleNext = surfaceQuery(xCand, zCand, preset.PodFootRadius, pod.Y + 1.0f);
|
||||
if (sampleNext.SurfaceY > pod.Y - 0.5f && sampleNow.SurfaceY <= pod.Y - 0.5f)
|
||||
if (IsBlockedHorizontalMove(pod, sampleNow, sampleNext, surfaceNow, hStop))
|
||||
{
|
||||
DropSurfaceSample slideX = surfaceQuery(xCand, pod.Z, preset.PodFootRadius, pod.Y + 1.0f);
|
||||
DropSurfaceSample slideZ = surfaceQuery(pod.X, zCand, preset.PodFootRadius, pod.Y + 1.0f);
|
||||
if (slideX.SurfaceY <= pod.Y - 0.5f)
|
||||
if (!IsBlockedHorizontalMove(pod, sampleNow, slideX, surfaceNow, hStop))
|
||||
{
|
||||
zCand = pod.Z;
|
||||
vzNext = 0f;
|
||||
sampleNext = slideX;
|
||||
}
|
||||
else if (slideZ.SurfaceY <= pod.Y - 0.5f)
|
||||
else if (!IsBlockedHorizontalMove(pod, sampleNow, slideZ, surfaceNow, hStop))
|
||||
{
|
||||
xCand = pod.X;
|
||||
vxNext = 0f;
|
||||
|
|
@ -312,9 +313,30 @@ namespace RustToDust.Core
|
|||
? MathF.Max(terrainNext, sampleNext.SurfaceY)
|
||||
: terrainNext;
|
||||
|
||||
// 3. Closing speed & burn trigger (use continuous terrain slope so vertical building edges never spike vClose to ~800 m/s)
|
||||
float terrainAhead = MathF.Max(
|
||||
terrainNext,
|
||||
terrain.SampleHeight(xCand + vxNext * 0.28f, zCand + vzNext * 0.28f));
|
||||
float surfaceAhead = terrainAhead;
|
||||
if (pod.AllowFlatRoofLanding && (vxNext * vxNext + vzNext * vzNext) > 0.25f)
|
||||
{
|
||||
DropSurfaceSample aheadSample = surfaceQuery(
|
||||
xCand + vxNext * 0.28f,
|
||||
zCand + vzNext * 0.28f,
|
||||
preset.PodFootRadius,
|
||||
pod.Y + 1.0f);
|
||||
if (aheadSample.IsBuildingRoof && aheadSample.IsFlatRoofValid && aheadSample.SurfaceY <= pod.Y - (hStop + 1.5f))
|
||||
{
|
||||
surfaceAhead = MathF.Max(surfaceAhead, aheadSample.SurfaceY);
|
||||
}
|
||||
}
|
||||
float hEff = pod.Y - MathF.Max(surfaceNext, surfaceAhead);
|
||||
|
||||
// 3. Closing speed & burn trigger (continuous terrain/same-roof slope so vertical building edges never spike vClose)
|
||||
float vDown = MathF.Max(0f, -pod.VelY);
|
||||
float slopeRiseRate = MathF.Max(0f, (terrainNext - terrainNow) / dt);
|
||||
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 vClose = vDown + slopeRiseRate;
|
||||
float hBurn = MathF.Max(
|
||||
8.0f,
|
||||
|
|
@ -439,6 +461,38 @@ namespace RustToDust.Core
|
|||
return false;
|
||||
}
|
||||
|
||||
private static bool IsBlockedHorizontalMove(
|
||||
OrbitalPod pod,
|
||||
in DropSurfaceSample sampleNow,
|
||||
in DropSurfaceSample sampleNext,
|
||||
float surfaceNow,
|
||||
float hStop)
|
||||
{
|
||||
if (sampleNext.SurfaceY > pod.Y - (hStop + 1.5f) &&
|
||||
(sampleNext.SurfaceY > surfaceNow + 0.25f || sampleNext.SurfaceY > pod.Y - 0.5f))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!pod.AllowFlatRoofLanding &&
|
||||
sampleNext.IsBuildingRoof &&
|
||||
(!sampleNow.IsBuildingRoof || sampleNext.SurfaceY > surfaceNow + 0.25f))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (pod.AllowFlatRoofLanding &&
|
||||
sampleNext.IsBuildingRoof &&
|
||||
!sampleNext.IsFlatRoofValid &&
|
||||
!sampleNow.IsBuildingRoof &&
|
||||
(pod.Phase == OrbitalPodPhase.RetroBurn || pod.Y - sampleNext.SurfaceY < 8f))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static Vector3 ToNormalVec((float Nx, float Ny, float Nz) n)
|
||||
{
|
||||
var v = new Vector3(n.Nx, n.Ny, n.Nz);
|
||||
|
|
@ -689,13 +743,32 @@ namespace RustToDust.Core
|
|||
return pod;
|
||||
}
|
||||
|
||||
public void CancelContenderPod(int contenderId)
|
||||
public void CancelContenderPod(int contenderId, bool emitEvent = true)
|
||||
{
|
||||
for (int i = _activePods.Count - 1; i >= 0; i--)
|
||||
{
|
||||
if (_activePods[i].PodKind == OrbitalPodKind.Contender && _activePods[i].ContenderId == contenderId)
|
||||
var pod = _activePods[i];
|
||||
if (pod.PodKind == OrbitalPodKind.Contender && pod.ContenderId == contenderId)
|
||||
{
|
||||
_activePods.RemoveAt(i);
|
||||
if (emitEvent)
|
||||
{
|
||||
EmitLifecycleEvent(
|
||||
DropPodEventKind.PodCancelled,
|
||||
pod.WaveIndex,
|
||||
pod.PodId,
|
||||
pod.PodKind,
|
||||
pod.ContenderId,
|
||||
pod.X, pod.Y, pod.Z,
|
||||
0f, 0f, 0f,
|
||||
Vector3.UnitY,
|
||||
pod.Chassis?.Id,
|
||||
pod.Module?.Id,
|
||||
dropId: 0,
|
||||
_respawnCutoffReached,
|
||||
gearCount: 0,
|
||||
respawnCount: 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (contenderId >= 0 && contenderId < _state.Contenders.Count)
|
||||
|
|
@ -704,6 +777,14 @@ namespace RustToDust.Core
|
|||
}
|
||||
}
|
||||
|
||||
public void RemoveActivePodAt(int index)
|
||||
{
|
||||
if (index >= 0 && index < _activePods.Count)
|
||||
{
|
||||
_activePods.RemoveAt(index);
|
||||
}
|
||||
}
|
||||
|
||||
public void DeployAllPodsImmediately(DropSurfaceQuery? surfaceQuery = null)
|
||||
{
|
||||
surfaceQuery ??= _state.DefaultDropSurfaceQuery;
|
||||
|
|
@ -1286,21 +1367,35 @@ namespace RustToDust.Core
|
|||
_respawnCutoffReached = respawnCutoffReached;
|
||||
}
|
||||
|
||||
public void ApplyReplicatedActivePods(IEnumerable<OrbitalPodDto> pods)
|
||||
public void ApplyReplicatedActivePods(IEnumerable<OrbitalPodDto> pods, DropSurfaceQuery? surfaceQuery = null)
|
||||
{
|
||||
surfaceQuery ??= _state.DefaultDropSurfaceQuery;
|
||||
_activePods.Clear();
|
||||
foreach (var dto in pods)
|
||||
{
|
||||
var podKind = (OrbitalPodKind)dto.PodKind;
|
||||
var preset = OrbitalDropKinematics.GetPreset(podKind);
|
||||
float surfY = ResolveSurfaceUnderPod(dto.X, dto.Y, dto.Z, preset.PodFootRadius, surfaceQuery);
|
||||
var q = Quaternion.CreateFromAxisAngle(Vector3.UnitY, dto.Yaw);
|
||||
bool allowFlatRoof = false;
|
||||
if (podKind == OrbitalPodKind.Contender && dto.ContenderId >= 0 && dto.ContenderId < _state.Contenders.Count)
|
||||
{
|
||||
var c = _state.Contenders[dto.ContenderId];
|
||||
c.ActivePodId = dto.PodId;
|
||||
allowFlatRoof = c.IsHuman && _state.MapKind == ArenaMapKind.Sion;
|
||||
}
|
||||
var pod = new OrbitalPod
|
||||
{
|
||||
PodId = dto.PodId,
|
||||
PodKind = (OrbitalPodKind)dto.PodKind,
|
||||
PodKind = podKind,
|
||||
Phase = (OrbitalPodPhase)dto.Phase,
|
||||
WaveIndex = dto.WaveIndex,
|
||||
ContenderId = dto.ContenderId,
|
||||
Chassis = dto.ChassisId is not null && Catalog.ChassisById.TryGetValue(dto.ChassisId, out var cs) ? cs : null,
|
||||
Module = dto.ModuleId is not null && Catalog.ModulesById.TryGetValue(dto.ModuleId, out var ms) ? ms : null,
|
||||
AllowFlatRoofLanding = allowFlatRoof,
|
||||
TargetX = dto.X,
|
||||
TargetZ = dto.Z,
|
||||
X = dto.X,
|
||||
Y = dto.Y,
|
||||
Z = dto.Z,
|
||||
|
|
@ -1311,7 +1406,10 @@ namespace RustToDust.Core
|
|||
CurrRotX = q.X,
|
||||
CurrRotY = q.Y,
|
||||
CurrRotZ = q.Z,
|
||||
CurrRotW = q.W
|
||||
CurrRotW = q.W,
|
||||
LookForwardX = MathF.Sin(dto.Yaw),
|
||||
LookForwardZ = MathF.Cos(dto.Yaw),
|
||||
LastAgl = MathF.Max(0f, dto.Y - surfY)
|
||||
};
|
||||
pod.SnapPreviousPose();
|
||||
_activePods.Add(pod);
|
||||
|
|
@ -1319,8 +1417,9 @@ namespace RustToDust.Core
|
|||
}
|
||||
}
|
||||
|
||||
public void ApplyReplicatedDropPodEvent(DropPodEvent ev)
|
||||
public void ApplyReplicatedDropPodEvent(DropPodEvent ev, DropSurfaceQuery? surfaceQuery = null)
|
||||
{
|
||||
surfaceQuery ??= _state.DefaultDropSurfaceQuery;
|
||||
var kind = (DropPodEventKind)ev.Kind;
|
||||
switch (kind)
|
||||
{
|
||||
|
|
@ -1331,33 +1430,67 @@ namespace RustToDust.Core
|
|||
break;
|
||||
case DropPodEventKind.PodLaunched:
|
||||
{
|
||||
var podKind = (OrbitalPodKind)ev.PodKind;
|
||||
var preset = OrbitalDropKinematics.GetPreset(podKind);
|
||||
float surfY = ResolveSurfaceUnderPod(ev.X, ev.Y, ev.Z, preset.PodFootRadius, surfaceQuery);
|
||||
float yaw = 0f;
|
||||
bool allowFlatRoof = false;
|
||||
if (ev.ContenderId >= 0 && ev.ContenderId < _state.Contenders.Count)
|
||||
{
|
||||
var c = _state.Contenders[ev.ContenderId];
|
||||
c.Lifecycle = ContenderLifecycle.Deploying;
|
||||
c.ActivePodId = ev.PodId;
|
||||
yaw = c.Yaw;
|
||||
allowFlatRoof = c.IsHuman && _state.MapKind == ArenaMapKind.Sion;
|
||||
}
|
||||
else
|
||||
{
|
||||
yaw = (float)((ev.PodId * 1.17f) % MathF.Tau);
|
||||
}
|
||||
var q = Quaternion.CreateFromAxisAngle(Vector3.UnitY, yaw);
|
||||
|
||||
var existing = FindPodById(ev.PodId);
|
||||
if (existing is null)
|
||||
{
|
||||
var pod = new OrbitalPod
|
||||
{
|
||||
PodId = ev.PodId,
|
||||
PodKind = (OrbitalPodKind)ev.PodKind,
|
||||
PodKind = podKind,
|
||||
Phase = OrbitalPodPhase.Freefall,
|
||||
WaveIndex = ev.WaveIndex,
|
||||
ContenderId = ev.ContenderId,
|
||||
Chassis = ev.ChassisId is not null && Catalog.ChassisById.TryGetValue(ev.ChassisId, out var cs) ? cs : null,
|
||||
Module = ev.ModuleId is not null && Catalog.ModulesById.TryGetValue(ev.ModuleId, out var ms) ? ms : null,
|
||||
AllowFlatRoofLanding = allowFlatRoof,
|
||||
TargetX = ev.X,
|
||||
TargetZ = ev.Z,
|
||||
X = ev.X,
|
||||
Y = ev.Y,
|
||||
Z = ev.Z,
|
||||
VelX = ev.VelX,
|
||||
VelY = ev.VelY,
|
||||
VelZ = ev.VelZ
|
||||
VelZ = ev.VelZ,
|
||||
Yaw = yaw,
|
||||
CurrRotX = q.X,
|
||||
CurrRotY = q.Y,
|
||||
CurrRotZ = q.Z,
|
||||
CurrRotW = q.W,
|
||||
LookForwardX = MathF.Sin(yaw),
|
||||
LookForwardZ = MathF.Cos(yaw),
|
||||
LastAgl = MathF.Max(0f, ev.Y - surfY)
|
||||
};
|
||||
pod.SnapPreviousPose();
|
||||
_activePods.Add(pod);
|
||||
}
|
||||
if (ev.ContenderId >= 0 && ev.ContenderId < _state.Contenders.Count)
|
||||
else
|
||||
{
|
||||
var c = _state.Contenders[ev.ContenderId];
|
||||
c.Lifecycle = ContenderLifecycle.Deploying;
|
||||
c.ActivePodId = ev.PodId;
|
||||
existing.X = ev.X;
|
||||
existing.Y = ev.Y;
|
||||
existing.Z = ev.Z;
|
||||
existing.VelX = ev.VelX;
|
||||
existing.VelY = ev.VelY;
|
||||
existing.VelZ = ev.VelZ;
|
||||
existing.LastAgl = MathF.Max(0f, ev.Y - surfY);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
@ -1366,6 +1499,8 @@ namespace RustToDust.Core
|
|||
var pod = FindPodById(ev.PodId);
|
||||
if (pod is not null)
|
||||
{
|
||||
var preset = OrbitalDropKinematics.GetPreset(pod.PodKind);
|
||||
float surfY = ResolveSurfaceUnderPod(ev.X, ev.Y, ev.Z, preset.PodFootRadius, surfaceQuery);
|
||||
pod.Phase = OrbitalPodPhase.RetroBurn;
|
||||
pod.X = ev.X;
|
||||
pod.Y = ev.Y;
|
||||
|
|
@ -1373,6 +1508,7 @@ namespace RustToDust.Core
|
|||
pod.VelX = ev.VelX;
|
||||
pod.VelY = ev.VelY;
|
||||
pod.VelZ = ev.VelZ;
|
||||
pod.LastAgl = MathF.Max(0f, ev.Y - surfY);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
@ -1393,6 +1529,25 @@ namespace RustToDust.Core
|
|||
}
|
||||
break;
|
||||
}
|
||||
case DropPodEventKind.PodCancelled:
|
||||
{
|
||||
for (int i = _activePods.Count - 1; i >= 0; i--)
|
||||
{
|
||||
if (_activePods[i].PodId == ev.PodId)
|
||||
{
|
||||
_activePods.RemoveAt(i);
|
||||
}
|
||||
}
|
||||
if (ev.ContenderId >= 0 && ev.ContenderId < _state.Contenders.Count)
|
||||
{
|
||||
var c = _state.Contenders[ev.ContenderId];
|
||||
if (c.ActivePodId == ev.PodId)
|
||||
{
|
||||
c.ActivePodId = null;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
_state.PodEvents.Add(new DropPodLifecycleEvent(
|
||||
|
|
@ -1417,6 +1572,13 @@ namespace RustToDust.Core
|
|||
}
|
||||
}
|
||||
|
||||
private float ResolveSurfaceUnderPod(float x, float y, float z, float radius, DropSurfaceQuery surfaceQuery)
|
||||
{
|
||||
float terrainY = _state.Terrain.SampleHeight(x, z);
|
||||
var sample = surfaceQuery(x, z, radius, y + 1.0f);
|
||||
return sample.IsBuildingRoof ? MathF.Max(terrainY, sample.SurfaceY) : terrainY;
|
||||
}
|
||||
|
||||
private static Quaternion AlignUp(Quaternion baseYawQ, Vector3 targetUp)
|
||||
{
|
||||
Vector3 currentUp = Vector3.Transform(Vector3.UnitY, baseYawQ);
|
||||
|
|
|
|||
|
|
@ -42,7 +42,8 @@ namespace RustToDust.Core
|
|||
WaveAnnounced = 0,
|
||||
PodLaunched = 1,
|
||||
PodRetroBurnStart = 2,
|
||||
PodTouchdownBlowPetals = 3
|
||||
PodTouchdownBlowPetals = 3,
|
||||
PodCancelled = 4
|
||||
}
|
||||
|
||||
[MessagePackObject]
|
||||
|
|
|
|||
|
|
@ -78,6 +78,9 @@ namespace RustToDust.Net
|
|||
private int _pingMs;
|
||||
private int _connectedHumans = 1;
|
||||
private long _lastServerPacketUtcMs;
|
||||
private float _podStepAccum;
|
||||
private float _timeSinceLastPhysicsPodStep;
|
||||
private bool _physicsPodSteppingActive;
|
||||
private bool _joinSent;
|
||||
private bool _joined;
|
||||
private bool _everJoined;
|
||||
|
|
@ -212,6 +215,24 @@ namespace RustToDust.Net
|
|||
MatchRules.AdvanceTracers(_viewState, fdt);
|
||||
MatchRules.AdvanceHitEvents(_viewState, fdt);
|
||||
|
||||
if (_joined && fdt > 0f)
|
||||
{
|
||||
_timeSinceLastPhysicsPodStep += fdt;
|
||||
if (_timeSinceLastPhysicsPodStep > 0.08f)
|
||||
{
|
||||
_physicsPodSteppingActive = false;
|
||||
}
|
||||
if (!_physicsPodSteppingActive)
|
||||
{
|
||||
_podStepAccum += fdt;
|
||||
while (_podStepAccum >= ArenaSession.FixedDt)
|
||||
{
|
||||
StepAllReplicatedPods(ArenaSession.FixedDt);
|
||||
_podStepAccum -= ArenaSession.FixedDt;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (_joined)
|
||||
{
|
||||
_renderTime += fdt;
|
||||
|
|
@ -292,6 +313,10 @@ namespace RustToDust.Net
|
|||
_unackedInputs.Add(new BufferedInput(seq, input, preWalker));
|
||||
|
||||
StepLocalPredictionTick(input, updatePreviousPose: true);
|
||||
StepNonLocalReplicatedPods(ArenaSession.FixedDt);
|
||||
_physicsPodSteppingActive = true;
|
||||
_timeSinceLastPhysicsPodStep = 0f;
|
||||
_podStepAccum = 0f;
|
||||
}
|
||||
|
||||
public bool RequestEquipCargo(int cargoIndex, string hardpointId)
|
||||
|
|
@ -707,9 +732,11 @@ namespace RustToDust.Net
|
|||
dto.CurrentWaveIndex,
|
||||
Math.Min(DropWaveConfig.WaveTimes.Length, dto.CurrentWaveIndex + 1),
|
||||
dto.RespawnCutoffReached);
|
||||
_viewState.OrbitalDrop.ApplyReplicatedActivePods(dto.ActivePods);
|
||||
_latestServerSimTime = dto.SimTime;
|
||||
_renderTime = Math.Max(0f, dto.SimTime - InterpDelaySec);
|
||||
_podStepAccum = 0f;
|
||||
_timeSinceLastPhysicsPodStep = 0f;
|
||||
_physicsPodSteppingActive = false;
|
||||
|
||||
for (int i = 0; i < dto.TerrainStamps.Count; i++)
|
||||
{
|
||||
|
|
@ -797,6 +824,7 @@ namespace RustToDust.Net
|
|||
_spectatorWalkerTimelines.Clear();
|
||||
|
||||
RebuildPredictionWorld();
|
||||
_viewState.OrbitalDrop.ApplyReplicatedActivePods(dto.ActivePods, QueryLocalDropSurface);
|
||||
}
|
||||
|
||||
private void RebuildPredictionWorld()
|
||||
|
|
@ -901,6 +929,74 @@ namespace RustToDust.Net
|
|||
_predChassisId = spec.Id;
|
||||
}
|
||||
|
||||
private DropSurfaceSample QueryLocalDropSurface(float x, float z, float footRadius, float referenceMaxY) =>
|
||||
ArenaSession.QueryDropSurface(_viewState, _predWorld, x, z, footRadius, referenceMaxY);
|
||||
|
||||
private OrbitalPod? FindActivePodForContender(int contenderId)
|
||||
{
|
||||
var pods = _viewState.OrbitalDrop.ActivePods;
|
||||
for (int i = 0; i < pods.Count; i++)
|
||||
{
|
||||
if (pods[i].PodKind == OrbitalPodKind.Contender && pods[i].ContenderId == contenderId)
|
||||
{
|
||||
return pods[i];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void StepAllReplicatedPods(float dt)
|
||||
{
|
||||
var local = LocalContender;
|
||||
if (local.IsInDropPod)
|
||||
{
|
||||
var input = new PlayerInput(
|
||||
local.ThrottleCmd,
|
||||
local.SteerCmd,
|
||||
local.AimX,
|
||||
local.AimZ,
|
||||
Fire: false,
|
||||
InteractPickup: false,
|
||||
Brake: false,
|
||||
AimWorldY: local.AimY,
|
||||
VerticalThrottle: 0f);
|
||||
StepLocalPredictionTick(input, updatePreviousPose: true);
|
||||
}
|
||||
StepNonLocalReplicatedPods(dt);
|
||||
}
|
||||
|
||||
private void StepNonLocalReplicatedPods(float dt)
|
||||
{
|
||||
var pods = _viewState.OrbitalDrop.ActivePods;
|
||||
for (int i = pods.Count - 1; i >= 0; i--)
|
||||
{
|
||||
var pod = pods[i];
|
||||
if (pod.PodKind == OrbitalPodKind.Contender && pod.ContenderId == _localContenderId)
|
||||
{
|
||||
if (pod.FlightTime > 12f)
|
||||
{
|
||||
_viewState.OrbitalDrop.RemoveActivePodAt(i);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
pod.SnapPreviousPose();
|
||||
pod.AllowFlatRoofLanding = false;
|
||||
bool touched = OrbitalDropKinematics.StepPod(
|
||||
pod,
|
||||
dt,
|
||||
_viewState.Terrain,
|
||||
QueryLocalDropSurface,
|
||||
_viewState.FindClearDropPoint,
|
||||
out _,
|
||||
out _);
|
||||
if (touched || pod.FlightTime > 12f)
|
||||
{
|
||||
_viewState.OrbitalDrop.RemoveActivePodAt(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void StepLocalPredictionTick(in PlayerInput input, bool updatePreviousPose)
|
||||
{
|
||||
var local = LocalContender;
|
||||
|
|
@ -913,6 +1009,47 @@ namespace RustToDust.Net
|
|||
}
|
||||
}
|
||||
|
||||
if (local.IsInDropPod)
|
||||
{
|
||||
MatchRules.ApplyHumanInput(_viewState, _localContenderId, input with { InteractPickup = false });
|
||||
var localPod = FindActivePodForContender(_localContenderId);
|
||||
if (localPod is not null)
|
||||
{
|
||||
if (updatePreviousPose)
|
||||
{
|
||||
localPod.SnapPreviousPose();
|
||||
}
|
||||
localPod.AllowFlatRoofLanding = local.IsHuman && _viewState.MapKind == ArenaMapKind.Sion;
|
||||
bool touched = OrbitalDropKinematics.StepPod(
|
||||
localPod,
|
||||
ArenaSession.FixedDt,
|
||||
_viewState.Terrain,
|
||||
QueryLocalDropSurface,
|
||||
_viewState.FindClearDropPoint,
|
||||
out _,
|
||||
out _);
|
||||
if (touched)
|
||||
{
|
||||
localPod.Phase = OrbitalPodPhase.RetroBurn;
|
||||
localPod.LastAgl = 0f;
|
||||
localPod.VelY = -OrbitalPodPreset.Contender.TargetTouchdownSpeed;
|
||||
}
|
||||
local.X = localPod.X;
|
||||
local.Y = localPod.Y + local.Grid.Spec.HalfHeight;
|
||||
local.Z = localPod.Z;
|
||||
local.Yaw = localPod.Yaw;
|
||||
local.CurrRotX = localPod.CurrRotX;
|
||||
local.CurrRotY = localPod.CurrRotY;
|
||||
local.CurrRotZ = localPod.CurrRotZ;
|
||||
local.CurrRotW = localPod.CurrRotW;
|
||||
local.VelX = localPod.VelX;
|
||||
local.VelY = localPod.VelY;
|
||||
local.VelZ = localPod.VelZ;
|
||||
local.Speed = MathF.Sqrt(localPod.VelX * localPod.VelX + localPod.VelZ * localPod.VelZ);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (_predWorld is null || !_predBody.HasValue || !local.IsGroundedActive)
|
||||
{
|
||||
return;
|
||||
|
|
@ -962,7 +1099,7 @@ namespace RustToDust.Net
|
|||
_viewState.OrbitalDrop.ApplyReplicatedWaveState(pkt.CurrentWaveIndex, nextWaveIdx, pkt.RespawnCutoffReached);
|
||||
if (local.Lifecycle != ContenderLifecycle.Deploying)
|
||||
{
|
||||
_viewState.OrbitalDrop.CancelContenderPod(local.Id);
|
||||
_viewState.OrbitalDrop.CancelContenderPod(local.Id, emitEvent: false);
|
||||
}
|
||||
local.InArcWeaponCount = pkt.InArcWeapons;
|
||||
local.OutOfArcWeaponCount = pkt.OutOfArcWeapons;
|
||||
|
|
@ -1017,6 +1154,29 @@ namespace RustToDust.Net
|
|||
local.TargetHoverAltAgl = pkt.LocalTargetHoverAltAgl;
|
||||
SpawnLocalPredictionBody(pkt.LocalPos, pkt.LocalRot, pkt.LocalVel, pkt.LocalAngVel);
|
||||
|
||||
if (local.Lifecycle == ContenderLifecycle.Deploying &&
|
||||
FindActivePodForContender(local.Id) is { } localPod)
|
||||
{
|
||||
var qPod = NormalizeQuat(pkt.LocalRot);
|
||||
var fwdPod = Vector3.Transform(Vector3.UnitZ, qPod);
|
||||
localPod.X = pkt.LocalPos.X;
|
||||
localPod.Y = pkt.LocalPos.Y - local.Grid.Spec.HalfHeight;
|
||||
localPod.Z = pkt.LocalPos.Z;
|
||||
localPod.VelX = pkt.LocalVel.X;
|
||||
localPod.VelY = pkt.LocalVel.Y;
|
||||
localPod.VelZ = pkt.LocalVel.Z;
|
||||
localPod.CurrRotX = qPod.X;
|
||||
localPod.CurrRotY = qPod.Y;
|
||||
localPod.CurrRotZ = qPod.Z;
|
||||
localPod.CurrRotW = qPod.W;
|
||||
localPod.Yaw = MathF.Atan2(fwdPod.X, fwdPod.Z);
|
||||
localPod.Phase = pkt.LocalPodPhase;
|
||||
var surfSample = QueryLocalDropSurface(localPod.X, localPod.Z, OrbitalPodPreset.Contender.PodFootRadius, localPod.Y + 1.0f);
|
||||
float terrainY = _viewState.Terrain.SampleHeight(localPod.X, localPod.Z);
|
||||
float surfY = surfSample.IsBuildingRoof ? MathF.Max(terrainY, surfSample.SurfaceY) : terrainY;
|
||||
localPod.LastAgl = MathF.Max(0f, localPod.Y - surfY);
|
||||
}
|
||||
|
||||
if (replayBaseWalker is { } baseCp &&
|
||||
_predWalker is { Initialized: true } &&
|
||||
baseCp.GeomLegCount == _predWalker.Geom.LegCount &&
|
||||
|
|
@ -1039,13 +1199,17 @@ namespace RustToDust.Net
|
|||
Quaternion deltaRot = NormalizeQuat(prevVisRot * Quaternion.Inverse(newPredRot));
|
||||
if (deltaRot.W < 0f) deltaRot = -deltaRot;
|
||||
|
||||
bool hardSnap = !pkt.LocalAlive || prevLocalLifecycle != local.Lifecycle || !local.IsGroundedActive || chassisChanged || _pendingChassisSwapSnap || deltaPos.Length() > HardSnapThresholdM;
|
||||
bool hardSnap = !pkt.LocalAlive || prevLocalLifecycle != local.Lifecycle || (!local.IsGroundedActive && !local.IsInDropPod) || chassisChanged || _pendingChassisSwapSnap || deltaPos.Length() > HardSnapThresholdM;
|
||||
if (hardSnap)
|
||||
{
|
||||
_predErrorPos = Vector3.Zero;
|
||||
_predErrorRot = Quaternion.Identity;
|
||||
_pendingChassisSwapSnap = false;
|
||||
local.SnapPreviousPose();
|
||||
if (local.IsInDropPod && FindActivePodForContender(local.Id) is { } lp)
|
||||
{
|
||||
lp.SnapPreviousPose();
|
||||
}
|
||||
if (_predWalker is { Initialized: true })
|
||||
{
|
||||
_predWalker.SnapshotPrev();
|
||||
|
|
@ -1074,6 +1238,7 @@ namespace RustToDust.Net
|
|||
if (!inPvs)
|
||||
{
|
||||
_contenderTimeline[i].Clear();
|
||||
_viewState.OrbitalDrop.CancelContenderPod(i, emitEvent: false);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1086,7 +1251,7 @@ namespace RustToDust.Net
|
|||
c.Lifecycle = nc.Lifecycle;
|
||||
if (nc.Lifecycle != ContenderLifecycle.Deploying)
|
||||
{
|
||||
_viewState.OrbitalDrop.CancelContenderPod(c.Id);
|
||||
_viewState.OrbitalDrop.CancelContenderPod(c.Id, emitEvent: false);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -1095,14 +1260,33 @@ namespace RustToDust.Net
|
|||
{
|
||||
if (pods[p].PodKind == OrbitalPodKind.Contender && pods[p].ContenderId == c.Id)
|
||||
{
|
||||
pods[p].SnapPreviousPose();
|
||||
pods[p].X = nc.Pos.X;
|
||||
pods[p].Y = nc.Pos.Y - c.Grid.Spec.HalfHeight;
|
||||
pods[p].Z = nc.Pos.Z;
|
||||
pods[p].VelX = nc.Vel.X;
|
||||
pods[p].VelY = nc.Vel.Y;
|
||||
pods[p].VelZ = nc.Vel.Z;
|
||||
pods[p].Phase = nc.PodRetroBurn ? OrbitalPodPhase.RetroBurn : OrbitalPodPhase.Freefall;
|
||||
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();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -1339,6 +1523,10 @@ namespace RustToDust.Net
|
|||
}
|
||||
l.SnapPreviousPose();
|
||||
}
|
||||
if (FindActivePodForContender(l.Id) is { } lp)
|
||||
{
|
||||
lp.Chassis = l.Grid.Spec;
|
||||
}
|
||||
SpawnLocalPredictionBody(
|
||||
new Vector3(l.X, l.Y, l.Z),
|
||||
NormalizeQuat(new Quaternion(l.CurrRotX, l.CurrRotY, l.CurrRotZ, l.CurrRotW)),
|
||||
|
|
@ -1372,7 +1560,7 @@ namespace RustToDust.Net
|
|||
}
|
||||
break;
|
||||
case DropPodEvent dpe:
|
||||
_viewState.OrbitalDrop.ApplyReplicatedDropPodEvent(dpe);
|
||||
_viewState.OrbitalDrop.ApplyReplicatedDropPodEvent(dpe, QueryLocalDropSurface);
|
||||
break;
|
||||
case SpectatorDestroyedEvent sdet:
|
||||
{
|
||||
|
|
@ -1405,6 +1593,7 @@ namespace RustToDust.Net
|
|||
if (sync.IsContender && sync.EntityId >= 0 && sync.EntityId < _viewState.Contenders.Count)
|
||||
{
|
||||
var c = _viewState.Contenders[sync.EntityId];
|
||||
string prevChassisId = c.Grid.Spec.Id;
|
||||
c.X = sync.PosX; c.Y = sync.PosY; c.Z = sync.PosZ; c.Yaw = sync.Yaw;
|
||||
var q = Quaternion.CreateFromAxisAngle(Vector3.UnitY, sync.Yaw);
|
||||
c.CurrRotX = q.X; c.CurrRotY = q.Y; c.CurrRotZ = q.Z; c.CurrRotW = q.W;
|
||||
|
|
@ -1415,6 +1604,24 @@ namespace RustToDust.Net
|
|||
}
|
||||
c.Grid.ApplyReplicatedArmorBytes(sync.ArmorBytes);
|
||||
c.Grid.ApplyReplicatedDamage(0, 0, c.Grid.Armor[0, 0], c.Grid.Temperature[0, 0], sync.Alive ? sync.CoreHp : 0f, c.Grid.HitSequence);
|
||||
if (sync.EntityId == _localContenderId)
|
||||
{
|
||||
if (!string.Equals(prevChassisId, c.Grid.Spec.Id, StringComparison.Ordinal))
|
||||
{
|
||||
_pendingChassisSwapSnap = true;
|
||||
_predErrorPos = Vector3.Zero;
|
||||
_predErrorRot = Quaternion.Identity;
|
||||
}
|
||||
if (FindActivePodForContender(c.Id) is { } lp)
|
||||
{
|
||||
lp.Chassis = c.Grid.Spec;
|
||||
}
|
||||
SpawnLocalPredictionBody(
|
||||
new Vector3(c.X, c.Y, c.Z),
|
||||
q,
|
||||
new Vector3(c.VelX, c.VelY, c.VelZ),
|
||||
Vector3.Zero);
|
||||
}
|
||||
_contenderTimeline[c.Id].Clear();
|
||||
PushPoseSample(_contenderTimeline[c.Id], _latestServerSimTime, new Vector3(c.X, c.Y, c.Z), q, Vector3.Zero);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ namespace RustToDust.Net
|
|||
public readonly EntityPvsTracker[] ContenderTrackers = new EntityPvsTracker[MatchState.ContenderCount];
|
||||
public readonly EntityPvsTracker[] SpectatorTrackers = new EntityPvsTracker[SpectatorRing.DefaultSpectatorCount];
|
||||
public readonly HashSet<int> SentDropIds = new();
|
||||
public readonly HashSet<int> SentPodIds = new();
|
||||
}
|
||||
|
||||
private struct EntityPvsTracker
|
||||
|
|
@ -571,6 +572,25 @@ namespace RustToDust.Net
|
|||
peer.SentDropIds.Add(d.Id);
|
||||
}
|
||||
}
|
||||
peer.SentPodIds.Clear();
|
||||
var activePods = _session.State.OrbitalDrop.ActivePods;
|
||||
for (int i = 0; i < activePods.Count; i++)
|
||||
{
|
||||
var pod = activePods[i];
|
||||
if (IsPodVisibleToPeer(peer.AssignedContenderId, pod))
|
||||
{
|
||||
peer.SentPodIds.Add(pod.PodId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool IsPodVisibleToPeer(int obsId, OrbitalPod pod)
|
||||
{
|
||||
if (pod.PodKind == OrbitalPodKind.Contender)
|
||||
{
|
||||
return pod.ContenderId == obsId || _session.IsEntityInPeerPvs(obsId, true, pod.ContenderId);
|
||||
}
|
||||
return _session.IsPointInPeerPvs(obsId, pod.X, pod.Y + 2.0f, pod.Z);
|
||||
}
|
||||
|
||||
private void FlushEventsAndPvsEnter()
|
||||
|
|
@ -582,11 +602,11 @@ namespace RustToDust.Net
|
|||
if (!peer.Active) continue;
|
||||
int obsId = peer.AssignedContenderId;
|
||||
|
||||
// Check PVS-enter resyncs
|
||||
// Track PVS transitions & lifecycle snaps
|
||||
for (int i = 0; i < _session.State.Contenders.Count; i++)
|
||||
{
|
||||
var c = _session.State.Contenders[i];
|
||||
bool inPvs = _session.IsEntityInPeerPvs(obsId, true, c.Id);
|
||||
bool inPvs = c.Id == obsId || _session.IsEntityInPeerPvs(obsId, true, c.Id);
|
||||
ref var tracker = ref peer.ContenderTrackers[i];
|
||||
if (c.Lifecycle != tracker.LastLifecycle)
|
||||
{
|
||||
|
|
@ -596,22 +616,6 @@ namespace RustToDust.Net
|
|||
if (inPvs && !tracker.InPvs)
|
||||
{
|
||||
tracker.SnapNext = true;
|
||||
if (tracker.AckedLoadoutVersion != c.LoadoutVersion || tracker.AckedDamageVersion != c.DamageVersion)
|
||||
{
|
||||
tracker.AckedLoadoutVersion = c.LoadoutVersion;
|
||||
tracker.AckedDamageVersion = c.DamageVersion;
|
||||
SendSchemaToPeer(peer, new EntitySyncSnapshotMsg
|
||||
{
|
||||
IsContender = true,
|
||||
EntityId = c.Id,
|
||||
Alive = c.Alive,
|
||||
PosX = c.X, PosY = c.Y, PosZ = c.Z, Yaw = c.Yaw,
|
||||
CoreHp = c.Grid.CoreHp,
|
||||
MaxCoreHp = c.Grid.MaxCoreHp,
|
||||
ArmorBytes = c.Grid.QuantizeArmorBytes(),
|
||||
ContenderLoadout = ArenaSession.BuildContenderLoadoutEvent(c, includeCargo: c.Id == obsId)
|
||||
});
|
||||
}
|
||||
}
|
||||
tracker.InPvs = inPvs;
|
||||
}
|
||||
|
|
@ -672,6 +676,7 @@ namespace RustToDust.Net
|
|||
{
|
||||
var c = _session.State.Contenders[loadout.ContenderId];
|
||||
peer.ContenderTrackers[loadout.ContenderId].AckedLoadoutVersion = c.LoadoutVersion;
|
||||
peer.ContenderTrackers[loadout.ContenderId].AckedDamageVersion = c.DamageVersion;
|
||||
filtered.Add(loadout.ContenderId == obsId
|
||||
? loadout
|
||||
: ArenaSession.BuildContenderLoadoutEvent(c, includeCargo: false));
|
||||
|
|
@ -767,12 +772,52 @@ namespace RustToDust.Net
|
|||
case DropPodEvent dpe:
|
||||
{
|
||||
var kind = (DropPodEventKind)dpe.Kind;
|
||||
bool deliver = kind == DropPodEventKind.WaveAnnounced ||
|
||||
bool inPvs = kind == DropPodEventKind.WaveAnnounced ||
|
||||
(dpe.ContenderId == obsId) ||
|
||||
(dpe.PodKind == (byte)OrbitalPodKind.Contender && dpe.ContenderId >= 0 &&
|
||||
_session.IsEntityInPeerPvs(obsId, true, dpe.ContenderId)) ||
|
||||
_session.IsPointInPeerPvs(obsId, dpe.X, dpe.Y + 2.0f, dpe.Z);
|
||||
if (deliver)
|
||||
|
||||
if (kind == DropPodEventKind.PodLaunched)
|
||||
{
|
||||
if (inPvs)
|
||||
{
|
||||
peer.SentPodIds.Add(dpe.PodId);
|
||||
filtered.Add(dpe);
|
||||
}
|
||||
}
|
||||
else if (kind == DropPodEventKind.PodTouchdownBlowPetals || kind == DropPodEventKind.PodCancelled)
|
||||
{
|
||||
bool wasSent = peer.SentPodIds.Remove(dpe.PodId);
|
||||
if (inPvs && kind == DropPodEventKind.PodTouchdownBlowPetals)
|
||||
{
|
||||
filtered.Add(dpe);
|
||||
}
|
||||
else if (wasSent)
|
||||
{
|
||||
filtered.Add(new DropPodEvent
|
||||
{
|
||||
EventId = dpe.EventId,
|
||||
Kind = (byte)DropPodEventKind.PodCancelled,
|
||||
WaveIndex = dpe.WaveIndex,
|
||||
PodId = dpe.PodId,
|
||||
PodKind = dpe.PodKind,
|
||||
ContenderId = dpe.ContenderId == obsId ? obsId : -1,
|
||||
X = 0f,
|
||||
Y = 0f,
|
||||
Z = 0f,
|
||||
VelX = 0f,
|
||||
VelY = 0f,
|
||||
VelZ = 0f,
|
||||
NormalX = 0f,
|
||||
NormalY = 1f,
|
||||
NormalZ = 0f,
|
||||
DropId = 0,
|
||||
RespawnsClosed = dpe.RespawnsClosed
|
||||
});
|
||||
}
|
||||
}
|
||||
else if (inPvs)
|
||||
{
|
||||
filtered.Add(dpe);
|
||||
}
|
||||
|
|
@ -784,6 +829,30 @@ namespace RustToDust.Net
|
|||
}
|
||||
}
|
||||
|
||||
// Sync any PVS-visible contender (including local player!) whose loadout/damage version still differs
|
||||
for (int i = 0; i < _session.State.Contenders.Count; i++)
|
||||
{
|
||||
ref var tracker = ref peer.ContenderTrackers[i];
|
||||
if (!tracker.InPvs) continue;
|
||||
var c = _session.State.Contenders[i];
|
||||
if (tracker.AckedLoadoutVersion != c.LoadoutVersion || tracker.AckedDamageVersion != c.DamageVersion)
|
||||
{
|
||||
tracker.AckedLoadoutVersion = c.LoadoutVersion;
|
||||
tracker.AckedDamageVersion = c.DamageVersion;
|
||||
SendSchemaToPeer(peer, new EntitySyncSnapshotMsg
|
||||
{
|
||||
IsContender = true,
|
||||
EntityId = c.Id,
|
||||
Alive = c.Alive,
|
||||
PosX = c.X, PosY = c.Y, PosZ = c.Z, Yaw = c.Yaw,
|
||||
CoreHp = c.Grid.CoreHp,
|
||||
MaxCoreHp = c.Grid.MaxCoreHp,
|
||||
ArmorBytes = c.Grid.QuantizeArmorBytes(),
|
||||
ContenderLoadout = ArenaSession.BuildContenderLoadoutEvent(c, includeCargo: c.Id == obsId)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (filtered.Count > 0)
|
||||
{
|
||||
SendSchemaToPeer(peer, new SimEventBatchMsg
|
||||
|
|
@ -1130,14 +1199,7 @@ namespace RustToDust.Net
|
|||
for (int i = 0; i < activePods.Count; i++)
|
||||
{
|
||||
var pod = activePods[i];
|
||||
if (pod.PodKind == OrbitalPodKind.Contender &&
|
||||
pod.ContenderId != forContenderId &&
|
||||
!_session.IsEntityInPeerPvs(forContenderId, true, pod.ContenderId))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (pod.PodKind != OrbitalPodKind.Contender &&
|
||||
!_session.IsPointInPeerPvs(forContenderId, pod.X, pod.Y + 2.0f, pod.Z))
|
||||
if (!IsPodVisibleToPeer(forContenderId, pod))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ namespace RustToDust.Ymir
|
|||
|
||||
State.ChassisSwapped += OnContenderChassisSwapped;
|
||||
State.LoadoutChanged += OnContenderLoadoutChanged;
|
||||
State.ContenderRespawned += OnContenderLoadoutChanged;
|
||||
State.DropSpawned += OnDropSpawned;
|
||||
State.DropPickedUp += OnDropPickedUp;
|
||||
State.ContenderPodTouchedDown += OnContenderPodTouchedDown;
|
||||
|
|
@ -833,89 +834,114 @@ namespace RustToDust.Ymir
|
|||
}
|
||||
}
|
||||
|
||||
public DropSurfaceSample QueryDropSurface(float x, float z, float footRadius, float referenceMaxY)
|
||||
public DropSurfaceSample QueryDropSurface(float x, float z, float footRadius, float referenceMaxY) =>
|
||||
QueryDropSurface(State, _world, x, z, footRadius, referenceMaxY);
|
||||
|
||||
public static DropSurfaceSample QueryDropSurface(
|
||||
MatchState state,
|
||||
Box3DSoaWorld? world,
|
||||
float x,
|
||||
float z,
|
||||
float footRadius,
|
||||
float referenceMaxY)
|
||||
{
|
||||
float terrainY = State.Terrain.SampleHeight(x, z);
|
||||
var (nx, ny, nz) = State.Terrain.SampleNormal(x, z);
|
||||
float terrainY = state.Terrain.SampleHeight(x, z);
|
||||
var (nx, ny, nz) = state.Terrain.SampleNormal(x, z);
|
||||
Vector3 terrainNorm = new(nx, ny, nz);
|
||||
if (terrainNorm.LengthSquared() < 1e-4f) terrainNorm = Vector3.UnitY;
|
||||
else terrainNorm = Vector3.Normalize(terrainNorm);
|
||||
|
||||
if (State.MapKind == ArenaMapKind.Sion && State.SionMap is { } sionMap)
|
||||
if (state.MapKind == ArenaMapKind.Sion && state.SionMap is { } sionMap)
|
||||
{
|
||||
if (!sionMap.TryGetBuildingAt(x, z, footRadius, out var bldg))
|
||||
bool centerOverBuilding = sionMap.TryGetBuildingAt(x, z, 0f, out var centerBldg);
|
||||
bool lateralWallOverlap = centerOverBuilding || sionMap.TryGetBuildingAt(x, z, footRadius, out _);
|
||||
|
||||
if (!centerOverBuilding)
|
||||
{
|
||||
return new DropSurfaceSample(
|
||||
terrainY,
|
||||
terrainNorm,
|
||||
IsBuildingRoof: false,
|
||||
IsFlatRoofValid: false,
|
||||
IsInsideBuildingFootprint: false);
|
||||
IsInsideBuildingFootprint: lateralWallOverlap);
|
||||
}
|
||||
|
||||
float castStartY = MathF.Max(referenceMaxY, bldg.RoofY + 6f);
|
||||
float castSpan = MathF.Max(20f, castStartY - (terrainY - 12f));
|
||||
var centerHit = _world.CastRayClosest((x, castStartY, z), (0f, -castSpan, 0f));
|
||||
if (centerHit.Hit &&
|
||||
centerHit.StableId >= StaticMeshStableIdBase &&
|
||||
centerHit.StableId < ContenderStableIdBase)
|
||||
if (world is not null)
|
||||
{
|
||||
float roofY = centerHit.Point.Y;
|
||||
Vector3 roofNorm = new(centerHit.Normal.X, centerHit.Normal.Y, centerHit.Normal.Z);
|
||||
if (roofNorm.LengthSquared() < 1e-4f) roofNorm = Vector3.UnitY;
|
||||
else roofNorm = Vector3.Normalize(roofNorm);
|
||||
|
||||
bool flatValid = false;
|
||||
if (roofNorm.Y >= 0.90f)
|
||||
float castStartY = MathF.Max(referenceMaxY, centerBldg.RoofY + 6f);
|
||||
float castSpan = MathF.Max(20f, castStartY - (terrainY - 12f));
|
||||
var centerHit = world.CastRayClosest((x, castStartY, z), (0f, -castSpan, 0f));
|
||||
if (centerHit.Hit &&
|
||||
centerHit.StableId >= StaticMeshStableIdBase &&
|
||||
centerHit.StableId < ContenderStableIdBase)
|
||||
{
|
||||
flatValid = true;
|
||||
float r = MathF.Max(0.8f, footRadius);
|
||||
ReadOnlySpan<(float Ox, float Oz)> offsets = stackalloc (float, float)[]
|
||||
float roofY = centerHit.Point.Y;
|
||||
if (roofY > referenceMaxY || roofY <= terrainY + 0.1f)
|
||||
{
|
||||
(-r, -r), (r, -r), (-r, r), (r, r)
|
||||
};
|
||||
for (int k = 0; k < 4; k++)
|
||||
return new DropSurfaceSample(
|
||||
terrainY,
|
||||
terrainNorm,
|
||||
IsBuildingRoof: false,
|
||||
IsFlatRoofValid: false,
|
||||
IsInsideBuildingFootprint: true);
|
||||
}
|
||||
|
||||
Vector3 roofNorm = new(centerHit.Normal.X, centerHit.Normal.Y, centerHit.Normal.Z);
|
||||
if (roofNorm.LengthSquared() < 1e-4f) roofNorm = Vector3.UnitY;
|
||||
else roofNorm = Vector3.Normalize(roofNorm);
|
||||
|
||||
bool flatValid = false;
|
||||
if (roofNorm.Y >= 0.90f)
|
||||
{
|
||||
float cx = x + offsets[k].Ox;
|
||||
float cz = z + offsets[k].Oz;
|
||||
var cornerHit = _world.CastRayClosest((cx, roofY + 2.5f, cz), (0f, -5.0f, 0f));
|
||||
if (!cornerHit.Hit ||
|
||||
cornerHit.StableId < StaticMeshStableIdBase ||
|
||||
cornerHit.StableId >= ContenderStableIdBase ||
|
||||
MathF.Abs(cornerHit.Point.Y - roofY) > 0.45f)
|
||||
flatValid = true;
|
||||
float r = MathF.Max(0.8f, footRadius);
|
||||
ReadOnlySpan<(float Ox, float Oz)> offsets = stackalloc (float, float)[]
|
||||
{
|
||||
flatValid = false;
|
||||
break;
|
||||
}
|
||||
var aboveHit = _world.CastRayClosest((cx, roofY + 60f, cz), (0f, -58f, 0f));
|
||||
if (aboveHit.Hit &&
|
||||
aboveHit.StableId >= StaticMeshStableIdBase &&
|
||||
aboveHit.StableId < ContenderStableIdBase &&
|
||||
aboveHit.Point.Y > roofY + 0.6f)
|
||||
(-r, -r), (r, -r), (-r, r), (r, r)
|
||||
};
|
||||
for (int k = 0; k < 4; k++)
|
||||
{
|
||||
flatValid = false;
|
||||
break;
|
||||
float cx = x + offsets[k].Ox;
|
||||
float cz = z + offsets[k].Oz;
|
||||
var cornerHit = world.CastRayClosest((cx, roofY + 2.5f, cz), (0f, -5.0f, 0f));
|
||||
if (!cornerHit.Hit ||
|
||||
cornerHit.StableId < StaticMeshStableIdBase ||
|
||||
cornerHit.StableId >= ContenderStableIdBase ||
|
||||
MathF.Abs(cornerHit.Point.Y - roofY) > 0.45f)
|
||||
{
|
||||
flatValid = false;
|
||||
break;
|
||||
}
|
||||
var aboveHit = world.CastRayClosest((cx, roofY + 60f, cz), (0f, -58f, 0f));
|
||||
if (aboveHit.Hit &&
|
||||
aboveHit.StableId >= StaticMeshStableIdBase &&
|
||||
aboveHit.StableId < ContenderStableIdBase &&
|
||||
aboveHit.Point.Y > roofY + 0.6f)
|
||||
{
|
||||
flatValid = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new DropSurfaceSample(
|
||||
MathF.Max(terrainY, roofY),
|
||||
roofNorm,
|
||||
IsBuildingRoof: true,
|
||||
IsFlatRoofValid: flatValid,
|
||||
IsInsideBuildingFootprint: true);
|
||||
}
|
||||
|
||||
return new DropSurfaceSample(
|
||||
MathF.Max(terrainY, roofY),
|
||||
roofNorm,
|
||||
IsBuildingRoof: true,
|
||||
IsFlatRoofValid: flatValid,
|
||||
IsInsideBuildingFootprint: true);
|
||||
terrainY,
|
||||
terrainNorm,
|
||||
IsBuildingRoof: false,
|
||||
IsFlatRoofValid: false,
|
||||
IsInsideBuildingFootprint: lateralWallOverlap);
|
||||
}
|
||||
|
||||
return new DropSurfaceSample(
|
||||
MathF.Max(terrainY, bldg.RoofY),
|
||||
terrainNorm,
|
||||
IsBuildingRoof: true,
|
||||
IsFlatRoofValid: false,
|
||||
IsInsideBuildingFootprint: true);
|
||||
}
|
||||
|
||||
return State.DefaultDropSurfaceQuery(x, z, footRadius, referenceMaxY);
|
||||
return state.DefaultDropSurfaceQuery(x, z, footRadius, referenceMaxY);
|
||||
}
|
||||
|
||||
public static float GetPhysicsHalfHeight(ChassisSpec spec) =>
|
||||
|
|
@ -3147,6 +3173,7 @@ namespace RustToDust.Ymir
|
|||
_disposed = true;
|
||||
State.ChassisSwapped -= OnContenderChassisSwapped;
|
||||
State.LoadoutChanged -= OnContenderLoadoutChanged;
|
||||
State.ContenderRespawned -= OnContenderLoadoutChanged;
|
||||
State.DropSpawned -= OnDropSpawned;
|
||||
State.DropPickedUp -= OnDropPickedUp;
|
||||
State.ContenderPodTouchedDown -= OnContenderPodTouchedDown;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in a new issue