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

@@ -43,7 +43,7 @@ fn create_tile_collider(pos: Vec3, verts: &mut Vec<Vec3>, indices: &mut Vec<[u32
create_tile_wall_collider(
idx,
Vec3::new(pos.x, n_height.min(pos.y - OUTER_RADIUS / 2.), pos.z),
(i + 1) % 6,
i,
verts,
indices,
);

View File

@@ -217,7 +217,6 @@ fn sample_point(
let z_s = z / cfg.scale;
let mut elevation: f64 = 0.;
let mut first_layer: f64 = 0.;
for i in 0..cfg.layers.len() {
let value: f64;
let layer = &cfg.layers[i];
@@ -226,15 +225,8 @@ fn sample_point(
} else {
value = sample_simple(x_s, z_s, layer, noise);
}
if i == 0 {
first_layer = value;
}
if layer.first_layer_mask {
elevation += mask(first_layer, value);
} else {
elevation += value;
}
}
elevation += value;
}
if border_size == 0.0 {
return elevation as f32;
@@ -251,10 +243,6 @@ fn sample_point(
return border_value.lerp(elevation as f32, d);
}
fn mask(mask: f64, value: f64) -> f64 {
return value * mask;
}
fn sample_simple(x: f64, z: f64, cfg: &GeneratorLayer, noise: &impl NoiseFn<f64, 2>) -> f64 {
let mut freq: f64 = cfg.base_roughness;
let mut amp: f64 = 1.;

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];