Major Refactor: separate project into multiple crates
This commit is contained in:
parent
f943e4c945
commit
d0440f3da3
24 changed files with 209 additions and 2232 deletions
4
raidillon_core/Cargo.toml
Normal file
4
raidillon_core/Cargo.toml
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
[package]
|
||||
name = "raidillon_core"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
3
raidillon_core/src/lib.rs
Normal file
3
raidillon_core/src/lib.rs
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
pub mod time;
|
||||
|
||||
pub use time::Time;
|
||||
34
raidillon_core/src/time.rs
Normal file
34
raidillon_core/src/time.rs
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
use std::time::{Duration, Instant};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Time {
|
||||
last: Instant,
|
||||
delta: Duration,
|
||||
total: Duration,
|
||||
}
|
||||
|
||||
impl Time {
|
||||
pub fn new() -> Self {
|
||||
let now = Instant::now();
|
||||
Self {
|
||||
last: now,
|
||||
delta: Duration::ZERO,
|
||||
total: Duration::ZERO,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn tick(&mut self) {
|
||||
let now = Instant::now();
|
||||
self.delta = now - self.last;
|
||||
self.total += self.delta;
|
||||
self.last = now;
|
||||
}
|
||||
|
||||
pub fn delta_seconds(&self) -> f32 {
|
||||
self.delta.as_secs_f32()
|
||||
}
|
||||
|
||||
pub fn total_seconds(&self) -> f32 {
|
||||
self.total.as_secs_f32()
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue