Improve Timer ergonomics#923
Improve Timer ergonomics#923cart merged 1 commit intobevyengine:masterfrom CleanCut:timer-ergonomics
Conversation
ambeeeeee
left a comment
There was a problem hiding this comment.
I like how it replaces the fancy logic with easier to understand at-a-glance logic
|
Here's an example from a showcase I'm making that demonstrates using these changes to directly power a shrinking death animation and a punching boxing glove animation. You need to have at least one gamepad connected to your computer to try it out (controls are gamepad-only). |
|
Ooh I love the look of that boxing game.
In this case I prefer the clarity of division over storing / multiplying by the inverse. Using percentages seems like a common enough requirement for timers that I think its worth including, largely because the function name helps encode intent. I think this is good to go! |
|
Semi-relevant idea that I'd love to discuss with yall (I'm pulling in @amberkowalski because they're also working on timers): I think it might be a good idea to remove the "auto ticking" timer system.
Its a bit inconsistent that only raw Timer components auto-tick and theres no good way to force all timers to tick. I think I'd rather just make ticking explicit everywhere for simplicity. |
|
@amberkowalski if we make ticking explicit everywhere, maybe we don't need built in pausing? users could "pause" by not ticking where relevant according to their own context-specific logic. |
|
My two cents:
🥳 🎉 |
Good enough for me. @amberkowalski, if you update your pr to account for the changes in this pr I think it'll be merge-ready! |
Having said that, having a way to opt-in to auto-ticking could be very convenient. 🤔 But I think I'm just feature creeping now. 😆 |
Would providing a system that auto-ticks all timers and an example how to include it into the App, count as opt-in? |
|
Haha I'm very curious how you would do this across wrapper types without adding some sort of internal shared state |
|
Nyah. Just for the not wrapped ones - like it works now. We could use the example to put a note reminding users that it ticks only not wrapped Timers and if you want to tick a wrapped one, you need to do it manually. |

I often use timers to drive animation by converting it to a percentage. The fact that
elapsedcould exceeddurationfor non-repeating timers means that I had to check for that everywhere I used them, or the percentage could go negative (which can do various unexpected things, such as flip vector direction). This is a paper cut for me, so I made this PR which:elapsedto the range[0.0, duration]percentandpercent_left)Timersmall is more important than the speed of the calculation. A more speed-optimized approach would store the inverse of duration and do multiplication. Is there a general principle we're following that could inform the approach? Or should we leave the methods out altogether?