-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
98 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,58 @@ | ||
use bevy::{ | ||
core::{FixedTimestep, FixedTimesteps}, | ||
core::{FixedTimestep, FixedTimestepState}, | ||
prelude::*, | ||
}; | ||
|
||
const LABEL: &str = "my_fixed_timestep"; | ||
|
||
#[derive(Debug, Hash, PartialEq, Eq, Clone, StageLabel)] | ||
struct FixedUpdateStage; | ||
|
||
fn main() { | ||
App::new() | ||
.add_plugins(DefaultPlugins) | ||
// this system will run once every update (it should match your screen's refresh rate) | ||
.add_startup_system(set_fixed_timestep) | ||
// This system will run once every update. | ||
.add_system(frame_update) | ||
// add a new stage that runs twice a second | ||
// This stage will run ten times a second. | ||
.add_stage_after( | ||
CoreStage::Update, | ||
FixedUpdateStage, | ||
SystemStage::parallel() | ||
.with_run_criteria( | ||
FixedTimestep::step(0.5) | ||
// labels are optional. they provide a way to access the current | ||
// FixedTimestep state from within a system | ||
.with_label(LABEL), | ||
) | ||
.with_run_criteria(FixedTimestep::step) | ||
.with_system(fixed_update), | ||
) | ||
.run(); | ||
} | ||
|
||
fn frame_update(mut last_time: Local<f64>, time: Res<Time>) { | ||
info!("update: {}", time.seconds_since_startup() - *last_time); | ||
*last_time = time.seconds_since_startup(); | ||
fn set_fixed_timestep(mut time: ResMut<FixedTime>) { | ||
time.set_steps_per_second(10.0); | ||
} | ||
|
||
fn fixed_update(mut last_time: Local<f64>, time: Res<Time>, fixed_timesteps: Res<FixedTimesteps>) { | ||
fn frame_update(mut last_time: Local<f32>, time: Res<Time>) { | ||
info!( | ||
"fixed_update: {}", | ||
time.seconds_since_startup() - *last_time, | ||
"time since last frame_update: {}", | ||
time.seconds_since_startup() - *last_time | ||
); | ||
*last_time = time.seconds_since_startup(); | ||
} | ||
|
||
let fixed_timestep = fixed_timesteps.get(LABEL).unwrap(); | ||
fn fixed_update( | ||
mut last_time: Local<f32>, | ||
time: Res<Time>, | ||
fixed_time: Res<FixedTime>, | ||
accumulator: Res<FixedTimestepState>, | ||
) { | ||
info!( | ||
" overstep_percentage: {}", | ||
fixed_timestep.overstep_percentage() | ||
"time since last fixed_update: {}\n", | ||
time.seconds_since_startup() - *last_time | ||
); | ||
info!("fixed timestep: {}\n", fixed_time.delta_seconds()); | ||
info!( | ||
"time accrued toward next fixed_update: {}\n", | ||
accumulator.overstep().as_secs_f32() | ||
); | ||
info!( | ||
"time accrued toward next fixed_update (% of timestep): {}", | ||
accumulator.overstep_percentage(fixed_time.delta()) | ||
); | ||
|
||
*last_time = time.seconds_since_startup(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.