Merge origin/nibu/rtd-prototype (5820817) into nibu/rtd-cut13a-terrain

This commit is contained in:
Meta Vens 2026-12-06 01:41:22 +01:00
commit 9a07a4bc43
56 changed files with 5490 additions and 345 deletions

View file

@ -917,6 +917,51 @@ namespace RustToDust.Tests
$"Expected liveHostEdgeH ({liveHostEdgeH:F4}) == postResetHostEdgeH ({postResetHostEdgeH:F4}) within 0.001m");
}
[Fact]
public void RemoteArenaSession_AppliesRemoteContenderCoreHpRatioOnPvsSnapshot()
{
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, "HpProbe");
long nowMs = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
Assert.True(PumpUntil(host, new[] { client }, () => client.IsJoined, ref nowMs, 3000));
int localSlot = client.LocalContenderId;
int rivalSlot = localSlot == 0 ? 1 : 0;
var serverLocal = host.Session.State.Contenders[localSlot];
var serverRival = host.Session.State.Contenders[rivalSlot];
host.Session.SetContenderPose(localSlot, 0f, 0f, 0f);
host.Session.SetContenderPose(rivalSlot, 0f, 40f, MathF.PI);
float targetHp = serverRival.Grid.MaxCoreHp * 0.42f;
serverRival.Grid.ApplyReplicatedDamage(0, 0, 0f, 20f, targetHp, serverRival.Grid.HitSequence + 1);
float expectedRatio = serverRival.Grid.CoreHp / serverRival.Grid.MaxCoreHp;
bool synced = PumpUntil(host, new[] { client }, () =>
{
if (!client.IsContenderVisible(rivalSlot)) return false;
var c = client.ViewState.Contenders[rivalSlot];
float r = c.Grid.MaxCoreHp > 0f ? c.Grid.CoreHp / c.Grid.MaxCoreHp : 1f;
return MathF.Abs(r - expectedRatio) < 0.02f;
}, ref nowMs, 2500);
var clientRival = client.ViewState.Contenders[rivalSlot];
float actualRatio = clientRival.Grid.MaxCoreHp > 0f ? clientRival.Grid.CoreHp / clientRival.Grid.MaxCoreHp : 1f;
Assert.True(synced, $"Expected remote contender {rivalSlot} CoreHpRatio ~ {expectedRatio:F3}, got {actualRatio:F3}");
// Edge case: living rival at 0.30 HP rounds 8-bit CoreHpRatio to 0, yet must remain Alive on remote client
serverRival.Grid.ApplyReplicatedDamage(0, 0, 0f, 20f, 0.30f, serverRival.Grid.HitSequence + 1);
Assert.True(serverRival.Alive);
bool lowHpSynced = PumpUntil(host, new[] { client }, () =>
{
var c = client.ViewState.Contenders[rivalSlot];
return c.Alive && c.Grid.CoreHp > 0f && c.Grid.CoreHp <= 0.5f;
}, ref nowMs, 2500);
Assert.True(lowHpSynced && clientRival.Alive && !clientRival.Grid.IsDestroyed && clientRival.Grid.CoreHp > 0f,
$"Expected living 0.30 HP rival to stay Alive on remote client, got Alive={clientRival.Alive}, CoreHp={clientRival.Grid.CoreHp:F3}");
}
private static byte[] EncodeRudpLatestDatagram(byte[] frameBytes, uint sequence) =>
CultNetRudpPacketCodec.Encode(new CultNetRudpPacket
{