diff --git a/client/src/lib.rs b/client/src/lib.rs index d5bde04a28..fc1318f95a 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -30,9 +30,6 @@ use common::{ vol::RectVolSize, ChatType, }; -// TODO: remove CONFIG dependency by passing CONFIG.sea_level explicitly. -// In general any WORLD dependencies need to go away ASAP... we should see if we -// can pull out map drawing into common somehow. use hashbrown::HashMap; use image::DynamicImage; use log::{error, warn}; @@ -44,10 +41,9 @@ use std::{ }; use uvth::{ThreadPool, ThreadPoolBuilder}; use vek::*; -use world::{ - sim::{neighbors, Alt}, - CONFIG, -}; +// TODO: remove world dependencies. We should see if we +// can pull out map drawing into common somehow. +use world::sim::{neighbors, Alt}; // The duration of network inactivity until the player is kicked // @TODO: in the future, this should be configurable on the server @@ -135,9 +131,8 @@ impl Client { assert_eq!(rgba.len(), (map_size.x * map_size.y) as usize); let [west, east] = world_map.horizons; let scale_angle = - |a: u8| (a as Alt / 255.0 / ::FRAC_2_PI()).tan(); - let scale_height = - |h: u8| h as Alt * max_height as Alt / 255.0 + CONFIG.sea_level as Alt; + |a: u8| (a as Alt / 255.0 * ::FRAC_PI_2()).tan(); + let scale_height = |h: u8| h as Alt / 255.0 * max_height as Alt; log::debug!("Preparing image..."); let unzip_horizons = |(angles, heights): (Vec<_>, Vec<_>)| { @@ -154,8 +149,8 @@ impl Client { map_config.lgain = 1.0; map_config.gain = max_height; map_config.horizons = Some(&horizons); - let rescale_height = - |h: Alt| (h as f32 - map_config.focus.z as f32) / map_config.gain as f32; + map_config.focus.z = 0.0; + let rescale_height = |h: Alt| (h / max_height as Alt) as f32; let bounds_check = |pos: Vec2| { pos.reduce_partial_min() >= 0 && pos.x < map_size.x as i32 @@ -211,7 +206,7 @@ impl Client { let posi = pos.y as usize * map_size.x as usize + pos.x as usize; scale_height(rgba[posi].to_le_bytes()[3]) } else { - CONFIG.sea_level as Alt + 0.0 }) }, |pos, (r, g, b, a)| { diff --git a/world/src/sim/map.rs b/world/src/sim/map.rs index 311ed32d6e..2835743fbb 100644 --- a/world/src/sim/map.rs +++ b/world/src/sim/map.rs @@ -273,6 +273,8 @@ impl<'a> MapConfig<'a> { }) .map(|sample| { // TODO: Eliminate the redundancy between this and the block renderer. + let alt = sample.alt; + let basement = sample.basement; let grass_depth = (1.5 + 2.0 * sample.chaos).min(alt - basement); let wposz = if is_basement { basement } else { alt }; if is_basement && wposz < alt - grass_depth { @@ -615,7 +617,8 @@ impl<'a> MapConfig<'a> { }) .map(|(angle, height)| { let w = 0.1; - if angle != 0.0 && light_direction.x != 0.0 { + let height = (height - alt as Alt * gain as Alt).max(0.0); + if angle != 0.0 && light_direction.x != 0.0 && height != 0.0 { let deltax = height / angle; let lighty = (light_direction.y / light_direction.x * deltax).abs(); let deltay = lighty - height; diff --git a/world/src/sim/mod.rs b/world/src/sim/mod.rs index c177885b3b..dafbbda996 100644 --- a/world/src/sim/mod.rs +++ b/world/src/sim/mod.rs @@ -1314,9 +1314,8 @@ impl WorldSim { // Build a horizon map. let scale_angle = |angle: Alt| (angle.atan() * ::FRAC_2_PI() * 255.0).floor() as u8; - let scale_height = |height: Alt| { - ((height - CONFIG.sea_level as Alt) * 255.0 / self.max_height as Alt).floor() as u8 - }; + let scale_height = + |height: Alt| (height as Alt * 255.0 / self.max_height as Alt).floor() as u8; let horizons = get_horizon_map( map_config.lgain, Aabr { diff --git a/world/src/sim/util.rs b/world/src/sim/util.rs index e194a9aed5..d25c115b45 100644 --- a/world/src/sim/util.rs +++ b/world/src/sim/util.rs @@ -392,6 +392,10 @@ pub fn get_horizon_map( to_angle: impl Fn(F) -> A + Sync, to_height: impl Fn(F) -> H + Sync, ) -> Result<[(Vec, Vec); 2], ()> { + if maxh < minh { + // maxh must be greater than minh + return Err(()); + } let map_size = Vec2::::from(bounds.size()).map(|e| e as usize); let map_len = map_size.product(); @@ -421,9 +425,11 @@ pub fn get_horizon_map( // March in the given direction. let maxdx = maxdx(wposi.x as isize); let mut slope = F::zero(); - let mut max_height = F::zero(); let h0 = h(posi); - if h0 >= minh { + let h = if h0 < minh { + F::zero() + } else { + let mut max_height = F::zero(); let maxdz = maxh - h0; let posi = posi as isize; for deltax in 1..maxdx { @@ -441,9 +447,9 @@ pub fn get_horizon_map( max_height = h_j_act; } } - } + h0 - minh + max_height + }; let a = slope * lgain; - let h = h0 + max_height; (to_angle(a), to_height(h)) }) .unzip_into_vecs(&mut angles, &mut heights);