FERRETGame engine over Babylon.js
Ferret

Making physics cheap

Every capability steps at the rate you give it. Most cost grows with how often it steps and how finely it sub-steps, rarely with how much it models. That makes tuning mostly a matter of three knobs. For the tier table and the governor that turns them for you, see budgets and tiers; this page is the by-hand version.

1. Sub-steps: the biggest lever#

A stiff model (a reactor's prompt neutrons, a circuit's switching) is sub-stepped to stay stable. The sub-step is a cap, maxSubstep (maxStep on a Circuit), and a long, slow process does not need the fine one:

reactor.maxSubstep = 0.5;     // a coast: coarse
reactor.step(1);

Fine sub-steps while something fast is happening (rods moving, a reactivity step); maxSubstep of 0.25 to 1 for a coast. A coarser sub-step makes the call several times cheaper and a coast gives the same temperatures and decay heat either way. The same holds for Circuit and Boiler. The comparison is in tests/unit/examples/physics-scenarios-tuning.test.ts.

2. Step rate: most things do not need 60 Hz#

ModelTime constantA sensible rate
Heat network, a steel parttens of seconds2–10 Hz
Liquid network (pipes, cellar)seconds10–20 Hz
Boiler, chemistry vesselseconds10 Hz
Reactor coastminutes1 Hz, maxSubstep 0.25+
Circuit with a switchmsper frame, sub-stepped
Bodies, strength, impactframethe host's fixed step

Step slow models from an accumulator, not every frame: add the frame time to acc, and when acc >= 0.2 call net.step(acc) and zero it, passing the true interval so the energy is right.

3. Switch off what nobody can see#

SituationSwitchCosts you
A room the player leftstop stepping its networks; keep the numbersa jump when they return: advance by the elapsed time in one coarse step
Far-away fragments and debristhin the effects (see fx)prettiness, not behaviour
A static structureleave it asleep; wake it on a hitnothing
A long coast (decay heat, cooling)one big step(3600)nothing, if the model is linear over the span

Order of removal#

When the frame is over budget, give up in this order: fx particles, then step rates of slow models, then sub-steps, then off-screen simulation. Do not touch the rigid-body step before these; it is what the player's hands feel.