rts camera

center camera
spawn basic water
fix generator config
set camera bounds
This commit is contained in:
2024-05-02 22:11:40 -04:00
parent b2622f2126
commit ed94f77323
5 changed files with 127 additions and 36 deletions

View File

@@ -19,6 +19,7 @@ pub fn generate_heightmap(cfg: &GenerationConfig, seed: u32) -> Map {
chunks,
height: cfg.size.y as usize,
width: cfg.size.x as usize,
sea_level: cfg.sea_level as f32,
};
}
@@ -40,12 +41,8 @@ pub fn generate_chunk(chunk_x: f64, chunk_z: f64, cfg: &GenerationConfig, seed:
(x as f64 + chunk_x * Chunk::SIZE as f64) / &cfg.noise_scale,
(z as f64 + chunk_z * Chunk::SIZE as f64) / &cfg.noise_scale,
]) as f32;
temp[x + z * Chunk::SIZE] = sample_tempurature(
z as f32 + chunk_z as f32 * Chunk::SIZE as f32,
sample,
&cfg,
100.,
);
temp[x + z * Chunk::SIZE] =
sample_tempurature(z as f32 + chunk_z as f32 * Chunk::SIZE as f32, sample, &cfg, 100.);
}
}
return Chunk {
@@ -95,10 +92,7 @@ fn sample_point(x: f64, z: f64, cfg: &GenerationConfig, noise: &impl NoiseFn<f64
let d1 = p.x.min(p.y);
let od = outer - p;
let d2 = od.x.min(od.y);
let d = d1
.min(d2)
.min(cfg.border_size)
.remap(0., cfg.border_size, 0., 1.);
let d = d1.min(d2).min(cfg.border_size).remap(0., cfg.border_size, 0., 1.);
return (elevation as f32) * d;
}

View File

@@ -8,7 +8,7 @@ pub mod tile_manager;
pub mod tile_mapper;
pub mod prelude {
use crate::hex_utils::{HexCoord, INNER_RADIUS, OUTER_RADIUS};
use crate::hex_utils::{tile_to_world_distance, HexCoord, INNER_RADIUS, OUTER_RADIUS};
use bevy::math::{IVec2, UVec2, Vec2, Vec3};
use bevy::prelude::Resource;
use bevy::prelude::*;
@@ -84,6 +84,7 @@ pub mod prelude {
pub chunks: Vec<Chunk>,
pub height: usize,
pub width: usize,
pub sea_level: f32,
}
impl Map {
@@ -105,7 +106,7 @@ pub mod prelude {
return results;
}
pub fn get_height(&self, pos: &HexCoord) -> f32 {
pub fn sample_height(&self, pos: &HexCoord) -> f32 {
let chunk = &self.chunks[pos.to_chunk_index(self.width)];
return chunk.heights[pos.to_chunk_local_index()];
}
@@ -119,6 +120,23 @@ pub mod prelude {
let chunk = &self.chunks[pos.to_chunk_index(self.width)];
return chunk.temperature[pos.to_chunk_local_index()];
}
pub fn get_center(&self) -> Vec3 {
let w = self.width * Chunk::SIZE;
let h = self.height * Chunk::SIZE;
return Vec3::new(
tile_to_world_distance(w as i32 / 2),
self.sea_level,
tile_to_world_distance(h as i32 / 2),
);
}
pub fn get_world_width(&self) -> f32 {
return tile_to_world_distance((self.width * Chunk::SIZE) as i32);
}
pub fn get_world_height(&self) -> f32 {
return tile_to_world_distance((self.height * Chunk::SIZE) as i32);
}
}
pub const ATTRIBUTE_PACKED_VERTEX_DATA: MeshVertexAttribute =
MeshVertexAttribute::new("PackedVertexData", 988540817, VertexFormat::Uint32);