Skip to main content
← PSoXide SDK guides and examples · SDK f2fec1c301f1 · All Cargo features enabled; check feature gates before use.

Crate psx_tick

Crate psx_tick 

Source
Expand description

Fixed-timestep game clock shared by every PSoXide game.

Game logic runs in fixed ticks of a whole number of VBlanks; rendering runs as often as the frame cost allows and shows the latest tick (optionally interpolated with FixedClock::phase_q12). Logic speed then never depends on how long a frame takes to draw.

Each game picks its own TickConfig (tick rate and catch-up policy); the functions are the same everywhere, so behaviour and the TickStats consistency counters mean the same thing in every game.

The clock never reads hardware. Callers pass the current VBlank count (psx_rt::interrupts::vblank_count() on the console), which keeps every rule host-testable.

use psx_tick::{FixedClock, TickConfig, TickRate};
let now = 100;
let mut clock = FixedClock::new(TickConfig::new(TickRate::HZ60), now);
// A frame that took three VBlanks owes three ticks.
let mut ran = 0;
while clock.due(now + 2) {
    ran += 1; // simulate one tick
}
clock.end_frame();
assert_eq!(ran, 3);

Structs§

FixedClock
Fixed-timestep clock. See the crate docs.
TickConfig
A game’s clock settings.
TickRate
Tick length in VBlanks: 1 is 60 Hz on NTSC, 2 is 30 Hz, 3 is 20 Hz.
TickStats
Frame-consistency counters since construction or FixedClock::reset_stats.

Enums§

CatchUp
What to do when a frame falls further behind than the game allows.

Constants§

TICK_HISTOGRAM_BUCKETS
Buckets in TickStats::ticks_per_frame; the last one collects every frame with that many ticks or more.