Cut 13a: 0.5m Sion DEM, compute TerrainRenderer, tiled Box3D heightfields, and scar ledger
This commit is contained in:
parent
fb9a706b84
commit
e86fee31da
34 changed files with 3360 additions and 1033 deletions
|
|
@ -797,6 +797,87 @@ namespace RustToDust.Tests
|
|||
"Client must receive Exemplar walker snapshot even under dense 12 quad-walker contention");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Cut13a_OutOfPvsHistoricalCratersSyncViaPersistentScars_AndLiveCratersEnterWithin576mBubble()
|
||||
{
|
||||
using var host = new ServerMatchHost(IPAddress.Loopback, 0, seed: 42, ArenaMapKind.Sion, maxHumans: 12, autoRestartSec: 0);
|
||||
var ep = new IPEndPoint(IPAddress.Loopback, host.BoundPort);
|
||||
|
||||
const float histX = 700f;
|
||||
const float histZ = 700f;
|
||||
float baseHistH = host.Session.State.Terrain.SampleHeight(histX, histZ);
|
||||
|
||||
// 1. Historical out-of-PVS crater stamped before Client A joins
|
||||
((IOrdnanceTargetSink)host.Session).StampTerrainImpact(histX, histZ, craterRadius: 6f, craterDepth: 2.0f, scorchRadius: 7f);
|
||||
long nowMs = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
||||
host.StepOnce(nowMs += 16);
|
||||
float scarredHistH = host.Session.State.Terrain.SampleHeight(histX, histZ);
|
||||
Assert.True(scarredHistH < baseHistH - 1.2f);
|
||||
|
||||
using var clientA = new RemoteArenaSession(ep, "Scout");
|
||||
Assert.True(PumpUntil(host, new[] { clientA }, () => clientA.IsJoined, ref nowMs, 3000));
|
||||
|
||||
// Out-of-PVS historical crater must be present immediately via PersistentScars
|
||||
Assert.Equal(scarredHistH, clientA.ViewState.Terrain.SampleHeight(histX, histZ), precision: 3);
|
||||
Assert.InRange(clientA.PredTileSync.ResidentTileCount, 1, 9);
|
||||
|
||||
// 2. Live crater stamped far outside 576m bubble (-700, 100 vs open-sky ~700, 100 = ~1400m apart)
|
||||
int slotA = clientA.LocalContenderId;
|
||||
var sion = host.Session.State.SionMap!;
|
||||
float liveX = 700f, liveZ = 100f;
|
||||
for (float x = 640f; x <= 760f; x += 8f)
|
||||
{
|
||||
if (!sion.IsInsideAnyBuildingXz(x, liveZ, padding: 10f))
|
||||
{
|
||||
liveX = x;
|
||||
break;
|
||||
}
|
||||
}
|
||||
float baseLiveH = host.Session.State.Terrain.SampleHeight(liveX, liveZ);
|
||||
|
||||
host.Session.SetContenderPose(slotA, -700f, liveZ, 0f);
|
||||
host.StepOnce(nowMs += 16);
|
||||
((IOrdnanceTargetSink)host.Session).StampTerrainImpact(liveX, liveZ, craterRadius: 6f, craterDepth: 2.0f, scorchRadius: 7f);
|
||||
for (int t = 0; t < 10; t++)
|
||||
{
|
||||
nowMs += 16;
|
||||
host.StepOnce(nowMs);
|
||||
clientA.PumpNetwork();
|
||||
Thread.Sleep(1);
|
||||
}
|
||||
float hostLiveH = host.Session.State.Terrain.SampleHeight(liveX, liveZ);
|
||||
Assert.True(hostLiveH < baseLiveH - 1.2f);
|
||||
Assert.Equal(baseLiveH, clientA.ViewState.Terrain.SampleHeight(liveX, liveZ), precision: 3);
|
||||
|
||||
// 3. Client A enters 576m local geometry bubble (liveX - 450m -> dist = 450m <= 576m)
|
||||
host.Session.SetContenderPose(slotA, liveX - 450f, liveZ, 0f);
|
||||
Assert.True(PumpUntil(
|
||||
host,
|
||||
new[] { clientA },
|
||||
() => MathF.Abs(clientA.ViewState.Terrain.SampleHeight(liveX, liveZ) - hostLiveH) < 0.05f,
|
||||
ref nowMs,
|
||||
3000),
|
||||
"Client must receive live TerrainStampEvent upon entering 576m bubble before reaching _predWorld 3x3 window");
|
||||
|
||||
// 4. Client A steps into (liveX, liveZ) tile -> _predWorld 3x3 window matches server Box3D crater depth 1:1
|
||||
host.Session.SetContenderPose(slotA, liveX - 20f, liveZ, 0f);
|
||||
for (int t = 0; t < 10; t++)
|
||||
{
|
||||
nowMs += 16;
|
||||
host.StepOnce(nowMs);
|
||||
clientA.BeginRenderFrame(1.0 / 60.0, 1f);
|
||||
Thread.Sleep(1);
|
||||
}
|
||||
Assert.InRange(clientA.PredTileSync.ResidentTileCount, 1, 9);
|
||||
float rayStartY = sion.Metadata.MaxY + 25f;
|
||||
float raySpanY = -(sion.Metadata.MaxY - sion.Metadata.MinY + 60f);
|
||||
var hostHit = host.Session.CastWorldRayClosest(new Vector3(liveX, rayStartY, liveZ), new Vector3(0f, raySpanY, 0f));
|
||||
var predHit = clientA.CastWorldRayClosest(new Vector3(liveX, rayStartY, liveZ), new Vector3(0f, raySpanY, 0f));
|
||||
Assert.True(hostHit.Hit && predHit.Hit);
|
||||
Assert.True(MathF.Abs(hostHit.Point.Y - predHit.Point.Y) < 0.05f,
|
||||
$"Expected _predWorld crater impact Y ({predHit.Point.Y:F3}m) to match server ({hostHit.Point.Y:F3}m)");
|
||||
}
|
||||
|
||||
private static byte[] EncodeRudpLatestDatagram(byte[] frameBytes, uint sequence) =>
|
||||
CultNetRudpPacketCodec.Encode(new CultNetRudpPacket
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Numerics;
|
||||
using RustToDust.Core;
|
||||
using RustToDust.Net;
|
||||
using RustToDust.Ymir;
|
||||
using Xunit;
|
||||
using Ymir.Box3D;
|
||||
|
|
@ -16,20 +19,24 @@ namespace RustToDust.Tests
|
|||
var meta = sion.Metadata;
|
||||
|
||||
Assert.Equal(3072f, meta.SizeMeters);
|
||||
Assert.Equal(6, meta.TileGrid);
|
||||
Assert.Equal(512f, meta.TileSizeMeters);
|
||||
Assert.Equal(1025, meta.GridRes);
|
||||
Assert.Equal(3.0f, meta.CellSizeMeters);
|
||||
Assert.Equal(16, meta.TileGrid);
|
||||
Assert.Equal(192f, meta.TileSizeMeters);
|
||||
Assert.Equal(6145, meta.GridRes);
|
||||
Assert.Equal(0.5f, meta.CellSizeMeters);
|
||||
Assert.Equal("heightmap_05m.u16z", meta.HeightmapFile);
|
||||
Assert.False(string.IsNullOrWhiteSpace(meta.DemAssetHash));
|
||||
Assert.Contains("swisstopo", meta.Attribution, StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
Assert.Equal(1025 * 1025, sion.Heights.Length);
|
||||
Assert.Equal(6145 * 6145, sion.BaseDem.Length);
|
||||
Assert.Equal(2319, sion.Buildings.Count);
|
||||
Assert.Equal(36, sion.CollisionMeshes.Count);
|
||||
|
||||
var terrain = TerrainField.LoadHeightmap(
|
||||
meta.SizeMeters, meta.GridRes, sion.Heights, meta.MinY, meta.MaxY);
|
||||
var terrain = TerrainField.LoadSharedHeightmap(
|
||||
meta.SizeMeters, meta.GridRes, meta.TileGrid,
|
||||
sion.BaseDem, sion.BaseDemMinY, sion.BaseDemScale,
|
||||
meta.MinY, meta.MaxY);
|
||||
|
||||
// Verify Basilique de Valere and valley buildings align cleanly with heightmap.f32 (0.00m coordinate drift)
|
||||
// Verify Basilique de Valere and valley buildings align cleanly with heightmap_05m.u16z (0.00m coordinate drift)
|
||||
bool foundValere = false;
|
||||
int flatAlignChecked = 0;
|
||||
int closeAlignCount = 0;
|
||||
|
|
@ -82,16 +89,19 @@ namespace RustToDust.Tests
|
|||
{
|
||||
var sion = SionMapLoader.Load();
|
||||
var meta = sion.Metadata;
|
||||
var terrain = TerrainField.LoadHeightmap(
|
||||
meta.SizeMeters, meta.GridRes, sion.Heights, meta.MinY, meta.MaxY);
|
||||
var terrain = TerrainField.LoadSharedHeightmap(
|
||||
meta.SizeMeters, meta.GridRes, meta.TileGrid,
|
||||
sion.BaseDem, sion.BaseDemMinY, sion.BaseDemScale,
|
||||
meta.MinY, meta.MaxY);
|
||||
|
||||
Assert.True(terrain.IsHeightmapMode);
|
||||
Assert.Equal(3072f, terrain.MapSize);
|
||||
Assert.Equal(1536f, terrain.MapHalfExtent);
|
||||
Assert.Equal(16, terrain.TileGridCount);
|
||||
|
||||
// Grid vertex exactness at (-1536, -1536) and (0, 0)
|
||||
Assert.Equal(sion.Heights[0], terrain.SampleHeight(-1536f, -1536f), precision: 4);
|
||||
Assert.Equal(sion.Heights[512 * 1025 + 512], terrain.SampleHeight(0f, 0f), precision: 4);
|
||||
Assert.Equal(sion.SampleBaseDemAtIndex(0), terrain.SampleHeight(-1536f, -1536f), precision: 4);
|
||||
Assert.Equal(sion.SampleBaseDemAtIndex(3072 * 6145 + 3072), terrain.SampleHeight(0f, 0f), precision: 4);
|
||||
|
||||
// Plaza spawn area is flat; Valere hill rises > 100m
|
||||
var (_, plazaNy, _) = terrain.SampleNormal(-60f, 360f);
|
||||
|
|
@ -126,7 +136,7 @@ namespace RustToDust.Tests
|
|||
Assert.Empty(state.ArenaCoverBoxes);
|
||||
Assert.Equal(MatchState.SionInitialSafeRadius, state.Spectators.SafeRadius);
|
||||
|
||||
// Verify StaticHeightField (1) + StaticMesh (36) exist in Ymir
|
||||
// Verify lazy tiled StaticHeightField (192m tiles) + StaticMesh (36) exist in Ymir
|
||||
int hfCount = 0;
|
||||
int meshCount = 0;
|
||||
var view = session.World.View;
|
||||
|
|
@ -136,7 +146,8 @@ namespace RustToDust.Tests
|
|||
if (kind == Box3DSoaKind.StaticHeightField) hfCount++;
|
||||
else if (kind == Box3DSoaKind.StaticMesh) meshCount++;
|
||||
}
|
||||
Assert.Equal(1, hfCount);
|
||||
Assert.InRange(hfCount, 1, 255);
|
||||
Assert.Equal(hfCount, session.TileSync.ResidentTileCount);
|
||||
Assert.Equal(36, meshCount);
|
||||
|
||||
// Verify zero contenders, spectators, or drops spawned inside any building
|
||||
|
|
@ -225,5 +236,147 @@ namespace RustToDust.Tests
|
|||
float pDisp = MathF.Sqrt((player.X - pStartX) * (player.X - pStartX) + (player.Z - pStartZ) * (player.Z - pStartZ));
|
||||
Assert.True(pDisp > 5f, $"Expected player displacement > 5m on Sion after 180 ticks, got {pDisp:F2}m");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SionBox3DTile_CraterRebuildsLocalTileOnlyAndLeavesNeighborsIntact()
|
||||
{
|
||||
using var session = new ArenaSession(seed: 42, ArenaMapKind.Sion, slot0Human: true, skipInitialDrop: true);
|
||||
var terrain = session.State.Terrain;
|
||||
|
||||
// Tile (7, 7) spans [-192, 0) x [-192, 0); neighbor tile (8, 7) spans [0, 192) x [-192, 0).
|
||||
// Pick an open-sky coordinate strictly inside tile (7, 7) away from any building footprint.
|
||||
var sion = session.State.SionMap!;
|
||||
float cx = -96f, cz = -96f;
|
||||
bool foundSpot = false;
|
||||
for (float z = -176f; z <= -16f && !foundSpot; z += 8f)
|
||||
{
|
||||
for (float x = -176f; x <= -16f; x += 8f)
|
||||
{
|
||||
if (!sion.IsInsideAnyBuildingXz(x, z, padding: 10f))
|
||||
{
|
||||
cx = x;
|
||||
cz = z;
|
||||
foundSpot = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
Assert.True(foundSpot, "Expected open-sky spot inside Sion tile (7, 7)");
|
||||
|
||||
session.TileSync.EnsureTileRegion(session.World, terrain, cx, cz, halfTileRadius: 1);
|
||||
|
||||
Assert.True(session.TileSync.TryGetResidentHandle(7, 7, terrain.TileGridCount, out var handleTargetBefore));
|
||||
Assert.True(session.TileSync.TryGetResidentHandle(8, 7, terrain.TileGridCount, out var handleNeighborBefore));
|
||||
|
||||
float rayStartY = sion.Metadata.MaxY + 25f;
|
||||
float raySpanY = -(sion.Metadata.MaxY - sion.Metadata.MinY + 60f);
|
||||
var hitBefore = session.CastWorldRayClosest(new Vector3(cx, rayStartY, cz), new Vector3(0f, raySpanY, 0f));
|
||||
Assert.True(hitBefore.Hit);
|
||||
Assert.Equal(Box3DPhysicsTileSync.HeightfieldTileStableIdBase + (ulong)(7 * 16 + 7), hitBefore.StableId);
|
||||
|
||||
// Stamp crater strictly inside tile (7, 7)
|
||||
session.State.ApplyTerrainStamp(new TerrainStampEvent
|
||||
{
|
||||
Kind = (byte)TerrainStampKind.Crater,
|
||||
X = cx,
|
||||
Z = cz,
|
||||
Radius = 6f,
|
||||
Depth = 2.0f
|
||||
});
|
||||
int rebuilt = session.TileSync.FlushDirtyHeightfields(session.World, terrain, maxTilesPerTick: 4);
|
||||
Assert.Equal(1, rebuilt);
|
||||
|
||||
Assert.True(session.TileSync.TryGetResidentHandle(7, 7, terrain.TileGridCount, out var handleTargetAfter));
|
||||
Assert.True(session.TileSync.TryGetResidentHandle(8, 7, terrain.TileGridCount, out var handleNeighborAfter));
|
||||
|
||||
Assert.NotEqual(handleTargetBefore, handleTargetAfter);
|
||||
Assert.Equal(handleNeighborBefore, handleNeighborAfter);
|
||||
|
||||
var hitAfter = session.CastWorldRayClosest(new Vector3(cx, rayStartY, cz), new Vector3(0f, raySpanY, 0f));
|
||||
Assert.True(hitAfter.Hit);
|
||||
Assert.True(hitAfter.Point.Y < hitBefore.Point.Y - 1.2f,
|
||||
$"Expected Box3D raycast impact height to drop in crater (before={hitBefore.Point.Y:F3}, after={hitAfter.Point.Y:F3})");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ArenaScarLedgerStore_PersistsCratersAndRubbleAcrossResetAndRepairsToLayer0()
|
||||
{
|
||||
string tempDir = Path.Combine(Path.GetTempPath(), "rtd-cut13a-scar-test-" + Guid.NewGuid().ToString("N"));
|
||||
Directory.CreateDirectory(tempDir);
|
||||
string scarPath = Path.Combine(tempDir, "sion_scars_test.cultcache");
|
||||
|
||||
try
|
||||
{
|
||||
const float craterX = -120f;
|
||||
const float craterZ = 180f;
|
||||
const float rubbleX = 140f;
|
||||
const float rubbleZ = 180f;
|
||||
float baseCraterH;
|
||||
float baseRubbleH;
|
||||
float scarredCraterH;
|
||||
float scarredRubbleH;
|
||||
|
||||
using (var host1 = new ServerMatchHost(
|
||||
IPAddress.Loopback, 0, seed: 42, ArenaMapKind.Sion,
|
||||
autoRestartSec: 0, scarFilePath: scarPath, persistScars: true))
|
||||
{
|
||||
var state1 = host1.Session.State;
|
||||
baseCraterH = state1.Terrain.SampleHeight(craterX, craterZ);
|
||||
baseRubbleH = state1.Terrain.SampleHeight(rubbleX, rubbleZ);
|
||||
|
||||
state1.ApplyTerrainStamp(new TerrainStampEvent
|
||||
{
|
||||
Kind = (byte)TerrainStampKind.Crater,
|
||||
X = craterX,
|
||||
Z = craterZ,
|
||||
Radius = 5.5f,
|
||||
Depth = 1.8f
|
||||
});
|
||||
state1.ApplyTerrainStamp(new TerrainStampEvent
|
||||
{
|
||||
Kind = (byte)TerrainStampKind.Rubble,
|
||||
X = rubbleX,
|
||||
Z = rubbleZ,
|
||||
Radius = 6.0f,
|
||||
Depth = 1.2f,
|
||||
Yaw = 0.4f
|
||||
});
|
||||
|
||||
scarredCraterH = state1.Terrain.SampleHeight(craterX, craterZ);
|
||||
scarredRubbleH = state1.Terrain.SampleHeight(rubbleX, rubbleZ);
|
||||
Assert.True(scarredCraterH < baseCraterH - 1.2f);
|
||||
Assert.True(scarredRubbleH > baseRubbleH + 0.6f);
|
||||
|
||||
// ResetMatch preserves scars in RAM & flushes to CultCache
|
||||
host1.ResetMatch(43, ArenaMapKind.Sion, startInLobby: false);
|
||||
Assert.Equal(scarredCraterH, host1.Session.State.Terrain.SampleHeight(craterX, craterZ), precision: 3);
|
||||
Assert.Equal(scarredRubbleH, host1.Session.State.Terrain.SampleHeight(rubbleX, rubbleZ), precision: 3);
|
||||
}
|
||||
|
||||
Assert.True(File.Exists(scarPath), "Expected CultCache scar file on disk after host dispose");
|
||||
|
||||
using (var host2 = new ServerMatchHost(
|
||||
IPAddress.Loopback, 0, seed: 44, ArenaMapKind.Sion,
|
||||
autoRestartSec: 0, scarFilePath: scarPath, persistScars: true))
|
||||
{
|
||||
var state2 = host2.Session.State;
|
||||
Assert.Equal(scarredCraterH, state2.Terrain.SampleHeight(craterX, craterZ), precision: 3);
|
||||
Assert.Equal(scarredRubbleH, state2.Terrain.SampleHeight(rubbleX, rubbleZ), precision: 3);
|
||||
|
||||
// RepairArenaScars zeroes back to Layer 0
|
||||
host2.RepairArenaScars();
|
||||
Assert.Equal(baseCraterH, state2.Terrain.SampleHeight(craterX, craterZ), precision: 3);
|
||||
Assert.Equal(baseRubbleH, state2.Terrain.SampleHeight(rubbleX, rubbleZ), precision: 3);
|
||||
Assert.Empty(state2.ScarLedger.Terrain);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (Directory.Exists(tempDir))
|
||||
{
|
||||
Directory.Delete(tempDir, recursive: true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ namespace RustToDust.Tests
|
|||
public void Generate_ProducesDeterministicNonFlatReliefWithinBounds()
|
||||
{
|
||||
Assert.Equal(1536f, TerrainField.ArenaSize);
|
||||
Assert.Equal(8, TerrainField.TileGridCount);
|
||||
Assert.Equal(8, TerrainField.DesertTileGridCount);
|
||||
Assert.Equal(192f, TerrainField.TileSize);
|
||||
Assert.Equal(-18f, TerrainField.MinWorldHeight);
|
||||
Assert.Equal(52f, TerrainField.MaxWorldHeight);
|
||||
|
|
@ -56,7 +56,6 @@ namespace RustToDust.Tests
|
|||
public void StampCrater_LowersCenterRaisesRimAndDirtyOnlyOverlappingTiles()
|
||||
{
|
||||
var terrain = TerrainField.Generate(42UL, Array.Empty<ArenaBoxSpec>());
|
||||
terrain.ClearDirtyMask();
|
||||
|
||||
// Tile (3, 3) spans X in [-192, 0), Z in [-192, 0).
|
||||
// Point (-96, -96) with radius 6m is strictly inside tile (3, 3) and nowhere else.
|
||||
|
|
@ -79,15 +78,15 @@ namespace RustToDust.Tests
|
|||
$"Expected crater ejecta rim to rise >0.2m (before {beforeRim:F2}, after {afterRim:F2})");
|
||||
|
||||
// Only tile (3, 3) should have incremented from version 1 to 2
|
||||
for (int tz = 0; tz < TerrainField.TileGridCount; tz++)
|
||||
for (int tz = 0; tz < terrain.TileGridCount; tz++)
|
||||
{
|
||||
for (int tx = 0; tx < TerrainField.TileGridCount; tx++)
|
||||
for (int tx = 0; tx < terrain.TileGridCount; tx++)
|
||||
{
|
||||
int expected = (tx == 3 && tz == 3) ? 2 : 1;
|
||||
Assert.Equal(expected, terrain.TileVersions[tx, tz]);
|
||||
Assert.Equal(expected, terrain.StructuralTileVersions[tx, tz]);
|
||||
Assert.Equal(expected, terrain.VisualTileVersions[tx, tz]);
|
||||
}
|
||||
}
|
||||
Assert.Equal(1UL << (3 * TerrainField.TileGridCount + 3), terrain.DirtyTileMask);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
|
|||
Loading…
Reference in a new issue