mirror of
https://github.com/PixelGuys/Cubyz.git
synced 2025-08-03 19:28:49 -04:00
Add an option to keep (some) of the original terrain data for transition biomes.
This commit is contained in:
parent
60f5da1724
commit
92348c09e3
@ -326,6 +326,7 @@ 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: u12 = @bitCast(dst.propertyMask);
|
var properties: u12 = @bitCast(dst.propertyMask);
|
||||||
@ -587,12 +588,14 @@ 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) = .{};
|
||||||
|
|
||||||
@ -695,12 +698,14 @@ 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);
|
||||||
|
@ -358,12 +358,13 @@ const GenerationStructure = struct {
|
|||||||
result = (result | result >> 1 | result >> 2);
|
result = (result | result >> 1 | result >> 2);
|
||||||
if(result & mask == mask) {
|
if(result & mask == mask) {
|
||||||
if(random.nextFloat(&seed) < transitionBiome.chance) {
|
if(random.nextFloat(&seed) < transitionBiome.chance) {
|
||||||
|
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 = transitionBiome.biome.roughness,
|
.roughness = std.math.lerp(transitionBiome.biome.roughness, map[x][y].roughness, transitionBiome.keepOriginalTerrain),
|
||||||
.hills = transitionBiome.biome.hills,
|
.hills = std.math.lerp(transitionBiome.biome.hills, map[x][y].hills, transitionBiome.keepOriginalTerrain),
|
||||||
.mountains = transitionBiome.biome.mountains,
|
.mountains = std.math.lerp(transitionBiome.biome.mountains, map[x][y].mountains, transitionBiome.keepOriginalTerrain),
|
||||||
.height = @as(f32, @floatFromInt(transitionBiome.biome.minHeight)) + @as(f32, @floatFromInt(transitionBiome.biome.maxHeight - transitionBiome.biome.minHeight))*random.nextFloat(&seed),
|
.height = std.math.lerp(newHeight, map[x][y].height, transitionBiome.keepOriginalTerrain),
|
||||||
.seed = map[x][y].seed,
|
.seed = map[x][y].seed,
|
||||||
};
|
};
|
||||||
break;
|
break;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user