-
-
Notifications
You must be signed in to change notification settings - Fork 688
Description
Godot version
4.5
godot-cpp version
4.5
System information
Linux
Issue description
I just finished up setting up my code to compile for both godot-cpp and as a module and figured it might be helpful to document some of the issues I ran into since one of the goals of godot-cpp is to have compatibility with Godot module code.
For the most part they are the same but there are still quite a few issues I ran into. I did end up getting it working but to prevent littering my code with a quadrillion ifdefs I had to make a bunch of macros:
#ifdef GODOT_MODULE
// Virtuals
#define gd_unhandled_key_input unhandled_key_input
#define gd_unhandled_input unhandled_input
#define gd_get_plugin_name get_plugin_name
#define gd_has_main_screen has_main_screen
#define gd_handles handles
#define gd_make_visible make_visible
#define gd_forward_3d_gui_input forward_3d_gui_input
#define gd_forward_3d_gui_input_return_type EditorPlugin::AfterGUIInput
// Functions
#define gd_load ResourceLoader::load
#define gd_rand_from_seed(m_seed) Math::rand_from_seed(&m_seed)
#define gd_object_get_class(m_obj) m_obj->get_class_name()
#define gd_variant_args_ptr_cast(m_args) reinterpret_cast<const Variant **>(argptrs)
#define gd_get_node(m_class, m_node_name) Object::cast_to<m_class>(get_node(NodePath(m_node_name)))
#define gd_hex_encode_buffer(m_byte_array) String::hex_encode_buffer(m_byte_array.ptr(), m_byte_array.size())
#define gd_get_editor_undo_redo_manager(m_plugin_class) EditorUndoRedoManager::get_singleton()
// Types
#define GodotResourceFormatCacheMode ResourceFormatLoader::CacheMode
#define GodotCallableError Callable::CallError
#define GodotCmdLineArgsType List<String>
// Enums
#define gd_mb_right MouseButton::RIGHT
#define gd_mb_left MouseButton::LEFT
#define gd_key_space Key::SPACE
#elif GDEXTENSION
// Virtual functions
#define gd_unhandled_key_input _unhandled_key_input
#define gd_unhandled_input _unhandled_input
#define gd_get_plugin_name _get_plugin_name
#define gd_has_main_screen _has_main_screen
#define gd_handles _handles
#define gd_make_visible _make_visible
#define gd_forward_3d_gui_input _forward_3d_gui_input
#define gd_forward_3d_gui_input_return_type int32_t
// Functions
#define gd_load ResourceLoader::get_singleton()->load
#define gd_rand_from_seed(m_seed) UtilityFunctions::rand_from_seed(m_seed)[0]
#define gd_object_get_class(m_obj) m_obj->get_class()
#define gd_variant_args_ptr_cast(m_args) reinterpret_cast<GDExtensionConstVariantPtr *>(argptrs)
#define gd_get_node(m_class, m_node_name) Object::cast_to<m_class>(get_node_internal(NodePath(m_node_name)))
#define gd_hex_encode_buffer(m_byte_array) m_byte_array.hex_encode()
#define gd_get_editor_undo_redo_manager(m_plugin_class) m_plugin_class->get_undo_redo()
// Types
#define GodotResourceFormatCacheMode ResourceLoader::CacheMode
#define GodotCallableError GDExtensionCallError
#define GodotCmdLineArgsType PackedStringArray
// Enums
#define gd_mb_right MouseButton::MOUSE_BUTTON_RIGHT
#define gd_mb_left MouseButton::MOUSE_BUTTON_LEFT
#define gd_key_space Key::KEY_SPACE
// Godot defines missing in godot-cpp
#define SNAME(m_arg) StringName(m_arg, false)
#endifAll of the virtuals being different makes sense to me because they are actually different, internally they are C++ virtual functions but in godot-cpp they are the GDVIRTUAL thing.
Some of the functions, types, and enums seem like they may be an oversight though. Some of the enums having different names in particular is pretty rough.