Skip to content

Commit

Permalink
Replace durtofl with recently stabilized duration_float
Browse files Browse the repository at this point in the history
The duration_float feature will arrive in Rust 1.38.0 stable.

rust-lang/rust#54361
  • Loading branch information
est31 committed Aug 14, 2019
1 parent 4e6f438 commit f7f84e8
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 11 deletions.
6 changes: 1 addition & 5 deletions mehlon-server/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ impl<S :NetworkServerSocket> Server<S> {
/// 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;
Expand Down Expand Up @@ -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<isize>) -> Vector3<isize> {
fn r(x :isize) -> isize {
Expand Down
8 changes: 2 additions & 6 deletions mehlon/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -211,7 +211,7 @@ impl<C :NetworkClientConn> Game<C> {
/// 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;
Expand Down Expand Up @@ -875,10 +875,6 @@ fn hand_mesh(pos :Vector3<f32>, 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 {
Expand Down

0 comments on commit f7f84e8

Please sign in to comment.