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

Expose the get_rid method of Joint2D and Joint3D #80736

Merged
merged 1 commit into from
Sep 17, 2023

Conversation

Ughuuu
Copy link
Contributor

@Ughuuu Ughuuu commented Aug 17, 2023

Adds the get_rid property to Joint2D and Joint3D nodes.

@Ughuuu Ughuuu requested review from a team as code owners August 17, 2023 19:57
@AThousandShips
Copy link
Member

AThousandShips commented Aug 17, 2023

I'd say to call it by the original method name, the documentation makes it clear, and having it named thus makes it clearer what you are getting

Using a different name from the c++ method for the bind feels error prone, and breaks with how Camera3D, VisualInstance3D, NavigationRegion3D, Viewport, etc. does things

@Ughuuu Ughuuu force-pushed the add-get-rid-to-joints branch 2 times, most recently from e9050f1 to d492d4a Compare August 17, 2023 20:20
Copy link
Member

@rburing rburing left a comment

Choose a reason for hiding this comment

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

It makes sense to expose this, e.g. to allow physics server extensions to add features to joints and to make those features usable from joint nodes.

@rburing rburing changed the title Expose the get_rid property from Join2D and Joint3D Expose the get_rid method of Joint2D and Joint3D Aug 17, 2023
@mihe
Copy link
Contributor

mihe commented Aug 17, 2023

With stuff like the physics bodies (RigidBody3D, etc.) you can currently (in GDScript at least) pass references of them into parameters that accept a RID and it will implicitly convert it for you, without you having to call self.get_rid() or anything like that.

So you can do stuff like:

extends RigidBody3D

func _physics_process(_delta: float):
    print("My collision layer: ", PhysicsServer3D.body_get_collision_layer(self))

Does anyone know through what mechanism that happens?

That might be worth adding to this PR as well, if it's something that needs to be explicitly bound somehow.

@mihe
Copy link
Contributor

mihe commented Aug 17, 2023

It looks like the implicit cast is done through Variant::operator RID(), where it just assumes that the object will have a bound method on it called get_rid:

Variant ret = _get_obj().obj->callp(CoreStringNames::get_singleton()->get_rid, nullptr, 0, ce);

I guess that should work just fine then. Nevermind. :)

@Ughuuu
Copy link
Contributor Author

Ughuuu commented Aug 17, 2023

I'd say to call it by the original method name, the documentation makes it clear, and having it named thus makes it clearer what you are getting

Using a different name from the c++ method for the bind feels error prone, and breaks with how Camera3D, VisualInstance3D, NavigationRegion3D, Viewport, etc. does things

Not sure what the original name is or what to change. Can you explain or leave code feedback where the change should be?

@lyuma
Copy link
Contributor

lyuma commented Aug 17, 2023

I'd say to call it by the original method name, the documentation makes it clear, and having it named thus makes it clearer what you are getting

@AThousandShips I agree with the principle but disagree with naming it get_joint(). As suggested in Variant::operator RID(), Godot expects this method to be called get_rid() so we should use that in the public facing API.

Since the current C++ code uses a private API named get_joint() (not exposed), there would be no API breakage by renaming existing C++ code. Therefore I would rather suggest the C++ code be changed to use naming consistent with other Node classes that use RID internally, such that the public API can be named get_rid().

@lyuma
Copy link
Contributor

lyuma commented Aug 17, 2023

Sorry I don't always write clearly. Keep get_rid() in the public API. Consider changing existing C++ code and private APIs to match other classes, for example:

 _FORCE_INLINE_ RID get_rid() const { return rid; }

It will change many more lines of code, but it would be the right thing to do, IMHO.

The reason why @AThousandShips' comment matters, is because GDExtension C++ code will use an API generated from the method bindings. GDExtension is designed to be mostly compatible with Godot modules. However, when there is a mismatch in method naming, it would mean that GDExtension code would use a different function name (get_rid) than the module code which accessess the C++ headers (get_joint). Therefore, we should change the existing private C++ code to match.

@AThousandShips
Copy link
Member

AThousandShips commented Aug 17, 2023

Keep get_rid() in the public API

They aren't named get_rid in the API though, all these examples use that in the API, in fact most non-Resource types do not use get_rid but something else, exceptions are CollisionObject and a few others, though I don't remember which else

@akien-mga akien-mga changed the title Expose the get_rid method of Joint2D and Joint3D Expose the get_rid method of Joint2D and Joint3D Aug 17, 2023
@lyuma
Copy link
Contributor

lyuma commented Aug 17, 2023

exceptions are CollisionObject and a few others

Irrespective of what other decisions were made in the past for other Node types, it makes sense for Joint to be consistent with CollisionObject, since both are part of physics. I still think it should be get_rid() because CollisionObject* also uses get_rid().

@Ughuuu
Copy link
Contributor Author

Ughuuu commented Aug 18, 2023

Changed it. It wasn't used at all it seems, so it was simple. Now the method is also called get_rid instead of get_joint

@AThousandShips
Copy link
Member

As long as the c++ and API names line up I'm for either option, though I think it needs some more reviewers to confirm

@Ughuuu Ughuuu force-pushed the add-get-rid-to-joints branch from a598a90 to b53fead Compare August 20, 2023 14:26
@YuriSizov YuriSizov modified the milestones: 4.x, 4.2 Aug 25, 2023
@YuriSizov
Copy link
Contributor

exceptions are CollisionObject and a few others

Irrespective of what other decisions were made in the past for other Node types, it makes sense for Joint to be consistent with CollisionObject, since both are part of physics. I still think it should be get_rid() because CollisionObject* also uses get_rid().

There is an argument to be made that this makes things more inconsistent in the engine overall. If we only have a handful of exception it's not that bad, but if we start using exceptions as a second rule, then we end up with a mess.

Resources and RefCounted objects seem to use get_rid consistently, while nodes seems to use pretty much whatever makes sense to them (get_canvas_item, get_skeleton, get_camera_rid, get_instance). There isn't many of such methods on nodes, but they are all unique. Whether we can consider that the preferred style or not I don't know.

Well, as long as there is consensus on this PR, we can go with either option.


@Ughuuu Could you please amend the commit message? The title of this PR is a good option for it.

@AThousandShips
Copy link
Member

Please squash your commits into one, see here

update occurance of get_joint

Update documentation as per feedback.

update

update

Co-Authored-By: A Thousand Ships <[email protected]>
@Ughuuu Ughuuu force-pushed the add-get-rid-to-joints branch from 2ed8ac1 to f9435b6 Compare August 26, 2023 21:34
@Ughuuu
Copy link
Contributor Author

Ughuuu commented Aug 26, 2023

Oh, sorry, I am trying, hope I got it right this time.

Copy link
Member

@akien-mga akien-mga left a comment

Choose a reason for hiding this comment

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

Seems good.

@akien-mga akien-mga merged commit f4d85d5 into godotengine:master Sep 17, 2023
@akien-mga
Copy link
Member

Thanks! And congrats for your first merged Godot contribution 🎉

@Ughuuu
Copy link
Contributor Author

Ughuuu commented Sep 17, 2023

Thank you! Can't wait to have my name permanently immortalised in the list of godot contributors(jk)

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

Successfully merging this pull request may close these issues.

Expose the get_rid property from joints
7 participants