Skip to content

Conversation

@raulsntos
Copy link
Member

The engine uses the names int and float to refer to the 64-bit types, so in the bindings generator we have a hardcoded conversion for those types.

But this type conversion should not be used for metadata. Even though the underlying type should still be 64-bit for interop, metadata is meant to specify the correct type to expose. So if metadata says float it means the type is really meant to be a 32-bit float and not double. Other hardcoded type conversions (int and Nil) won't ever be metadata.

This change corrects the float type, to use the right type in the generated C++ code. Before we were always using double due to this type conversion.


For example, the InputEventMouseButton::get_factor API changes with this PR to return float which matches the method signature in the engine:

https://github.com/godotengine/godot/blob/826de7976a6add282c7b14d4be2a7e6d775821d8/core/input/input_event.h#L245

The engine uses the names `int` and `float` to refer to the 64-bit types, so in the bindings generator we have a hardcoded conversion for those types. But this type conversion should not be used for metadata. Even though the underlying type should still be 64-bit for interop, metadata is meant to specify the correct type to expose. So if metadata says `float` it means the type is really meant to be a 32-bit `float` and not `double`. Other hardcoded type conversions (`int` and `Nil`) won't ever be metadata. This change corrects the `float` type, to use the right type in the generated C++ code. Before we were always using `double` due to this type conversion.
@raulsntos raulsntos added bug This has been identified as a bug topic:gdextension This relates to the new Godot 4 extension implementation labels Aug 20, 2024
@raulsntos raulsntos added this to the 4.x milestone Aug 20, 2024
@raulsntos raulsntos requested a review from a team as a code owner August 20, 2024 13:01
Copy link
Collaborator

@dsnopek dsnopek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a pre-existing PR to address the float vs double situation: #1433

Although, it handles it differently, adding an explicit case for float, rather than removing the lookup in type_conversion.

Hm. I think yours probably makes more sense!

@dsnopek
Copy link
Collaborator

dsnopek commented Sep 3, 2024

Cherry-picked for 4.3 in PR #1569

@dsnopek
Copy link
Collaborator

dsnopek commented Sep 3, 2024

Cherry-picked for 4.2 in PR #1570

@dsnopek
Copy link
Collaborator

dsnopek commented Sep 4, 2024

Cherry-picked for 4.1 in PR #1572

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug This has been identified as a bug topic:gdextension This relates to the new Godot 4 extension implementation

2 participants