New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix incorrect delta reset in Native.Time.fpsWhen. #135

Merged
merged 3 commits into from Jan 24, 2015

Conversation

Projects
None yet
3 participants
@jwmerrill
Contributor

jwmerrill commented Jan 23, 2015

Fixes issue mentioned in:

elm-lang@274cd7e#commitcomment-9425007

Also designed to avoid creating a new function on every frame.

Fix incorrect delta reset in Native.Time.fpsWhen.
Fixes issue mentioned in:

elm-lang@274cd7e#commitcomment-9425007

Also designed to avoid creating a new function on every frame.

jwmerrill referenced this pull request Jan 23, 2015

make every/fps,fpsWhen work well together
preventing inconsistencies between timestamps and deltas in timestamp
(fps n)
@jvoigtlaender

This comment has been minimized.

Show comment
Hide comment
@jvoigtlaender

jvoigtlaender Jan 23, 2015

Yes, I'm all for this. :)

Though I think the !wasOn && isOn in there should be simplified, given that we know isOn to be true at that point.

jvoigtlaender commented on 6a36cd7 Jan 23, 2015

Yes, I'm all for this. :)

Though I think the !wasOn && isOn in there should be simplified, given that we know isOn to be true at that point.

@jwmerrill

This comment has been minimized.

Show comment
Hide comment
@jwmerrill

jwmerrill Jan 23, 2015

Contributor

@jvoigtlaender do you have a good idea for how to test that this works correctly? I don't really understand how to test impure code in Elm yet.

Contributor

jwmerrill commented Jan 23, 2015

@jvoigtlaender do you have a good idea for how to test that this works correctly? I don't really understand how to test impure code in Elm yet.

Simplify conditional
`isOn` is known to be true at this point.
@jvoigtlaender

This comment has been minimized.

Show comment
Hide comment
@jvoigtlaender

jvoigtlaender Jan 23, 2015

Contributor

I don't think it would be doable as a unit test or so that could be included for running in the test builts.

I'd write a small interactive test and check it live.

The thing to look out here is that an fpsWhen signal should really show 0 as delta in the update round where its isOn input signal switches from false to true.

Contributor

jvoigtlaender commented Jan 23, 2015

I don't think it would be doable as a unit test or so that could be included for running in the test builts.

I'd write a small interactive test and check it live.

The thing to look out here is that an fpsWhen signal should really show 0 as delta in the update round where its isOn input signal switches from false to true.

@jwmerrill

This comment has been minimized.

Show comment
Hide comment
@jwmerrill

jwmerrill Jan 23, 2015

Contributor

I did verify that the following simple program worked incorrectly before, and works correctly after this commit:

import Time
import Signal
import Text
import Mouse

display n = Text.plainText (toString n)

input = Time.fpsWhen 60 Mouse.isDown

main = Signal.map display (Signal.foldp (+) 0 input)
Contributor

jwmerrill commented Jan 23, 2015

I did verify that the following simple program worked incorrectly before, and works correctly after this commit:

import Time
import Signal
import Text
import Mouse

display n = Text.plainText (toString n)

input = Time.fpsWhen 60 Mouse.isDown

main = Signal.map display (Signal.foldp (+) 0 input)
@jvoigtlaender

This comment has been minimized.

Show comment
Hide comment
@jvoigtlaender

jvoigtlaender Jan 23, 2015

Contributor

What about my additional https://github.com/elm-lang/core/pull/76#issuecomment-70839236 that the var wasOn = true; line would better be var wasOn = isOn.value;?

Contributor

jvoigtlaender commented Jan 23, 2015

What about my additional https://github.com/elm-lang/core/pull/76#issuecomment-70839236 that the var wasOn = true; line would better be var wasOn = isOn.value;?

@jwmerrill

This comment has been minimized.

Show comment
Hide comment
@jwmerrill

jwmerrill Jan 23, 2015

Contributor

What about my additional #76 (comment) that the var wasOn = true; line would better be var wasOn = isOn.value;?

Sorry, I don't follow what you mean here. 61c8dbc was meant to address your comment that the conditional could be simplified.

isOn is currently a boolean, so it doesn't have a .value property.

Contributor

jwmerrill commented Jan 23, 2015

What about my additional #76 (comment) that the var wasOn = true; line would better be var wasOn = isOn.value;?

Sorry, I don't follow what you mean here. 61c8dbc was meant to address your comment that the conditional could be simplified.

isOn is currently a boolean, so it doesn't have a .value property.

@jvoigtlaender

This comment has been minimized.

Show comment
Hide comment
@jvoigtlaender

jvoigtlaender Jan 23, 2015

Contributor

This is about a comment (https://github.com/elm-lang/core/pull/76#issuecomment-70839236) I made to Evan in my original PR, not the other comment about simplifying the conditional I made on your PR and which you have adressed. Anyway:

There are two isOn in that function. The one that is current in the line where wasOn = true; happens is not a boolean. It is a signal of booleans. And I think wasOn should initially be set to the initial value of that signal instead of to the constant true.

Contributor

jvoigtlaender commented Jan 23, 2015

This is about a comment (https://github.com/elm-lang/core/pull/76#issuecomment-70839236) I made to Evan in my original PR, not the other comment about simplifying the conditional I made on your PR and which you have adressed. Anyway:

There are two isOn in that function. The one that is current in the line where wasOn = true; happens is not a boolean. It is a signal of booleans. And I think wasOn should initially be set to the initial value of that signal instead of to the constant true.

@evancz

This comment has been minimized.

Show comment
Hide comment
@evancz

evancz Jan 23, 2015

Member

To put it another way, maybe the initial value of wasOn should be false because it has never been on before? Or maybe it should depend on whether things are on or off at the beginning as @jvoigtlaender is suggesting?

Member

evancz commented Jan 23, 2015

To put it another way, maybe the initial value of wasOn should be false because it has never been on before? Or maybe it should depend on whether things are on or off at the beginning as @jvoigtlaender is suggesting?

@jwmerrill

This comment has been minimized.

Show comment
Hide comment
@jwmerrill

jwmerrill Jan 23, 2015

Contributor

I understand now. Added 297b548 implementing @jvoigtlaender's suggestion.

Contributor

jwmerrill commented Jan 23, 2015

I understand now. Added 297b548 implementing @jvoigtlaender's suggestion.

@jwmerrill

This comment has been minimized.

Show comment
Hide comment
@jwmerrill

jwmerrill Jan 23, 2015

Contributor

the following simple program

BTW, I get a thrill every time I look at code this short that manages to put something on the screen that depends on dynamic mouse input. So much nicer than wrangling 3 languages and event listeners to do the same.

Contributor

jwmerrill commented Jan 23, 2015

the following simple program

BTW, I get a thrill every time I look at code this short that manages to put something on the screen that depends on dynamic mouse input. So much nicer than wrangling 3 languages and event listeners to do the same.

@jvoigtlaender

This comment has been minimized.

Show comment
Hide comment
@jvoigtlaender

jvoigtlaender Jan 24, 2015

Contributor

@evancz, I think it shouldn't be false initially if isOn is true initially. The reason being that when the overall return signal of fpsWhen gets intialized, it will call startStopTimer with the initial value of isOn. If that one is true but wasOn was initially set to false, then startStopTimer will set up a first timeout, to occur after msPerFrame, but using notifyTrue, thus forcing the first delta to be reported as 0 (instead of the proper amount of msPerFrame milliseconds which will have passed by then).

(That would even happen then with just fps instead of fpsWhen.)

Contributor

jvoigtlaender commented Jan 24, 2015

@evancz, I think it shouldn't be false initially if isOn is true initially. The reason being that when the overall return signal of fpsWhen gets intialized, it will call startStopTimer with the initial value of isOn. If that one is true but wasOn was initially set to false, then startStopTimer will set up a first timeout, to occur after msPerFrame, but using notifyTrue, thus forcing the first delta to be reported as 0 (instead of the proper amount of msPerFrame milliseconds which will have passed by then).

(That would even happen then with just fps instead of fpsWhen.)

@jvoigtlaender

This comment has been minimized.

Show comment
Hide comment
@jvoigtlaender

jvoigtlaender Jan 24, 2015

Contributor

@jwmerrill, Thanks for catching what I had done there in my original PR!

I learned to be more careful about refactoring JavaScript.

Contributor

jvoigtlaender commented Jan 24, 2015

@jwmerrill, Thanks for catching what I had done there in my original PR!

I learned to be more careful about refactoring JavaScript.

@jwmerrill

This comment has been minimized.

Show comment
Hide comment
@jwmerrill

jwmerrill Jan 24, 2015

Contributor

I have been bitten by exactly this problem so many times...

Contributor

jwmerrill commented Jan 24, 2015

I have been bitten by exactly this problem so many times...

evancz pushed a commit that referenced this pull request Jan 24, 2015

Merge pull request #135 from jwmerrill/fix-reset-fpswhen
Fix incorrect delta reset in Native.Time.fpsWhen.

@evancz evancz merged commit 37f931d into elm:master Jan 24, 2015

1 check passed

continuous-integration/travis-ci The Travis CI build passed
Details
@evancz

This comment has been minimized.

Show comment
Hide comment
@evancz

evancz Jan 24, 2015

Member

Alright, it looks good to me, thank you so much!

Member

evancz commented Jan 24, 2015

Alright, it looks good to me, thank you so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment