Description
Describe the project you are working on
Godot Sandbox In-editor scripting and sandboxing for Godot and many other addons/modules
Describe the problem or limitation you are having in your project
Writting an addon using gdextension (godot-cpp) and building it also as a module (godot).
- The functions don't match (eg. godot uses functions as they are, godot-cpp uses underscore) eg.:
virtual void get_script_property_list(List<PropertyInfo> *r_propertys) const // godot
//vs
virtual TypedArray<Dictionary> _get_script_property_list() const override; // godot-cpp
- Some functions parameters don't match, godot has sometimes extra params:
virtual void get_script_property_list(List<PropertyInfo> *r_propertys) const
//vs
virtual TypedArray<Dictionary> _get_script_property_list() const override;
- Some functions don't exist:
modules/sandbox/src/cpp/resource_saver_cpp.cpp: In static member function 'static void ResourceFormatSaverCPP::init()':
modules/sandbox/src/cpp/resource_saver_cpp.cpp:26:24: error: 'get_singleton' is not a member of 'ResourceSaver'
26 | ResourceSaver::get_singleton()->add_resource_format_saver(cpp_saver);
Here godot-cpp has the get_singleton
function, godot doesn't. Would be nice to even duplicate that function so the code works same for both.
- Some function names don't match:
modules/sandbox/src/rust/resource_saver_rust.cpp:87:59: error: 'class EditorInterface' has no member named 'get_resource_filesystem'; did you mean 'get_resource_file_system'?
87 | EditorInterface::get_singleton()->get_resource_filesystem()->scan();
| ^~~~~~~~~~~~~~~~~~~~~~~
| get_resource_file_system
Here it seems that one function is caleld get_resource_file_system
, one is called get_resource_filesystem
. Would be nice that if they match.
NOTE: for all these cases, there are multiple cases, not just these individual ones. These are classes or problems.
Describe the feature / enhancement and how it helps to overcome the problem or limitation
Part 1. The includes
There is already proposal for making sure godot-cpp generates includes that point to both godot-cpp and godot: #9212. There is also a PR for it godotengine/godot-cpp#1415 that adds a compatibility layer to godot-cpp:
eg.
#ifdef GODOT_MODULE
// The next included file is generated: if we had `godot_repo="..."` it'll contain the Godot includes, if not, it'll just be an empty file.
#include <godot_cpp/compat/HEADER.hpp>
#else
// ... the code that's there now ...
#endif
Part 2. Some macros
After this, the writter of the addon, needs to just update the using namespace godot;
part and create a SCsub
and can use the existing build systems for both gdextension and module builds.
Eg.
#include <godot_cpp/classes/resource_saver.hpp>
GODOT_NAMESPACE
class ResourceFormatSaverELF : public ResourceFormatSaver {
GDCLASS(ResourceFormatSaverELF, ResourceFormatSaver);
protected:
static void GODOT_CPP_FUNC (bind_methods)() {}
For the defines, they would look like:
#ifdef GODOT_MODULE
#define GODOT_CPP_FUNC(name) name
#define GODOT_NAMESPACE
#else
#define GODOT_CPP_FUNC(name) _##name
#define GODOT_NAMESPACE using namespace godot;
#endif
Part 3. Godot changes
As said above in the limitations chapter, some functions in godot either don't match, don't exist, have extra parameters or different names. Where it's possible to fix this by a macro, thats ok. Where no, it would be really nice if we change the function to match godot-cpp. I would even say we don't do that ugly macro and instead make the godot function (o underscore) also match the godot-cpp function naming.
Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
Changin godot internal API (functions) to match godot-cpp one. (it would be incremental change).
Downsides of this proposal:
If people have modules, they need to update them. But if they do, they would in theory be able to migrate also to support addons too out of the box, so it would be a necesary change for those people. A big project that does this, supports both addon/module is godot voxel, and you can see there how many ifdefs there are.
If this enhancement will not be used often, can it be worked around with a few lines of script?
Is there a reason why this should be core and not an add-on in the asset library?
EDIT: Updated 1. with another function example, not bind_methods.