Skip to content

Commit

Permalink
Set the climate zone wavelength to 4096 by default and make it config…
Browse files Browse the repository at this point in the history
…urable per world.
  • Loading branch information
IntegratedQuantum committed Dec 20, 2024
1 parent 84afe1a commit 363edfb
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
6 changes: 6 additions & 0 deletions src/gui/windows/save_creation.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 4 additions & 5 deletions src/server/terrain/biomes.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -544,15 +542,16 @@ 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});
const result = leaf.aliasTable.sample(&biomeSeed);
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) {
Expand All @@ -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);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/server/terrain/climategen/NoiseBasedVoronoi.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions src/server/terrain/terrain.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
}

Expand Down

0 comments on commit 363edfb

Please sign in to comment.