Commit 7f9c2534 authored by neosam's avatar neosam
Browse files

Merge branch 'rahix/update-time' into 'master'

gamestate: Pass frame timestamp to state update method

See merge request !30
parents 75305010 b5f95278
......@@ -50,7 +50,7 @@ pub trait State {
fn init(&mut self, init: StateInitializer) -> Transition;
fn deinit(&mut self) {}
fn update(&mut self) -> Transition {
fn update(&mut self, _timestamp: f64) -> Transition {
Transition::Keep
}
#[allow(unused_variables)]
......@@ -261,8 +261,8 @@ impl StateStorage {
self.event_handlers.deregister_all();
}
pub fn update(&mut self) -> Transition {
self.state.update()
pub fn update(&mut self, timestamp: f64) -> Transition {
self.state.update(timestamp)
}
fn event(&mut self, event: Event) -> Transition {
......@@ -272,7 +272,7 @@ impl StateStorage {
pub struct StateMachine {
states: Vec<StateStorage>,
loop_handler: Option<closure::Closure<dyn FnMut(wasm_bindgen::JsValue)>>,
loop_handler: Option<closure::Closure<dyn FnMut(f64)>>,
loop_scheduled: bool,
}
......@@ -287,7 +287,7 @@ impl StateMachine {
// Sadly Rc::new_cyclic() isn't stable yet ...
let loop_handler = {
let this = this.clone();
closure::Closure::wrap(Box::new(move |_timestamp| {
closure::Closure::wrap(Box::new(move |timestamp| {
{
let mut sm = this.borrow_mut();
if !sm.loop_scheduled {
......@@ -306,11 +306,11 @@ impl StateMachine {
return;
}
active.update()
active.update(timestamp)
};
StateMachine::do_transition(&this, t);
}) as Box<dyn FnMut(wasm_bindgen::JsValue)>)
}) as Box<dyn FnMut(f64)>)
};
this.borrow_mut().loop_handler = Some(loop_handler);
......
......@@ -77,7 +77,7 @@ impl gamestate::State for HeavenState {
.unwrap();
}
fn update(&mut self) -> gamestate::Transition {
fn update(&mut self, _timestamp: f64) -> gamestate::Transition {
{
let rendering = self.resources.get_mut::<resources::Rendering>().unwrap();
rendering.set_fill_style(&colors::BACKGROUND);
......
......@@ -126,7 +126,7 @@ impl gamestate::State for InGameState {
gamestate::Transition::Keep
}
fn update(&mut self) -> gamestate::Transition {
fn update(&mut self, _timestamp: f64) -> gamestate::Transition {
use legion::IntoQuery;
{
......
......@@ -74,7 +74,7 @@ impl gamestate::State for LevelLoadingState {
gamestate::Transition::Loop
}
fn update(&mut self) -> gamestate::Transition {
fn update(&mut self, _timestamp: f64) -> gamestate::Transition {
{
let rendering = self.resources.get_mut::<resources::Rendering>().unwrap();
rendering.set_fill_style(&colors::BACKGROUND);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment