[][src]Struct spectrusty_core::chip::ThreadSyncTimer

pub struct ThreadSyncTimer {
    pub time: Instant,
    pub frame_duration: Duration,
}

A tool for synchronizing emulation with a running thread.

Fields

time: Instant

The start time of a current synchronization period.

frame_duration: Duration

The desired duration of a single synchronization period.

Implementations

impl ThreadSyncTimer[src]

pub fn new(frame_duration_nanos: u32) -> Self[src]

Pass the real time duration of a desired synchronization period (usually a duration of a video frame).

pub fn set_frame_duration(&mut self, frame_duration_nanos: u32)[src]

Sets ThreadSyncTimer::frame_duration from the provided frame_duration_nanos.

pub fn restart(&mut self) -> Instant[src]

Restarts the synchronization period. Useful e.g. for resuming paused emulation.

pub fn synchronize_thread_to_frame(&mut self) -> Result<(), u32>[src]

Calculates the difference between the desired duration of a synchronization period and the real time that has passed from the start of the current period and levels the difference by calling std::thread::sleep.

This method may be called at the end of each iteration of an emulation loop to synchronize the running thread with a desired iteration period.

Returns Ok if the thread is in sync with the emulation. In this instance the value of ThreadSyncTimer::frame_duration is being added to ThreadSyncTimer::time to mark the beginning of a new period.

Returns Err(missed_periods) if the elapsed time exceeds the desired period duration. In this intance the start of a new period is set to Instant::now.

pub fn check_frame_elapsed(&mut self) -> Option<Duration>[src]

Returns Some(excess_duration) if the time elapsed from the beginning of the current period exceeds or is equal to the desired duration of a synchronization period. Otherwise returns None.

The value returned is the excess time that has elapsed above the desired duration. If the time elapsed equals to the frame_duration the returned value equals to zero.

In case Some variant is returned the value of ThreadSyncTimer::frame_duration is being added to ThreadSyncTimer::time to mark the beginning of a new period.

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.