forked from bevyengine/bevy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fixed_timestep.rs
38 lines (33 loc) · 1.24 KB
/
fixed_timestep.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
//! Shows how to create systems that run every fixed timestep, rather than every tick.
use bevy::prelude::*;
const FIXED_TIMESTEP: f32 = 0.5;
fn main() {
App::new()
.add_plugins(DefaultPlugins)
// this system will run once every update (it should match your screen's refresh rate)
.add_system(frame_update)
// add our system to the fixed timestep schedule
.add_system_to_schedule(CoreSchedule::FixedUpdate, fixed_update)
// configure our fixed timestep schedule to run twice a second
.insert_resource(FixedTime::new_from_secs(FIXED_TIMESTEP))
.run();
}
fn frame_update(mut last_time: Local<f32>, time: Res<Time>) {
info!(
"time since last frame_update: {}",
time.raw_elapsed_seconds() - *last_time
);
*last_time = time.raw_elapsed_seconds();
}
fn fixed_update(mut last_time: Local<f32>, time: Res<Time>, fixed_time: Res<FixedTime>) {
info!(
"time since last fixed_update: {}\n",
time.raw_elapsed_seconds() - *last_time
);
info!("fixed timestep: {}\n", FIXED_TIMESTEP);
info!(
"time accrued toward next fixed_update: {}\n",
fixed_time.accumulated().as_secs_f32()
);
*last_time = time.raw_elapsed_seconds();
}