TerrainField: prevent dune/mesa over-stacking and widen traversal test

This commit is contained in:
Meta Vens 2026-12-04 13:59:25 +01:00
commit de3786feb6
2 changed files with 18 additions and 14 deletions

View file

@ -139,23 +139,27 @@ namespace RustToDust.Core
// 3. Sweeping desert dune ridges (~20 ridges + 2 dry-wash troughs), kept clear of cover boxes & center plaza // 3. Sweeping desert dune ridges (~20 ridges + 2 dry-wash troughs), kept clear of cover boxes & center plaza
int duneCount = 0; int duneCount = 0;
int attempts = 0; int attempts = 0;
while (duneCount < 20 && attempts < 240) while (duneCount < 20 && attempts < 300)
{ {
attempts++; attempts++;
float x = (float)(rng.NextDouble() * 320.0 - 160.0); float x = (float)(rng.NextDouble() * 320.0 - 160.0);
float z = (float)(rng.NextDouble() * 320.0 - 160.0); float z = (float)(rng.NextDouble() * 320.0 - 160.0);
float radiusX = 14f + (float)rng.NextDouble() * 14f; float radiusX = 14f + (float)rng.NextDouble() * 12f;
float radiusZ = 28f + (float)rng.NextDouble() * 28f; float radiusZ = 26f + (float)rng.NextDouble() * 24f;
if (OverlapsProtectedPads(x, z, MathF.Max(radiusX, radiusZ) * 0.95f, coverBoxes)) if (OverlapsProtectedPads(x, z, MathF.Max(radiusX, radiusZ) * 0.95f, coverBoxes))
{ {
continue; continue;
} }
if (MathF.Abs(field.SampleHeight(x, z)) > 1.8f)
{
continue;
}
bool dryWash = duneCount is 5 or 13; bool dryWash = duneCount is 5 or 13;
float heightDelta = dryWash float heightDelta = dryWash
? -(1.4f + (float)rng.NextDouble() * 1.1f) ? -(1.2f + (float)rng.NextDouble() * 0.9f)
: 1.8f + (float)rng.NextDouble() * 3.1f; : 1.6f + (float)rng.NextDouble() * 2.0f;
float rot = (float)(rng.NextDouble() * MathF.PI); float rot = (float)(rng.NextDouble() * MathF.PI);
field.AddBrush(new TerrainBrush( field.AddBrush(new TerrainBrush(
@ -179,18 +183,19 @@ namespace RustToDust.Core
// 4. Terraced rust-mesa hills (~7 mesas), mainly mid/outer desert away from spawns & cover // 4. Terraced rust-mesa hills (~7 mesas), mainly mid/outer desert away from spawns & cover
int mesaCount = 0; int mesaCount = 0;
attempts = 0; attempts = 0;
while (mesaCount < 7 && attempts < 100) while (mesaCount < 7 && attempts < 160)
{ {
attempts++; attempts++;
float angle = (float)(rng.NextDouble() * MathF.Tau); float angle = (float)(rng.NextDouble() * MathF.Tau);
float dist = 54f + (float)rng.NextDouble() * 116f; float dist = 54f + (float)rng.NextDouble() * 116f;
float x = MathF.Cos(angle) * dist; float x = MathF.Cos(angle) * dist;
float z = MathF.Sin(angle) * dist; float z = MathF.Sin(angle) * dist;
float rx = 14f + (float)rng.NextDouble() * 11f; float rx = 14f + (float)rng.NextDouble() * 10f;
float rz = 13f + (float)rng.NextDouble() * 11f; float rz = 13f + (float)rng.NextDouble() * 10f;
if (OverlapsProtectedPads(x, z, MathF.Max(rx, rz) + 6f, coverBoxes) || if (OverlapsProtectedPads(x, z, MathF.Max(rx, rz) + 6f, coverBoxes) ||
OverlapsSpawnRing(x, z, MathF.Max(rx, rz) + 5f)) OverlapsSpawnRing(x, z, MathF.Max(rx, rz) + 5f) ||
MathF.Abs(field.SampleHeight(x, z)) > 1.6f)
{ {
continue; continue;
} }
@ -203,7 +208,7 @@ namespace RustToDust.Core
RotationRad: (float)(rng.NextDouble() * MathF.PI), RotationRad: (float)(rng.NextDouble() * MathF.PI),
RadiusX: rx, RadiusX: rx,
RadiusZ: rz, RadiusZ: rz,
HeightDelta: 3.4f + (float)rng.NextDouble() * 3.8f, HeightDelta: 3.1f + (float)rng.NextDouble() * 2.4f,
Roughness: 0.86f, Roughness: 0.86f,
Metallic: 0.08f, Metallic: 0.08f,
AlbedoR: 0.48f, AlbedoR: 0.48f,

View file

@ -102,17 +102,16 @@ namespace RustToDust.Tests
[Fact] [Fact]
public void ArenaSession_BuggyDrivesAcrossDunesWithoutNanAndTracksElevation() public void ArenaSession_BuggyDrivesAcrossDunesWithoutNanAndTracksElevation()
{ {
using var session = new ArenaSession(seed: 108); using var session = new ArenaSession(seed: 42);
var player = session.State.Player; var player = session.State.Player;
int initialBrushes = session.State.Terrain.Brushes.Count; int initialBrushes = session.State.Terrain.Brushes.Count;
float minGround = float.PositiveInfinity; float minGround = float.PositiveInfinity;
float maxGround = float.NegativeInfinity; float maxGround = float.NegativeInfinity;
for (int tick = 0; tick < 240; tick++) for (int tick = 0; tick < 360; tick++)
{ {
// Steer gently across the desert ring float steer = MathF.Sin(tick * 0.025f) * 0.45f;
float steer = MathF.Sin(tick * 0.03f) * 0.35f;
session.Step(new PlayerInput( session.Step(new PlayerInput(
Throttle: 1f, Throttle: 1f,
Steer: steer, Steer: steer,