feat(world-gen): integrate CaveCarver into WorldGenerator.Generate

This commit is contained in:
2026-06-01 15:43:32 +02:00
parent 645fd00868
commit 9410fee78b
4 changed files with 39 additions and 6 deletions

View File

@@ -1,4 +1,5 @@
using OpenTK.Mathematics;
using VoxelEngine.Core;
using VoxelEngine.World.Blocks;
using VoxelChunk = VoxelEngine.World.Chunk.Chunk;
@@ -12,8 +13,9 @@ public sealed class WorldGenerator
private readonly BlockRegistry _blocks;
private readonly BiomeMap _biomeMap;
private readonly TerrainSampler _terrain;
private readonly CaveCarver _caves;
public WorldGenerator(int seed, BlockRegistry blocks)
public WorldGenerator(int seed, BlockRegistry blocks, Configuration cfg)
{
this._blocks = blocks;
NoiseSource noise = new(seed);
@@ -21,6 +23,7 @@ public sealed class WorldGenerator
BiomeRegistry biomes = new(seed, blocks);
this._biomeMap = new BiomeMap(noise, cells, biomes);
this._terrain = new TerrainSampler(noise, this._biomeMap);
this._caves = new CaveCarver(seed, blocks, cfg);
}
public int SurfaceHeightAt(int worldX, int worldZ) => this._terrain.HeightAt(worldX, worldZ);
@@ -46,10 +49,11 @@ public sealed class WorldGenerator
chunk[x, y, z] = WorldGenerator.BlockAt(worldY, height, biome, this._blocks);
}
}
this._caves.Carve(chunk, chunkPos);
return chunk;
}
// Pure column fill rule, extracted for testability.
public static ushort BlockAt(int worldY, int surfaceHeight, IBiome biome, BlockRegistry blocks)
{
if (worldY > surfaceHeight)