Skip to main content

TickRateManager

Struct TickRateManager 

Source
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: f32

The current tick rate in ticks per second.

§nanoseconds_per_tick: u64

The number of nanoseconds per tick based on the tick rate.

§tick_count: u64

The current server tick count, including ticks where game elements are frozen.

§is_frozen: bool

Whether the server is currently frozen.

§frozen_ticks_to_run: i32

The number of ticks to run while frozen (stepping).

§run_game_elements: bool

Whether game elements should run this tick.

§remaining_sprint_ticks: i64

The number of ticks remaining to sprint.

§scheduled_current_sprint_ticks: i64

The 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: i64

The total time spent sprinting in nanoseconds.

§previous_is_frozen: bool

Whether 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: u64

Aggregated sum of tick times for fast average calculation.

§smoothed_tick_time_ms: f32

Exponentially smoothed tick time in milliseconds.

Implementations§

Source§

impl TickRateManager

Source

pub const fn new() -> Self

Creates a new TickRateManager with the default tick rate (20.0 TPS).

Source

pub fn set_tick_rate(&mut self, rate: f32)

Sets the tick rate.

Source

pub const fn tick_rate(&self) -> f32

Returns the tick rate.

Source

pub fn milliseconds_per_tick(&self) -> f32

Returns milliseconds per tick based on the current tick rate.

Source

pub const fn set_frozen(&mut self, frozen: bool)

Sets the frozen state of the server.

Source

pub const fn is_frozen(&self) -> bool

Returns whether the server is frozen.

Source

pub const fn is_stepping_forward(&self) -> bool

Returns whether the server is currently stepping forward.

Source

pub const fn frozen_ticks_to_run(&self) -> i32

Returns the number of frozen ticks to run.

Source

pub const fn runs_normally(&self) -> bool

Returns whether game elements should run this tick.

Source

pub const fn tick(&mut self)

Updates the state for the current tick. Call this at the start of each server tick.

Source

pub const fn increment_tick_count(&mut self)

Increments the server tick count.

Source

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.

Source

pub const fn stop_stepping(&mut self) -> bool

Stops the current step operation. Returns true if stepping was stopped, false if not stepping.

Source

pub const fn is_sprinting(&self) -> bool

Returns whether the server is currently sprinting.

Source

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.

Source

pub fn stop_sprinting(&mut self) -> Option<SprintReport>

Stops the current sprint. Returns the sprint report if a sprint was stopped, None otherwise.

Source

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).

Source

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.

Source

fn finish_tick_sprint(&mut self) -> SprintReport

Finishes the current tick sprint and returns the sprint report.

Source

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.

Source

pub fn get_average_tick_time_nanos(&self) -> u64

Returns the average tick time in nanoseconds over the last 100 ticks.

Source

pub fn get_average_mspt(&self) -> f32

Returns the average tick time in milliseconds over the last 100 ticks.

Source

pub const fn get_smoothed_mspt(&self) -> f32

Returns the exponentially smoothed tick time in milliseconds.

Source

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).

Source

pub const fn get_tick_times_nanos(&self) -> [u64; 100]

Returns a copy of the tick times array for percentile calculation.

Source

pub fn get_p50(&self) -> f32

Returns the P50 (median) tick time in milliseconds.

Source

pub fn get_p95(&self) -> f32

Returns the P95 tick time in milliseconds.

Source

pub fn get_p99(&self) -> f32

Returns the P99 tick time in milliseconds.

Source

pub fn get_sample_count(&self) -> usize

Returns the number of tick samples currently available.

Source

fn get_percentile(&self, percentile: u8) -> f32

Returns the tick time at a given percentile in milliseconds.

Trait Implementations§

Source§

impl Default for TickRateManager

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> IntoShared for T

Source§

fn into_shared(self) -> Arc<Mutex<RawMutex, Self>>

Wraps this value in an Arc<SyncMutex<>>
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more