Move egui layer to a separate DebugGuiStack structure
This commit is contained in:
parent
3f367e19ac
commit
92c0278ef0
5 changed files with 104 additions and 9 deletions
43
src/core/time.rs
Normal file
43
src/core/time.rs
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
//! Provides time related functionality for Clocks.
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
use flax::component;
|
||||
|
||||
component! {
|
||||
pub clock: Clock,
|
||||
}
|
||||
|
||||
/// Measures high precision time
|
||||
#[allow(dead_code)]
|
||||
pub struct Clock {
|
||||
start: Instant,
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
impl Clock {
|
||||
// Creates and starts a new clock
|
||||
pub fn new() -> Self {
|
||||
Clock {
|
||||
start: Instant::now(),
|
||||
}
|
||||
}
|
||||
|
||||
// Returns the elapsed time
|
||||
pub fn elapsed(&self) -> Duration {
|
||||
Instant::now() - self.start
|
||||
}
|
||||
|
||||
// Resets the clock and returns the elapsed time
|
||||
pub fn reset(&mut self) -> Duration {
|
||||
let elapsed = self.elapsed();
|
||||
|
||||
self.start = Instant::now();
|
||||
elapsed
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Clock {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue