From f7f84e8484de318d5c1dd25b7fcb70eafe6f3274 Mon Sep 17 00:00:00 2001 From: est31 Date: Wed, 14 Aug 2019 17:49:05 +0200 Subject: [PATCH] Replace durtofl with recently stabilized duration_float The duration_float feature will arrive in Rust 1.38.0 stable. https://github.com/rust-lang/rust/issues/54361 --- mehlon-server/lib.rs | 6 +----- mehlon/client.rs | 8 ++------ 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/mehlon-server/lib.rs b/mehlon-server/lib.rs index e905a62..161e227 100644 --- a/mehlon-server/lib.rs +++ b/mehlon-server/lib.rs @@ -213,7 +213,7 @@ impl Server { /// Update the stored fps value and return the delta time fn update_fps(&mut self) -> f32 { let cur_time = Instant::now(); - let float_delta = durtofl(cur_time - self.last_frame_time); + let float_delta = (cur_time - self.last_frame_time).as_secs_f32(); self.last_frame_time = cur_time; const EPS :f32 = 0.1; @@ -820,10 +820,6 @@ fn close_connections(conns_to_close :&[PlayerIdPair], connections :&mut HashMap< } } -fn durtofl(d :Duration) -> f32 { - d.as_millis() as f32 / 1_000.0 -} - /// Block position to chunk position pub fn btchn(v :Vector3) -> Vector3 { fn r(x :isize) -> isize { diff --git a/mehlon/client.rs b/mehlon/client.rs index 8130f4f..5c28229 100644 --- a/mehlon/client.rs +++ b/mehlon/client.rs @@ -10,7 +10,7 @@ use glium_glyph::glyph_brush::{ rusttype::Font, Section, }; use std::collections::{HashMap, VecDeque}; -use std::time::{Instant, Duration}; +use std::time::Instant; use std::thread; use std::sync::mpsc::{channel, Receiver}; use std::sync::Arc; @@ -211,7 +211,7 @@ impl Game { /// Update the stored fps value and return the delta time fn update_fps(&mut self) -> f32 { let cur_time = Instant::now(); - let float_delta = durtofl(cur_time - self.last_frame_time); + let float_delta = (cur_time - self.last_frame_time).as_secs_f32(); self.last_frame_time = cur_time; const EPS :f32 = 0.1; @@ -875,10 +875,6 @@ fn hand_mesh(pos :Vector3, blk :MapBlock, vertices } -fn durtofl(d :Duration) -> f32 { - d.as_millis() as f32 / 1_000.0 -} - fn clamp(a :f32, min :f32, max :f32) -> f32 { if a > min { if a < max {