Files
VoxelEngine/VoxelEngine.Tests/WorldGen/TerrainSamplerTests.cs
MDietermann e034d10339 feat(world-gen): larger biomes, smooth height blending, capped mountains; centralize tunables in Configuration
Terrain feel: biome regions ~10x larger (Voronoi cell size 96->960); terrain height now eases across biome borders via a Voronoi distance blend (smooth, and ~25x cheaper than the old 169-sample box blur); mountains capped to ~2/3 world height and gentled (ridged amplitude/frequency lowered), snow line lowered to match.

Centralization: ~27 world-gen/render tuning constants (biome amplitudes & frequencies, climate-noise frequencies/octaves, biome-selection thresholds, blend width, cell size, filler depth, snow line, camera near plane, spawn offset, overlay scale) hoisted from scattered literals into a region-organized, fully-commented Configuration. Configuration is threaded into NoiseSource, the biomes, BiomeRegistry, BiomeMap (+Classify), TerrainSampler, WorldGenerator (+BlockAt filler depth), and Camera via Player. Defaults equal the prior values, so generation is unchanged; worldgen tests updated for the new constructor signatures.
2026-06-03 16:27:06 +02:00

55 lines
1.7 KiB
C#

using VoxelEngine.Core;
using VoxelEngine.World.Blocks;
using VoxelEngine.World.WorldGen;
using Xunit;
namespace VoxelEngine.Tests.WorldGen;
public class TerrainSamplerTests
{
private static TerrainSampler Build(int seed = 42)
{
var blocks = new BlockRegistry();
var biomes = new BiomeRegistry(seed, blocks, new Configuration());
var noise = new NoiseSource(seed, new Configuration());
var cells = new VoronoiCells(seed, 96f);
var map = new BiomeMap(noise, cells, biomes, new Configuration());
return new TerrainSampler(noise, map, new Configuration());
}
[Fact]
public void Height_StaysWithinWorldBounds()
{
var sampler = Build();
for (int x = -300; x < 300; x += 7)
for (int z = -300; z < 300; z += 7)
{
int h = sampler.HeightAt(x, z);
Assert.InRange(h, 0, WorldConstants.WorldHeight - 1);
}
}
[Fact]
public void Height_IsDeterministic()
{
var a = Build();
var b = Build();
Assert.Equal(a.HeightAt(120, 240), b.HeightAt(120, 240));
}
[Fact]
public void AdjacentColumns_DoNotCliff()
{
var sampler = Build();
for (int x = -200; x < 200; x += 3)
for (int z = -200; z < 200; z += 3)
{
// The dense blur removes inter-biome cliffs. Remaining deltas are
// rugged intra-Mountains ridged slopes, now ~4x larger after the
// 128->512 rescale; 64 separates intended slopes from true cliffs.
int dx = System.Math.Abs(sampler.HeightAt(x, z) - sampler.HeightAt(x + 1, z));
Assert.True(dx <= 64, $"height jump {dx} at ({x},{z})");
}
}
}