Permalink
Browse files

Remove the `time` crate

The vast majority of our `time` usage can now be done with
`std::time`.

The one bit that can't is the datetime in the replay file names.

This doesn't compile until that's resolved.
  • Loading branch information...
tomassedovic committed Dec 13, 2017
1 parent 6a16a6a commit 386ef64717c8961dcd79165c505e1d96d8bdceca
Showing with 93 additions and 72 deletions.
  1. +0 −13 Cargo.lock
  2. +0 −1 Cargo.toml
  3. +7 −7 src/animation.rs
  4. +9 −7 src/engine/glium.rs
  5. +1 −1 src/engine/mod.rs
  6. +11 −10 src/game.rs
  7. +1 −1 src/graphics.rs
  8. +1 −1 src/item.rs
  9. +1 −1 src/level.rs
  10. +1 −1 src/main.rs
  11. +1 −1 src/monster.rs
  12. +1 −1 src/player.rs
  13. +8 −7 src/render.rs
  14. +5 −6 src/state.rs
  15. +6 −5 src/stats.rs
  16. +12 −9 src/timer.rs
  17. +28 −0 src/util.rs

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -12,7 +12,6 @@ path = "src/main.rs"

[dependencies]
bitflags = "1.0"
time = "0.1.38"
rand = "0.3.18"
clap = { version = "2.20.1", optional = true }
serde = "1.0"
@@ -1,7 +1,7 @@
use color::Color;
use point::{Point, SquareArea};

use time::Duration;
use std::time::Duration;
use timer::Timer;

pub trait AreaOfEffect {
@@ -34,15 +34,15 @@ impl SquareExplosion {
assert!(initial_radius <= max_radius);
// Count the initial wave plus the rest that makes the difference
let wave_count = max_radius - initial_radius + 1;
let wave_duration = Duration::milliseconds(100);
let wave_duration = Duration::from_millis(100);
SquareExplosion {
center,
max_radius,
initial_radius,
current_radius: initial_radius,
color,
wave_count,
timer: Timer::new(wave_duration * wave_count),
timer: Timer::new(wave_duration.checked_mul(wave_count as u32).unwrap()),
}
}
}
@@ -98,7 +98,7 @@ impl CardinalExplosion {
assert!(initial_radius <= max_radius);
// Count the initial wave plus the rest that makes the difference
let wave_count = max_radius - initial_radius + 1;
let wave_duration = Duration::milliseconds(100);
let wave_duration = Duration::from_millis(100);
CardinalExplosion {
center,
max_radius,
@@ -107,7 +107,7 @@ impl CardinalExplosion {
kill_color,
shatter_color,
wave_count,
timer: Timer::new(wave_duration * wave_count),
timer: Timer::new(wave_duration.checked_mul(wave_count as u32).unwrap()),
}
}
}
@@ -222,7 +222,7 @@ impl DiagonalExplosion {
assert!(initial_radius <= max_radius);
// Count the initial wave plus the rest that makes the difference
let wave_count = max_radius - initial_radius + 1;
let wave_duration = Duration::milliseconds(100);
let wave_duration = Duration::from_millis(100);
DiagonalExplosion {
center,
max_radius,
@@ -231,7 +231,7 @@ impl DiagonalExplosion {
kill_color,
shatter_color,
wave_count,
timer: Timer::new(wave_duration * wave_count),
timer: Timer::new(wave_duration.checked_mul(wave_count as u32).unwrap()),
}
}
}
@@ -10,7 +10,9 @@ use glium::glutin::VirtualKeyCode as BackendKey;
use image;
use keys::{Key, KeyCode};
use point::Point;
use time::{Duration, PreciseTime};
use std::time::{Duration, Instant};
use util;


// NOTE: This is designed specifically to deduplicated characters on
// the same position (using Vec::dedup). So the only thing considered
@@ -228,25 +230,25 @@ pub fn main_loop<T>(
let mut keys = vec![];
// We're not using alpha at all for now, but it's passed everywhere.
let alpha = 1.0;
let mut previous_frame_time = PreciseTime::now();
let mut fps_clock = Duration::milliseconds(0);
let mut previous_frame_time = Instant::now();
let mut fps_clock = Duration::from_millis(0);
let mut frame_counter = 0;
let mut fps = 1;
let mut running = true;


while running {
let now = PreciseTime::now();
let dt = previous_frame_time.to(now);
let now = Instant::now();
let dt = previous_frame_time.duration_since(now);
previous_frame_time = now;

// Calculate FPS
fps_clock = fps_clock + dt;
frame_counter += 1;
if fps_clock.num_milliseconds() > 1000 {
if util::num_milliseconds(fps_clock) > 1000 {
fps = frame_counter;
frame_counter = 1;
fps_clock = Duration::milliseconds(0);
fps_clock = Duration::from_millis(0);
}

drawcalls.clear();
@@ -5,7 +5,7 @@ use keys::Key;
use point::Point;
use std::borrow::Cow;

use time::Duration;
use std::time::Duration;


#[cfg(feature = "opengl")]
@@ -18,11 +18,12 @@ use render;
use state::{self, Command, Side, State};
use stats::{FrameStats, Stats};
use std::collections::{HashMap, VecDeque};
use std::i64;
use std::u64;
use std::io::Write;
use std::iter::FromIterator;
use time::Duration;
use std::time::Duration;
use timer::{Stopwatch, Timer};
use util;
use world::World;


@@ -101,9 +102,9 @@ pub fn update(

let paused_one_step = state.paused && state.keys.matches_code(KeyCode::Right);
let timed_step = if state.replay && !state.paused &&
(state.replay_step.num_milliseconds() >= 50 || state.replay_full_speed)
(util::num_milliseconds(state.replay_step) >= 50 || state.replay_full_speed)
{
state.replay_step = Duration::zero();
state.replay_step = Duration::new(0, 0);
true
} else {
false
@@ -227,9 +228,9 @@ pub fn update(
};
state.screen_fading = Some(animation::ScreenFade::new(
fade_color,
Duration::milliseconds(fade_duration),
Duration::milliseconds(200),
Duration::milliseconds(300),
Duration::from_millis(fade_duration),
Duration::from_millis(200),
Duration::from_millis(300),
fade_percentage,
));
}
@@ -252,7 +253,7 @@ pub fn update(
// NOTE: re-centre the display if the player reached the end of the screen
if state.pos_timer.finished() {
let display_pos = state.player.pos - screen_left_top_corner;
let dur = Duration::milliseconds(400);
let dur = Duration::from_millis(400);
let exploration_radius = formula::exploration_radius(state.player.mind);
// TODO: move the screen roughly the same distance along X and Y
if display_pos.x < exploration_radius ||
@@ -930,13 +931,13 @@ fn show_exit_stats(stats: &Stats) {
stats
.longest_update_durations()
.iter()
.map(|dur| dur.num_microseconds().unwrap_or(i64::MAX))
.map(|dur| util::num_microseconds(*dur).unwrap_or(u64::MAX))
.map(|us| us as f32 / 1000.0)
.collect::<Vec<_>>(),
stats
.longest_drawcall_durations()
.iter()
.map(|dur| dur.num_microseconds().unwrap_or(i64::MAX))
.map(|dur| util::num_microseconds(*dur).unwrap_or(u64::MAX))
.map(|us| us as f32 / 1000.0)
.collect::<Vec<_>>()
);
@@ -3,7 +3,7 @@
use color::Color;
use engine::Draw;
use point::Point;
use time::Duration;
use std::time::Duration;


pub trait Render {
@@ -5,7 +5,7 @@ use self::Kind::*;
use color::{self, Color};
use graphics::Render;
use player::Modifier;
use time::Duration;
use std::time::Duration;


#[derive(Clone, Copy, PartialEq, Debug, Eq, Hash)]
@@ -6,7 +6,7 @@ use point;

use rand::{self, Rng};
use std::collections::HashMap;
use time::Duration;
use std::time::Duration;


/// Position within a level. Ensured to be always within bounds.
@@ -4,7 +4,6 @@
#[macro_use]
extern crate bitflags;
extern crate rand;
extern crate time;
#[macro_use]
extern crate serde_derive;
extern crate serde_json;
@@ -56,6 +55,7 @@ mod render;
mod state;
mod stats;
mod timer;
mod util;
mod world;


@@ -9,7 +9,7 @@ use player::Modifier;
use point::Point;

use rand::{Rand, Rng};
use time::Duration;
use std::time::Duration;
use world::World;


@@ -6,7 +6,7 @@ use monster::{Monster, CompanionBonus};
use point::Point;
use ranged_int::Ranged;
use std::fmt::{Display, Error, Formatter};
use time::Duration;
use std::time::Duration;


#[derive(Copy, Clone, PartialEq, Debug)]
@@ -14,7 +14,8 @@ use state::{Side, State};
use std::borrow::Cow;
use std::collections::HashMap;

use time::Duration;
use std::time::Duration;
use util;
use world::Chunk;


@@ -55,7 +56,7 @@ pub fn render_game(state: &State, dt: Duration, fps: i32, drawcalls: &mut Vec<Dr
let display_area = Rectangle::center(state.screen_position_in_world, state.map_size / 2);
let screen_coords_from_world = |pos| pos - screen_left_top_corner;

let total_time_ms = state.clock.num_milliseconds();
let total_time_ms = util::num_milliseconds(state.clock) as i64;
let world_size = state.world_size;

let player_will_is_max = state.player.will.is_max();
@@ -443,21 +444,21 @@ fn render_panel(
lines.push(
format!(
"upd: {}, dc: {}",
frame_stat.update.num_milliseconds(),
frame_stat.drawcalls.num_milliseconds()
util::num_milliseconds(frame_stat.update),
util::num_milliseconds(frame_stat.drawcalls)
).into(),
);
}
lines.push(
format!(
"longest upd: {}",
state.stats.longest_update().num_milliseconds()
util::num_milliseconds(state.stats.longest_update())
).into(),
);
lines.push(
format!(
"longest dc: {}",
state.stats.longest_drawcalls().num_milliseconds()
util::num_milliseconds(state.stats.longest_drawcalls())
).into(),
);
}
@@ -501,7 +502,7 @@ fn render_panel(
x: x + 1,
y: bottom - 1,
},
format!("dt: {}ms", dt.num_milliseconds()).into(),
format!("dt: {}ms", util::num_milliseconds(dt)).into(),
fg,
));
drawcalls.push(Draw::Text(
@@ -13,8 +13,7 @@ use std::collections::VecDeque;
use std::fs::{self, File};
use std::io::{self, BufRead, BufReader, Write};
use std::path::{Path, PathBuf};
use time;
use time::Duration;
use std::time::{self, Duration};
use timer::Timer;
use world::World;

@@ -52,7 +51,7 @@ pub enum Command {


pub fn generate_replay_path() -> PathBuf {
let cur_time = time::now();
let cur_time = time::Instant::now();
// Timestamp in format: 2016-11-20T20-04-39.123. We can't use the
// colons in the timestamp -- Windows don't allow them in a path.
let timestamp = format!(
@@ -177,10 +176,10 @@ impl State {
replay,
replay_full_speed,
exit_after,
clock: Duration::zero(),
replay_step: Duration::zero(),
clock: Duration::new(0, 0),
replay_step: Duration::new(0, 0),
stats: Stats::new(6000), // about a minute and a half at 60 FPS
pos_timer: Timer::new(Duration::milliseconds(0)),
pos_timer: Timer::new(Duration::from_millis(0)),
old_screen_pos: (0, 0).into(),
new_screen_pos: (0, 0).into(),
paused: false,
Oops, something went wrong.

0 comments on commit 386ef64

Please sign in to comment.