cut11b: widen plant reach for steep slopes and add Option A regression tests
This commit is contained in:
parent
857bbd8f30
commit
70e4052452
3 changed files with 476 additions and 1 deletions
|
|
@ -797,6 +797,155 @@ namespace RustToDust.Tests
|
|||
"Client must receive Exemplar walker snapshot even under dense 12 quad-walker contention");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void OptionA_WalkerReplication_ChassisSwapLegCount_PvsExitClears_AndIdlePostBlastSync()
|
||||
{
|
||||
// 1. Direct snapshot interpolation guards: LegCount mismatch & >4m teleport jump must snap cleanly to curr
|
||||
var snap2Leg = new WalkerVisualSnapshot
|
||||
{
|
||||
HipYaw = 0f,
|
||||
ComPos = new Vector3(10f, 4f, 10f),
|
||||
PelvisOffset = Vector3.Zero,
|
||||
LeanPitch = 0.05f,
|
||||
LeanRoll = 0f,
|
||||
Scale = 1f,
|
||||
LegCount = 2,
|
||||
IsArachnidUp = false,
|
||||
IsDigitigrade = true,
|
||||
LegSoles = new[] { new Vector3(9f, 0f, 10f), new Vector3(11f, 0f, 10f), Vector3.Zero, Vector3.Zero }
|
||||
};
|
||||
var snap4Leg = new WalkerVisualSnapshot
|
||||
{
|
||||
HipYaw = 1.2f,
|
||||
ComPos = new Vector3(12f, 5f, 12f),
|
||||
PelvisOffset = new Vector3(0f, -0.1f, 0f),
|
||||
LeanPitch = -0.05f,
|
||||
LeanRoll = 0.04f,
|
||||
Scale = 1.15f,
|
||||
LegCount = 4,
|
||||
IsArachnidUp = false,
|
||||
IsDigitigrade = false,
|
||||
LegSoles = new[]
|
||||
{
|
||||
new Vector3(10f, 0f, 10f),
|
||||
new Vector3(14f, 0f, 10f),
|
||||
new Vector3(10f, 0f, 14f),
|
||||
new Vector3(14f, 0f, 14f)
|
||||
}
|
||||
};
|
||||
var swapInterp = WalkerVisualSnapshot.Interpolate(in snap2Leg, in snap4Leg, 0.5f);
|
||||
Assert.Equal(4, swapInterp.LegCount);
|
||||
Assert.Equal(snap4Leg.ComPos, swapInterp.ComPos);
|
||||
|
||||
var snap4Far = snap4Leg;
|
||||
snap4Far.ComPos = new Vector3(95f, 5f, 95f);
|
||||
var jumpInterp = WalkerVisualSnapshot.Interpolate(in snap4Leg, in snap4Far, 0.5f);
|
||||
Assert.Equal(snap4Far.ComPos, jumpInterp.ComPos);
|
||||
|
||||
// 2. End-to-end ServerMatchHost + RemoteArenaSession checks
|
||||
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, "NetWalker");
|
||||
long nowMs = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
||||
Assert.True(PumpUntil(host, new[] { client }, () => client.IsJoined, ref nowMs, 3000));
|
||||
int slot = client.LocalContenderId;
|
||||
int rivalId = (slot + 1) % MatchState.ContenderCount;
|
||||
|
||||
// Isolate others far away; put rival close to client as 2-leg Breaker
|
||||
for (int i = 0; i < MatchState.ContenderCount; i++)
|
||||
{
|
||||
if (i == slot) host.Session.SetContenderPose(i, 0f, 0f, 0f);
|
||||
else if (i == rivalId) host.Session.SetContenderPose(i, 16f, 0f, 0f);
|
||||
else host.Session.SetContenderPose(i, 900f + i * 20f, 900f);
|
||||
}
|
||||
host.Session.State.SpawnChassisDrop(16f, 0f, Catalog.Breaker);
|
||||
Assert.True(host.Session.TrySwapNearbyChassis(rivalId));
|
||||
|
||||
bool sawRival2Leg = PumpUntil(
|
||||
host,
|
||||
new[] { client },
|
||||
() => client.TrySampleInterpolatedWalkerPose(true, rivalId, 1f, out var s) && s.LegCount == 2,
|
||||
ref nowMs,
|
||||
2500);
|
||||
Assert.True(sawRival2Leg, "Expected client to observe 2-leg rival Breaker snapshot");
|
||||
|
||||
// Swap rival to 4-leg Bastion via genuine chassis swap event (must emit ContenderLoadoutEvent & clear timeline)
|
||||
var rival = host.Session.State.Contenders[rivalId];
|
||||
host.Session.State.SpawnChassisDrop(rival.X, rival.Z, Catalog.Bastion);
|
||||
Assert.True(host.Session.TrySwapNearbyChassis(rivalId));
|
||||
|
||||
bool sawRival4Leg = PumpUntil(
|
||||
host,
|
||||
new[] { client },
|
||||
() => client.TrySampleInterpolatedWalkerPose(true, rivalId, 1f, out var s) && s.LegCount == 4,
|
||||
ref nowMs,
|
||||
2500);
|
||||
Assert.True(sawRival4Leg, "Expected client to swap rival walker timeline cleanly to 4-leg Bastion");
|
||||
|
||||
// Rival leaves PVS (>450m away) -> client must clear timeline rather than serving stale pose
|
||||
host.Session.SetContenderPose(rivalId, 650f, 650f, 0f);
|
||||
bool rivalCleared = PumpUntil(
|
||||
host,
|
||||
new[] { client },
|
||||
() => !client.TrySampleInterpolatedWalkerPose(true, rivalId, 1f, out _),
|
||||
ref nowMs,
|
||||
2500);
|
||||
Assert.True(rivalCleared, "Expected client to clear rival walker timeline upon PVS exit");
|
||||
|
||||
// Rival re-enters PVS at (-18, 0) -> must immediately appear near -18 rather than sliding from old +16 position!
|
||||
host.Session.SetContenderPose(rivalId, -18f, 0f, 0f);
|
||||
WalkerVisualSnapshot reenterSnap = default;
|
||||
bool reentered = PumpUntil(
|
||||
host,
|
||||
new[] { client },
|
||||
() => client.TrySampleInterpolatedWalkerPose(true, rivalId, 0.25f, out reenterSnap),
|
||||
ref nowMs,
|
||||
2500);
|
||||
Assert.True(reentered, "Expected rival walker to re-enter client PVS");
|
||||
Assert.True(reenterSnap.ComPos.X < -10f,
|
||||
$"Expected rival re-entry to snap near X=-18 instead of blending from stale X=+16 (got X={reenterSnap.ComPos.X:F2})");
|
||||
|
||||
// 3. Idle local walker post-blast server reconciliation (_unackedInputs.Count == 0):
|
||||
// Ensure local client is grounded and settled with NO pending movement inputs, then apply upward blast on server
|
||||
var localContender = host.Session.State.Contenders[slot];
|
||||
var localBody = host.Session.GetContenderBody(slot)!.Value;
|
||||
var localWs = host.Session.GetWalkerState(true, slot)!;
|
||||
var view = host.Session.World.View;
|
||||
int lane = localBody.Lane;
|
||||
|
||||
Assert.True(client.TrySampleInterpolatedWalkerPose(true, slot, 1f, out var preBlastSnap),
|
||||
"Expected local walker prediction snapshot while grounded idle");
|
||||
float preBlastY = preBlastSnap.ComPos.Y;
|
||||
|
||||
const float blastVy = 9.0f;
|
||||
localWs.NotifyExternalUpwardImpulse(blastVy);
|
||||
host.Session.World.ApplyImpulse(lane, (0f, view.Mass[lane] * blastVy, 0f), (view.PositionX[lane], view.PositionY[lane], view.PositionZ[lane]));
|
||||
|
||||
bool sawBlastClimb = false;
|
||||
for (int t = 0; t < 25; t++)
|
||||
{
|
||||
nowMs += 16;
|
||||
host.StepOnce(nowMs);
|
||||
client.PumpNetwork(nowMs);
|
||||
client.BeginRenderFrame(1.0 / 60.0, 1f);
|
||||
Thread.Sleep(1);
|
||||
if (client.TrySampleInterpolatedWalkerPose(true, slot, 1f, out var postBlastSnap))
|
||||
{
|
||||
if (postBlastSnap.ComPos.Y >= preBlastY + 0.40f)
|
||||
{
|
||||
sawBlastClimb = true;
|
||||
for (int i = 0; i < postBlastSnap.LegCount; i++)
|
||||
{
|
||||
float surfY = host.Session.State.Terrain.SampleHeight(postBlastSnap.LegSoles[i].X, postBlastSnap.LegSoles[i].Z);
|
||||
Assert.True(postBlastSnap.LegSoles[i].Y >= surfY - 0.10f,
|
||||
$"Idle post-blast pred foot {i} dove underground ({postBlastSnap.LegSoles[i].Y:F2} < {surfY:F2})");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Assert.True(sawBlastClimb, "Idle local client must sync _predWalker smoothly to server upward blast without stale prediction lock");
|
||||
}
|
||||
|
||||
private static byte[] EncodeRudpLatestDatagram(byte[] frameBytes, uint sequence) =>
|
||||
CultNetRudpPacketCodec.Encode(new CultNetRudpPacket
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue