Use instant over std::time, for wasm compat (#449)
Replace std::time with the `instant` crate, which bridges to std::time on native but on wasm calls performance.now() instead of panicking. A step towards 🕸️ Web support #446 * logo: replace SystemTime/UNIX_EPOCH with Instant
This commit is contained in:
parent
8e728830b3
commit
503a98d7a8
|
@ -2277,6 +2277,7 @@ dependencies = [
|
|||
"cfb8",
|
||||
"flate2",
|
||||
"hex",
|
||||
"instant",
|
||||
"log",
|
||||
"num-traits",
|
||||
"reqwest",
|
||||
|
@ -2310,6 +2311,7 @@ dependencies = [
|
|||
"glow",
|
||||
"glutin",
|
||||
"image",
|
||||
"instant",
|
||||
"lazy_static",
|
||||
"log",
|
||||
"rand 0.7.3",
|
||||
|
|
|
@ -38,6 +38,7 @@ collision = "0.20.1"
|
|||
rsa_public_encrypt_pkcs1 = "0.2.0"
|
||||
structopt = "0.3.21"
|
||||
clipboard = "0.5.0"
|
||||
instant = "0.1.9"
|
||||
# clippy = "*"
|
||||
|
||||
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
||||
|
|
|
@ -432,6 +432,15 @@ dependencies = [
|
|||
"hashbrown",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "instant"
|
||||
version = "0.1.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "61124eeebbd69b8190558df225adf7e4caafce0d743919e5d6b19652314ec5ec"
|
||||
dependencies = [
|
||||
"cfg-if 1.0.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "iovec"
|
||||
version = "0.1.4"
|
||||
|
@ -960,6 +969,7 @@ dependencies = [
|
|||
"cfb8",
|
||||
"flate2",
|
||||
"hex",
|
||||
"instant",
|
||||
"log",
|
||||
"num-traits",
|
||||
"reqwest",
|
||||
|
|
|
@ -15,6 +15,7 @@ byteorder = "1.3.4"
|
|||
log = { version = "0.4.11", features = ["std"] }
|
||||
flate2 = { version = "1.0.19", features = ["rust_backend"], default-features = false }
|
||||
num-traits = "0.2.12"
|
||||
instant = "0.1.9"
|
||||
|
||||
[dependencies.steven_shared]
|
||||
path = "../shared"
|
||||
|
|
|
@ -29,6 +29,7 @@ use crate::shared::Position;
|
|||
use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};
|
||||
use flate2::read::{ZlibDecoder, ZlibEncoder};
|
||||
use flate2::Compression;
|
||||
use instant::{Duration, Instant};
|
||||
use log::debug;
|
||||
use std::convert;
|
||||
use std::default;
|
||||
|
@ -37,7 +38,6 @@ use std::io;
|
|||
use std::io::{Read, Write};
|
||||
use std::net::TcpStream;
|
||||
use std::sync::atomic::{AtomicBool, AtomicI32, Ordering};
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
pub const SUPPORTED_PROTOCOLS: [i32; 24] = [
|
||||
754, 753, 751, 736, 735, 578, 575, 498, 490, 485, 480, 477, 452, 451, 404, 340, 316, 315, 210,
|
||||
|
|
|
@ -12,9 +12,9 @@ use crate::types::Gamemode;
|
|||
use crate::world;
|
||||
use cgmath::{self, Decomposed, Matrix4, Point3, Quaternion, Rad, Rotation3, Vector3};
|
||||
use collision::{Aabb, Aabb3};
|
||||
use instant::Instant;
|
||||
use std::collections::HashMap;
|
||||
use std::hash::BuildHasherDefault;
|
||||
use std::time::Instant;
|
||||
|
||||
pub fn add_systems(m: &mut ecs::Manager) {
|
||||
let sys = MovementHandler::new(m);
|
||||
|
|
|
@ -17,9 +17,9 @@
|
|||
#![allow(clippy::many_single_char_names)] // short variable names provide concise clarity
|
||||
#![allow(clippy::float_cmp)] // float comparison used to check if changed
|
||||
|
||||
use instant::{Duration, Instant};
|
||||
use log::{error, info, warn};
|
||||
use std::fs;
|
||||
use std::time::{Duration, Instant};
|
||||
extern crate steven_shared as shared;
|
||||
|
||||
use structopt::StructOpt;
|
||||
|
|
|
@ -24,8 +24,8 @@ use crate::protocol;
|
|||
use crate::render;
|
||||
use crate::ui;
|
||||
|
||||
use instant::Duration;
|
||||
use rand::Rng;
|
||||
use std::time::Duration;
|
||||
|
||||
pub struct ServerList {
|
||||
elements: Option<UIElements>,
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
use crate::render;
|
||||
use crate::resources;
|
||||
use crate::ui;
|
||||
use instant::Instant;
|
||||
use rand::{self, seq::SliceRandom};
|
||||
use std::f64::consts;
|
||||
use std::sync::{Arc, RwLock};
|
||||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
|
||||
pub struct Logo {
|
||||
_shadow: ui::BatchRef,
|
||||
|
@ -15,6 +15,7 @@ pub struct Logo {
|
|||
text_orig_x: f64,
|
||||
text_index: isize,
|
||||
text_strings: Vec<String>,
|
||||
started: Instant,
|
||||
}
|
||||
|
||||
impl Logo {
|
||||
|
@ -131,11 +132,12 @@ impl Logo {
|
|||
text_orig_x,
|
||||
text_index: -1,
|
||||
text_strings,
|
||||
started: Instant::now(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn tick(&mut self, renderer: &mut render::Renderer) {
|
||||
let now = SystemTime::now().duration_since(UNIX_EPOCH).unwrap();
|
||||
let now = Instant::now().duration_since(self.started);
|
||||
|
||||
// Splash text
|
||||
let text_index = (now.as_secs() / 15) as isize % self.text_strings.len() as isize;
|
||||
|
|
|
@ -206,7 +206,7 @@ impl World {
|
|||
|
||||
#[allow(clippy::verbose_bit_mask)] // "llvm generates better code" for updates_performed & 0xFFF "on x86"
|
||||
pub fn tick(&mut self, m: &mut ecs::Manager) {
|
||||
use std::time::Instant;
|
||||
use instant::Instant;
|
||||
let start = Instant::now();
|
||||
let mut updates_performed = 0;
|
||||
while !self.light_updates.is_empty() {
|
||||
|
|
Loading…
Reference in New Issue