Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Engel Simulator 2020
Engel Simulator 2020
Commits
7f9c2534
Commit
7f9c2534
authored
Dec 27, 2020
by
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
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/gamestate.rs
View file @
7f9c2534
...
...
@@ -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
);
...
...
src/states/heaven.rs
View file @
7f9c2534
...
...
@@ -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
);
...
...
src/states/ingame.rs
View file @
7f9c2534
...
...
@@ -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
;
{
...
...
src/states/level_loading.rs
View file @
7f9c2534
...
...
@@ -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
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment