Add a base class or interface for RefCounted (Resources) #7

Open
opened 2026-10-22 21:39:10 -07:00 by queertherians.org · 2 comments
Owner

GDExtensionInstanceBindingCallbacks.reference_callback lets us know whether Godot holds any active references to Godot objects that inherit from a RefCounted type. We should make use of this with a new type of base class, along the lines of a gdxx::RefCounted interface which assigns .reference_callback in the gdxx::GodotClass class registration at comptime, and manages the object's refcount accordingly.

`GDExtensionInstanceBindingCallbacks.reference_callback` lets us know whether Godot holds any active references to Godot objects that inherit from a RefCounted type. We should make use of this with a new type of base class, along the lines of a `gdxx::RefCounted` interface which assigns `.reference_callback` in the `gdxx::GodotClass` class registration at comptime, and manages the object's refcount accordingly.
Author
Owner

Clarification to functionality: There will be no gdxx::RefCounted interface tag; it should be determined at registration (comptime if possible, otherwise runtime) if we are deriving from a RefCounted class or not, then registration and callback structuring will be handled accordingly.

RefCounted translations (gdxx::variant_to_object #5) will need to be wrapped into a gdxx::Reference (?) native ref counter of some kind, and templating the gdxx::variant_to_object call with a non-Reference wrapped type for a RefCounted type needs to result in an error (static_assert).

Clarification to functionality: There will be no gdxx::RefCounted interface tag; it should be determined at registration (comptime if possible, otherwise runtime) if we are deriving from a RefCounted class or not, then registration and callback structuring will be handled accordingly. RefCounted translations (`gdxx::variant_to_object` #5) will need to be wrapped into a `gdxx::Reference (?)` native ref counter of some kind, and templating the `gdxx::variant_to_object` call with a non-Reference wrapped type for a RefCounted type needs to result in an error (static_assert).
Author
Owner

As mentioned elsewhere (which actually should have been principally mentioned here first... my bad-), this requires ClassDB, which requires GodotExternClass to be implemented first.

As mentioned elsewhere (which actually should have been principally mentioned here first... my bad-), this requires ClassDB, which requires GodotExternClass to be implemented first.
Sign in to join this conversation.
No description provided.