godot-rust / gdext

Rust bindings for Godot 4
https://mastodon.gamedev.place/@GodotRust
Mozilla Public License 2.0
3.09k stars 196 forks source link

Support every class-registration option that Godot offers #563

Open lilizoey opened 10 months ago

lilizoey commented 10 months ago

To register a class with godot we use the GDExtensionClassCreationInfo struct, which has two versions depending on the godot version:

pub struct GDExtensionClassCreationInfo2 {
    pub is_virtual: GDExtensionBool,
    pub is_abstract: GDExtensionBool,
    pub is_exposed: GDExtensionBool, // only in 2
    pub set_func: GDExtensionClassSet,
    pub get_func: GDExtensionClassGet,
    pub get_property_list_func: GDExtensionClassGetPropertyList,
    pub free_property_list_func: GDExtensionClassFreePropertyList,
    pub property_can_revert_func: GDExtensionClassPropertyCanRevert,
    pub property_get_revert_func: GDExtensionClassPropertyGetRevert,
    pub validate_property_func: GDExtensionClassValidateProperty, // only in 2
    pub notification_func: GDExtensionClassNotification2, // different type in 2
    pub to_string_func: GDExtensionClassToString,
    pub reference_func: GDExtensionClassReference,
    pub unreference_func: GDExtensionClassUnreference,
    pub create_instance_func: GDExtensionClassCreateInstance,
    pub free_instance_func: GDExtensionClassFreeInstance,
    pub recreate_instance_func: GDExtensionClassRecreateInstance,
    pub get_virtual_func: GDExtensionClassGetVirtual,
    pub get_virtual_call_data_func: GDExtensionClassGetVirtualCallData, // only in 2
    pub call_virtual_with_data_func: GDExtensionClassCallVirtualWithData, // only in 2
    pub get_rid_func: GDExtensionClassGetRID,
    pub class_userdata: *mut ::std::os::raw::c_void,
}

Each corresponding to something configurable about class registration.

Current state of user-available registration options:

The planned builder-api would likely want the ability to set/override these options as desired.

[^1]: See this pr for information about what virtual vs abstract classes mean in godot

Bromeon commented 10 months ago

Thanks for listing all these functions, very useful! 👍

Two things to keep in mind:

  1. The GDExtension API and user-facing bindings operate at different levels of abstraction -- not every functionality of the lower level should be 1:1 exposed as a public feature.
  2. Everything that we implement now via proc-macro will need to be (at least partially) rewritten, once we have the builder API. So we should be careful to not create too much technical debt, especially in cases where there is no current demand for a feature.

Maybe handy: direct link to Godot's gdextension_interface.h on master.

Bromeon commented 8 months ago

Recent updates:

I would exclude the following from the list -- let's only implement them if we have strong demand with concrete use cases.

Furthermore, is_virtual should probably not be set manually, but in conjunction with abstract classes (if that's implemented).

Bromeon commented 1 month ago

Let's make a concrete plan on what to support for which use cases, and then start working on them. Otherwise this becomes another eternal issue. If we don't have a use case right now, we can always open new issues once one comes up, but we shouldn't track all parameters pre-emptively just in case.

The only remaining one where I see immediate usefulness is get_rid_func. This one behaves like a regular virtual function and should be part of the interface trait for every Resource derived class. Note that this is being deprecated in favor of actual virtual functions in https://github.com/godotengine/godot/pull/96787; not sure if we want to add it for compat in older Godot versions.

Also ticked off a few that have been implemented in the meantime.

lilizoey commented 1 month ago

i think validate_property_func would also be useful, it can be used to override properties defined by a superclass.