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
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue