Replies: 1 comment 3 replies
-
Adding a link to the above-mentioned Discord discussion. I see no reason why the step rate shouldn't be runtime-mutable. The main thing is the API and documentation need to make it clear that changing this interval does not (and should not) change any " My suggestion would be to add a self.accumulator += time.delta_seconds_f64(); to self.accumulator += time.scale() * time.delta_seconds_f64(); That would make the app step faster or slower. While we're at it, I would modify the The pub struct FixedTimestepState {
time: f64,
pub steps: usize,
}
impl FixedTimestepState {
pub fn new(time: f64, steps: usize) -> Self {
Self {
time,
steps
}
}
// The number of accrued steps.
pub fn steps(&self) -> usize {
self.steps
}
// The amount of time (in seconds) accrued toward the next step.
pub fn overstep(&self) -> f64 {
self.time
}
// The amount of time (as % of timestep) accrued toward the next step.
pub fn overstep_percentage(&self, timestep: f64) -> f64 {
self.time / timestep
}
// Add to the stored time and then convert to as many timesteps as possible.
pub fn add_time(&mut self, time: f64, timestep: f64) {
self.time += time;
while self.time >= timestep {
self.time -= timestep;
self.steps += 1;
}
}
}
impl Default for FixedTimestepState {
fn default() -> Self {
Self {
time: 0.0,
steps: 0
}
}
} |
Beta Was this translation helpful? Give feedback.
-
Right now you specify the interval for FixedTimestep stages during
App::build
, i.e.However, there is no way to change that rate afterwards. This is desirable for simulation type games (think Rimworld or Prison Architect); those usually offer different speed modes. You can run the whole game twice as fast when not much is happening or slow it down to half the speed when a lot is going on. Please note that this usually does not affect the framerate, just the speed at which the game logic is executed.
A nice way to implement this is to add all game-logic systems to a FixedTimestep and if the speed is increased, you just run those more frequently. I asked in Discord about this and it seems currently there is no way to do that in bevy. The suggested work-around is that I create my own RunCriteria which is basically a copy of the FixedTimestep but allows for changing of the step.
If there is an interest in that, I would be willing to open a PR and make that change upstream instead of only fixing my personal project. But I am not sure what the preferred approach would be.
You can already use
mut timesteps: ResMut<FixedTimesteps>
in a system, but that only allows for read access sinceFixedTimesteps::get()
returns an immutable reference. It would be an option to add aFixedTimesteps::set_state(&self, name: &str, state: FixedTimestepState)
function, but that alone would not solve the issue, as the state inside FixedTimesteps is never read back, so modifying it would do nothing.So basically my question is two-fold:
Beta Was this translation helpful? Give feedback.
All reactions