Skip to main content
Verticopolis engineGitHub

Module fixed_step

Module fixed_step 

Source
Expand description

Driving the game from display frames. A host owes the game some game minutes each frame, set by the game speed it shows; FrameStepper cuts them into whole steps sized from the game’s own clock, so the tower comes out the same at any frame rate. The web game runs this same stepper, so a host that uses it matches the browser at the same speed.

use verticopolis_engine::clock::GameMode;
use verticopolis_engine::fixed_step::FrameStepper;
use verticopolis_engine::sim::Simulation;

let mut sim = Simulation::new_game(1, GameMode::Classic);
let mut stepper = FrameStepper::default();
let start = sim.clock.minutes;
// One second of 60 Hz frames at 10 game minutes per real second, with
// the canon day curve (steady_clock false).
for _ in 0..60 {
    stepper.advance(&mut sim, 1000.0 / 60.0, 10.0, false, true);
}
assert!(sim.clock.minutes > start);

Two rules sit outside the stepper, in the host. Clamp a frame longer than 200 ms to 1 ms before passing it in (a tab coming back from the background), and set stepper.acc_minutes = 0.0 when the player changes speed or the steady clock, while a blocking dialog is open, and once the game has stopped.

Structs§

FrameStepper
A host’s frame-to-steps state. Keep one per game and call advance once per display frame.

Constants§

MAX_CATCHUP_MINUTES
Hard cap on owed minutes carried between frames (the host half).
MAX_STEPS_PER_FRAME
At most this many steps run in one frame.

Traits§

StepSim
What the stepper drives: Simulation implements it.

Functions§

quantum_for
The step size, in whole game minutes, for a host running at minutes_per_second when the game clock reads minute_of_day.