pub struct TickRateManager {Show 14 fields
pub tick_rate: f32,
pub nanoseconds_per_tick: u64,
pub tick_count: u64,
is_frozen: bool,
frozen_ticks_to_run: i32,
run_game_elements: bool,
remaining_sprint_ticks: i64,
scheduled_current_sprint_ticks: i64,
sprint_tick_start_time: Option<Instant>,
sprint_time_spent: i64,
previous_is_frozen: bool,
tick_times_nanos: [u64; 100],
aggregated_tick_times_nanos: u64,
smoothed_tick_time_ms: f32,
}Expand description
Manages the server tick rate, including freezing, stepping, and sprinting.
Fields§
§tick_rate: f32The current tick rate in ticks per second.
nanoseconds_per_tick: u64The number of nanoseconds per tick based on the tick rate.
tick_count: u64The current server tick count, including ticks where game elements are frozen.
is_frozen: boolWhether the server is currently frozen.
frozen_ticks_to_run: i32The number of ticks to run while frozen (stepping).
run_game_elements: boolWhether game elements should run this tick.
remaining_sprint_ticks: i64The number of ticks remaining to sprint.
scheduled_current_sprint_ticks: i64The total number of ticks scheduled for the current sprint.
sprint_tick_start_time: Option<Instant>The start time of the current sprint tick.
sprint_time_spent: i64The total time spent sprinting in nanoseconds.
previous_is_frozen: boolWhether the server was frozen before sprinting started.
tick_times_nanos: [u64; 100]Rolling buffer of the last 100 tick times in nanoseconds.
aggregated_tick_times_nanos: u64Aggregated sum of tick times for fast average calculation.
smoothed_tick_time_ms: f32Exponentially smoothed tick time in milliseconds.
Implementations§
Source§impl TickRateManager
impl TickRateManager
Sourcepub const fn new() -> Self
pub const fn new() -> Self
Creates a new TickRateManager with the default tick rate (20.0 TPS).
Sourcepub fn set_tick_rate(&mut self, rate: f32)
pub fn set_tick_rate(&mut self, rate: f32)
Sets the tick rate.
Sourcepub fn milliseconds_per_tick(&self) -> f32
pub fn milliseconds_per_tick(&self) -> f32
Returns milliseconds per tick based on the current tick rate.
Sourcepub const fn set_frozen(&mut self, frozen: bool)
pub const fn set_frozen(&mut self, frozen: bool)
Sets the frozen state of the server.
Sourcepub const fn is_stepping_forward(&self) -> bool
pub const fn is_stepping_forward(&self) -> bool
Returns whether the server is currently stepping forward.
Sourcepub const fn frozen_ticks_to_run(&self) -> i32
pub const fn frozen_ticks_to_run(&self) -> i32
Returns the number of frozen ticks to run.
Sourcepub const fn runs_normally(&self) -> bool
pub const fn runs_normally(&self) -> bool
Returns whether game elements should run this tick.
Sourcepub const fn tick(&mut self)
pub const fn tick(&mut self)
Updates the state for the current tick. Call this at the start of each server tick.
Sourcepub const fn increment_tick_count(&mut self)
pub const fn increment_tick_count(&mut self)
Increments the server tick count.
Sourcepub const fn step_game_if_paused(&mut self, ticks: i32) -> bool
pub const fn step_game_if_paused(&mut self, ticks: i32) -> bool
Steps the game forward by the given number of ticks if paused. Returns true if stepping was started, false if the game is not frozen.
Sourcepub const fn stop_stepping(&mut self) -> bool
pub const fn stop_stepping(&mut self) -> bool
Stops the current step operation. Returns true if stepping was stopped, false if not stepping.
Sourcepub const fn is_sprinting(&self) -> bool
pub const fn is_sprinting(&self) -> bool
Returns whether the server is currently sprinting.
Sourcepub fn request_game_to_sprint(&mut self, ticks: i32) -> bool
pub fn request_game_to_sprint(&mut self, ticks: i32) -> bool
Requests the game to sprint for a given number of ticks. Returns true if an existing sprint was interrupted.
Sourcepub fn stop_sprinting(&mut self) -> Option<SprintReport>
pub fn stop_sprinting(&mut self) -> Option<SprintReport>
Stops the current sprint. Returns the sprint report if a sprint was stopped, None otherwise.
Sourcepub fn check_should_sprint_this_tick(&mut self) -> (bool, Option<SprintReport>)
pub fn check_should_sprint_this_tick(&mut self) -> (bool, Option<SprintReport>)
Checks if the server should sprint this tick. Returns Some(report) when the sprint finishes, None otherwise. The bool indicates whether we should sprint (skip sleep).
Sourcepub fn end_tick_work(&mut self)
pub fn end_tick_work(&mut self)
Ends the work for the current tick sprint. Call this at the end of each tick during a sprint.
Sourcefn finish_tick_sprint(&mut self) -> SprintReport
fn finish_tick_sprint(&mut self) -> SprintReport
Finishes the current tick sprint and returns the sprint report.
Sourcepub fn record_tick_time(&mut self, tick_time_nanos: u64)
pub fn record_tick_time(&mut self, tick_time_nanos: u64)
Records the duration of a tick in nanoseconds. This should be called at the end of each server tick.
Sourcepub fn get_average_tick_time_nanos(&self) -> u64
pub fn get_average_tick_time_nanos(&self) -> u64
Returns the average tick time in nanoseconds over the last 100 ticks.
Sourcepub fn get_average_mspt(&self) -> f32
pub fn get_average_mspt(&self) -> f32
Returns the average tick time in milliseconds over the last 100 ticks.
Sourcepub const fn get_smoothed_mspt(&self) -> f32
pub const fn get_smoothed_mspt(&self) -> f32
Returns the exponentially smoothed tick time in milliseconds.
Sourcepub fn get_tps(&self) -> f32
pub fn get_tps(&self) -> f32
Returns the current TPS (ticks per second) based on average MSPT. Capped at the configured tick rate (default 20.0).
Sourcepub const fn get_tick_times_nanos(&self) -> [u64; 100]
pub const fn get_tick_times_nanos(&self) -> [u64; 100]
Returns a copy of the tick times array for percentile calculation.
Sourcepub fn get_sample_count(&self) -> usize
pub fn get_sample_count(&self) -> usize
Returns the number of tick samples currently available.
Sourcefn get_percentile(&self, percentile: u8) -> f32
fn get_percentile(&self, percentile: u8) -> f32
Returns the tick time at a given percentile in milliseconds.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for TickRateManager
impl RefUnwindSafe for TickRateManager
impl Send for TickRateManager
impl Sync for TickRateManager
impl Unpin for TickRateManager
impl UnsafeUnpin for TickRateManager
impl UnwindSafe for TickRateManager
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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> 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 moreArc<SyncMutex<>>