diff --git a/tests/RustToDust.Tests/SionMapTests.cs b/tests/RustToDust.Tests/SionMapTests.cs index 6fd5682..0395045 100644 --- a/tests/RustToDust.Tests/SionMapTests.cs +++ b/tests/RustToDust.Tests/SionMapTests.cs @@ -516,11 +516,32 @@ namespace RustToDust.Tests } } - // Step a few ticks so all 20 craters flush into Box3D heightfields - for (int t = 0; t < 8; t++) + // Flush all 20 cratered tiles into Box3D heightfields without evicting non-actor tiles + int flushedBeforeRepair = session.TileSync.FlushDirtyHeightfields(session.World, terrain, maxTilesPerTick: 20); + Assert.Equal(20, flushedBeforeRepair); + session.World.Step(1f / 60f); + + var sion = session.State.SionMap!; + var sionMeta = sion.Metadata; + (float X, float Z, float BaseH) openSpot = default; + bool foundOpenSpot = false; + foreach (var s in spots) { - session.Step(); + if (!sion.IsInsideAnyBuildingXz(s.X, s.Z, padding: 6f)) + { + openSpot = s; + foundOpenSpot = true; + break; + } } + Assert.True(foundOpenSpot, "Expected at least one open-sky spot among the 20 cratered tiles"); + + float rayStartY = sionMeta.MaxY + 25f; + float raySpanY = -(sionMeta.MaxY - sionMeta.MinY + 60f); + var hitCratered = session.CastWorldRayClosest(new Vector3(openSpot.X, rayStartY, openSpot.Z), new Vector3(0f, raySpanY, 0f)); + Assert.True(hitCratered.Hit); + Assert.True(hitCratered.Point.Y < openSpot.BaseH - 1.0f, + $"Expected cratered Box3D raycast height ({hitCratered.Point.Y:F3}) well below base ({openSpot.BaseH:F3})"); int freeBeforeRepair = session.World.FreeBodySlots; Assert.True(freeBeforeRepair >= 20 + 32); @@ -530,14 +551,10 @@ namespace RustToDust.Tests $"Expected View.Count ({session.World.View.Count}) well below WorldBodyCapacity ({ArenaSession.WorldBodyCapacity}) after repair"); Assert.Equal(0, session.TileSync.CountDirtyResidentTiles(terrain)); - var (spotX, spotZ, spotBaseH) = spots[0]; - var sionMeta = session.State.SionMap!.Metadata; - float rayStartY = sionMeta.MaxY + 25f; - float raySpanY = -(sionMeta.MaxY - sionMeta.MinY + 60f); - var hitTick0 = session.CastWorldRayClosest(new Vector3(spotX, rayStartY, spotZ), new Vector3(0f, raySpanY, 0f)); + var hitTick0 = session.CastWorldRayClosest(new Vector3(openSpot.X, rayStartY, openSpot.Z), new Vector3(0f, raySpanY, 0f)); Assert.True(hitTick0.Hit); - Assert.True(MathF.Abs(hitTick0.Point.Y - spotBaseH) < 0.05f, - $"Expected tick-0 Box3D raycast height ({hitTick0.Point.Y:F3}) to match restored base ({spotBaseH:F3})"); + Assert.True(MathF.Abs(hitTick0.Point.Y - openSpot.BaseH) < 0.05f, + $"Expected tick-0 Box3D raycast height ({hitTick0.Point.Y:F3}) to match restored base ({openSpot.BaseH:F3})"); // Step across ticks so recycled slots remain healthy without exhausting world capacity for (int t = 0; t < 20; t++)