wip map border

This commit is contained in:
2024-03-31 11:45:22 -04:00
parent 45d4e8cfa0
commit 8e8ac1c79e
3 changed files with 15 additions and 11 deletions

View File

@@ -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<Chunk> = 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<Chunk> = 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 {

View File

@@ -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<GeneratorLayer>,
}
pub struct GeneratorLayer {

View File

@@ -79,8 +79,6 @@ fn create_map(
mut meshes: ResMut<Assets<Mesh>>,
) {
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,
);