bevyengine / bevy

A refreshingly simple data-driven game engine built in Rust
https://bevyengine.org
Apache License 2.0
35.57k stars 3.52k forks source link

Run some systems at different tickrate #1806

Closed sojuz151 closed 7 months ago

sojuz151 commented 3 years ago

What problem does this solve or what need does it fill?

In some games such as Minecraft and Factorio some systems run once per tick, with a usual tick rate being 10Hz. Additionally, in some multiplayer games, physics and the netcode also run at a constant tickrate, independent from the frame-rate. In the former case such computation could be performance intensive so you want to avoid doing everything on a single frame.

What solution would you like?

A way to separate systems into physics and render part of your game. You could mark systems as belonging to either of those categories. From the render part you could start computation of the next tick, check progress or apply already computed tick. Until you apply, all render systems would see components from the last tick. Ability to save and load full state of physical part would be nice for rollback netcode and access components from the last tick.

What alternative(s) have you considered?

Do it all manually.

Additional

Coping required for this previous tick access would not have a big performance impact. The memory footprint could be limited by marking system that require this. Additionally, if the coping was performed when the first &mut is required, all the coping would take place inside CPU cache.

alice-i-cecile commented 3 years ago

See also #1343 :)

james7132 commented 7 months ago

As of schedule v3, FixedUpdate exists now, and it should be possible to insert your own FixedUpdate-like schedule that run at their own cadence. Having another schedule run independently of the main schedule will likely either be unsound or require world separation like the render world. Closing this issue out for now.