-
-
Notifications
You must be signed in to change notification settings - Fork 589
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
Bindings for the new extension system #602
Conversation
@vnen by this time I think it's a good idea if you squash all the commits into one. For everyone else, while vnen left this as a draft I actually believe we should move to merging this into master sooner rather than later. As the current Godot master no longer works with the old gdnative approach we need to start focusing development on this. Merging this will make it easier for others to submit PRs and help out completing this. It will also open the door to raising issues to discuss further enhancements/short comings and get more people to help out by seeing what needs to be done. We'll need to create a I don't want to pollute this post any further, we should move this discussion into an issue and link it here. I'll set that up in a minute. |
Some issues encountered during godotengine/godot#52192 development:
Ref<TextServerTest> ts;
ts.instantiate();
/* void add_interface(const Ref<TextServer> &p_interface); */
TextServerManager::get_singleton()->add_interface(ts);
class TextServerTest : public TextServerExtension {
GDCLASS(TextServerTest, TextServerExtension);
....
virtual bool _has_feature(TextServer::Feature feature) override;
class TextServerTest : public TextServerExtension {
GDCLASS(TextServerTest, TextServerExtension);
....
virtual void _shaped_text_get_glyphs(const RID &shaped, Glyph *gl_array) const override;
|
I faced the same problems as @bruvzg. But I also want to add that virtual functions overloads such as |
And another inconvenience with the current implementation, there's no clear way to add a custom callbacks for init levels. GDExtensionBinding should have it's (de)initialize methods virtual. And we probably should have extra init levels after singleton registration, or change the init order on the engine side. |
Double checked, the issue related to the |
@bruvzg so far for me just having |
It's building, but |
af6c209
to
1045bbd
Compare
The extension creators then don't need to create those just to redirect to the bindings.
Use, e.g. Engine::get_singleton() to get the singleton object();
Now it needs a callback for each level so custom logic (like loading singletons) can be performed.
This makes sure custom constructors are always called on extension classes. However, note that constructors should not take any parameters, since Godot doesn't support that. Parameters are ignore in memnew macro. Use memnew(MyClass()) instead of memnew(MyClass) since it now needs a value instead of a class name. This macro calls MyClass::_new() (define in GDCLASS macro) which ultimately calls Godot to create the object, ensuring that both the Godot and the extension instances are created. Non Godot classes (that don't derive godot::Object) are constructed as usual an can have parameters. memdelete is also changed for the same reason, as it needs to destroy the Godot object as well, and that automatically frees the bound extension instance.
{ 0 } initializes only first element with zero explicitly and other elements with their default value (zeros too). Technically it will work the same, but will be more correct.
It didn't set the return value at all, changing the local value instead. Now instead correctly sets it as a generic pointer type from `_owner`.
Proper initialization for godot-cpp classes with memnew. Extension classes (i.e. the `GDCLASS` macro) behave differently from regular wrapped classes, and requires Godot to initialize them during object construction. This commit update the GDCLASS macro to not create/destroy the instance during the bindings callback, but during the extension callbacks. When setting the object instance, the bindings instance is set to the pointer of the extension instance so that it can later be retrieved normally via `object_get_instance_bindings`.
5b49003
to
d5e0fc8
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.
Commit history somewhat messy and there's too many changes for me to do an in-depth code review, but it's been tested and co-developed by many contributors so it should be good to merge now and refine in master
.
This is still not 100% functional and needs lots of testing.
This recreates the whole repository to work with the extension system that replaces GDNative in Godot 4.0.
The API is changed to be close to the one used in Godot itself to diminish the differences between an extension and a module (technically you could use the same code for both using a few
#ifdef
s).Missing things
godot-headers
as a submodule. That repo still needs an update formaster
so for now this includes the needed files ingodot-headers-temp
.How it works
The README file has a laconic description of the process. Check the demo project in the
test
folder to have an idea.You can regenerate the API JSON from Godot by running
godot --dump-extension-api
. The fileextension_api.json
will be created in the same folder from which you run the command.