diff --git a/src/action/components.rs b/src/action/components.rs index d6f86e6..8ea7c9f 100644 --- a/src/action/components.rs +++ b/src/action/components.rs @@ -1,4 +1,4 @@ -use std::time::Instant; +use std::time::{Duration, Instant}; use bevy::{ prelude::{Component, ReflectResource, Resource, Vec3}, @@ -14,6 +14,16 @@ impl Default for ActionDebugInstant { } } +impl ActionDebugInstant { + pub fn reset(&mut self) { + self.0 = Instant::now(); + } + + pub fn elapsed(&self) -> Duration { + self.0.elapsed() + } +} + #[derive(Debug, Component)] pub(super) struct Tunneling { pub frames: usize, diff --git a/src/action/systems.rs b/src/action/systems.rs index e36dc74..4506454 100644 --- a/src/action/systems.rs +++ b/src/action/systems.rs @@ -1,6 +1,4 @@ use std::f32::consts::PI; -#[cfg(feature = "inspector")] -use std::time::Instant; use bevy::prelude::{Commands, Entity, Query, Res, ResMut, Time, Transform, Vec3, With, Without}; use bevy_rapier3d::prelude::{ @@ -68,10 +66,9 @@ pub(super) fn falling_cat( #[cfg(feature = "inspector")] { - let now = Instant::now(); - if (now - debug_instant.0).as_millis() > 1000 { + if debug_instant.elapsed().as_millis() > 1000 { dbg!(&control_vars, mag); - debug_instant.0 = now; + debug_instant.reset(); } } control_vars.decay();