diff --git a/engine/world_generation/src/heightmap.rs b/engine/world_generation/src/heightmap.rs index fd4d318..16bf2f3 100644 --- a/engine/world_generation/src/heightmap.rs +++ b/engine/world_generation/src/heightmap.rs @@ -1,18 +1,20 @@ -use crate::prelude::*; use bevy::math::IVec2; +use bevy::prelude::{FloatExt, Vec2}; use noise::{NoiseFn, SuperSimplex}; -pub fn generate_heightmap(height: usize, width: usize, cfg: &GenerationConfig, seed: u32) -> Map { - let mut chunks: Vec = Vec::with_capacity(height * width); - for z in 0..height { - for x in 0..width { +use crate::prelude::*; + +pub fn generate_heightmap(cfg: &GenerationConfig, seed: u32) -> Map { + let mut chunks: Vec = Vec::with_capacity(cfg.size.length_squared() as usize); + for z in 0..cfg.size.y { + for x in 0..cfg.size.x { chunks.push(generate_chunk(x as f64, z as f64, cfg, seed)); } } return Map { chunks, - height, - width, + height: cfg.size.y as usize, + width: cfg.size.x as usize, }; } @@ -60,7 +62,7 @@ fn sample_point(x: f64, z: f64, cfg: &GenerationConfig, noise: &SuperSimplex) -> } } - return elevation as f32; + return (elevation as f32); } fn mask(mask: f64, value: f64, sea_level: f64) -> f64 { diff --git a/engine/world_generation/src/lib.rs b/engine/world_generation/src/lib.rs index 826d56b..32b401f 100644 --- a/engine/world_generation/src/lib.rs +++ b/engine/world_generation/src/lib.rs @@ -1,11 +1,13 @@ pub mod prelude { use crate::hex_utils::HexCoord; - use bevy::math::IVec2; + use bevy::math::{IVec2, UVec2}; use bevy::prelude::Resource; pub struct GenerationConfig { pub noise_scale: f64, pub sea_level: f64, + pub border_size: f32, + pub size: UVec2, pub layers: Vec, } pub struct GeneratorLayer { diff --git a/game/main/src/phos.rs b/game/main/src/phos.rs index 2777c21..c805fd3 100644 --- a/game/main/src/phos.rs +++ b/game/main/src/phos.rs @@ -79,8 +79,6 @@ fn create_map( mut meshes: ResMut>, ) { let heightmap = generate_heightmap( - 32, - 32, &GenerationConfig { layers: vec![ GeneratorLayer { @@ -134,6 +132,8 @@ fn create_map( ], noise_scale: 350., sea_level: 4., + border_size: 16., + size: (32, 32).into(), }, 2, );