mirror of
https://github.com/PixelGuys/Cubyz.git
synced 2025-08-03 19:28:49 -04:00
Set the climate zone wavelength to 4096 by default and make it configurable per world.
This commit is contained in:
parent
84afe1a189
commit
363edfb22d
@ -50,6 +50,12 @@ fn flawedCreateWorld() !void {
|
|||||||
const mapGenerator = main.ZonElement.initObject(main.stackAllocator);
|
const mapGenerator = main.ZonElement.initObject(main.stackAllocator);
|
||||||
mapGenerator.put("id", "cubyz:mapgen_v1"); // TODO: Make this configurable
|
mapGenerator.put("id", "cubyz:mapgen_v1"); // TODO: Make this configurable
|
||||||
generatorSettings.put("mapGenerator", mapGenerator);
|
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);
|
try main.files.writeZon(generatorSettingsPath, generatorSettings);
|
||||||
}
|
}
|
||||||
{ // Make assets subfolder
|
{ // Make assets subfolder
|
||||||
|
@ -453,7 +453,6 @@ pub const TreeNode = union(enum) { // MARK: TreeNode
|
|||||||
aliasTable: main.utils.AliasTable(Biome) = undefined,
|
aliasTable: main.utils.AliasTable(Biome) = undefined,
|
||||||
},
|
},
|
||||||
branch: struct {
|
branch: struct {
|
||||||
amplitude: f32,
|
|
||||||
lowerBorder: f32,
|
lowerBorder: f32,
|
||||||
upperBorder: f32,
|
upperBorder: f32,
|
||||||
children: [3]*TreeNode,
|
children: [3]*TreeNode,
|
||||||
@ -491,7 +490,6 @@ pub const TreeNode = union(enum) { // MARK: TreeNode
|
|||||||
|
|
||||||
self.* = .{
|
self.* = .{
|
||||||
.branch = .{
|
.branch = .{
|
||||||
.amplitude = 1024, // TODO!
|
|
||||||
.lowerBorder = terrain.noise.ValueNoise.percentile(chanceLower),
|
.lowerBorder = terrain.noise.ValueNoise.percentile(chanceLower),
|
||||||
.upperBorder = terrain.noise.ValueNoise.percentile(chanceLower + chanceMiddle),
|
.upperBorder = terrain.noise.ValueNoise.percentile(chanceLower + chanceMiddle),
|
||||||
.children = undefined,
|
.children = undefined,
|
||||||
@ -544,7 +542,7 @@ pub const TreeNode = union(enum) { // MARK: TreeNode
|
|||||||
allocator.destroy(self);
|
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.*) {
|
switch(self.*) {
|
||||||
.leaf => |leaf| {
|
.leaf => |leaf| {
|
||||||
var biomeSeed = main.random.initSeed2D(seed.*, main.vec.Vec2i{x, y});
|
var biomeSeed = main.random.initSeed2D(seed.*, main.vec.Vec2i{x, y});
|
||||||
@ -552,7 +550,8 @@ pub const TreeNode = union(enum) { // MARK: TreeNode
|
|||||||
return result;
|
return result;
|
||||||
},
|
},
|
||||||
.branch => |branch| {
|
.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;
|
var index: u2 = 0;
|
||||||
if(value >= branch.lowerBorder) {
|
if(value >= branch.lowerBorder) {
|
||||||
if(value >= branch.upperBorder) {
|
if(value >= branch.upperBorder) {
|
||||||
@ -561,7 +560,7 @@ pub const TreeNode = union(enum) { // MARK: TreeNode
|
|||||||
index = 1;
|
index = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return branch.children[index].getBiome(seed, x, y);
|
return branch.children[index].getBiome(seed, x, y, depth + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -143,7 +143,7 @@ const Chunk = struct {
|
|||||||
const x = random.nextIntBounded(u31, &seed, chunkSize) + wx;
|
const x = random.nextIntBounded(u31, &seed, chunkSize) + wx;
|
||||||
const y = random.nextIntBounded(u31, &seed, chunkSize) + wy;
|
const y = random.nextIntBounded(u31, &seed, chunkSize) + wy;
|
||||||
var biomeSeed: u64 = 562478564;
|
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);
|
const radius = drawnBiome.radius + drawnBiome.radiusVariation*random.nextFloatSigned(&seed);
|
||||||
if(!checkIfBiomeIsValid(x, y, radius, selectedBiomes.items(), chunkLocalMaxBiomeRadius)) {
|
if(!checkIfBiomeIsValid(x, y, radius, selectedBiomes.items(), chunkLocalMaxBiomeRadius)) {
|
||||||
rejections += 1;
|
rejections += 1;
|
||||||
|
@ -73,6 +73,7 @@ pub const TerrainGenerationProfile = struct {
|
|||||||
caveGenerators: []CaveMap.CaveGenerator = undefined,
|
caveGenerators: []CaveMap.CaveGenerator = undefined,
|
||||||
structureMapGenerators: []StructureMap.StructureMapGenerator = undefined,
|
structureMapGenerators: []StructureMap.StructureMapGenerator = undefined,
|
||||||
generators: []BlockGenerator = undefined,
|
generators: []BlockGenerator = undefined,
|
||||||
|
climateWavelengths: [4]f32 = undefined,
|
||||||
seed: u64,
|
seed: u64,
|
||||||
|
|
||||||
pub fn init(settings: ZonElement, seed: u64) !TerrainGenerationProfile {
|
pub fn init(settings: ZonElement, seed: u64) !TerrainGenerationProfile {
|
||||||
@ -99,6 +100,12 @@ pub const TerrainGenerationProfile = struct {
|
|||||||
generator = settings.getChild("generators");
|
generator = settings.getChild("generators");
|
||||||
self.generators = BlockGenerator.getAndInitGenerators(main.globalAllocator, generator);
|
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;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user