-
-
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
Improve Timer ergonomics using const generics with defaults #4380
Comments
Cool! I don't know that you always want these to be const though: in a lot of gameplay applications (think attack speed) you're going to want to change things like the reset period dynamically, or on a per-entity basis. |
You're right Alice. I do think the usefulness here is limited to quick prototyping or super simple cases like game-jam's. Certainly games are meant to be dynamic. But since the implementation is so simple and breakage is minimal it might be something fun to consider. Oh and only the initial value comes from compile time. It can certainly be changed at run-time. |
Ah I see! Okay cool, I'm open to the idea then! |
I think I'm opposed to having "two ways" to define timers (static and non-static), especially given that they exist next to each other on the same impl. Additionally, this adds "type complexity" to something that doesn't really need it, and it encourages building systems that "hard code" timer duration, which feels (generally) wrong to me. |
Those are fair points @cart. I'll leave it up to you to whether close this issue. Also. I suppose what I'd really like is a succinct way to set an initial value for any What I laid out in this issue could also be implemented as a wrapper. Maybe is should make a crate for it and have it exist outside of Bevy. |
This used to be possible, but we deprecated in favor of closure systems. That would work for this case. I think I'll close this out :) |
The link to the closure system seems to be broken (it just links to this thread). Does anyone have any examples of how you'd achieve this in the current version? |
What problem does this solve or what need does it fill?
Wouldn't it be cool if we could set the initial values for
duration
andrepeating
onTimer
at compile-time?What solution would you like?
Change the definition of
Timer
from:To:
So we can do this:
or this, a modified version of the timers example (with comments removed):
Blocked
By rust-lang/rust#95174 as we can only use integral types (e.g: i32, bool) in const generics for now.
We could use
But...
Breakage
This change compiled on all of bevy, and was tested on the existing timers example.
I don't think this breaks anything other than custom impl's for
Timer
.P.S
I don't think this is doable yet, but it sure is neat.
The text was updated successfully, but these errors were encountered: