-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
[Merged by Bors] - Make paused timers update just_finished
on tick
#4445
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both of the tests look good, but the fix is a bit questionable to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aha, that makes way more sense. LGTM now.
It would be great if this could make it into 0.7. |
Needs a second approval :) You should consider asking on Discord in #general-dev. |
I'm not sure about adding this functionality to paused. Real stopwatches don't change the state when they're paused. Only when the reset button is pushed, so holding the finished state makes sense. To me it feels like this should be a separate function that can be called to reset finished. |
The finished state will still be held even with this pr. Only Unless the the timer is repeating, in which case using Having As an example: See the linked issue(#4436) for an explanation of the problem by @Madadog. |
Yeah my previous suggestion was a little confused. But setting I think I would prefer if we just decouple the state of Also what is the reasoning to setting finished to false if it's paused and repeating? |
Oh, no. Another victim of the confusingly named variable I hope you did notice my latest commit renaming
When I started making this change this was exactly what I was going for, but as I was trying to do so I read the doc comment/tests for (Pinging @kokounet as they introduced
Purely because it would make this statement in the timers example, no longer true. |
yeah, definitely a bit confusing. So if we pause the timer the internal elapsed time might say evaluate to time_finished_this_tick to 2, but since it's paused it reports 0. But when we unpause the time it'll report 2 or more after the timer is unpaused and ticked, because the internal state hasn't been reset. What we want is for a tick to be a noop to the public api. So is reporting the timer as not having finished correct then? It might be? Honestly not sure. The timer actually finished before you paused the timer... Really need to see some use cases for this API to know for sure. |
Sorry, I should have explained the purpose of Timers do not track how many times they have finished, period, this has not been added (yet). So, But I am clearly failing terribly at explaining this with words. I hope these code examples do the trick. let mut t = Timer::from_seconds(1.0, true);
if t.tick(Duration::from_secs_f32(3.0)).just_finished() {
// only reached once!!!
}
for _ in 0..t.tick(Duration::from_secs_f32(3.0)).times_finished_this_tick() {
// reached three times!!!
}
t.tick(Duration::from_secs_f32(0.0));
assert_eq!(t.times_finished_this_tick(), 0);
t.tick(Duration::from_secs_f32(3.0));
assert_eq!(t.times_finished_this_tick(), 3);
t.tick(Duration::from_secs_f32(69.0));
assert_eq!(t.times_finished_this_tick(), 69); |
I definitely agree, that name is confusing. At that time I did not think it could be interpreted as the total number of wraps for repeating timers 😅 as I didn't see any use case for it. It's definitely a bad name if it's required to read the doc to understand what it does. |
I'm sorry to make you explain so much. This was definitely a me problem. I was getting my mental model confused with timers from other programs. Reseting times_finished_this_tick makes sense because this tick is the current/last call to tick, which is a no op if the timer is paused, so there definitely can't be any finishes on a paused tick. |
just_finished
on tick, even if paused.just_finished
on tick
Should this have a migration guide (label) for the rename? |
@devil-ira please edit your PR description to include the following migration guide section when you get a chance :) Migration Guide
|
bors r+ |
# Objective Make timers update `just_finished` on tick, even if paused. Fixes #4436 ## Solution `just_finished()` returns `times_finished > 0`. So I: * Renamed `times_finished` to `times_finished_this_tick` to reduce confusion. * Set `times_finished_this_tick` to `0` on tick when paused. * Additionally set `finished` to `false` if the timer is repeating. Notably this change broke none of the existing tests, so I added a couple for this. Files changed shows a lot of noise because of the rename. Check the first commit for the relevant changes. Co-authored-by: devil-ira <[email protected]>
just_finished
on tickjust_finished
on tick
# Objective Make timers update `just_finished` on tick, even if paused. Fixes bevyengine#4436 ## Solution `just_finished()` returns `times_finished > 0`. So I: * Renamed `times_finished` to `times_finished_this_tick` to reduce confusion. * Set `times_finished_this_tick` to `0` on tick when paused. * Additionally set `finished` to `false` if the timer is repeating. Notably this change broke none of the existing tests, so I added a couple for this. Files changed shows a lot of noise because of the rename. Check the first commit for the relevant changes. Co-authored-by: devil-ira <[email protected]>
# Objective Make timers update `just_finished` on tick, even if paused. Fixes bevyengine#4436 ## Solution `just_finished()` returns `times_finished > 0`. So I: * Renamed `times_finished` to `times_finished_this_tick` to reduce confusion. * Set `times_finished_this_tick` to `0` on tick when paused. * Additionally set `finished` to `false` if the timer is repeating. Notably this change broke none of the existing tests, so I added a couple for this. Files changed shows a lot of noise because of the rename. Check the first commit for the relevant changes. Co-authored-by: devil-ira <[email protected]>
Objective
Make timers update
just_finished
on tick, even if paused.Fixes #4436
Solution
just_finished()
returnstimes_finished > 0
. So I:times_finished
totimes_finished_this_tick
to reduce confusion.times_finished_this_tick
to0
on tick when paused.finished
tofalse
if the timer is repeating.Notably this change broke none of the existing tests, so I added a couple for this.
Files changed shows a lot of noise because of the rename. Check the first commit for the relevant changes.
Migration Guide
Timer::times_finished
has been renamed toTimer::times_finished_this_tick
for clarity.