Skip to content

Support f32 directly in process and physics_process #1110

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
merged 4 commits into from
Mar 30, 2025

Conversation

Bromeon
Copy link
Member

@Bromeon Bromeon commented Mar 30, 2025

It is now possible to write either of the following for process and physics_process:

#[godot_api]
impl INode for MyClass {
    // Continues to work: f64.
    fn process(&mut self, delta: f64) { ... }

    // Transparently cast to single-precision float:
    fn process(&mut self, delta: f32) {
        // Work with f32 here.
    }
}

New approach based on proc-macro transformation. It's a bit magic, but for now it's the only practical solution that doesn't put f64 users at a disadvantage. One viable alternative would have been adding extra process_64 + physics_process_64 overloads, but this would come at the cost of hundreds of extra generated methods. Another option would be to always use f32 and let f64 users query the delta via dedicated API.

Resolves #510. See this thread for discussion of the various approaches.

We need to see how this turns out, maybe this can change again in the future. Will definitely need doc updates.


This PR also took the opportunity to refactor some small parts in #[godot_api]. To skip those changes, just exclude the first commit from the diff.

@Bromeon Bromeon added feature Adds functionality to the library c: register Register classes, functions and other symbols to GDScript labels Mar 30, 2025
@GodotRust
Copy link

API docs are being generated and will be shortly available at: https://godot-rust.github.io/docs/gdext/pr-1110

@Bromeon Bromeon added this pull request to the merge queue Mar 30, 2025
Merged via the queue into master with commit a752851 Mar 30, 2025
16 checks passed
@Bromeon Bromeon deleted the feature/f32-process branch March 30, 2025 21:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: register Register classes, functions and other symbols to GDScript feature Adds functionality to the library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

f32 vs f64 in Godot APIs
2 participants