-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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 ergonomics of platform_support
's Instant
#17577
Conversation
Thanks to my friend https://github.com/repnop for helping me understand how to deal with function pointers in `unsafe` environments Co-authored-by: Wesley Norris <[email protected]>
Welcome, new contributor! Please make sure you've read our contributing guide and we look forward to reviewing your pull request shortly ✨ |
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.
Yeah that is better, thanks for submitting this! And thanks for confirming that the Playdate works too!
Thank YOU for all the hard work championing Bevy's |
The changes look good, and the demo video was super cool! (Now I want a Playdate ^^) |
# Objective - Make working with `bevy_time` more ergonomic in `no_std` environments. Currently `bevy_time` expects the getter in environments where time can't be obtained automatically via the instruction set or the standard library to be of type `*mut fn() -> Duration`. [`fn()`](https://doc.rust-lang.org/beta/std/primitive.fn.html) is already a function pointer, so `*mut fn()` is a _pointer to a function pointer_. This is harder to use and error prone since creating a pointer out of something like `&mut fn() -> Duration` when the lifetime of the reference isn't static will lead to an undefined behavior once the reference is freed ## Solution - Accept a `fn() -> Duration` instead ## Testing - I made a whole game on the Playdate that relies on `bevy_time` heavily, see: [bevydate_time](https://github.com/Mathspy/bevydate/blob/1b4f02adcde079cf9757fd3c7d20331c9ab04513/src/lib.rs#L510-L546) for usage of the Instant's getter. --- ## Showcase <details> <summary>Click to view showcase</summary> https://github.com/user-attachments/assets/f687847f-6b62-4322-95f3-c908ada3db30 </details> ## Migration Guide This is a breaking change but it's not for people coming from Bevy v0.15 ### Small thank you note Thanks to my friend https://github.com/repnop for helping me understand how to deal with function pointers in `unsafe` environments Co-authored-by: Wesley Norris <[email protected]>
# Objective - Make working with `bevy_time` more ergonomic in `no_std` environments. Currently `bevy_time` expects the getter in environments where time can't be obtained automatically via the instruction set or the standard library to be of type `*mut fn() -> Duration`. [`fn()`](https://doc.rust-lang.org/beta/std/primitive.fn.html) is already a function pointer, so `*mut fn()` is a _pointer to a function pointer_. This is harder to use and error prone since creating a pointer out of something like `&mut fn() -> Duration` when the lifetime of the reference isn't static will lead to an undefined behavior once the reference is freed ## Solution - Accept a `fn() -> Duration` instead ## Testing - I made a whole game on the Playdate that relies on `bevy_time` heavily, see: [bevydate_time](https://github.com/Mathspy/bevydate/blob/1b4f02adcde079cf9757fd3c7d20331c9ab04513/src/lib.rs#L510-L546) for usage of the Instant's getter. --- ## Showcase <details> <summary>Click to view showcase</summary> https://github.com/user-attachments/assets/f687847f-6b62-4322-95f3-c908ada3db30 </details> ## Migration Guide This is a breaking change but it's not for people coming from Bevy v0.15 ### Small thank you note Thanks to my friend https://github.com/repnop for helping me understand how to deal with function pointers in `unsafe` environments Co-authored-by: Wesley Norris <[email protected]>
Objective
bevy_time
more ergonomic inno_std
environments.Currently
bevy_time
expects the getter in environments where time can't be obtained automatically via the instruction set or the standard library to be of type*mut fn() -> Duration
.fn()
is already a function pointer, so*mut fn()
is a pointer to a function pointer. This is harder to use and error prone since creating a pointer out of something like&mut fn() -> Duration
when the lifetime of the reference isn't static will lead to an undefined behavior once the reference is freedSolution
fn() -> Duration
insteadTesting
bevy_time
heavily, see: bevydate_time for usage of the Instant's getter.Showcase
Click to view showcase
test2.mp4
Migration Guide
This is a breaking change but it's not for people coming from Bevy v0.15
Small thank you note
Thanks to my friend https://github.com/repnop for helping me understand how to deal with function pointers in
unsafe
environments