bevyengine / bevy

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

Allow use of systems for custom time handling #15455

Open maniwani opened 1 month ago

maniwani commented 1 month ago

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

Bevy is pretty great at handling time (time.delta_seconds() just working in both variable/fixed timestep is some nice UX that other engines don't really have) , but it'd be even better if users could simply take complete control of time for advanced usecases.

Time handling (especially fixed update) is still a bit clunky in a few noticeable ways.

What solution would you like?

Instead of going down the path of adding more parameters and preset[^1] behaviors to address these issues, Bevy could address the root problem of "time isn't configurable enough" by reworking time_system and run_fixed_main_schedule to call other systems that implement the actual behavior, e.g. based on "call this Entity" values stored in a publicly visible resource.

pub fn time_system(world: &mut World) {
    let res = world.resource::<BikeshedMe>();
    let system_id = res.system_id();
    world.run_system(system_id);
}

By turning time_system and run_fixed_main_schedule into dispatchers, a user could control how time is handled by creating their own "one-shot" systems and setting them as the systems that get called instead of the default ones.

[^1]: That being said, I do strongly recommend adding the behavior described in #12465 as a preset for Time<Fixed>.

What alternative(s) have you considered?

I think my proposed solution is more idiomatic and "ECS-y" (systems define behavior) and would let Bevy draw a clear line between "simple" and "advanced" configuration. Any behavior that isn't baked into one of the Time structs would become "advanced use" that users can achieve by overriding the default targets.

Additional context

IMO this is sort of a logical continuation of #8964. That one made whoever's calling (Main or FixedMain) transparent to the systems that are called. This would makes whoever's advancing Time and calling FixedMain transparent.

alice-i-cecile commented 1 month ago

Related requests for more Time customizability:

https://github.com/bevyengine/bevy/issues/12465 https://github.com/bevyengine/bevy/issues/14215 https://github.com/bevyengine/bevy/issues/15409