From 8aaf20242e76235057296a6f4964b606a57284e2 Mon Sep 17 00:00:00 2001 From: Tobias Berger Date: Tue, 6 Sep 2022 23:16:47 +0200 Subject: [PATCH] Tweak temperatures a6b113de6b0b5e13d1c9a1605885dbc189dda096 Also fix mouse world position, FPS display, and possible Divide-By-Zero --- save/src/math_util.rs | 5 ++--- save/src/world.rs | 16 ++++++---------- src/main.rs | 22 +++++++++++++++------- 3 files changed, 23 insertions(+), 20 deletions(-) diff --git a/save/src/math_util.rs b/save/src/math_util.rs index 70e9f9c..522b0f3 100644 --- a/save/src/math_util.rs +++ b/save/src/math_util.rs @@ -62,11 +62,10 @@ pub fn random_point_in_sphere(radius: f32) -> Vec3A { let x = rng.gen_range(-radius..radius); let y = rng.gen_range(-radius..radius); let z = rng.gen_range(-radius..radius); - let mult = 1.0 / (x * x + y * y + z * z).sqrt(); - if x == 0.0 && y == 0.0 && z == 0.0 { - return Vec3A::X; + return Vec3A::ZERO; } + let mult = 1.0 / (x * x + y * y + z * z).sqrt(); Vec3A::new(mult * x, mult * y, mult * z) } diff --git a/save/src/world.rs b/save/src/world.rs index ea3035c..832a20d 100644 --- a/save/src/world.rs +++ b/save/src/world.rs @@ -127,8 +127,8 @@ impl World { pub const RAINFALL_SPAN: f32 = Self::MAX_RAINFALL - Self::MIN_RAINFALL; pub const RAINFALL_ALTITUDE_FACTOR: f32 = 1.0; - pub const MIN_TEMPERATURE: f32 = -100.0; - pub const MAX_TEMPERATURE: f32 = 100.0; + pub const MIN_TEMPERATURE: f32 = -50.0; + pub const MAX_TEMPERATURE: f32 = 30.0; pub const TEMPERATURE_SPAN: f32 = Self::MAX_TEMPERATURE - Self::MIN_RAINFALL; pub const TEMPERATURE_ALTITUDE_FACTOR: f32 = 1.0; @@ -418,17 +418,13 @@ impl World { let cell = &mut self.terrain[y][x]; - let altitude_factor = 1.0 - - f32::clamp( - (cell.altitude / Self::MAX_ALTITUDE) * Self::TEMPERATURE_ALTITUDE_FACTOR, - 0.0, - 1.0, - ); + let altitude_factor = (cell.altitude / Self::MAX_ALTITUDE) + * (2.5 * Self::TEMPERATURE_ALTITUDE_FACTOR); let latitude_modifer = (alpha * 0.8) + (random_noise * 0.2 * PI); let base_temperature = Self::calculate_temperature(f32::sin(latitude_modifer)); - cell.temperature = base_temperature * altitude_factor; + cell.temperature = base_temperature * (1.0 - altitude_factor); } } @@ -438,7 +434,7 @@ impl World { fn calculate_temperature(raw_temperature: f32) -> f32 { f32::clamp( (raw_temperature * Self::TEMPERATURE_SPAN) + Self::MIN_TEMPERATURE, - 0.0, + Self::MIN_TEMPERATURE, Self::MAX_TEMPERATURE, ) } diff --git a/src/main.rs b/src/main.rs index 2244b34..52198da 100644 --- a/src/main.rs +++ b/src/main.rs @@ -182,7 +182,7 @@ fn update_cursor_map_position( let window_size = Vec2::new(window.width(), window.height()); // GPU coordinates [-1..1] - let ndc = (screen_position / window_size) * 2.0; + let ndc = (screen_position / window_size) * 2.0 - Vec2::ONE; // Matrix to reverse camera transform let ndc_to_world = transform.compute_matrix() * camera.projection_matrix().inverse(); @@ -190,8 +190,9 @@ fn update_cursor_map_position( let world_position = ndc_to_world.project_point3(ndc.extend(-1.0)).truncate() / WORLD_SCALE as f32; - cursor_map_position.x = world_position.x.round() as i32; - cursor_map_position.y = world_manager.world().height - world_position.y.round() as i32; + let world = world_manager.world(); + cursor_map_position.x = world_position.x as i32 + world.width / 2 - 1; + cursor_map_position.y = world.height / 2 - world_position.y as i32 - 1; } } @@ -219,10 +220,10 @@ fn update_info_panel( #[cfg(feature = "debug")] { format!( - "FPS: {}\nMouse position: {}\nAltitude: {}\nRainfall: {}\nTemperature: {}", + "FPS: ~{}\nMouse position: {}\nAltitude: {}\nRainfall: {}\nTemperature: {}", match diagnostics.get_measurement(FrameTimeDiagnosticsPlugin::FPS) { None => f64::NAN, - Some(fps) => fps.value, + Some(fps) => fps.value.round(), }, *cursor_position, cell.altitude, @@ -238,7 +239,14 @@ fn update_info_panel( ) } } else { - format!("Mouse position: {}\nOut of bounds", *cursor_position) + format!( + "FPS: ~{}\nMouse position: {}\nOut of bounds", + match diagnostics.get_measurement(FrameTimeDiagnosticsPlugin::FPS) { + None => f64::NAN, + Some(fps) => fps.value.round(), + }, + *cursor_position + ) }; } @@ -404,7 +412,7 @@ fn generate_graphics( } #[cfg(feature = "render")] -const WORLD_SCALE: i32 = 3; +const WORLD_SCALE: i32 = 4; fn main() -> Result<(), Box> { let mut app = App::new(); let mut manager = WorldManager::new();