From a414d496371bef072cd66a6ca509dab5fe7b9027 Mon Sep 17 00:00:00 2001 From: IntegratedQuantum Date: Wed, 29 Jan 2025 22:19:22 +0100 Subject: [PATCH] Generate all stone in underground LOD3+ chunks. This reduces the compressed size when initially sending chunks over the network by over 40%. helps with #830 makes #720 less important makes #631 less important makes #444 more useful fixes #135 (although in a different way than I expected) --- .../terrain/chunkgen/TerrainGenerator.zig | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/server/terrain/chunkgen/TerrainGenerator.zig b/src/server/terrain/chunkgen/TerrainGenerator.zig index 9ea567726..60df1dfa6 100644 --- a/src/server/terrain/chunkgen/TerrainGenerator.zig +++ b/src/server/terrain/chunkgen/TerrainGenerator.zig @@ -18,10 +18,14 @@ pub const priority = 1024; // Within Cubyz the first to be executed, but mods mi pub const generatorSeed = 0x65c7f9fdc0641f94; +var air: main.blocks.Block = undefined; +var stone: main.blocks.Block = undefined; var water: main.blocks.Block = undefined; pub fn init(parameters: ZonElement) void { _ = parameters; + air = main.blocks.getBlockById("cubyz:air"); + stone = main.blocks.getBlockById("cubyz:stone"); water = main.blocks.getBlockById("cubyz:water"); } @@ -30,6 +34,31 @@ pub fn deinit() void { } pub fn generate(worldSeed: u64, chunk: *main.chunk.ServerChunk, caveMap: CaveMap.CaveMapView, biomeMap: CaveBiomeMap.CaveBiomeMapView) void { + if(chunk.super.pos.voxelSize >= 8) { + var maxHeight: i32 = 0; + var minHeight: i32 = std.math.maxInt(i32); + var dx: i32 = -1; + while(dx < main.chunk.chunkSize + 1) : (dx += 1) { + var dy: i32 = -1; + while(dy < main.chunk.chunkSize + 1) : (dy += 1) { + const height = biomeMap.getSurfaceHeight(chunk.super.pos.wx +% dx*chunk.super.pos.voxelSize, chunk.super.pos.wy +% dy*chunk.super.pos.voxelSize); + maxHeight = @max(maxHeight, height); + minHeight = @min(minHeight, height); + } + } + if(minHeight > chunk.super.pos.wz +| chunk.super.width) { + chunk.super.data.deinit(); + chunk.super.data.init(); + chunk.super.data.palette[0] = stone; + return; + } + if(maxHeight < chunk.super.pos.wz) { + chunk.super.data.deinit(); + chunk.super.data.init(); + chunk.super.data.palette[0] = air; + return; + } + } const voxelSizeShift = @ctz(chunk.super.pos.voxelSize); var x: u31 = 0; while(x < chunk.super.width) : (x += chunk.super.pos.voxelSize) {