diff --git a/engine/world_generation/src/generators/chunk_colliders.rs b/engine/world_generation/src/generators/chunk_colliders.rs index 78a4baf..9beeb68 100644 --- a/engine/world_generation/src/generators/chunk_colliders.rs +++ b/engine/world_generation/src/generators/chunk_colliders.rs @@ -43,7 +43,7 @@ fn create_tile_collider(pos: Vec3, verts: &mut Vec, 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, ); diff --git a/engine/world_generation/src/heightmap.rs b/engine/world_generation/src/heightmap.rs index f2f198d..62a74dc 100644 --- a/engine/world_generation/src/heightmap.rs +++ b/engine/world_generation/src/heightmap.rs @@ -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 { let mut freq: f64 = cfg.base_roughness; let mut amp: f64 = 1.; diff --git a/engine/world_generation/src/map/biome_map.rs b/engine/world_generation/src/map/biome_map.rs index 6672111..000a8f7 100644 --- a/engine/world_generation/src/map/biome_map.rs +++ b/engine/world_generation/src/map/biome_map.rs @@ -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, 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, 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; } } diff --git a/engine/world_generation/src/map/config.rs b/engine/world_generation/src/map/config.rs index 84c22b4..2bd3d2a 100644 --- a/engine/world_generation/src/map/config.rs +++ b/engine/world_generation/src/map/config.rs @@ -44,5 +44,4 @@ pub struct GeneratorLayer { pub weight: f64, pub weight_multi: f64, pub layers: usize, - pub first_layer_mask: bool, } diff --git a/engine/world_generation/src/map/map.rs b/engine/world_generation/src/map/map.rs index cf690f5..8130116 100644 --- a/engine/world_generation/src/map/map.rs +++ b/engine/world_generation/src/map/map.rs @@ -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), diff --git a/engine/world_generation/src/map/mesh_chunk.rs b/engine/world_generation/src/map/mesh_chunk.rs index 3a09423..ac10e5e 100644 --- a/engine/world_generation/src/map/mesh_chunk.rs +++ b/engine/world_generation/src/map/mesh_chunk.rs @@ -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]; diff --git a/game/main/Cargo.toml b/game/main/Cargo.toml index 943a7ab..15d5ae0 100644 --- a/game/main/Cargo.toml +++ b/game/main/Cargo.toml @@ -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" } diff --git a/game/main/assets b/game/main/assets index f8f4375..5e5c821 160000 --- a/game/main/assets +++ b/game/main/assets @@ -1 +1 @@ -Subproject commit f8f4375919336356fc1efffe6e6e429cb622a3e9 +Subproject commit 5e5c821eb152f2f035415a17734d252dba7aed05 diff --git a/game/main/src/map_rendering/map_init.rs b/game/main/src/map_rendering/map_init.rs index 7698342..f698ebb 100644 --- a/game/main/src/map_rendering/map_init.rs +++ b/game/main/src/map_rendering/map_init.rs @@ -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 { @@ -176,7 +176,6 @@ fn create_heightmap( weight: 0., weight_multi: 0., layers: 1, - first_layer_mask: false, }], }, moisture_noise: NoiseConfig { @@ -191,7 +190,6 @@ fn create_heightmap( weight: 0., weight_multi: 0., layers: 1, - first_layer_mask: false, }], }, temperature_noise: NoiseConfig { @@ -206,7 +204,6 @@ fn create_heightmap( weight: 0., weight_multi: 0., layers: 1, - first_layer_mask: false, }], }, sea_level: 8.5, diff --git a/game/main/src/utlis/render_distance_system.rs b/game/main/src/utlis/render_distance_system.rs index 13f6286..efba6f0 100644 --- a/game/main/src/utlis/render_distance_system.rs +++ b/game/main/src/utlis/render_distance_system.rs @@ -9,6 +9,9 @@ impl Plugin for RenderDistancePlugin { app.register_type::(); app.add_systems(PostUpdate, render_distance_system) .insert_resource(RenderDistanceSettings::default()); + + #[cfg(debug_assertions)] + app.insert_resource(RenderDistanceSettings::new(f32::MAX)); } }