[−][src]Struct spectrusty_core::chip::ThreadSyncTimer
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
impl RefUnwindSafe for ThreadSyncTimer
[src]
impl Send for ThreadSyncTimer
[src]
impl Sync for ThreadSyncTimer
[src]
impl Unpin for ThreadSyncTimer
[src]
impl UnwindSafe for ThreadSyncTimer
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,