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

Add a real type #135

Closed
lilizoey opened this issue Mar 3, 2023 · 4 comments · Fixed by #149
Closed

Add a real type #135

lilizoey opened this issue Mar 3, 2023 · 4 comments · Fixed by #149
Labels
c: core Core components feature Adds functionality to the library

Comments

@lilizoey
Copy link
Member

lilizoey commented Mar 3, 2023

Currently a lot of struct and functions in rust are hard-coded to use f32s. Such as Vector2, Vector3 etc. But in godot these structs and functions may be either float or double depending on whether godot is compiled with precision=double or not.

In godot the type used is called real_t and will be either a float or double. We could do the same in our bindings. As it is, our bindings will likely break if we try to use it with a godot that is compiled with precision=double enabled.

The float type in godot, and thus the one used by variant, is always a double, see: https://docs.godotengine.org/en/stable/classes/class_float.html.

@Bromeon Bromeon added feature Adds functionality to the library c: core Core components labels Mar 3, 2023
@Bromeon
Copy link
Member

Bromeon commented Mar 3, 2023

godot-cpp could also serve as an inspiration here.

@ttencate
Copy link
Contributor

ttencate commented Mar 6, 2023

This is what godot-cpp does:

https://github.com/godotengine/godot-cpp/blob/9d1c396c54fc3bdfcc7da4f3abcb52b14f6cce8f/include/godot_cpp/core/defs.hpp#L102-L106

This REAL_T_IS_DOUBLE is set manually through scons when compiling godot-cpp, using a precision=double option just like the engine itself:

https://github.com/godotengine/godot-cpp/blob/2b7094f342beb11166f86a6309bba86fe4b21838/SConstruct#L207-L208

In our case, maybe we could even detect it from the Godot binary and generate the appropriate code?

@lilizoey
Copy link
Member Author

lilizoey commented Mar 6, 2023

In our case, maybe we could even detect it from the Godot binary and generate the appropriate code?

i couldn't really find a way to reliably detect it from the godot binary, but if you can find something that'd be useful! currently i've just added a feature called precision-double in #149.

@Bromeon
Copy link
Member

Bromeon commented Mar 7, 2023

Regarding detection, I got this answer from Godot devs:

There are feature tags called single and double that you can add to your *.gdextension file to make sure Godot loads the correct library

If you want to check it at runtime, then something like OS::get_singleton()->has_feature("double")
should probably work
Although I guess you probably wouldn't get to that point, if you try to do it from a library expecting a single-precision ABI while using a double-precision engine build or vice versa, so using the feature tags and separate libraries are probably your best bet

@bors bors bot closed this as completed in 48b509a Mar 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: core Core components feature Adds functionality to the library
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants