Skip to content
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

Make Timer.tick return &Self #820

Merged
merged 3 commits into from
Nov 13, 2020
Merged

Conversation

marcusbuffett
Copy link
Contributor

Just a small ergonomics improvement, so that systems that look like this:

    timer.tick(time.delta_seconds);
    if timer.finished {
      // ...

can look like this instead:

    if timer.tick(time.delta_seconds).finished {

@Moxinilian Moxinilian added C-Code-Quality A section of code that is hard to understand or change A-Core Common functionality for all bevy apps labels Nov 9, 2020
@cart
Copy link
Member

cart commented Nov 9, 2020

Yeah I think I'm in to this. Can you also adjust relevant bevy crates / examples to use this where possible?

@marcusbuffett
Copy link
Contributor Author

Yup, just updated all the usages I could find.

let c = rand::random::<u8>() as char;
if !text.value.contains(c) && state.timer.finished {
if !text.value.contains(c) && state.timer.tick(time.delta_seconds).finished {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this won't actually behave the same because && expressions will short-circuit when the first criteria isn't met. we want to tick every time, whether or not text.value contains c

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh right, I’m gonna keep this the old way, I didn’t like that the tick was kinda hidden in this case anyway. Good catch

@cart cart merged commit 1a92ec2 into bevyengine:master Nov 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Core Common functionality for all bevy apps C-Code-Quality A section of code that is hard to understand or change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants