mirror of
https://github.com/PixelGuys/Cubyz.git
synced 2025-09-10 04:41:32 -04:00
parent
b162199138
commit
1764de2912
@ -31,8 +31,10 @@ pub fn generate(map: *CaveBiomeMapFragment, worldSeed: u64) void {
|
|||||||
var validBiomes = main.ListUnmanaged(*const Biome).initCapacity(main.stackAllocator, caveBiomes.len);
|
var validBiomes = main.ListUnmanaged(*const Biome).initCapacity(main.stackAllocator, caveBiomes.len);
|
||||||
defer validBiomes.deinit(main.stackAllocator);
|
defer validBiomes.deinit(main.stackAllocator);
|
||||||
const worldPos = CaveBiomeMapFragment.rotateInverse(.{map.pos.wx, map.pos.wy, map.pos.wz});
|
const worldPos = CaveBiomeMapFragment.rotateInverse(.{map.pos.wx, map.pos.wy, map.pos.wz});
|
||||||
|
const marginDiv = 1024;
|
||||||
|
const marginMul: comptime_int = @reduce(.Max, @abs(comptime CaveBiomeMapFragment.rotate(.{marginDiv, marginDiv, marginDiv})));
|
||||||
for(caveBiomes) |*biome| {
|
for(caveBiomes) |*biome| {
|
||||||
if(biome.minHeight < worldPos[2] +% CaveBiomeMapFragment.caveBiomeMapSize and biome.maxHeight > worldPos[2]) {
|
if(biome.minHeight < worldPos[2] +% CaveBiomeMapFragment.caveBiomeMapSize*marginMul/marginDiv and biome.maxHeight > worldPos[2]) {
|
||||||
validBiomes.appendAssumeCapacity(biome);
|
validBiomes.appendAssumeCapacity(biome);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -46,18 +48,8 @@ pub fn generate(map: *CaveBiomeMapFragment, worldSeed: u64) void {
|
|||||||
while(z < CaveBiomeMapFragment.caveBiomeMapSize) : (z += CaveBiomeMapFragment.caveBiomeSize) {
|
while(z < CaveBiomeMapFragment.caveBiomeMapSize) : (z += CaveBiomeMapFragment.caveBiomeSize) {
|
||||||
// Sort all biomes to the start that fit into the height region of the given z plane:
|
// Sort all biomes to the start that fit into the height region of the given z plane:
|
||||||
var totalChance: f64 = 0;
|
var totalChance: f64 = 0;
|
||||||
var insertionIndex: usize = 0;
|
for(validBiomes.items) |b| {
|
||||||
var i: usize = 0;
|
totalChance += b.chance;
|
||||||
while(i < validBiomes.items.len) : (i += 1) {
|
|
||||||
if(validBiomes.items[i].minHeight < worldPos[2] + z + (CaveBiomeMapFragment.caveBiomeSize - 1) and validBiomes.items[i].maxHeight > worldPos[2] + z) {
|
|
||||||
if(insertionIndex != i) {
|
|
||||||
const swap = validBiomes.items[i];
|
|
||||||
validBiomes.items[i] = validBiomes.items[insertionIndex];
|
|
||||||
validBiomes.items[insertionIndex] = swap;
|
|
||||||
}
|
|
||||||
totalChance += validBiomes.items[insertionIndex].chance;
|
|
||||||
insertionIndex += 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if(totalChance == 0) {
|
if(totalChance == 0) {
|
||||||
totalChance = 1;
|
totalChance = 1;
|
||||||
@ -66,10 +58,12 @@ pub fn generate(map: *CaveBiomeMapFragment, worldSeed: u64) void {
|
|||||||
while(x < CaveBiomeMapFragment.caveBiomeMapSize) : (x += CaveBiomeMapFragment.caveBiomeSize) {
|
while(x < CaveBiomeMapFragment.caveBiomeMapSize) : (x += CaveBiomeMapFragment.caveBiomeSize) {
|
||||||
var y: u31 = 0;
|
var y: u31 = 0;
|
||||||
while(y < CaveBiomeMapFragment.caveBiomeMapSize) : (y += CaveBiomeMapFragment.caveBiomeSize) {
|
while(y < CaveBiomeMapFragment.caveBiomeMapSize) : (y += CaveBiomeMapFragment.caveBiomeSize) {
|
||||||
|
const biomeWorldPos = CaveBiomeMapFragment.rotateInverse(.{map.pos.wx + x, map.pos.wy + y, map.pos.wz + z});
|
||||||
for(0..2) |_map| {
|
for(0..2) |_map| {
|
||||||
|
while(true) {
|
||||||
var randomValue = random.nextDouble(&seed)*totalChance;
|
var randomValue = random.nextDouble(&seed)*totalChance;
|
||||||
var biome: *const Biome = undefined;
|
var biome: *const Biome = undefined;
|
||||||
i = 0;
|
var i: usize = 0;
|
||||||
while(true) {
|
while(true) {
|
||||||
biome = validBiomes.items[i];
|
biome = validBiomes.items[i];
|
||||||
i += 1;
|
i += 1;
|
||||||
@ -78,6 +72,10 @@ pub fn generate(map: *CaveBiomeMapFragment, worldSeed: u64) void {
|
|||||||
}
|
}
|
||||||
const index = CaveBiomeMapFragment.getIndex(x, y, z);
|
const index = CaveBiomeMapFragment.getIndex(x, y, z);
|
||||||
map.biomeMap[index][_map] = biome;
|
map.biomeMap[index][_map] = biome;
|
||||||
|
if(biome.minHeight < biomeWorldPos[2] + CaveBiomeMapFragment.caveBiomeSize*marginMul/marginDiv and biome.maxHeight > biomeWorldPos[2]) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user