keepOriginal is now specified in the biome and can be used for subbiomes.

fixes #1135
This commit is contained in:
IntegratedQuantum 2025-03-17 21:30:08 +01:00
parent 2f801c07f4
commit 6f26dde472
4 changed files with 21 additions and 20 deletions

View File

@ -2,8 +2,9 @@
.properties = .{}, .properties = .{},
.radius = 16, .radius = 16,
.chance = 0, .chance = 0,
.minHeight = 2, .minHeight = -2000,
.maxHeight = 10, .maxHeight = -1000,
.keepOriginalTerrain = 0.99,
.roughness = 1, .roughness = 1,
.stoneBlock = "cubyz:stone", .stoneBlock = "cubyz:stone",
.parentBiomes = .{ .parentBiomes = .{

View File

@ -2,8 +2,9 @@
.properties = .{}, .properties = .{},
.radius = 16, .radius = 16,
.chance = 0, .chance = 0,
.minHeight = 50, .minHeight = 1500,
.maxHeight = 80, .maxHeight = 3000,
.keepOriginalTerrain = 0.99,
.roughness = 1, .roughness = 1,
.mountains = 50, .mountains = 50,
.hills = 20, .hills = 20,

View File

@ -284,6 +284,7 @@ pub const Biome = struct { // MARK: Biome
roughness: f32, roughness: f32,
hills: f32, hills: f32,
mountains: f32, mountains: f32,
keepOriginalTerrain: f32,
caves: f32, caves: f32,
caveRadiusFactor: f32, caveRadiusFactor: f32,
crystals: u32, crystals: u32,
@ -326,6 +327,7 @@ pub const Biome = struct { // MARK: Biome
.roughness = zon.get(f32, "roughness", 0), .roughness = zon.get(f32, "roughness", 0),
.hills = zon.get(f32, "hills", 0), .hills = zon.get(f32, "hills", 0),
.mountains = zon.get(f32, "mountains", 0), .mountains = zon.get(f32, "mountains", 0),
.keepOriginalTerrain = zon.get(f32, "keepOriginalTerrain", 0),
.interpolation = std.meta.stringToEnum(Interpolation, zon.get([]const u8, "interpolation", "square")) orelse .square, .interpolation = std.meta.stringToEnum(Interpolation, zon.get([]const u8, "interpolation", "square")) orelse .square,
.interpolationWeight = @max(zon.get(f32, "interpolationWeight", 1), std.math.floatMin(f32)), .interpolationWeight = @max(zon.get(f32, "interpolationWeight", 1), std.math.floatMin(f32)),
.caves = zon.get(f32, "caves", -0.375), .caves = zon.get(f32, "caves", -0.375),
@ -357,7 +359,6 @@ pub const Biome = struct { // MARK: Biome
.chance = src.get(f32, "chance", 1), .chance = src.get(f32, "chance", 1),
.propertyMask = GenerationProperties.fromZon(src.getChild("properties"), false), .propertyMask = GenerationProperties.fromZon(src.getChild("properties"), false),
.width = src.get(u8, "width", 2), .width = src.get(u8, "width", 2),
.keepOriginalTerrain = src.get(f32, "keepOriginalTerrain", 0),
}; };
// Fill all unspecified property groups: // Fill all unspecified property groups:
var properties: u15 = @bitCast(dst.propertyMask); var properties: u15 = @bitCast(dst.propertyMask);
@ -615,14 +616,12 @@ const UnfinishedTransitionBiomeData = struct {
chance: f32, chance: f32,
propertyMask: Biome.GenerationProperties, propertyMask: Biome.GenerationProperties,
width: u8, width: u8,
keepOriginalTerrain: f32,
}; };
const TransitionBiome = struct { const TransitionBiome = struct {
biome: *const Biome, biome: *const Biome,
chance: f32, chance: f32,
propertyMask: Biome.GenerationProperties, propertyMask: Biome.GenerationProperties,
width: u8, width: u8,
keepOriginalTerrain: f32,
}; };
var unfinishedTransitionBiomes: std.StringHashMapUnmanaged([]UnfinishedTransitionBiomeData) = .{}; var unfinishedTransitionBiomes: std.StringHashMapUnmanaged([]UnfinishedTransitionBiomeData) = .{};
@ -725,14 +724,12 @@ pub fn finishLoading() void {
.chance = 0, .chance = 0,
.propertyMask = .{}, .propertyMask = .{},
.width = 0, .width = 0,
.keepOriginalTerrain = 0,
}; };
continue; continue;
}, },
.chance = src.chance, .chance = src.chance,
.propertyMask = src.propertyMask, .propertyMask = src.propertyMask,
.width = src.width, .width = src.width,
.keepOriginalTerrain = src.keepOriginalTerrain,
}; };
} }
main.globalAllocator.free(transitionBiomes); main.globalAllocator.free(transitionBiomes);

View File

@ -290,14 +290,16 @@ const GenerationStructure = struct {
while(y < max[1]) : (y += 1) { while(y < max[1]) : (y += 1) {
const distSquare = vec.lengthSquare(Vec2f{x, y} - relPos); const distSquare = vec.lengthSquare(Vec2f{x, y} - relPos);
if(distSquare < relRadius*relRadius) { if(distSquare < relRadius*relRadius) {
var seed = map.map[@intFromFloat(x)][@intFromFloat(y)].seed; const entry = &map.map[@intFromFloat(x)][@intFromFloat(y)];
map.map[@intFromFloat(x)][@intFromFloat(y)] = .{ var seed = entry.seed;
const newHeight = @as(f32, @floatFromInt(biome.minHeight)) + @as(f32, @floatFromInt(biome.maxHeight - biome.minHeight))*random.nextFloat(&seed);
entry.* = .{
.biome = biome, .biome = biome,
.roughness = biome.roughness, .roughness = std.math.lerp(biome.roughness, entry.roughness, biome.keepOriginalTerrain),
.hills = biome.hills, .hills = std.math.lerp(biome.hills, entry.hills, biome.keepOriginalTerrain),
.mountains = biome.mountains, .mountains = std.math.lerp(biome.mountains, entry.mountains, biome.keepOriginalTerrain),
.height = @as(f32, @floatFromInt(biome.minHeight)) + @as(f32, @floatFromInt(biome.maxHeight - biome.minHeight))*random.nextFloat(&seed), .height = std.math.lerp(newHeight, entry.height, biome.keepOriginalTerrain),
.seed = map.map[@intFromFloat(x)][@intFromFloat(y)].seed, .seed = entry.seed,
}; };
} }
} }
@ -379,10 +381,10 @@ const GenerationStructure = struct {
const newHeight = @as(f32, @floatFromInt(transitionBiome.biome.minHeight)) + @as(f32, @floatFromInt(transitionBiome.biome.maxHeight - transitionBiome.biome.minHeight))*random.nextFloat(&seed); const newHeight = @as(f32, @floatFromInt(transitionBiome.biome.minHeight)) + @as(f32, @floatFromInt(transitionBiome.biome.maxHeight - transitionBiome.biome.minHeight))*random.nextFloat(&seed);
map[x][y] = .{ map[x][y] = .{
.biome = transitionBiome.biome, .biome = transitionBiome.biome,
.roughness = std.math.lerp(transitionBiome.biome.roughness, map[x][y].roughness, transitionBiome.keepOriginalTerrain), .roughness = std.math.lerp(transitionBiome.biome.roughness, map[x][y].roughness, transitionBiome.biome.keepOriginalTerrain),
.hills = std.math.lerp(transitionBiome.biome.hills, map[x][y].hills, transitionBiome.keepOriginalTerrain), .hills = std.math.lerp(transitionBiome.biome.hills, map[x][y].hills, transitionBiome.biome.keepOriginalTerrain),
.mountains = std.math.lerp(transitionBiome.biome.mountains, map[x][y].mountains, transitionBiome.keepOriginalTerrain), .mountains = std.math.lerp(transitionBiome.biome.mountains, map[x][y].mountains, transitionBiome.biome.keepOriginalTerrain),
.height = std.math.lerp(newHeight, map[x][y].height, transitionBiome.keepOriginalTerrain), .height = std.math.lerp(newHeight, map[x][y].height, transitionBiome.biome.keepOriginalTerrain),
.seed = map[x][y].seed, .seed = map[x][y].seed,
}; };
break; break;