mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Merge branch 'master' into 'master'
Assorted tweaks See merge request veloren/veloren!59 Former-commit-id: dc90c1e6926cfad8bcd824b8ff6487aafe38dca7
This commit is contained in:
commit
b6d785f401
@ -13,6 +13,7 @@ pub struct Clock {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Clock {
|
impl Clock {
|
||||||
|
#[allow(dead_code)]
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
last_sys_time: SystemTime::now(),
|
last_sys_time: SystemTime::now(),
|
||||||
@ -21,12 +22,16 @@ impl Clock {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_tps(&self) -> f64 { self.running_tps_average }
|
#[allow(dead_code)]
|
||||||
|
pub fn get_tps(&self) -> f64 { 1.0 / self.running_tps_average }
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
pub fn get_last_delta(&self) -> Duration { self.last_delta.unwrap_or(Duration::new(0, 0)) }
|
pub fn get_last_delta(&self) -> Duration { self.last_delta.unwrap_or(Duration::new(0, 0)) }
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
pub fn get_avg_delta(&self) -> Duration { Duration::from_secs_f64(self.running_tps_average) }
|
pub fn get_avg_delta(&self) -> Duration { Duration::from_secs_f64(self.running_tps_average) }
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
pub fn tick(&mut self, tgt: Duration) {
|
pub fn tick(&mut self, tgt: Duration) {
|
||||||
let delta = SystemTime::now()
|
let delta = SystemTime::now()
|
||||||
.duration_since(self.last_sys_time)
|
.duration_since(self.last_sys_time)
|
||||||
@ -34,7 +39,12 @@ impl Clock {
|
|||||||
|
|
||||||
// Attempt to sleep to fill the gap
|
// Attempt to sleep to fill the gap
|
||||||
if let Some(sleep_dur) = tgt.checked_sub(delta) {
|
if let Some(sleep_dur) = tgt.checked_sub(delta) {
|
||||||
thread::sleep(sleep_dur);
|
let adjustment = if self.running_tps_average == 0.0 {
|
||||||
|
1.0
|
||||||
|
} else {
|
||||||
|
tgt.as_secs_f64() / self.running_tps_average
|
||||||
|
};
|
||||||
|
thread::sleep(Duration::from_secs_f64(sleep_dur.as_secs_f64() * adjustment));
|
||||||
}
|
}
|
||||||
|
|
||||||
let delta = SystemTime::now()
|
let delta = SystemTime::now()
|
||||||
@ -43,8 +53,11 @@ impl Clock {
|
|||||||
|
|
||||||
self.last_sys_time = SystemTime::now();
|
self.last_sys_time = SystemTime::now();
|
||||||
self.last_delta = Some(delta);
|
self.last_delta = Some(delta);
|
||||||
self.running_tps_average =
|
self.running_tps_average = if self.running_tps_average == 0.0 {
|
||||||
|
delta.as_secs_f64()
|
||||||
|
} else {
|
||||||
CLOCK_SMOOTHING * self.running_tps_average +
|
CLOCK_SMOOTHING * self.running_tps_average +
|
||||||
(1.0 - CLOCK_SMOOTHING) * delta.as_secs_f64();
|
(1.0 - CLOCK_SMOOTHING) * delta.as_secs_f64()
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ impl<'a> System<'a> for Sys {
|
|||||||
*bearing += Vec2::new(
|
*bearing += Vec2::new(
|
||||||
rand::random::<f32>().fract() - 0.5,
|
rand::random::<f32>().fract() - 0.5,
|
||||||
rand::random::<f32>().fract() - 0.5,
|
rand::random::<f32>().fract() - 0.5,
|
||||||
) - *bearing * 0.05 - pos.0 * 0.001;
|
) * 0.1 - *bearing * 0.01 - pos.0 * 0.0002;
|
||||||
|
|
||||||
if bearing.magnitude_squared() != 0.0 {
|
if bearing.magnitude_squared() != 0.0 {
|
||||||
control.move_dir = bearing.normalized();
|
control.move_dir = bearing.normalized();
|
||||||
|
Loading…
Reference in New Issue
Block a user