mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
CHANGE: moved time of day interpolation logic out of Client and into Scene for semantics and accessing the settings logically
This commit is contained in:
parent
775025ac63
commit
f22a9d030d
@ -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::<TimeOfDay>();
|
||||
|
||||
// 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
|
||||
|
@ -1,4 +1,7 @@
|
||||
use common::{comp::Ori, outcome::HealthChangeInfo};
|
||||
use common::{
|
||||
comp::Ori,
|
||||
outcome::HealthChangeInfo
|
||||
};
|
||||
use specs::{Component, VecStorage};
|
||||
use vek::*;
|
||||
|
||||
|
@ -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::<comp::HpFloaterList>();
|
||||
world.register::<comp::Interpolated>();
|
||||
|
@ -111,6 +111,7 @@ pub struct Scene {
|
||||
ambient_mgr: AmbientMgr,
|
||||
|
||||
integrated_rain_vel: f32,
|
||||
pub interpolated_time_of_day: f64,
|
||||
last_lightning: Option<(Vec3<f32>, 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<f32> { Globals::get_sun_dir(self.state.get_time_of_day()) }
|
||||
pub fn get_sun_dir(&self) -> Vec3<f32> { Globals::get_sun_dir(self.interpolated_time_of_day) }
|
||||
|
||||
pub fn get_moon_dir(&self) -> Vec3<f32> { Globals::get_moon_dir(self.state.get_time_of_day()) }
|
||||
pub fn get_moon_dir(&self) -> Vec3<f32> { 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());
|
||||
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user