-
-
Notifications
You must be signed in to change notification settings - Fork 21.2k
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
Implement native extension system (GDExtension) #49744
Implement native extension system (GDExtension) #49744
Conversation
786193e
to
5067206
Compare
5067206
to
ecd2e19
Compare
@CedNaru Oh I just forgot about the singletons, have to add them back. I also dont think it should export the classes beginning with _ as such, I will change that. |
}; | ||
|
||
typedef void *GDNativeVariantPtr; | ||
typedef void *GDNativeStringNamePtr; |
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.
This and other functions use GDNativeStringNamePtr
, so we should add helpers to convert from const char *
to StringName
and vice versa.
Or maybe these should just use const char *
and let Godot do the conversion internally?
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.
For this specific case, the only places where StringName is used is for the variant functions, for which I assume the binder has generated the right interfaces to use, so I am not sure its worth adding this. Generating a string from a CString and then a stringname from the right constructor is fast anyway.
uint32_t hint; | ||
const char *hint_string; | ||
uint32_t usage; |
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 wonder if we should also add PROPERTY_HINT
and PROPERTY_USAGE
enums to use with this. I know we can get this from the JSON but it's not very convenient when using this with pure C.
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 would probably avoid adding anything that is in the JSON to keep the API as simple as possible. If you want to actually use the Godot API from pure C for some strange reason, we could do pure C bindings too ala GTK.
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.
we were also discussing with @groud about making the hints string only, although its a lot of work to change..
void (*classdb_register_extension_class)(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name, const char *p_parent_class_name, const GDNativeExtensionClassCreationInfo *p_extension_funcs); | ||
void (*classdb_register_extension_class_method)(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name, const GDNativeExtensionClassMethodInfo *p_method_info); | ||
void (*classdb_register_extension_class_integer_constant)(const GDNativeExtensionClassLibraryPtr p_library, const char *p_enum_name, const char *p_class_name, const char *p_constant_name, uint32_t p_constant_value); | ||
void (*classdb_register_extension_class_property)(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name, const GDNativePropertyInfo *p_info, const char *p_setter, const char *p_getter); |
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.
Missing a way to register signals.
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.
Also: we should have a way of deregistering classes, for reloading purposes.
_FORCE_INLINE_ static void encode(const m_type &p_val, void *p_ptr) { \ | ||
*((m_type *)p_ptr) = p_val; \ | ||
} \ | ||
} | ||
|
||
MAKE_PTRARG(bool); | ||
MAKE_PTRARGCONV(bool, uint32_t); |
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.
Any reason to use uint32_t
instead of uint8_t
? What do most compilers tend to use for bool?
Also does the compiler optimize this when the size is the same for both? If not we should probably use if constexpr
.
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.
problem with bool is that, even if its uint8, most platforms will prefer 32 bit alignment (specially ARM) so I would rather leave it as 32.
MAKE_PTRARGCONV(uint8_t, int64_t); | ||
MAKE_PTRARGCONV(int8_t, int64_t); |
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.
Since the new extension API is a breaking change, can we take the opportunity to change this? GetTypeInfo
has included info about int size and sign for quite some time now, so this conversion should not be needed anymore if the bindings use that info (as already do the C# bindings).
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 added this information in the bindings already, but this is mostly to create the right ones on the exposed API. The ptrcall API will still send everything through the biggest possible format (int64)
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.
Also, the GDScript interpreter will use ptrcall if it knows the types now, and it always sends int64_t, its not possible to call the "right" one directly.
Do you mean those should not be exposed? Classes beginning with _ should not be hidden. They only begin with _ to avoid conflicting with other classes in C++. |
I think he means exposing them without the |
ecd2e19
to
aebe779
Compare
@CedNaru Added the singletons to the API json at the end of the file. |
aebe779
to
94d1d91
Compare
@arundilipan instead of creating the binary, the gdnativescript and manually assigning the script to the node, now you just create a new node type and it will appear directly in the editor for you to use. |
From what I understand, extensions are directly registered into the ClassDB so when you want to create an "extended Object" in the editor instead of creating the base class and attaching a script to it, it directly behaves like if it was a regular native Object. Unlike scripts, you can't switch extensions at runtime dynamically without creating a new Object but the bright side is that you will still be able to modulate the behavior of extended Object with another script, giving 2 levels of controls. I see a strong potential for add ons. Developers can provide extensions as new usable objects for Godot that can still have custom behavior overwritten by a script written by the user. Currently, when I use an add-on and want to change the behavior of the new custom node provided I can only control it using a script on a parent node or whatever properties it has in the inspector. Also as a maintainer of Godot Kotlin, this will simplify our module a lot as we won't have to keep the .kt files around to assign them to object as scripts. (Currently forcing us to have a hashmap (path of the script -> actual Kotlin class). Only the final jar will be used. Tell me if I got something wrong, it's the understanding I got by reading the commit changes. |
So @reduz if I'm understanding this, there's no separate GDNative scripts needed, it's first class support for Kotlin or Python or Ruby classes in the Godot editor? |
@CedNaru You got it perfectly right |
5753968
to
4e86a29
Compare
So, what exactly would this look like? From what I can understand of the changes, I will be able to write a C program that includes The thing that trips me up is that ScriptLanguage doesn't extend Object. It's effectively just an interface. So, if we are just registering things to the ClassDB as (I believe?) you said, we wouldn't be able to specify that the class we are introducing extends ScriptLanguage (we can only extend Object and its derivatives). Is this correct? If so, how does the dynamic language support work? Also, wouldn't that mean we need to include the I'm a little confused as to what the capabilities and restrictions are with this. |
@willnationsdev for the most part, virtual abstract classes like ScriptLanguage will have a special binder version (likely ScriptLanguageNative) like they do now, but it will be entirely defined in C++ using the new system for registering and native virtual functions. You can even pass pointers and other stuff to them. |
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 a few issues to iron out but the general idea looks good to me.
06955b9
to
402d83a
Compare
What's the future plans for the low-level extensions ( |
402d83a
to
012b4db
Compare
@bruvzg New new system for native extension virtuals should allow for this, which had to be hardcoded in C in the past. It should also allow for custom function formats for the very specific types. The idea is to first test this system for regular development, then add these classes so we can have what we had previously in GDNative. |
* Deprecates GDNative in favor of a simpler, lower level interface. * New extension system allows registering core engine classes. * Simple header interface in gdnative_interace.h
012b4db
to
b1d15c5
Compare
Thanks! |
@neikeq can U suggest use cases how C# developers can take advantage of this exciting GDExtension. |
@GeorgeS2019 It's not possible yet. I'll add support for it in the future. |
The API dump command line has also been re made, to invoke use:
Example of how API dumps look now: api.json
This PR is a draft for review.
TODO:
JSON API dumping.Function checksums to deprecate API HashVirtual FunctionsSingletons