Struct veloren_common_net::synced_components::inner::agent::Timer
pub struct Timer {
action_starts: Vec<Option<f64>>,
last_action: Option<TimerAction>,
}
Expand description
A time used for managing agent-related timeouts. The timer is designed to keep track of the start of any number of previous actions. However, starting/progressing an action will end previous actions. Therefore, the timer should be used for actions that are mutually-exclusive.
Fields§
§action_starts: Vec<Option<f64>>
§last_action: Option<TimerAction>
Implementations§
§impl Timer
impl Timer
pub fn reset(&mut self, action: TimerAction) -> bool
pub fn reset(&mut self, action: TimerAction) -> bool
Reset the timer for the given action, returning true if the timer was not already reset.
pub fn start(&mut self, time: f64, action: TimerAction)
pub fn start(&mut self, time: f64, action: TimerAction)
Start the timer for the given action, even if it was already started.
pub fn progress(&mut self, time: f64, action: TimerAction)
pub fn progress(&mut self, time: f64, action: TimerAction)
Continue timing the given action, starting it if it was not already started.
pub fn time_of_last(&self, action: TimerAction) -> Option<f64>
pub fn time_of_last(&self, action: TimerAction) -> Option<f64>
Return the time that the given action was last performed at.
pub fn time_since_exceeds(
&self,
time: f64,
action: TimerAction,
timeout: f64,
) -> bool
pub fn time_since_exceeds( &self, time: f64, action: TimerAction, timeout: f64, ) -> bool
Return true
if the time since the action was last started exceeds the
given timeout.
pub fn timeout_elapsed(
&mut self,
time: f64,
action: TimerAction,
timeout: f64,
) -> Option<bool>
pub fn timeout_elapsed( &mut self, time: f64, action: TimerAction, timeout: f64, ) -> Option<bool>
Return true
while the time since the action was last started is less
than the given period. Once the time has elapsed, reset the timer.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Timer
impl RefUnwindSafe for Timer
impl Send for Timer
impl Sync for Timer
impl Unpin for Timer
impl UnwindSafe for Timer
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more§impl<T> Pointable for T
impl<T> Pointable for T
§impl<Context> SubContext<Context> for Context
impl<Context> SubContext<Context> for Context
fn sub_context(self) -> Context
§impl<T> TryDefault for Twhere
T: Default,
impl<T> TryDefault for Twhere
T: Default,
§fn try_default() -> Result<T, String>
fn try_default() -> Result<T, String>
§fn unwrap_default() -> Self
fn unwrap_default() -> Self
try_default
and panics on an error case.