collision fixes

generator changes
This commit is contained in:
2024-09-02 20:53:11 -04:00
parent 9613e3ae0d
commit 2d1fb78ab8
10 changed files with 33 additions and 30 deletions

View File

@@ -134,6 +134,15 @@ impl BiomeMap {
return chunk.get_biome_id(x - (cx * Chunk::SIZE), y - (cy * Chunk::SIZE));
}
pub fn get_biome_id_dithered(&self, x: usize, y: usize, noise: &impl NoiseFn<f64, 2>, scale: f64) -> usize {
let cx = (x as f32 / Chunk::SIZE as f32).floor() as usize;
let cy = (y as f32 / Chunk::SIZE as f32).floor() as usize;
let chunk = &self.chunks[cx + cy * self.size.x as usize];
return chunk.get_biome_id_dithered(x - (cx * Chunk::SIZE), y - (cy * Chunk::SIZE), noise, scale);
}
pub fn get_biome_data(&self, x: usize, y: usize) -> &BiomeData {
let cx = (x as f32 / Chunk::SIZE as f32).floor() as usize;
let cy = (y as f32 / Chunk::SIZE as f32).floor() as usize;
@@ -175,16 +184,18 @@ impl BiomeChunk {
}
pub fn get_biome_id_dithered(&self, x: usize, y: usize, noise: &impl NoiseFn<f64, 2>, scale: f64) -> usize {
let cur_id = self.get_biome_id(x, y);
let mut cur_id = self.get_biome_id(x, y);
let b = self.get_biome(x, y);
let n = (noise.get([x as f64 / scale, y as f64 / scale]) as f32) * b[cur_id];
let n = (noise.get([x as f64 / scale, y as f64 / scale]) as f32 - 0.5)/ 2.0;
let mut max = b[cur_id] + n;
for i in 0..b.len() {
let blend = b[i];
if blend == 0. {
continue;
}
if n < blend {
return i;
if blend > max {
max = blend + n;
cur_id = i;
}
}

View File

@@ -44,5 +44,4 @@ pub struct GeneratorLayer {
pub weight: f64,
pub weight_multi: f64,
pub layers: usize,
pub first_layer_mask: bool,
}

View File

@@ -26,6 +26,7 @@ impl Map {
let chunk = &self.chunks[chunk_index];
return MeshChunkData {
min_height: self.min_level,
heights: chunk.heights.clone(),
textures: chunk.textures.clone(),
};
@@ -73,17 +74,16 @@ impl Map {
return pos.is_in_bounds(self.height * Chunk::SIZE, self.width * Chunk::SIZE);
}
pub fn get_biome_id(&self, pos: &HexCoord) -> usize {
assert!(
self.is_in_bounds(pos),
"The provided coordinate is not within the map bounds"
);
let chunk = &self.chunks[pos.to_chunk_index(self.width)];
return chunk.biome_id[pos.to_chunk_local_index()];
}
/*
/*
pub fn get_biome_noise(&self, pos: &HexCoord) -> &BiomeData {
assert!(
self.is_in_bounds(pos),

View File

@@ -5,11 +5,12 @@ use super::chunk::Chunk;
pub struct MeshChunkData {
pub heights: [f32; Chunk::AREA],
pub textures: [[u32; 2]; Chunk::AREA],
pub min_height: f32,
}
impl MeshChunkData {
pub fn get_neighbors(&self, coord: &HexCoord) -> [f32; 6] {
let mut data = [0.; 6];
let mut data = [self.min_height; 6];
let n_tiles = coord.get_neighbors();
for i in 0..6 {
let n = n_tiles[i];