Skip to content

Commit

Permalink
collision fixes
Browse files Browse the repository at this point in the history
generator changes
  • Loading branch information
Amatsugu committed Sep 3, 2024
1 parent 9613e3a commit 2d1fb78
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 30 deletions.
2 changes: 1 addition & 1 deletion engine/world_generation/src/generators/chunk_colliders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
Expand Down
16 changes: 2 additions & 14 deletions engine/world_generation/src/heightmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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;
Expand All @@ -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.;
Expand Down
19 changes: 15 additions & 4 deletions engine/world_generation/src/map/biome_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}

Expand Down
1 change: 0 additions & 1 deletion engine/world_generation/src/map/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,4 @@ pub struct GeneratorLayer {
pub weight: f64,
pub weight_multi: f64,
pub layers: usize,
pub first_layer_mask: bool,
}
6 changes: 3 additions & 3 deletions engine/world_generation/src/map/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
};
Expand Down Expand Up @@ -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),
Expand Down
3 changes: 2 additions & 1 deletion engine/world_generation/src/map/mesh_chunk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
6 changes: 5 additions & 1 deletion game/main/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ bevy-inspector-egui = "0.25.0"
iyes_perf_ui = "0.3.0"
noise = "0.8.2"
world_generation = { path = "../../engine/world_generation" }
bevy_rapier3d = { version = "0.27.0", features = ["simd-stable", "parallel"] }
bevy_rapier3d = { version = "0.27.0", features = [
"simd-stable",
"parallel",
"debug-render-3d",
] }
rayon = "1.10.0"
buildings = { path = "../buildings" }
units = { path = "../units" }
Expand Down
2 changes: 1 addition & 1 deletion game/main/assets
5 changes: 1 addition & 4 deletions game/main/src/map_rendering/map_init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ fn create_heightmap(
) {
let config = GenerationConfig {
biome_blend: 32,
biome_dither: 16.,
biome_dither: 10.,
continent_noise: NoiseConfig {
scale: 800.,
layers: vec![GeneratorLayer {
Expand All @@ -176,7 +176,6 @@ fn create_heightmap(
weight: 0.,
weight_multi: 0.,
layers: 1,
first_layer_mask: false,
}],
},
moisture_noise: NoiseConfig {
Expand All @@ -191,7 +190,6 @@ fn create_heightmap(
weight: 0.,
weight_multi: 0.,
layers: 1,
first_layer_mask: false,
}],
},
temperature_noise: NoiseConfig {
Expand All @@ -206,7 +204,6 @@ fn create_heightmap(
weight: 0.,
weight_multi: 0.,
layers: 1,
first_layer_mask: false,
}],
},
sea_level: 8.5,
Expand Down
3 changes: 3 additions & 0 deletions game/main/src/utlis/render_distance_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ impl Plugin for RenderDistancePlugin {
app.register_type::<RenderDistanceSettings>();
app.add_systems(PostUpdate, render_distance_system)
.insert_resource(RenderDistanceSettings::default());

#[cfg(debug_assertions)]
app.insert_resource(RenderDistanceSettings::new(f32::MAX));
}
}

Expand Down

0 comments on commit 2d1fb78

Please sign in to comment.