-
-
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
Implement ClassDB
singleton
#936
Implement ClassDB
singleton
#936
Conversation
c290481
to
5f3262b
Compare
src/core/class_db.cpp
Outdated
CLASSDB_GET_SINGLETON(ClassDB) | ||
#endif | ||
|
||
CLASSDB_SOUECE_IMPLEMENT(ClassDB) |
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.
SOUECE
typo?
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, thanks for your warning.
5f3262b
to
660aa06
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.
I can approve it, but I don't really have any permissions here😅
At least class_get_property_list
works
But actually I would probably just rename classes/ClassDB
to something like ClassDBImp
if possible. This would allow me to exclude this file from the build if necessary, as I am doing now with the rest of the classes in the classes/*
folder. But I am not from the core team to solve such issues.
aae9f71
to
3987cb5
Compare
7b123c7
to
7ee4f38
Compare
@akien-mga , please review and consider to merge this pr, I already overhaul this pr multi times because of the changes from later commits. |
7ee4f38
to
c6e9d6f
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.
Thanks!
I'm definitely in favor of exposing the "real" ClassDB
- being able to get metadata about classes declared outside of the current GDExtension would be very useful.
Assuming I'm understanding correctly, the approach in this PR is to generate usual class declaration for ClassDB
, but do it as a preprocessor macro, which can then be expanded in the hand-written ClassDB
that we already have.
I'm not so sure about this approach for a couple reasons:
- The changes to
bindings_generator.py
are pretty large, just to accommodate this one case. - Functions that are static when writing a Godot module (ex.
ClassDB::get_class_list()
) become members of the singleton in godot-cpp (ex.ClassDB::get_singleton()->get_class_list()
). Ideally, the code would be the same for both Godot modules and godot-cpp.
As an alternative: what if we changed binding_generator.py
to generate ClassDB
under a different name, for example, ClassDBSingleton
and then added static methods to the hand-written ClassDB
to forward them? So:
static PackedStringArray get_class_list() {
return ClassDBSingleton::get_singleton()->get_class_list();
}
If we wanted, these "forwarding functions" could be also generated into a preprocessor macro by binding_generator.py
similar to what this PR is doing, and then expanded into the hand-written ClassDB
in the same way.
I think this would require fewer changes to binding_generator.py
, because we're just swapping a name, and adding some new code to generator (as opposed to changing how some existing code is generated). And it would keep the API similar between Godot modules and godot-cpp.
What do you think?
binding_generator.py
Outdated
|
||
result.append("namespace godot {") | ||
result.append("") | ||
|
||
if is_class_db: | ||
append_continue_line(result, "#define CLASSDB_HEADER_DECLEAR()") |
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 DECLEAR
mean? Or, is this a type-o of DECLARE
?
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, it should be DECLARE
, my terrible English.
@dsnopek the principle of this pr is like your description. The reson why
Generated preprocess macros similar to normal codes of other classes, but they are alaway have a "" character at the end of line.
For In other word, the most of changes of |
Maybe I should generated preprocess macro like other classes normal code first, then append "\" character for lines after generating Anyway, I will refactor this pr again. |
@dsnopek I found that Classes which in Is it means that GDExtension should work like GDScript, not godot module? Because If we want some classes work with a "static" style in GDExtension like in godot module, refactor the logic of generating |
What about generating
This will require renaming in all existing libraries, but it will allow us to use |
8bf4c50
to
5940b58
Compare
5940b58
to
df79065
Compare
Understood. My thought was simply that this is a pretty large refactor just to account for one special class, especially when there's alternative ways to do it.
While, in general, GDExtension ends up working kinda like GDScript, I think that godot-cpp is special case where we want to maintain some level of source compatibility with Godot modules. For other bindings, like the Rust or Python binding, this doesn't matter. But for C++, we want to be able to use some minimal In any case, because This is something we could discuss further at upcoming GDExtension meetings! |
Like I described above, I personally think we want some level of source compatibility with Godot modules, and so all the methods would need to end up on the same class (even if one class is just forwarding to the other). If I find the time, I may make an alternative PR to demonstrate the idea I had in my comment above. |
I alraedy refactor this pr in a way that fewer change, please review it. |
Thanks! I skimmed it, and it definitely is fewer changes. :-) I think we just need to figure out the |
I've created this alternate PR #1164 Which implements the approach that I described in this comment. |
Alternated by #1164. |
Implement
ClassDB
singleton.Relate to this issue.
And where can I find the code style for godot?