From 363edfb22d7fb4c958fc02b7d17cb67e9c53b75e Mon Sep 17 00:00:00 2001 From: IntegratedQuantum Date: Fri, 20 Dec 2024 21:53:13 +0100 Subject: [PATCH] Set the climate zone wavelength to 4096 by default and make it configurable per world. --- src/gui/windows/save_creation.zig | 6 ++++++ src/server/terrain/biomes.zig | 9 ++++----- src/server/terrain/climategen/NoiseBasedVoronoi.zig | 2 +- src/server/terrain/terrain.zig | 7 +++++++ 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/gui/windows/save_creation.zig b/src/gui/windows/save_creation.zig index 30e0bf99..62fcd26d 100644 --- a/src/gui/windows/save_creation.zig +++ b/src/gui/windows/save_creation.zig @@ -50,6 +50,12 @@ fn flawedCreateWorld() !void { const mapGenerator = main.ZonElement.initObject(main.stackAllocator); mapGenerator.put("id", "cubyz:mapgen_v1"); // TODO: Make this configurable generatorSettings.put("mapGenerator", mapGenerator); + const climateWavelengths = main.ZonElement.initObject(main.stackAllocator); + climateWavelengths.put("hot_cold", 4096); + climateWavelengths.put("land_ocean", 4096); + climateWavelengths.put("wet_dry", 4096); + climateWavelengths.put("mountain", 4096); + generatorSettings.put("climateWavelengths", climateWavelengths); try main.files.writeZon(generatorSettingsPath, generatorSettings); } { // Make assets subfolder diff --git a/src/server/terrain/biomes.zig b/src/server/terrain/biomes.zig index 9f50876f..6a8ea128 100644 --- a/src/server/terrain/biomes.zig +++ b/src/server/terrain/biomes.zig @@ -453,7 +453,6 @@ pub const TreeNode = union(enum) { // MARK: TreeNode aliasTable: main.utils.AliasTable(Biome) = undefined, }, branch: struct { - amplitude: f32, lowerBorder: f32, upperBorder: f32, children: [3]*TreeNode, @@ -491,7 +490,6 @@ pub const TreeNode = union(enum) { // MARK: TreeNode self.* = .{ .branch = .{ - .amplitude = 1024, // TODO! .lowerBorder = terrain.noise.ValueNoise.percentile(chanceLower), .upperBorder = terrain.noise.ValueNoise.percentile(chanceLower + chanceMiddle), .children = undefined, @@ -544,7 +542,7 @@ pub const TreeNode = union(enum) { // MARK: TreeNode allocator.destroy(self); } - pub fn getBiome(self: *const TreeNode, seed: *u64, x: i32, y: i32) *const Biome { + pub fn getBiome(self: *const TreeNode, seed: *u64, x: i32, y: i32, depth: usize) *const Biome { switch(self.*) { .leaf => |leaf| { var biomeSeed = main.random.initSeed2D(seed.*, main.vec.Vec2i{x, y}); @@ -552,7 +550,8 @@ pub const TreeNode = union(enum) { // MARK: TreeNode return result; }, .branch => |branch| { - const value = terrain.noise.ValueNoise.samplePoint2D(@as(f32, @floatFromInt(x))/branch.amplitude, @as(f32, @floatFromInt(y))/branch.amplitude, main.random.nextInt(u32, seed)); + const wavelength = main.server.world.?.chunkManager.terrainGenerationProfile.climateWavelengths[depth]; + const value = terrain.noise.ValueNoise.samplePoint2D(@as(f32, @floatFromInt(x))/wavelength, @as(f32, @floatFromInt(y))/wavelength, main.random.nextInt(u32, seed)); var index: u2 = 0; if(value >= branch.lowerBorder) { if(value >= branch.upperBorder) { @@ -561,7 +560,7 @@ pub const TreeNode = union(enum) { // MARK: TreeNode index = 1; } } - return branch.children[index].getBiome(seed, x, y); + return branch.children[index].getBiome(seed, x, y, depth + 1); } } } diff --git a/src/server/terrain/climategen/NoiseBasedVoronoi.zig b/src/server/terrain/climategen/NoiseBasedVoronoi.zig index a6aba38c..d7d2f56f 100644 --- a/src/server/terrain/climategen/NoiseBasedVoronoi.zig +++ b/src/server/terrain/climategen/NoiseBasedVoronoi.zig @@ -143,7 +143,7 @@ const Chunk = struct { const x = random.nextIntBounded(u31, &seed, chunkSize) + wx; const y = random.nextIntBounded(u31, &seed, chunkSize) + wy; var biomeSeed: u64 = 562478564; - const drawnBiome = tree.getBiome(&biomeSeed, x, y); + const drawnBiome = tree.getBiome(&biomeSeed, x, y, 0); const radius = drawnBiome.radius + drawnBiome.radiusVariation*random.nextFloatSigned(&seed); if(!checkIfBiomeIsValid(x, y, radius, selectedBiomes.items(), chunkLocalMaxBiomeRadius)) { rejections += 1; diff --git a/src/server/terrain/terrain.zig b/src/server/terrain/terrain.zig index 4101451c..d948594a 100644 --- a/src/server/terrain/terrain.zig +++ b/src/server/terrain/terrain.zig @@ -73,6 +73,7 @@ pub const TerrainGenerationProfile = struct { caveGenerators: []CaveMap.CaveGenerator = undefined, structureMapGenerators: []StructureMap.StructureMapGenerator = undefined, generators: []BlockGenerator = undefined, + climateWavelengths: [4]f32 = undefined, seed: u64, pub fn init(settings: ZonElement, seed: u64) !TerrainGenerationProfile { @@ -99,6 +100,12 @@ pub const TerrainGenerationProfile = struct { generator = settings.getChild("generators"); self.generators = BlockGenerator.getAndInitGenerators(main.globalAllocator, generator); + const climateWavelengths = settings.getChild("climateWavelengths"); + self.climateWavelengths[0] = climateWavelengths.get(f32, "hot_cold", 4096); + self.climateWavelengths[1] = climateWavelengths.get(f32, "land_ocean", 4096); + self.climateWavelengths[2] = climateWavelengths.get(f32, "wet_dry", 4096); + self.climateWavelengths[3] = climateWavelengths.get(f32, "mountain", 4096); + return self; }