wip map border
This commit is contained in:
@@ -1,18 +1,20 @@
|
|||||||
use crate::prelude::*;
|
|
||||||
use bevy::math::IVec2;
|
use bevy::math::IVec2;
|
||||||
|
use bevy::prelude::{FloatExt, Vec2};
|
||||||
use noise::{NoiseFn, SuperSimplex};
|
use noise::{NoiseFn, SuperSimplex};
|
||||||
|
|
||||||
pub fn generate_heightmap(height: usize, width: usize, cfg: &GenerationConfig, seed: u32) -> Map {
|
use crate::prelude::*;
|
||||||
let mut chunks: Vec<Chunk> = Vec::with_capacity(height * width);
|
|
||||||
for z in 0..height {
|
pub fn generate_heightmap(cfg: &GenerationConfig, seed: u32) -> Map {
|
||||||
for x in 0..width {
|
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));
|
chunks.push(generate_chunk(x as f64, z as f64, cfg, seed));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Map {
|
return Map {
|
||||||
chunks,
|
chunks,
|
||||||
height,
|
height: cfg.size.y as usize,
|
||||||
width,
|
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 {
|
fn mask(mask: f64, value: f64, sea_level: f64) -> f64 {
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
pub mod prelude {
|
pub mod prelude {
|
||||||
use crate::hex_utils::HexCoord;
|
use crate::hex_utils::HexCoord;
|
||||||
use bevy::math::IVec2;
|
use bevy::math::{IVec2, UVec2};
|
||||||
use bevy::prelude::Resource;
|
use bevy::prelude::Resource;
|
||||||
|
|
||||||
pub struct GenerationConfig {
|
pub struct GenerationConfig {
|
||||||
pub noise_scale: f64,
|
pub noise_scale: f64,
|
||||||
pub sea_level: f64,
|
pub sea_level: f64,
|
||||||
|
pub border_size: f32,
|
||||||
|
pub size: UVec2,
|
||||||
pub layers: Vec<GeneratorLayer>,
|
pub layers: Vec<GeneratorLayer>,
|
||||||
}
|
}
|
||||||
pub struct GeneratorLayer {
|
pub struct GeneratorLayer {
|
||||||
|
|||||||
@@ -79,8 +79,6 @@ fn create_map(
|
|||||||
mut meshes: ResMut<Assets<Mesh>>,
|
mut meshes: ResMut<Assets<Mesh>>,
|
||||||
) {
|
) {
|
||||||
let heightmap = generate_heightmap(
|
let heightmap = generate_heightmap(
|
||||||
32,
|
|
||||||
32,
|
|
||||||
&GenerationConfig {
|
&GenerationConfig {
|
||||||
layers: vec![
|
layers: vec![
|
||||||
GeneratorLayer {
|
GeneratorLayer {
|
||||||
@@ -134,6 +132,8 @@ fn create_map(
|
|||||||
],
|
],
|
||||||
noise_scale: 350.,
|
noise_scale: 350.,
|
||||||
sea_level: 4.,
|
sea_level: 4.,
|
||||||
|
border_size: 16.,
|
||||||
|
size: (32, 32).into(),
|
||||||
},
|
},
|
||||||
2,
|
2,
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user