From 3e580138df67a9ad06ec0af2abd2bf244bebe6e1 Mon Sep 17 00:00:00 2001 From: pepsalt <68469008+KingPEPSALT@users.noreply.github.com> Date: Fri, 26 Aug 2022 13:44:01 +0100 Subject: [PATCH 1/5] FIX #1622, /time command will not allow time going backwards as rtsim cannot handle time regression, time given in seconds is treated as if it were seconds ahead of the next midnight --- server/src/cmd.rs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/server/src/cmd.rs b/server/src/cmd.rs index 036cb728b2..f5cad3721e 100644 --- a/server/src/cmd.rs +++ b/server/src/cmd.rs @@ -955,8 +955,14 @@ fn handle_time( Some("dusk") => { next_cycle(NaiveTime::from_hms(17, 0, 0).num_seconds_from_midnight() as f64) }, - Some(n) => match n.parse() { - Ok(n) => n, + Some(n) => match n.parse::() { + Ok(n) => { + if n < 0.0{ + return Err(format!("{:?} is invalid, cannot be negative.", n)); + } + // Seconds from next midnight + next_cycle(0.0) + n + }, Err(_) => match NaiveTime::parse_from_str(n, "%H:%M") { // Relative to current day Ok(time) => next_cycle(time.num_seconds_from_midnight() as f64), @@ -966,8 +972,13 @@ fn handle_time( .filter(|_| n.starts_with('u')) .and_then(|n| n.trim_start_matches('u').parse::().ok()) { - // Absolute time (i.e: since in-game epoch) - Some(n) => n as f64, + // Absolute time (i.e. from world epoch) + Some(n) => { + if (n as f64) < time_in_seconds { + return Err(format!("{:?} is before the current time, time cannot go backwards.", n)) + } + n as f64 + }, None => { return Err(format!("{:?} is not a valid time.", n)); }, From 775025ac63e219489184d81225f8745be8c8f630 Mon Sep 17 00:00:00 2001 From: pepsalt <68469008+KingPEPSALT@users.noreply.github.com> Date: Fri, 26 Aug 2022 13:45:00 +0100 Subject: [PATCH 2/5] CHANGE, client time lerp would cause flashing lights for large discrepancies, it now no longer lerps if the flashing lights setting is not on --- client/src/lib.rs | 26 ++++++++++++++++++++++++-- voxygen/src/session/settings_change.rs | 6 ++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/client/src/lib.rs b/client/src/lib.rs index 79ef38080f..fffc9d8fa5 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -252,8 +252,10 @@ pub struct Client { tick: u64, state: State, - server_view_distance_limit: Option, + flashing_lights_enabled: bool, + /// Terrrain view distance + server_view_distance_limit: Option, view_distance: Option, lod_distance: f32, // TODO: move into voxygen @@ -731,6 +733,9 @@ impl Client { tick: 0, state, + + flashing_lights_enabled: true, + server_view_distance_limit: None, view_distance: None, lod_distance: 4.0, @@ -1003,6 +1008,10 @@ impl Client { self.lod_distance = lod_distance; } + pub fn set_flashing_lights_enabled(&mut self, flashing_lights_enabled: bool){ + self.flashing_lights_enabled = flashing_lights_enabled; + } + pub fn use_slot(&mut self, slot: Slot) { self.control_action(ControlAction::InventoryAction(InventoryAction::Use(slot))) } @@ -1766,12 +1775,25 @@ impl Client { // Lerp towards the target time of day - this ensures a smooth transition for // large jumps in TimeOfDay such as when using /time + const DAY: f64 = 86400.0; if let Some(target_tod) = self.target_time_of_day { let mut tod = self.state.ecs_mut().write_resource::(); - tod.0 = Lerp::lerp(tod.0, target_tod.0, dt.as_secs_f64()); + + // When the target time of day and time of day have a large discrepancy + // (i.e two days), the linear interpolation causes brght flashing effects + // in the sky. This will instantly set the time of day to the target + // time of day for the client to avoid the flashing effect if flashing + // lights is disabled. + if !self.flashing_lights_enabled && target_tod.0 - tod.0 >= DAY*2 { + tod.0 = target_tod.0; + } else { + tod.0 = Lerp::lerp(tod.0, target_tod.0, dt.as_secs_f64()); + } + if tod.0 >= target_tod.0 { self.target_time_of_day = None; } + } // 4) Tick the client's LocalState diff --git a/voxygen/src/session/settings_change.rs b/voxygen/src/session/settings_change.rs index f2778abcbc..51ae0ebf18 100644 --- a/voxygen/src/session/settings_change.rs +++ b/voxygen/src/session/settings_change.rs @@ -470,7 +470,13 @@ impl SettingsChange { .renderer_mut() .set_render_mode((*new_render_mode).clone()) .unwrap(); + session_state + .client + .borrow_mut() + .set_flashing_lights_enabled((*new_render_mode).flashing_lights_enabled); + settings.graphics.render_mode = *new_render_mode; + }, Graphics::ChangeFullscreenMode(new_fullscreen_settings) => { global_state From f22a9d030dbe80cabc043d92996ba5815f3a6a96 Mon Sep 17 00:00:00 2001 From: pepsalt <68469008+KingPEPSALT@users.noreply.github.com> Date: Fri, 26 Aug 2022 15:52:13 +0100 Subject: [PATCH 3/5] CHANGE: moved time of day interpolation logic out of Client and into Scene for semantics and accessing the settings logically --- client/src/lib.rs | 21 ++------------------- voxygen/src/ecs/comp.rs | 5 ++++- voxygen/src/ecs/mod.rs | 1 + voxygen/src/scene/mod.rs | 23 ++++++++++++++++++++--- voxygen/src/session/mod.rs | 2 ++ voxygen/src/session/settings_change.rs | 6 +----- 6 files changed, 30 insertions(+), 28 deletions(-) diff --git a/client/src/lib.rs b/client/src/lib.rs index fffc9d8fa5..f5c79d5bcf 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -1773,27 +1773,10 @@ impl Client { // Lerp the clientside weather. self.weather.update(&mut self.state.weather_grid_mut()); - // Lerp towards the target time of day - this ensures a smooth transition for - // large jumps in TimeOfDay such as when using /time - const DAY: f64 = 86400.0; if let Some(target_tod) = self.target_time_of_day { let mut tod = self.state.ecs_mut().write_resource::(); - - // When the target time of day and time of day have a large discrepancy - // (i.e two days), the linear interpolation causes brght flashing effects - // in the sky. This will instantly set the time of day to the target - // time of day for the client to avoid the flashing effect if flashing - // lights is disabled. - if !self.flashing_lights_enabled && target_tod.0 - tod.0 >= DAY*2 { - tod.0 = target_tod.0; - } else { - tod.0 = Lerp::lerp(tod.0, target_tod.0, dt.as_secs_f64()); - } - - if tod.0 >= target_tod.0 { - self.target_time_of_day = None; - } - + tod.0 = target_tod.0; + self.target_time_of_day = None; } // 4) Tick the client's LocalState diff --git a/voxygen/src/ecs/comp.rs b/voxygen/src/ecs/comp.rs index ecc769ca93..f0fd63e990 100644 --- a/voxygen/src/ecs/comp.rs +++ b/voxygen/src/ecs/comp.rs @@ -1,4 +1,7 @@ -use common::{comp::Ori, outcome::HealthChangeInfo}; +use common::{ + comp::Ori, + outcome::HealthChangeInfo +}; use specs::{Component, VecStorage}; use vek::*; diff --git a/voxygen/src/ecs/mod.rs b/voxygen/src/ecs/mod.rs index 8b7b647b38..2edb75929c 100644 --- a/voxygen/src/ecs/mod.rs +++ b/voxygen/src/ecs/mod.rs @@ -5,6 +5,7 @@ use crate::audio::sfx::SfxEventItem; use common::{event::EventBus, slowjob::SlowJobPool}; use specs::{World, WorldExt}; + pub fn init(world: &mut World) { world.register::(); world.register::(); diff --git a/voxygen/src/scene/mod.rs b/voxygen/src/scene/mod.rs index 5a20ddbb3f..a348b14e19 100644 --- a/voxygen/src/scene/mod.rs +++ b/voxygen/src/scene/mod.rs @@ -111,6 +111,7 @@ pub struct Scene { ambient_mgr: AmbientMgr, integrated_rain_vel: f32, + pub interpolated_time_of_day: f64, last_lightning: Option<(Vec3, f64)>, } @@ -134,12 +135,13 @@ pub struct SceneData<'a> { pub flashing_lights_enabled: bool, pub figure_lod_render_distance: f32, pub is_aiming: bool, + pub interpolated_time_of_day: f64 } impl<'a> SceneData<'a> { - pub fn get_sun_dir(&self) -> Vec3 { Globals::get_sun_dir(self.state.get_time_of_day()) } + pub fn get_sun_dir(&self) -> Vec3 { Globals::get_sun_dir(self.interpolated_time_of_day) } - pub fn get_moon_dir(&self) -> Vec3 { Globals::get_moon_dir(self.state.get_time_of_day()) } + pub fn get_moon_dir(&self) -> Vec3 { Globals::get_moon_dir(self.interpolated_time_of_day) } } /// Approximate a scalar field of view angle using the parameterization from @@ -339,6 +341,7 @@ impl Scene { ambience: ambient::load_ambience_items(), }, integrated_rain_vel: 0.0, + interpolated_time_of_day: 0.0, last_lightning: None, } } @@ -500,7 +503,7 @@ impl Scene { audio: &mut AudioFrontend, scene_data: &SceneData, client: &Client, - ) { + ) { span!(_guard, "maintain", "Scene::maintain"); // Get player position. let ecs = scene_data.state.ecs(); @@ -714,7 +717,21 @@ impl Scene { self.loaded_distance = loaded_distance; // Update light projection matrices for the shadow map. + + // When the target time of day and time of day have a large discrepancy + // (i.e two days), the linear interpolation causes brght flashing effects + // in the sky. This will snap the time of day to the target time of day + // for the client to avoid the flashing effect if flashing lights is + // disabled. + const DAY: f64 = 60.0 * 60.0 * 24.0; let time_of_day = scene_data.state.get_time_of_day(); + self.interpolated_time_of_day = if (self.interpolated_time_of_day - time_of_day).abs() > DAY*2.0 + && !scene_data.flashing_lights_enabled{ + time_of_day + } else { + Lerp::lerp(self.interpolated_time_of_day, time_of_day, dt as f64) + }; + let time_of_day = self.interpolated_time_of_day; let focus_pos = self.camera.get_focus_pos(); let focus_off = focus_pos.map(|e| e.trunc()); diff --git a/voxygen/src/session/mod.rs b/voxygen/src/session/mod.rs index a84ebceab6..b2d0360f94 100644 --- a/voxygen/src/session/mod.rs +++ b/voxygen/src/session/mod.rs @@ -1736,6 +1736,7 @@ impl PlayState for SessionState { .figure_lod_render_distance as f32, is_aiming, + interpolated_time_of_day: self.scene.interpolated_time_of_day, }; // Runs if either in a multiplayer server or the singleplayer server is unpaused @@ -1817,6 +1818,7 @@ impl PlayState for SessionState { weapon_trails_enabled: settings.graphics.weapon_trails_enabled, flashing_lights_enabled: settings.graphics.render_mode.flashing_lights_enabled, is_aiming: self.is_aiming, + interpolated_time_of_day: self.scene.interpolated_time_of_day }; // Render world diff --git a/voxygen/src/session/settings_change.rs b/voxygen/src/session/settings_change.rs index 51ae0ebf18..5956715f7c 100644 --- a/voxygen/src/session/settings_change.rs +++ b/voxygen/src/session/settings_change.rs @@ -470,11 +470,7 @@ impl SettingsChange { .renderer_mut() .set_render_mode((*new_render_mode).clone()) .unwrap(); - session_state - .client - .borrow_mut() - .set_flashing_lights_enabled((*new_render_mode).flashing_lights_enabled); - + settings.graphics.render_mode = *new_render_mode; }, From 52946034313a8b4e015b5f5a323c5031cdfc0fa0 Mon Sep 17 00:00:00 2001 From: pepsalt <68469008+KingPEPSALT@users.noreply.github.com> Date: Fri, 2 Sep 2022 15:39:09 +0100 Subject: [PATCH 4/5] changed {:?}s to {}s in format strings --- server/src/cmd.rs | 11 +++++++---- voxygen/src/session/settings_change.rs | 2 -- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/server/src/cmd.rs b/server/src/cmd.rs index f5cad3721e..d23bbc9f12 100644 --- a/server/src/cmd.rs +++ b/server/src/cmd.rs @@ -957,8 +957,8 @@ fn handle_time( }, Some(n) => match n.parse::() { Ok(n) => { - if n < 0.0{ - return Err(format!("{:?} is invalid, cannot be negative.", n)); + if n < 0.0 { + return Err(format!("{} is invalid, cannot be negative.", n)); } // Seconds from next midnight next_cycle(0.0) + n @@ -975,12 +975,15 @@ fn handle_time( // Absolute time (i.e. from world epoch) Some(n) => { if (n as f64) < time_in_seconds { - return Err(format!("{:?} is before the current time, time cannot go backwards.", n)) + return Err(format!( + "{} is before the current time, time cannot go backwards.", + n + )); } n as f64 }, None => { - return Err(format!("{:?} is not a valid time.", n)); + return Err(format!("{} is not a valid time.", n)); }, }, }, diff --git a/voxygen/src/session/settings_change.rs b/voxygen/src/session/settings_change.rs index 5956715f7c..f2778abcbc 100644 --- a/voxygen/src/session/settings_change.rs +++ b/voxygen/src/session/settings_change.rs @@ -470,9 +470,7 @@ impl SettingsChange { .renderer_mut() .set_render_mode((*new_render_mode).clone()) .unwrap(); - settings.graphics.render_mode = *new_render_mode; - }, Graphics::ChangeFullscreenMode(new_fullscreen_settings) => { global_state From f6e2c6885c671392f54738bb12be0ad5881d6bd4 Mon Sep 17 00:00:00 2001 From: LunarEclipse Date: Thu, 10 Nov 2022 17:19:43 +0100 Subject: [PATCH 5/5] Cargo fmt --- client/src/lib.rs | 2 +- voxygen/src/ecs/comp.rs | 5 +---- voxygen/src/ecs/mod.rs | 1 - voxygen/src/scene/mod.rs | 22 ++++++++++++---------- voxygen/src/session/mod.rs | 2 +- 5 files changed, 15 insertions(+), 17 deletions(-) diff --git a/client/src/lib.rs b/client/src/lib.rs index f5c79d5bcf..78b70022ab 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -1008,7 +1008,7 @@ impl Client { self.lod_distance = lod_distance; } - pub fn set_flashing_lights_enabled(&mut self, flashing_lights_enabled: bool){ + pub fn set_flashing_lights_enabled(&mut self, flashing_lights_enabled: bool) { self.flashing_lights_enabled = flashing_lights_enabled; } diff --git a/voxygen/src/ecs/comp.rs b/voxygen/src/ecs/comp.rs index f0fd63e990..ecc769ca93 100644 --- a/voxygen/src/ecs/comp.rs +++ b/voxygen/src/ecs/comp.rs @@ -1,7 +1,4 @@ -use common::{ - comp::Ori, - outcome::HealthChangeInfo -}; +use common::{comp::Ori, outcome::HealthChangeInfo}; use specs::{Component, VecStorage}; use vek::*; diff --git a/voxygen/src/ecs/mod.rs b/voxygen/src/ecs/mod.rs index 2edb75929c..8b7b647b38 100644 --- a/voxygen/src/ecs/mod.rs +++ b/voxygen/src/ecs/mod.rs @@ -5,7 +5,6 @@ use crate::audio::sfx::SfxEventItem; use common::{event::EventBus, slowjob::SlowJobPool}; use specs::{World, WorldExt}; - pub fn init(world: &mut World) { world.register::(); world.register::(); diff --git a/voxygen/src/scene/mod.rs b/voxygen/src/scene/mod.rs index a348b14e19..9056ee1743 100644 --- a/voxygen/src/scene/mod.rs +++ b/voxygen/src/scene/mod.rs @@ -135,7 +135,7 @@ pub struct SceneData<'a> { pub flashing_lights_enabled: bool, pub figure_lod_render_distance: f32, pub is_aiming: bool, - pub interpolated_time_of_day: f64 + pub interpolated_time_of_day: f64, } impl<'a> SceneData<'a> { @@ -503,7 +503,7 @@ impl Scene { audio: &mut AudioFrontend, scene_data: &SceneData, client: &Client, - ) { + ) { span!(_guard, "maintain", "Scene::maintain"); // Get player position. let ecs = scene_data.state.ecs(); @@ -718,16 +718,18 @@ impl Scene { // Update light projection matrices for the shadow map. - // When the target time of day and time of day have a large discrepancy - // (i.e two days), the linear interpolation causes brght flashing effects - // in the sky. This will snap the time of day to the target time of day - // for the client to avoid the flashing effect if flashing lights is - // disabled. + // When the target time of day and time of day have a large discrepancy + // (i.e two days), the linear interpolation causes brght flashing effects + // in the sky. This will snap the time of day to the target time of day + // for the client to avoid the flashing effect if flashing lights is + // disabled. const DAY: f64 = 60.0 * 60.0 * 24.0; let time_of_day = scene_data.state.get_time_of_day(); - self.interpolated_time_of_day = if (self.interpolated_time_of_day - time_of_day).abs() > DAY*2.0 - && !scene_data.flashing_lights_enabled{ - time_of_day + self.interpolated_time_of_day = if (self.interpolated_time_of_day - time_of_day).abs() + > DAY * 2.0 + && !scene_data.flashing_lights_enabled + { + time_of_day } else { Lerp::lerp(self.interpolated_time_of_day, time_of_day, dt as f64) }; diff --git a/voxygen/src/session/mod.rs b/voxygen/src/session/mod.rs index b2d0360f94..4b9e223ff2 100644 --- a/voxygen/src/session/mod.rs +++ b/voxygen/src/session/mod.rs @@ -1818,7 +1818,7 @@ impl PlayState for SessionState { weapon_trails_enabled: settings.graphics.weapon_trails_enabled, flashing_lights_enabled: settings.graphics.render_mode.flashing_lights_enabled, is_aiming: self.is_aiming, - interpolated_time_of_day: self.scene.interpolated_time_of_day + interpolated_time_of_day: self.scene.interpolated_time_of_day, }; // Render world