-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
Fix use of non-existent Vector3.Axis
enum type in built-in methods and members
#99341
Conversation
f00b61e
to
5aaf02b
Compare
Vector3.Axis
enum type in built-in methods and members
5d8710c
to
1f848c0
Compare
1f848c0
to
0c6cff3
Compare
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.
Unless I'm missing something, this breaks the API in many places and downgrades type safety from enum to int.
Validate extension JSON: Error: Field 'classes/PhysicsServer3D/methods/generic_6dof_joint_set_param/arguments/1': type changed value in new API, from "enum::Vector3.Axis" to "int". | ||
Validate extension JSON: Error: Field 'classes/PhysicsServer3D/methods/generic_6dof_joint_get_param/arguments/1': type changed value in new API, from "enum::Vector3.Axis" to "int". |
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.
I'm not sure this is the right approach. Even if binary compatibility is retained, this changes the public API exposed towards extensions.
Bindings such as godot-rust and Swift-Godot have been built around a type Vector3Axis (Rust) or Vector3.Axis (Swift). You can't just remove it because of an issue in set_axis()
, while it works everywhere else.
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.
If I may (as someone who noticed the issue but isn't proficient in C++), the issue seems to be deeper than just set_axis(), since this PR finds and eliminates references to the same enum in multiple classes. I've just checked & found that the enum Vector3.Axis does exist in the code after all, but trying to access it in GDScript results in errors. If eliminating it breaks compat, then perhaps the right approach would be finding a way to expose it?
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.
perhaps the right approach would be finding a way to expose it?
I thought the same but no class has exposed enums, so I thought that wasn't the intended approach.
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.
Precisely my thoughts. These enums from Variants should be exposed appropriately and used across the codebase like Vector3.Axis
is. However, doing so is not straightforward because, unlike enums from classes inheriting Object, there's currently no way to do it.
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.
I thought the same but no class has exposed enums, so I thought that wasn't the intended approach.
Some low-level classes have them; off the top of my head - HTTPClient has enums for Method, Status and ResponseCode.
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.
@Bromeon
I looked at other implementations for other classes like Vector4
and Vector2
. None of them had that issue, instead they treated Vector2.Axis
params and return types as an int
. At least for binded methods. So I thought I'd change any binded method that uses Vector3.Axis
as param/return type to int
.
I basically matched Vector3
's implementation with Vector2
, Vector2I
, Vector3I
, Vector4
, Vector4I
, and Plane
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.
Precisely my thoughts. These enums from Variants should be exposed appropriately and used across the codebase like
Vector3.Axis
is. However, doing so is not straightforward because, unlike enums from classes inheriting Object, there's currently no way to do it.
There are global enums though. They already contain enums such as EulerOrder
specific to geometric builtin types, so Vector3Axis
and future Vector2Axis/Vector4Axis
wouldn't be that out of place.
DitIt would still technically be a compatibility breakage, but we don't just plain remove a valid feature.
- There's clear continuity; the binding just needs to unederstand both
Vector3.Axis
andVector3Axis
in the JSON. - There's no downgrade in type safety (int may work for GDScript but is a non-starter for other languages).
Edit: what's not so nice with that is that the constants are effectively duplicated. But retrofitting builtin enums seems like a huge endeavour for these few (others like EulerAngle
, VariantType
, VariantOperator
already exist in global scope and can't just be moved...)
Maybe status quo is still the lesser evil?
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.
There are global enums though. They already contain enums such as
EulerOrder
specific to geometric builtin types, soVector3Axis
and futureVector2Axis/Vector4Axis
wouldn't be that out of place.It would still technically be a compatibility breakage, but we don't just plain remove a valid feature.
- There's clear continuity; the binding just needs to understand both
Vector3.Axis
andVector3Axis
in the JSON.- There's no downgrade in type safety (int may work for GDScript but is a non-starter for other languages).
What if we just deprecated VectorX.Axis enums and replaced them with @GlobalScope.VectorAxis
that would looks something like this
VectorAxis {
VECTOR_AXIS_X,
VECTOR_AXIS_Y,
VECTOR_AXIS_Z,
VECTOR_AXIS_W
}
that way its only one enum for all vector types
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.
Not sure about a single enum type; you could then pass VECTOR_AXIS_W
to an API that expects Vector2.Axis
. If all APIs refer to VectorAxis
, the documentation aspect (which dimension) also gets lost.
Given the discussion above, it seems like this needs some more design. To sum up the status quo:
Now, moving forward, there are multiple options.
Personally, I'd prefer option 3, as it would provide a way forward to enhance type safety for other APIs (which currently work with I'd love to hear other opinions on the subject. |
Superseded by #99424. Thanks for the contribution! |
fixes #99309