-
-
Notifications
You must be signed in to change notification settings - Fork 21.6k
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
Discern between VIRTUAL and ABSTRACT class bindings #58972
Conversation
Wow this is super cool ! 😃
Does it means the plan is to expose |
@touilleMan I think ScriptInstance will be exposed via a native extension API (Plain C), since its more efficient if it does not use the binder, but Script and ScriptLanguage will be exposed as regular ClassDB classes. Likely as ScriptExtension and ScriptLanguageExtension. |
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.
Looks pretty good to me, some comments and nitpicks.
MethodInfo get_rid_bind("_get_rid"); | ||
get_rid_bind.return_val.type = Variant::RID; | ||
|
||
::ClassDB::add_virtual_method(get_class_static(), get_rid_bind, true, Vector<String>(), true); |
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.
Just curious, does it actually need the ::
scope here? Just above there's ClassDB::bind_method
without extra scoping.
return false; | ||
} | ||
#endif | ||
return (!ti->disabled && ti->creation_func != nullptr && !(ti->native_extension && !ti->native_extension->create_instance) && ti->is_virtual); |
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 see you adapted this from can_instantiate()
so this is basically can_instantiate() && is_virtual
.
Just wondering if all checks from can_instantiate()
are indeed wanted - e.g. do we want to exclude classes without creation func or disabled from being qualified virtual? Just a theoretical question.
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.
Good point, I am not sure. For the time being I only made this changes to affect the editor, but not more. We can improve it towards the future I suppose.
GDREGISTER_ABSTRACT_CLASS(StreamPeer); | ||
GDREGISTER_CLASS(StreamPeerExtension); |
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.
StreamPeer
, PacketPeer
and MultiplayerPeer
all have an *Extension
wrapper which AFAIU was specifically added to workaround the limitation that this PR lifts. So these could likely be registered as virtual instead, and the *Extension
wrappers dropped.
But that's probably stuff for a future PR so it might be good to keep it as is in this one. CC @Faless
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.
Extension makes sense if its something very large, so I guess it is up to Fabio to change.
GDREGISTER_CLASS(AStar); | ||
GDREGISTER_CLASS(AStar2D); | ||
GDREGISTER_CLASS(EncodedObjectAsID); | ||
GDREGISTER_CLASS(RandomNumberGenerator); | ||
|
||
GDREGISTER_VIRTUAL_CLASS(ResourceImporter); | ||
GDREGISTER_ABSTRACT_CLASS(ResourceImporter); |
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.
Isn't that something that might typically make sense to implement as virtual?
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.
Yes, I completely forgot about these, I will add 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.
Looking at them, this will require likely another PR because its a lot of code.
<method name="_draw" qualifiers="virtual const"> | ||
<return type="void" /> |
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.
Just a note in passing but as we recently moved the docs for constructors and operators to dedicated <constructors>
and <operators>
sections, it might make sense to do the same (in a follow-up) with a <virtuals>
or something like this.
So we can make the docs a bit clearer with a separation between the API users can use, and the one users can extend/reimplement.
virtual int get_depth() const = 0; | ||
virtual bool has_mipmaps() const = 0; | ||
virtual Vector<Ref<Image>> get_data() const = 0; | ||
TypedArray<Image> _get_datai() const; |
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.
What does i
stand for here?
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.
internal I suppose, its not user exposed and _get_data is virtual already.
GDREGISTER_ABSTRACT_CLASS(TextServer); | ||
GDREGISTER_CLASS(TextServerExtension); |
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.
Another candidate for merging TextServerExtension
into a virtual TextServer
I guess @bruvzg.
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 make sense, but last time I have tried to do so, every GDVIRTUAL
binding which is using enums for the TextServer
stopped working, seems like registering enums and binding virtual methods should have a certain order. So it might need some extra changes.
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.
It also sounds like @reduz suggests keeping *Extension
classes for classes where a lot of the API is virtual, so this might be the case here.
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 think for the large ones (like script, physics server, etc. Using Extension makes more sense because otherwise the code gets to be a mess.
Looking at the kind of So this: Ref<Material> Mesh::surface_get_material(int p_idx) const {
Ref<Material> ret;
if (GDVIRTUAL_CALL(_surface_get_material, p_idx, ret)) {
return ret;
}
ERR_FAIL_V_MSG(Ref<Material>(), "Unimplemented function");
} Would become this: Ref<Material> Mesh::surface_get_material(int p_idx) const {
Ref<Material> ret;
if (GDVIRTUAL_CALL_REQUIRED(_surface_get_material, p_idx, ret)) {
return ret;
}
return Ref<Material>();
} And
|
For the record,
We need to disable the godot-cpp test in this PR temporarily until this is merged and a matching counterpart is merged in godot-cpp. |
For the record, here's the list of classes currently exposed as virtual as of this PR (it's not visible in the diff due to the name swap with virtual -> abstract so those didn't get a diff):
|
038ea7c
to
f3b3c1e
Compare
* Previous "virtual" classes (which can't be instantiated) are not corretly named "abstract". * Added a new "virtual" category for classes, they can't be instantiated from the editor, but can be inherited from script and extensions. * Converted a large amount of classes from "abstract" to "virtual" where it makes sense. Most classes that make sense have been converted. Missing: * Physics servers * VideoStream * Script* classes. which will go in a separate PR due to the complexity involved.
f3b3c1e
to
6f51eca
Compare
Thanks! |
Most classes (that make sense) have been converted. Missing:
which will go in separate PRs due to the complexity involved.