Skip to main content

Module scheduler

Module scheduler 

Expand description

The bit-exact foundations, from their own crate (banished-core). Game time, and the entity manager’s update buckets.

Time. The engine counts time in integer microseconds (System::Time). ticks and seconds convert as the original does: through f64, truncating to time and rounding to f32 seconds.

Buckets. A town has tens of thousands of entities, so the game does not update all of them in every simulation iteration. EntityScheduler keeps them in five buckets, and each iteration visits at most QUOTAS entities of each bucket, starting where the last visit stopped. Each entity receives the time since its own last visit, so no time is lost.

use banished_core::scheduler::{seconds, ticks};

assert_eq!(ticks(1.5), 1_500_000);
assert_eq!(seconds(ticks(1.5)), 1.5);

The port’s handles are stable indices; the engine uses object pointers. Removing an entity still swaps it with the last one of its bucket, as in the engine.

Original: FUN_1400c9460, FUN_1400c9560, FUN_1400c9d70.

Structs§

EntityScheduler
The entity manager’s buckets: which entities are visited in each simulation iteration, and the time each one has had since its last visit. T is the caller’s value for an entity.

Constants§

EXTRA
Handles of entities registered with EntityScheduler::register_extra start here, so that a placed entity’s handle stays its index. The game gives such entities values from here too: citizens EXTRA + citizen, and entities the town does not model (the map ambience, a saved game’s entities of templates it skips) from FOREIGN.
FOREIGN
Values of scheduled entities with no behaviour in the port (visited for the cursors’ sake).
QUOTAS
How many entities of each bucket one iteration visits, for buckets 0 to 4.
SECONDS_PER_TICK
The length of one tick of game time, in seconds: the engine’s timer counts 1,000,000 ticks per second.

Functions§

seconds
Game time to seconds: through f64, rounded to f32.
ticks
Seconds to game time: through f64, truncated.