Delta time is wrong in UpdateArgs
jtuu opened this issue · comments
The dt property of UpdateArgs is incorrect. It seems to always be the same value regardless of how long the time between updates actually is. Below is some code to demonstrate the problem. It sleeps for one second every tick which means dt should be at least one second but it is not.
extern crate piston_window;
use std::thread;
use std::time;
use piston_window::*;
fn main() {
let mut window: PistonWindow = WindowSettings::new("Hello", [640, 480])
.vsync(true)
.exit_on_esc(true)
.build().unwrap();
// run event loop
while let Some(event) = window.next() {
// grab Event::Loop::Update
match event {
Event::Loop(loop_event) => {
match loop_event {
Loop::Update(UpdateArgs{dt}) => {
// sleep for one second every tick
thread::sleep(time::Duration::from_secs(1));
// dt should be at least one second
// but it's 0.008333333333333333 every time
println!("{}", dt);
},
_ => {}
}
},
_ => {}
}
}
}
This is called a "fixed time step" event loop. The delta time is constant to preserve determinism and accuracy is defined by UPS (Updates Per Second).
I see, my bad. This issue is invalid then.