RustToDust Phase 2: Procedural brush terrain, 4-corner Ymir support, and Godot 4.7.2 Mono client
This commit is contained in:
parent
32b040a59b
commit
215b5ea834
20 changed files with 3486 additions and 56 deletions
143
tests/RustToDust.Tests/TerrainTests.cs
Normal file
143
tests/RustToDust.Tests/TerrainTests.cs
Normal file
|
|
@ -0,0 +1,143 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using RustToDust.Core;
|
||||
using RustToDust.Ymir;
|
||||
using Xunit;
|
||||
|
||||
namespace RustToDust.Tests
|
||||
{
|
||||
public sealed class TerrainTests
|
||||
{
|
||||
[Fact]
|
||||
public void Generate_ProducesDeterministicNonFlatReliefWithinBounds()
|
||||
{
|
||||
var emptyCover = Array.Empty<ArenaBoxSpec>();
|
||||
var a = TerrainField.Generate(42UL, emptyCover);
|
||||
var b = TerrainField.Generate(42UL, emptyCover);
|
||||
var c = TerrainField.Generate(999UL, emptyCover);
|
||||
|
||||
float minH = float.PositiveInfinity;
|
||||
float maxH = float.NegativeInfinity;
|
||||
bool anyDifferentSeed = false;
|
||||
|
||||
for (int gx = -160; gx <= 160; gx += 16)
|
||||
{
|
||||
for (int gz = -160; gz <= 160; gz += 16)
|
||||
{
|
||||
float ha = a.SampleHeight(gx, gz);
|
||||
float hb = b.SampleHeight(gx, gz);
|
||||
float hc = c.SampleHeight(gx, gz);
|
||||
|
||||
Assert.Equal(ha, hb);
|
||||
if (MathF.Abs(ha - hc) > 0.05f)
|
||||
{
|
||||
anyDifferentSeed = true;
|
||||
}
|
||||
|
||||
minH = MathF.Min(minH, ha);
|
||||
maxH = MathF.Max(maxH, ha);
|
||||
}
|
||||
}
|
||||
|
||||
Assert.True(maxH - minH > 2.5f, $"Expected non-flat dune/mesa relief > 2.5m span, got [{minH:F2}, {maxH:F2}]");
|
||||
Assert.InRange(minH, -4.5f, 1.0f);
|
||||
Assert.InRange(maxH, 2.0f, 9.5f);
|
||||
Assert.True(anyDifferentSeed, "Different seeds should generate distinct desert relief");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void StampCrater_LowersCenterRaisesRimAndDirtyOnlyOverlappingTiles()
|
||||
{
|
||||
var terrain = TerrainField.Generate(42UL, Array.Empty<ArenaBoxSpec>());
|
||||
terrain.ClearDirtyMask();
|
||||
|
||||
// Tile (1, 1) spans X in [-96, 0), Z in [-96, 0).
|
||||
// Point (-48, -48) with radius 6m is strictly inside tile (1, 1) and nowhere else.
|
||||
const float cx = -48f;
|
||||
const float cz = -48f;
|
||||
const float radius = 6f;
|
||||
const float depth = 1.6f;
|
||||
|
||||
float beforeCenter = terrain.SampleHeight(cx, cz);
|
||||
float beforeRim = terrain.SampleHeight(cx + radius * 0.775f, cz);
|
||||
|
||||
terrain.StampCrater(cx, cz, radius, depth);
|
||||
|
||||
float afterCenter = terrain.SampleHeight(cx, cz);
|
||||
float afterRim = terrain.SampleHeight(cx + radius * 0.775f, cz);
|
||||
|
||||
Assert.True(afterCenter < beforeCenter - 1.0f,
|
||||
$"Expected crater center to drop >1.0m (before {beforeCenter:F2}, after {afterCenter:F2})");
|
||||
Assert.True(afterRim > beforeRim + 0.2f,
|
||||
$"Expected crater ejecta rim to rise >0.2m (before {beforeRim:F2}, after {afterRim:F2})");
|
||||
|
||||
// Only tile (1, 1) should have incremented from version 1 to 2
|
||||
for (int tz = 0; tz < TerrainField.TileGridCount; tz++)
|
||||
{
|
||||
for (int tx = 0; tx < TerrainField.TileGridCount; tx++)
|
||||
{
|
||||
int expected = (tx == 1 && tz == 1) ? 2 : 1;
|
||||
Assert.Equal(expected, terrain.TileVersions[tx, tz]);
|
||||
}
|
||||
}
|
||||
Assert.Equal(1u << (1 * TerrainField.TileGridCount + 1), terrain.DirtyTileMask);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void StampTrack_BoundsDynamicDecalCount()
|
||||
{
|
||||
var terrain = TerrainField.Generate(7UL, Array.Empty<ArenaBoxSpec>());
|
||||
int initialCount = terrain.Brushes.Count;
|
||||
|
||||
for (int i = 0; i < TerrainField.MaxDynamicDecals + 40; i++)
|
||||
{
|
||||
float x = -80f + (i % 40) * 4f;
|
||||
float z = -80f + (i / 40) * 8f;
|
||||
terrain.StampTrack(x, z, yaw: 0.4f, width: 1.6f, length: 2.5f);
|
||||
}
|
||||
|
||||
Assert.Equal(initialCount + TerrainField.MaxDynamicDecals, terrain.Brushes.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ArenaSession_BuggyDrivesAcrossDunesWithoutNanAndTracksElevation()
|
||||
{
|
||||
using var session = new ArenaSession(seed: 108);
|
||||
var player = session.State.Player;
|
||||
int initialBrushes = session.State.Terrain.Brushes.Count;
|
||||
|
||||
float minGround = float.PositiveInfinity;
|
||||
float maxGround = float.NegativeInfinity;
|
||||
|
||||
for (int tick = 0; tick < 240; tick++)
|
||||
{
|
||||
// Steer gently across the desert ring
|
||||
float steer = MathF.Sin(tick * 0.03f) * 0.35f;
|
||||
session.Step(new PlayerInput(
|
||||
Throttle: 1f,
|
||||
Steer: steer,
|
||||
AimWorldX: player.X + 30f,
|
||||
AimWorldZ: player.Z,
|
||||
Fire: false,
|
||||
InteractPickup: false,
|
||||
Brake: false));
|
||||
|
||||
Assert.False(float.IsNaN(player.X) || float.IsNaN(player.Y) || float.IsNaN(player.Z),
|
||||
$"NaN pose at tick {tick}");
|
||||
|
||||
float gh = session.State.Terrain.SampleHeight(player.X, player.Z);
|
||||
minGround = MathF.Min(minGround, gh);
|
||||
maxGround = MathF.Max(maxGround, gh);
|
||||
|
||||
// Chassis should remain supported near the terrain surface (never sink under -12m or rocket into orbit)
|
||||
float bottomY = player.Y - player.Grid.Spec.HalfHeight;
|
||||
Assert.InRange(bottomY - gh, -0.75f, 4.0f);
|
||||
}
|
||||
|
||||
Assert.True(session.State.Terrain.Brushes.Count > initialBrushes,
|
||||
"Driving across dust should stamp tire track brushes");
|
||||
Assert.True(maxGround - minGround > 0.25f,
|
||||
$"Expected buggy to traverse non-flat terrain (span {maxGround - minGround:F2}m)");
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue