diff options
author | reduz <reduzio@gmail.com> | 2021-08-21 22:52:44 -0300 |
---|---|---|
committer | reduz <reduzio@gmail.com> | 2021-08-22 08:23:58 -0300 |
commit | 3682978aee06cd5cf26ba462a4e44d352e9e0cd1 (patch) | |
tree | fee311b675144ae3a5fecc58857912ea250b1bb7 | |
parent | 2a5c64f2a188360d09f793c0dbd35e1911b4c073 (diff) |
Replace BIND_VMETHOD by new GDVIRTUAL syntax
* New syntax is type safe.
* New syntax allows for type safe virtuals in native extensions.
* New syntax permits extremely fast calling.
Note: Everything was replaced where possible except for `_gui_input` `_input` and `_unhandled_input`.
These will require API rework on a separate PR as they work different than the rest of the functions.
Added a new method flag METHOD_FLAG_OBJECT_CORE, used internally. Allows to not dump the core virtuals like `_notification` to the json API, since each language will implement those as it is best fits.
104 files changed, 1347 insertions, 1185 deletions
diff --git a/core/core_constants.cpp b/core/core_constants.cpp index 5791f79053..ffddcbabc4 100644 --- a/core/core_constants.cpp +++ b/core/core_constants.cpp @@ -605,6 +605,7 @@ void register_global_constants() { BIND_CORE_ENUM_CONSTANT(METHOD_FLAG_VIRTUAL); BIND_CORE_ENUM_CONSTANT(METHOD_FLAG_FROM_SCRIPT); BIND_CORE_ENUM_CONSTANT(METHOD_FLAG_STATIC); + BIND_CORE_ENUM_CONSTANT(METHOD_FLAG_OBJECT_CORE); BIND_CORE_ENUM_CONSTANT(METHOD_FLAGS_DEFAULT); BIND_CORE_ENUM_CONSTANT_CUSTOM("TYPE_NIL", Variant::NIL); diff --git a/core/extension/extension_api_dump.cpp b/core/extension/extension_api_dump.cpp index 49570cd1c1..46dc5f284b 100644 --- a/core/extension/extension_api_dump.cpp +++ b/core/extension/extension_api_dump.cpp @@ -653,7 +653,7 @@ Dictionary NativeExtensionAPIDump::generate_extension_api() { ClassDB::get_method_list(class_name, &method_list, true); for (const MethodInfo &F : method_list) { StringName method_name = F.name; - if (F.flags & METHOD_FLAG_VIRTUAL) { + if ((F.flags & METHOD_FLAG_VIRTUAL) && !(F.flags & METHOD_FLAG_OBJECT_CORE)) { //virtual method const MethodInfo &mi = F; Dictionary d2; diff --git a/core/io/resource.cpp b/core/io/resource.cpp index 0262655927..87b4d7195d 100644 --- a/core/io/resource.cpp +++ b/core/io/resource.cpp @@ -352,9 +352,8 @@ Node *Resource::get_local_scene() const { } void Resource::setup_local_to_scene() { - if (get_script_instance()) { - get_script_instance()->call("_setup_local_to_scene"); - } + // Can't use GDVIRTUAL in Resource, so this will have to be done with a signal + emit_signal(SNAME("setup_local_to_scene_requested")); } Node *(*Resource::_get_local_scene_func)() = nullptr; @@ -422,12 +421,12 @@ void Resource::_bind_methods() { ClassDB::bind_method(D_METHOD("duplicate", "subresources"), &Resource::duplicate, DEFVAL(false)); ADD_SIGNAL(MethodInfo("changed")); + ADD_SIGNAL(MethodInfo("setup_local_to_scene_requested")); + ADD_GROUP("Resource", "resource_"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "resource_local_to_scene"), "set_local_to_scene", "is_local_to_scene"); ADD_PROPERTY(PropertyInfo(Variant::STRING, "resource_path", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR), "set_path", "get_path"); ADD_PROPERTY(PropertyInfo(Variant::STRING_NAME, "resource_name"), "set_name", "get_name"); - - BIND_VMETHOD(MethodInfo("_setup_local_to_scene")); } Resource::Resource() : diff --git a/core/io/resource_loader.cpp b/core/io/resource_loader.cpp index d02d827443..64237f3b15 100644 --- a/core/io/resource_loader.cpp +++ b/core/io/resource_loader.cpp @@ -68,25 +68,28 @@ bool ResourceFormatLoader::recognize_path(const String &p_path, const String &p_ } bool ResourceFormatLoader::handles_type(const String &p_type) const { - if (get_script_instance() && get_script_instance()->has_method("_handles_type")) { - // I guess custom loaders for custom resources should use "Resource" - return get_script_instance()->call("_handles_type", p_type); + bool success; + if (GDVIRTUAL_CALL(_handles_type, p_type, success)) { + return success; } return false; } String ResourceFormatLoader::get_resource_type(const String &p_path) const { - if (get_script_instance() && get_script_instance()->has_method("_get_resource_type")) { - return get_script_instance()->call("_get_resource_type", p_path); + String ret; + + if (GDVIRTUAL_CALL(_get_resource_type, p_path, ret)) { + return ret; } return ""; } ResourceUID::ID ResourceFormatLoader::get_resource_uid(const String &p_path) const { - if (get_script_instance() && get_script_instance()->has_method("_get_resource_uid")) { - return get_script_instance()->call("_get_resource_uid", p_path); + int64_t uid; + if (GDVIRTUAL_CALL(_get_resource_uid, p_path, uid)) { + return uid; } return ResourceUID::INVALID_ID; @@ -105,27 +108,26 @@ void ResourceLoader::get_recognized_extensions_for_type(const String &p_type, Li } bool ResourceFormatLoader::exists(const String &p_path) const { + bool success; + if (GDVIRTUAL_CALL(_exists, p_path, success)) { + return success; + } return FileAccess::exists(p_path); //by default just check file } void ResourceFormatLoader::get_recognized_extensions(List<String> *p_extensions) const { - if (get_script_instance() && get_script_instance()->has_method("_get_recognized_extensions")) { - PackedStringArray exts = get_script_instance()->call("_get_recognized_extensions"); - - { - const String *r = exts.ptr(); - for (int i = 0; i < exts.size(); ++i) { - p_extensions->push_back(r[i]); - } + PackedStringArray exts; + if (GDVIRTUAL_CALL(_get_recognized_extensions, exts)) { + const String *r = exts.ptr(); + for (int i = 0; i < exts.size(); ++i) { + p_extensions->push_back(r[i]); } } } RES ResourceFormatLoader::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, CacheMode p_cache_mode) { - // Check user-defined loader if there's any. Hard fail if it returns an error. - if (get_script_instance() && get_script_instance()->has_method("_load")) { - Variant res = get_script_instance()->call("_load", p_path, p_original_path, p_use_sub_threads, p_cache_mode); - + Variant res; + if (GDVIRTUAL_CALL(_load, p_path, p_original_path, p_use_sub_threads, p_cache_mode, res)) { if (res.get_type() == Variant::INT) { // Error code, abort. if (r_error) { *r_error = (Error)res.operator int64_t(); @@ -143,48 +145,42 @@ RES ResourceFormatLoader::load(const String &p_path, const String &p_original_pa } void ResourceFormatLoader::get_dependencies(const String &p_path, List<String> *p_dependencies, bool p_add_types) { - if (get_script_instance() && get_script_instance()->has_method("_get_dependencies")) { - PackedStringArray deps = get_script_instance()->call("_get_dependencies", p_path, p_add_types); - - { - const String *r = deps.ptr(); - for (int i = 0; i < deps.size(); ++i) { - p_dependencies->push_back(r[i]); - } + PackedStringArray deps; + if (GDVIRTUAL_CALL(_get_dependencies, p_path, p_add_types, deps)) { + const String *r = deps.ptr(); + for (int i = 0; i < deps.size(); ++i) { + p_dependencies->push_back(r[i]); } } } Error ResourceFormatLoader::rename_dependencies(const String &p_path, const Map<String, String> &p_map) { - if (get_script_instance() && get_script_instance()->has_method("_rename_dependencies")) { - Dictionary deps_dict; - for (Map<String, String>::Element *E = p_map.front(); E; E = E->next()) { - deps_dict[E->key()] = E->value(); - } + Dictionary deps_dict; + for (Map<String, String>::Element *E = p_map.front(); E; E = E->next()) { + deps_dict[E->key()] = E->value(); + } - int64_t res = get_script_instance()->call("_rename_dependencies", deps_dict); - return (Error)res; + int64_t err; + if (GDVIRTUAL_CALL(_rename_dependencies, p_path, deps_dict, err)) { + return (Error)err; } return OK; } void ResourceFormatLoader::_bind_methods() { - { - MethodInfo info = MethodInfo(Variant::NIL, "_load", PropertyInfo(Variant::STRING, "path"), PropertyInfo(Variant::STRING, "original_path"), PropertyInfo(Variant::BOOL, "use_sub_threads"), PropertyInfo(Variant::INT, "cache_mode")); - info.return_val.usage |= PROPERTY_USAGE_NIL_IS_VARIANT; - BIND_VMETHOD(info); - } - - BIND_VMETHOD(MethodInfo(Variant::PACKED_STRING_ARRAY, "_get_recognized_extensions")); - BIND_VMETHOD(MethodInfo(Variant::BOOL, "_handles_type", PropertyInfo(Variant::STRING_NAME, "typename"))); - BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_resource_type", PropertyInfo(Variant::STRING, "path"))); - BIND_VMETHOD(MethodInfo("_get_dependencies", PropertyInfo(Variant::STRING, "path"), PropertyInfo(Variant::STRING, "add_types"))); - BIND_VMETHOD(MethodInfo(Variant::INT, "_rename_dependencies", PropertyInfo(Variant::STRING, "path"), PropertyInfo(Variant::STRING, "renames"))); - BIND_ENUM_CONSTANT(CACHE_MODE_IGNORE); BIND_ENUM_CONSTANT(CACHE_MODE_REUSE); BIND_ENUM_CONSTANT(CACHE_MODE_REPLACE); + + GDVIRTUAL_BIND(_get_recognized_extensions); + GDVIRTUAL_BIND(_handles_type, "type"); + GDVIRTUAL_BIND(_get_resource_type, "path"); + GDVIRTUAL_BIND(_get_resource_uid, "path"); + GDVIRTUAL_BIND(_get_dependencies, "path", "add_types"); + GDVIRTUAL_BIND(_rename_dependencies, "path", "renames"); + GDVIRTUAL_BIND(_exists, "path"); + GDVIRTUAL_BIND(_load, "path", "original_path", "use_sub_threads", "cache_mode"); } /////////////////////////////////// diff --git a/core/io/resource_loader.h b/core/io/resource_loader.h index e525e80a9d..f1d9815635 100644 --- a/core/io/resource_loader.h +++ b/core/io/resource_loader.h @@ -32,6 +32,8 @@ #define RESOURCE_LOADER_H #include "core/io/resource.h" +#include "core/object/gdvirtual.gen.inc" +#include "core/object/script_language.h" #include "core/os/semaphore.h" #include "core/os/thread.h" @@ -48,6 +50,16 @@ public: protected: static void _bind_methods(); + GDVIRTUAL0RC(Vector<String>, _get_recognized_extensions) + GDVIRTUAL1RC(bool, _handles_type, StringName) + GDVIRTUAL1RC(String, _get_resource_type, String) + GDVIRTUAL1RC(ResourceUID::ID, _get_resource_uid, String) + GDVIRTUAL2RC(Vector<String>, _get_dependencies, String, bool) + GDVIRTUAL2RC(int64_t, _rename_dependencies, String, Dictionary) + GDVIRTUAL1RC(bool, _exists, String) + + GDVIRTUAL4RC(Variant, _load, String, String, bool, int) + public: virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, CacheMode p_cache_mode = CACHE_MODE_REUSE); virtual bool exists(const String &p_path) const; diff --git a/core/io/resource_saver.cpp b/core/io/resource_saver.cpp index 564de5ee69..823b5f75b1 100644 --- a/core/io/resource_saver.cpp +++ b/core/io/resource_saver.cpp @@ -42,44 +42,37 @@ ResourceSavedCallback ResourceSaver::save_callback = nullptr; ResourceSaverGetResourceIDForPath ResourceSaver::save_get_id_for_path = nullptr; Error ResourceFormatSaver::save(const String &p_path, const RES &p_resource, uint32_t p_flags) { - if (get_script_instance() && get_script_instance()->has_method("_save")) { - return (Error)get_script_instance()->call("_save", p_path, p_resource, p_flags).operator int64_t(); + int64_t res; + if (GDVIRTUAL_CALL(_save, p_path, p_resource, p_flags, res)) { + return (Error)res; } return ERR_METHOD_NOT_FOUND; } bool ResourceFormatSaver::recognize(const RES &p_resource) const { - if (get_script_instance() && get_script_instance()->has_method("_recognize")) { - return get_script_instance()->call("_recognize", p_resource); + bool success; + if (GDVIRTUAL_CALL(_recognize, p_resource, success)) { + return success; } return false; } void ResourceFormatSaver::get_recognized_extensions(const RES &p_resource, List<String> *p_extensions) const { - if (get_script_instance() && get_script_instance()->has_method("_get_recognized_extensions")) { - PackedStringArray exts = get_script_instance()->call("_get_recognized_extensions", p_resource); - - { - const String *r = exts.ptr(); - for (int i = 0; i < exts.size(); ++i) { - p_extensions->push_back(r[i]); - } + PackedStringArray exts; + if (GDVIRTUAL_CALL(_get_recognized_extensions, p_resource, exts)) { + const String *r = exts.ptr(); + for (int i = 0; i < exts.size(); ++i) { + p_extensions->push_back(r[i]); } } } void ResourceFormatSaver::_bind_methods() { - { - PropertyInfo arg0 = PropertyInfo(Variant::STRING, "path"); - PropertyInfo arg1 = PropertyInfo(Variant::OBJECT, "resource", PROPERTY_HINT_RESOURCE_TYPE, "Resource"); - PropertyInfo arg2 = PropertyInfo(Variant::INT, "flags"); - BIND_VMETHOD(MethodInfo(Variant::INT, "_save", arg0, arg1, arg2)); - } - - BIND_VMETHOD(MethodInfo(Variant::PACKED_STRING_ARRAY, "_get_recognized_extensions", PropertyInfo(Variant::OBJECT, "resource", PROPERTY_HINT_RESOURCE_TYPE, "Resource"))); - BIND_VMETHOD(MethodInfo(Variant::BOOL, "_recognize", PropertyInfo(Variant::OBJECT, "resource", PROPERTY_HINT_RESOURCE_TYPE, "Resource"))); + GDVIRTUAL_BIND(_save, "path", "resource", "flags"); + GDVIRTUAL_BIND(_recognize, "resource"); + GDVIRTUAL_BIND(_get_recognized_extensions, "resource"); } Error ResourceSaver::save(const String &p_path, const RES &p_resource, uint32_t p_flags) { diff --git a/core/io/resource_saver.h b/core/io/resource_saver.h index 2fc8d32126..fcde835dab 100644 --- a/core/io/resource_saver.h +++ b/core/io/resource_saver.h @@ -32,6 +32,8 @@ #define RESOURCE_SAVER_H #include "core/io/resource.h" +#include "core/object/gdvirtual.gen.inc" +#include "core/object/script_language.h" class ResourceFormatSaver : public RefCounted { GDCLASS(ResourceFormatSaver, RefCounted); @@ -39,6 +41,10 @@ class ResourceFormatSaver : public RefCounted { protected: static void _bind_methods(); + GDVIRTUAL3R(int64_t, _save, String, RES, uint32_t) + GDVIRTUAL1RC(bool, _recognize, RES) + GDVIRTUAL1RC(Vector<String>, _get_recognized_extensions, RES) + public: virtual Error save(const String &p_path, const RES &p_resource, uint32_t p_flags = 0); virtual bool recognize(const RES &p_resource) const; diff --git a/core/math/a_star.cpp b/core/math/a_star.cpp index 322eb7ac61..b380860522 100644 --- a/core/math/a_star.cpp +++ b/core/math/a_star.cpp @@ -382,8 +382,9 @@ bool AStar::_solve(Point *begin_point, Point *end_point) { } real_t AStar::_estimate_cost(int p_from_id, int p_to_id) { - if (get_script_instance() && get_script_instance()->has_method(SceneStringNames::get_singleton()->_estimate_cost)) { - return get_script_instance()->call(SceneStringNames::get_singleton()->_estimate_cost, p_from_id, p_to_id); + real_t scost; + if (GDVIRTUAL_CALL(_estimate_cost, p_from_id, p_to_id, scost)) { + return scost; } Point *from_point; @@ -398,8 +399,9 @@ real_t AStar::_estimate_cost(int p_from_id, int p_to_id) { } real_t AStar::_compute_cost(int p_from_id, int p_to_id) { - if (get_script_instance() && get_script_instance()->has_method(SceneStringNames::get_singleton()->_compute_cost)) { - return get_script_instance()->call(SceneStringNames::get_singleton()->_compute_cost, p_from_id, p_to_id); + real_t scost; + if (GDVIRTUAL_CALL(_compute_cost, p_from_id, p_to_id, scost)) { + return scost; } Point *from_point; @@ -557,8 +559,8 @@ void AStar::_bind_methods() { ClassDB::bind_method(D_METHOD("get_point_path", "from_id", "to_id"), &AStar::get_point_path); ClassDB::bind_method(D_METHOD("get_id_path", "from_id", "to_id"), &AStar::get_id_path); - BIND_VMETHOD(MethodInfo(Variant::FLOAT, "_estimate_cost", PropertyInfo(Variant::INT, "from_id"), PropertyInfo(Variant::INT, "to_id"))); - BIND_VMETHOD(MethodInfo(Variant::FLOAT, "_compute_cost", PropertyInfo(Variant::INT, "from_id"), PropertyInfo(Variant::INT, "to_id"))); + GDVIRTUAL_BIND(_estimate_cost, "from_id", "to_id") + GDVIRTUAL_BIND(_compute_cost, "from_id", "to_id") } AStar::~AStar() { @@ -654,8 +656,9 @@ Vector2 AStar2D::get_closest_position_in_segment(const Vector2 &p_point) const { } real_t AStar2D::_estimate_cost(int p_from_id, int p_to_id) { - if (get_script_instance() && get_script_instance()->has_method(SceneStringNames::get_singleton()->_estimate_cost)) { - return get_script_instance()->call(SceneStringNames::get_singleton()->_estimate_cost, p_from_id, p_to_id); + real_t scost; + if (GDVIRTUAL_CALL(_estimate_cost, p_from_id, p_to_id, scost)) { + return scost; } AStar::Point *from_point; @@ -670,8 +673,9 @@ real_t AStar2D::_estimate_cost(int p_from_id, int p_to_id) { } real_t AStar2D::_compute_cost(int p_from_id, int p_to_id) { - if (get_script_instance() && get_script_instance()->has_method(SceneStringNames::get_singleton()->_compute_cost)) { - return get_script_instance()->call(SceneStringNames::get_singleton()->_compute_cost, p_from_id, p_to_id); + real_t scost; + if (GDVIRTUAL_CALL(_compute_cost, p_from_id, p_to_id, scost)) { + return scost; } AStar::Point *from_point; @@ -875,6 +879,6 @@ void AStar2D::_bind_methods() { ClassDB::bind_method(D_METHOD("get_point_path", "from_id", "to_id"), &AStar2D::get_point_path); ClassDB::bind_method(D_METHOD("get_id_path", "from_id", "to_id"), &AStar2D::get_id_path); - BIND_VMETHOD(MethodInfo(Variant::FLOAT, "_estimate_cost", PropertyInfo(Variant::INT, "from_id"), PropertyInfo(Variant::INT, "to_id"))); - BIND_VMETHOD(MethodInfo(Variant::FLOAT, "_compute_cost", PropertyInfo(Variant::INT, "from_id"), PropertyInfo(Variant::INT, "to_id"))); + GDVIRTUAL_BIND(_estimate_cost, "from_id", "to_id") + GDVIRTUAL_BIND(_compute_cost, "from_id", "to_id") } diff --git a/core/math/a_star.h b/core/math/a_star.h index 44758cb046..64fa32a325 100644 --- a/core/math/a_star.h +++ b/core/math/a_star.h @@ -31,7 +31,9 @@ #ifndef A_STAR_H #define A_STAR_H +#include "core/object/gdvirtual.gen.inc" #include "core/object/ref_counted.h" +#include "core/object/script_language.h" #include "core/templates/oa_hash_map.h" /** @@ -122,6 +124,9 @@ protected: virtual real_t _estimate_cost(int p_from_id, int p_to_id); virtual real_t _compute_cost(int p_from_id, int p_to_id); + GDVIRTUAL2RC(real_t, _estimate_cost, int64_t, int64_t) + GDVIRTUAL2RC(real_t, _compute_cost, int64_t, int64_t) + public: int get_available_point_id() const; @@ -169,6 +174,9 @@ protected: virtual real_t _estimate_cost(int p_from_id, int p_to_id); virtual real_t _compute_cost(int p_from_id, int p_to_id); + GDVIRTUAL2RC(real_t, _estimate_cost, int64_t, int64_t) + GDVIRTUAL2RC(real_t, _compute_cost, int64_t, int64_t) + public: int get_available_point_id() const; diff --git a/core/object/class_db.cpp b/core/object/class_db.cpp index 75145e1b65..b29b2bd421 100644 --- a/core/object/class_db.cpp +++ b/core/object/class_db.cpp @@ -1421,7 +1421,7 @@ MethodBind *ClassDB::bind_methodfi(uint32_t p_flags, MethodBind *p_bind, const c return p_bind; } -void ClassDB::add_virtual_method(const StringName &p_class, const MethodInfo &p_method, bool p_virtual) { +void ClassDB::add_virtual_method(const StringName &p_class, const MethodInfo &p_method, bool p_virtual, const Vector<String> &p_arg_names, bool p_object_core) { ERR_FAIL_COND_MSG(!classes.has(p_class), "Request for nonexistent class '" + p_class + "'."); OBJTYPE_WLOCK; @@ -1431,6 +1431,19 @@ void ClassDB::add_virtual_method(const StringName &p_class, const MethodInfo &p_ if (p_virtual) { mi.flags |= METHOD_FLAG_VIRTUAL; } + if (p_object_core) { + mi.flags |= METHOD_FLAG_OBJECT_CORE; + } + if (p_arg_names.size()) { + if (p_arg_names.size() != mi.arguments.size()) { + WARN_PRINT("Mismatch argument name count for virtual function: " + String(p_class) + "::" + p_method.name); + } else { + for (int i = 0; i < p_arg_names.size(); i++) { + mi.arguments[i].name = p_arg_names[i]; + } + } + } + classes[p_class].virtual_methods.push_back(mi); classes[p_class].virtual_methods_map[p_method.name] = mi; diff --git a/core/object/class_db.h b/core/object/class_db.h index 8add0285f7..39e523da27 100644 --- a/core/object/class_db.h +++ b/core/object/class_db.h @@ -372,7 +372,7 @@ public: static bool get_method_info(const StringName &p_class, const StringName &p_method, MethodInfo *r_info, bool p_no_inheritance = false, bool p_exclude_from_properties = false); static MethodBind *get_method(const StringName &p_class, const StringName &p_name); - static void add_virtual_method(const StringName &p_class, const MethodInfo &p_method, bool p_virtual = true); + static void add_virtual_method(const StringName &p_class, const MethodInfo &p_method, bool p_virtual = true, const Vector<String> &p_arg_names = Vector<String>(), bool p_object_core = false); static void get_virtual_methods(const StringName &p_class, List<MethodInfo> *p_methods, bool p_no_inheritance = false); static void bind_integer_constant(const StringName &p_class, const StringName &p_enum, const StringName &p_name, int p_constant); diff --git a/core/object/make_virtuals.py b/core/object/make_virtuals.py index 9948620c73..af90593140 100644 --- a/core/object/make_virtuals.py +++ b/core/object/make_virtuals.py @@ -1,8 +1,8 @@ proto = """ #define GDVIRTUAL$VER($RET m_name $ARG) \\ StringName _gdvirtual_##m_name##_sn = #m_name;\\ +GDNativeExtensionClassCallVirtual _gdvirtual_##m_name = (_get_extension() && _get_extension()->get_virtual) ? _get_extension()->get_virtual(_get_extension()->class_userdata, #m_name) : (GDNativeExtensionClassCallVirtual) nullptr;\\ bool _gdvirtual_##m_name##_call($CALLARGS) $CONST { \\ - GDNativeExtensionClassCallVirtual _gdvirtual_##m_name = (_get_extension() && _get_extension()->get_virtual) ? _get_extension()->get_virtual(_get_extension()->class_userdata, #m_name) : (GDNativeExtensionClassCallVirtual) nullptr;\\ ScriptInstance *script_instance = ((Object*)(this))->get_script_instance();\\ if (script_instance) {\\ Callable::CallError ce; \\ @@ -23,6 +23,16 @@ bool _gdvirtual_##m_name##_call($CALLARGS) $CONST { \\ \\ return false;\\ }\\ +bool _gdvirtual_##m_name##_overriden() const { \\ + ScriptInstance *script_instance = ((Object*)(this))->get_script_instance();\\ + if (script_instance) {\\ + return script_instance->has_method(_gdvirtual_##m_name##_sn);\\ + }\\ + if (_gdvirtual_##m_name) {\\ + return true;\\ + }\\ + return false;\\ +}\\ \\ _FORCE_INLINE_ static MethodInfo _gdvirtual_##m_name##_get_method_info() { \\ MethodInfo method_info;\\ @@ -77,7 +87,7 @@ def generate_version(argcount, const=False, returns=False): callptrargs += "\t\t" callptrargsptr += ", " argtext += "m_type" + str(i + 1) - callargtext += "const m_type" + str(i + 1) + "& arg" + str(i + 1) + callargtext += "m_type" + str(i + 1) + " arg" + str(i + 1) callsiargs += "Variant(arg" + str(i + 1) + ")" callsiargptrs += "&vargs[" + str(i) + "]" callptrargs += ( @@ -103,7 +113,7 @@ def generate_version(argcount, const=False, returns=False): if returns: if argcount > 0: callargtext += "," - callargtext += " m_ret& r_ret" + callargtext += " m_ret& r_ret" s = s.replace("$CALLSIBEGIN", "Variant ret = ") s = s.replace("$CALLSIRET", "r_ret = ret;") s = s.replace("$CALLPTRRETPASS", "&ret") diff --git a/core/object/method_bind.h b/core/object/method_bind.h index 92b964772a..b0b379873e 100644 --- a/core/object/method_bind.h +++ b/core/object/method_bind.h @@ -43,6 +43,7 @@ enum MethodFlags { METHOD_FLAG_FROM_SCRIPT = 64, METHOD_FLAG_VARARG = 128, METHOD_FLAG_STATIC = 256, + METHOD_FLAG_OBJECT_CORE = 512, METHOD_FLAGS_DEFAULT = METHOD_FLAG_NORMAL, }; diff --git a/core/object/object.cpp b/core/object/object.cpp index 2bb4b981b9..3335942fb3 100644 --- a/core/object/object.cpp +++ b/core/object/object.cpp @@ -1619,22 +1619,25 @@ void Object::_bind_methods() { ADD_SIGNAL(MethodInfo("script_changed")); ADD_SIGNAL(MethodInfo("property_list_changed")); - BIND_VMETHOD(MethodInfo("_notification", PropertyInfo(Variant::INT, "what"))); - BIND_VMETHOD(MethodInfo(Variant::BOOL, "_set", PropertyInfo(Variant::STRING_NAME, "property"), PropertyInfo(Variant::NIL, "value"))); +#define BIND_OBJ_CORE_METHOD(m_method) \ + ::ClassDB::add_virtual_method(get_class_static(), m_method, true, Vector<String>(), true); + + BIND_OBJ_CORE_METHOD(MethodInfo("_notification", PropertyInfo(Variant::INT, "what"))); + BIND_OBJ_CORE_METHOD(MethodInfo(Variant::BOOL, "_set", PropertyInfo(Variant::STRING_NAME, "property"), PropertyInfo(Variant::NIL, "value"))); #ifdef TOOLS_ENABLED MethodInfo miget("_get", PropertyInfo(Variant::STRING_NAME, "property")); miget.return_val.name = "Variant"; miget.return_val.usage |= PROPERTY_USAGE_NIL_IS_VARIANT; - BIND_VMETHOD(miget); + BIND_OBJ_CORE_METHOD(miget); MethodInfo plget("_get_property_list"); plget.return_val.type = Variant::ARRAY; - BIND_VMETHOD(plget); + BIND_OBJ_CORE_METHOD(plget); #endif - BIND_VMETHOD(MethodInfo("_init")); - BIND_VMETHOD(MethodInfo(Variant::STRING, "_to_string")); + BIND_OBJ_CORE_METHOD(MethodInfo("_init")); + BIND_OBJ_CORE_METHOD(MethodInfo(Variant::STRING, "_to_string")); BIND_CONSTANT(NOTIFICATION_POSTINITIALIZE); BIND_CONSTANT(NOTIFICATION_PREDELETE); diff --git a/core/object/object.h b/core/object/object.h index 94531f1cd0..aede48343c 100644 --- a/core/object/object.h +++ b/core/object/object.h @@ -282,7 +282,14 @@ struct ObjectNativeExtension { }; #define GDVIRTUAL_CALL(m_name, ...) _gdvirtual_##m_name##_call(__VA_ARGS__) -#define GDVIRTUAL_BIND(m_name) ::ClassDB::add_virtual_method(get_class_static(), _gdvirtual_##m_name##_get_method_info()); +#define GDVIRTUAL_CALL_PTR(m_obj, m_name, ...) m_obj->_gdvirtual_##m_name##_call(__VA_ARGS__) +#ifdef DEBUG_METHODS_ENABLED +#define GDVIRTUAL_BIND(m_name, ...) ::ClassDB::add_virtual_method(get_class_static(), _gdvirtual_##m_name##_get_method_info(), true, sarray(__VA_ARGS__)); +#else +#define GDVIRTUAL_BIND(m_name, ...) +#endif +#define GDVIRTUAL_IS_OVERRIDEN(m_name) _gdvirtual_##m_name##_overriden() +#define GDVIRTUAL_IS_OVERRIDEN_PTR(m_obj, m_name) m_obj->_gdvirtual_##m_name##_overriden() /* the following is an incomprehensible blob of hacks and workarounds to compensate for many of the fallencies in C++. As a plus, this macro pretty much alone defines the object model. diff --git a/core/object/ref_counted.h b/core/object/ref_counted.h index e0af2c18bb..f2dd2aa324 100644 --- a/core/object/ref_counted.h +++ b/core/object/ref_counted.h @@ -274,8 +274,6 @@ struct PtrToArg<const Ref<T> &> { } }; -#ifdef DEBUG_METHODS_ENABLED - template <class T> struct GetTypeInfo<Ref<T>> { static const Variant::Type VARIANT_TYPE = Variant::OBJECT; @@ -296,6 +294,4 @@ struct GetTypeInfo<const Ref<T> &> { } }; -#endif // DEBUG_METHODS_ENABLED - #endif // REF_COUNTED_H diff --git a/core/os/main_loop.cpp b/core/os/main_loop.cpp index 3c0e56f5a8..0ba69a8d47 100644 --- a/core/os/main_loop.cpp +++ b/core/os/main_loop.cpp @@ -33,11 +33,6 @@ #include "core/object/script_language.h" void MainLoop::_bind_methods() { - BIND_VMETHOD(MethodInfo("_initialize")); - BIND_VMETHOD(MethodInfo(Variant::BOOL, "_physics_process", PropertyInfo(Variant::FLOAT, "delta"))); - BIND_VMETHOD(MethodInfo(Variant::BOOL, "_process", PropertyInfo(Variant::FLOAT, "delta"))); - BIND_VMETHOD(MethodInfo("_finalize")); - BIND_CONSTANT(NOTIFICATION_OS_MEMORY_WARNING); BIND_CONSTANT(NOTIFICATION_TRANSLATION_CHANGED); BIND_CONSTANT(NOTIFICATION_WM_ABOUT); @@ -50,7 +45,12 @@ void MainLoop::_bind_methods() { BIND_CONSTANT(NOTIFICATION_TEXT_SERVER_CHANGED); ADD_SIGNAL(MethodInfo("on_request_permissions_result", PropertyInfo(Variant::STRING, "permission"), PropertyInfo(Variant::BOOL, "granted"))); -}; + + GDVIRTUAL_BIND(_initialize); + GDVIRTUAL_BIND(_physics_process, "delta"); + GDVIRTUAL_BIND(_process, "delta"); + GDVIRTUAL_BIND(_finalize); +} void MainLoop::set_initialize_script(const Ref<Script> &p_initialize_script) { initialize_script = p_initialize_script; @@ -61,30 +61,31 @@ void MainLoop::initialize() { set_script(initialize_script); } - if (get_script_instance()) { - get_script_instance()->call("_initialize"); - } + GDVIRTUAL_CALL(_initialize); } bool MainLoop::physics_process(double p_time) { - if (get_script_instance()) { - return get_script_instance()->call("_physics_process", p_time); + bool quit; + if (GDVIRTUAL_CALL(_physics_process, p_time, quit)) { + return quit; } return false; } bool MainLoop::process(double p_time) { - if (get_script_instance()) { - return get_script_instance()->call("_process", p_time); + bool quit; + if (GDVIRTUAL_CALL(_process, p_time, quit)) { + return quit; } return false; } void MainLoop::finalize() { + GDVIRTUAL_CALL(_finalize); + if (get_script_instance()) { - get_script_instance()->call("_finalize"); set_script(Variant()); //clear script } } diff --git a/core/os/main_loop.h b/core/os/main_loop.h index b42e9b18ff..4da01d767e 100644 --- a/core/os/main_loop.h +++ b/core/os/main_loop.h @@ -32,6 +32,7 @@ #define MAIN_LOOP_H #include "core/input/input_event.h" +#include "core/object/gdvirtual.gen.inc" #include "core/object/ref_counted.h" #include "core/object/script_language.h" @@ -44,6 +45,11 @@ class MainLoop : public Object { protected: static void _bind_methods(); + GDVIRTUAL0(_initialize) + GDVIRTUAL1R(bool, _physics_process, double) + GDVIRTUAL1R(bool, _process, double) + GDVIRTUAL0(_finalize) + public: enum { //make sure these are replicated in Node diff --git a/core/variant/typed_array.h b/core/variant/typed_array.h index 900dcf7689..2e96f4e445 100644 --- a/core/variant/typed_array.h +++ b/core/variant/typed_array.h @@ -125,7 +125,7 @@ struct PtrToArg<TypedArray<T>> { _FORCE_INLINE_ static TypedArray<T> convert(const void *p_ptr) { return TypedArray<T>(*reinterpret_cast<const Array *>(p_ptr)); } - + typedef Array EncodeT; _FORCE_INLINE_ static void encode(TypedArray<T> p_val, void *p_ptr) { *(Array *)p_ptr = p_val; } @@ -133,13 +133,13 @@ struct PtrToArg<TypedArray<T>> { template <class T> struct PtrToArg<const TypedArray<T> &> { - _FORCE_INLINE_ static TypedArray<T> convert(const void *p_ptr) { + typedef Array EncodeT; + _FORCE_INLINE_ static TypedArray<T> + convert(const void *p_ptr) { return TypedArray<T>(*reinterpret_cast<const Array *>(p_ptr)); } }; -#ifdef DEBUG_METHODS_ENABLED - template <class T> struct GetTypeInfo<TypedArray<T>> { static const Variant::Type VARIANT_TYPE = Variant::ARRAY; @@ -218,6 +218,4 @@ MAKE_TYPED_ARRAY_INFO(Vector<Vector2>, Variant::PACKED_VECTOR2_ARRAY) MAKE_TYPED_ARRAY_INFO(Vector<Vector3>, Variant::PACKED_VECTOR3_ARRAY) MAKE_TYPED_ARRAY_INFO(Vector<Color>, Variant::PACKED_COLOR_ARRAY) -#endif - #endif // TYPED_ARRAY_H diff --git a/doc/classes/@GlobalScope.xml b/doc/classes/@GlobalScope.xml index d4680d1836..46b9bdd52d 100644 --- a/doc/classes/@GlobalScope.xml +++ b/doc/classes/@GlobalScope.xml @@ -2458,6 +2458,8 @@ </constant> <constant name="METHOD_FLAG_STATIC" value="256" enum="MethodFlags"> </constant> + <constant name="METHOD_FLAG_OBJECT_CORE" value="512" enum="MethodFlags"> + </constant> <constant name="METHOD_FLAGS_DEFAULT" value="1" enum="MethodFlags"> Default method flags. </constant> diff --git a/doc/classes/AStar.xml b/doc/classes/AStar.xml index 63dd250dbc..3e91184a65 100644 --- a/doc/classes/AStar.xml +++ b/doc/classes/AStar.xml @@ -38,7 +38,7 @@ <tutorials> </tutorials> <methods> - <method name="_compute_cost" qualifiers="virtual"> + <method name="_compute_cost" qualifiers="virtual const"> <return type="float" /> <argument index="0" name="from_id" type="int" /> <argument index="1" name="to_id" type="int" /> @@ -47,7 +47,7 @@ Note that this function is hidden in the default [code]AStar[/code] class. </description> </method> - <method name="_estimate_cost" qualifiers="virtual"> + <method name="_estimate_cost" qualifiers="virtual const"> <return type="float" /> <argument index="0" name="from_id" type="int" /> <argument index="1" name="to_id" type="int" /> diff --git a/doc/classes/AStar2D.xml b/doc/classes/AStar2D.xml index 31d695b051..453e8b6315 100644 --- a/doc/classes/AStar2D.xml +++ b/doc/classes/AStar2D.xml @@ -9,7 +9,7 @@ <tutorials> </tutorials> <methods> - <method name="_compute_cost" qualifiers="virtual"> + <method name="_compute_cost" qualifiers="virtual const"> <return type="float" /> <argument index="0" name="from_id" type="int" /> <argument index="1" name="to_id" type="int" /> @@ -18,7 +18,7 @@ Note that this function is hidden in the default [code]AStar2D[/code] class. </description> </method> - <method name="_estimate_cost" qualifiers="virtual"> + <method name="_estimate_cost" qualifiers="virtual const"> <return type="float" /> <argument index="0" name="from_id" type="int" /> <argument index="1" name="to_id" type="int" /> diff --git a/doc/classes/AnimationNode.xml b/doc/classes/AnimationNode.xml index a9a08efcf1..173ff43d2a 100644 --- a/doc/classes/AnimationNode.xml +++ b/doc/classes/AnimationNode.xml @@ -11,46 +11,46 @@ <link title="AnimationTree">https://docs.godotengine.org/en/latest/tutorials/animation/animation_tree.html</link> </tutorials> <methods> - <method name="_get_caption" qualifiers="virtual"> + <method name="_get_caption" qualifiers="virtual const"> <return type="String" /> <description> Gets the text caption for this node (used by some editors). </description> </method> - <method name="_get_child_by_name" qualifiers="virtual"> - <return type="Object" /> - <argument index="0" name="name" type="String" /> + <method name="_get_child_by_name" qualifiers="virtual const"> + <return type="AnimationNode" /> + <argument index="0" name="name" type="StringName" /> <description> Gets a child node by index (used by editors inheriting from [AnimationRootNode]). </description> </method> - <method name="_get_child_nodes" qualifiers="virtual"> + <method name="_get_child_nodes" qualifiers="virtual const"> <return type="Dictionary" /> <description> Gets all children nodes in order as a [code]name: node[/code] dictionary. Only useful when inheriting [AnimationRootNode]. </description> </method> - <method name="_get_parameter_default_value" qualifiers="virtual"> + <method name="_get_parameter_default_value" qualifiers="virtual const"> <return type="Variant" /> - <argument index="0" name="name" type="StringName" /> + <argument index="0" name="parameter" type="StringName" /> <description> Gets the default value of a parameter. Parameters are custom local memory used for your nodes, given a resource can be reused in multiple trees. </description> </method> - <method name="_get_parameter_list" qualifiers="virtual"> + <method name="_get_parameter_list" qualifiers="virtual const"> <return type="Array" /> <description> Gets the property information for parameter. Parameters are custom local memory used for your nodes, given a resource can be reused in multiple trees. Format is similar to [method Object.get_property_list]. </description> </method> - <method name="_has_filter" qualifiers="virtual"> + <method name="_has_filter" qualifiers="virtual const"> <return type="bool" /> <description> Returns [code]true[/code] whether you want the blend tree editor to display filter editing on this node. </description> </method> - <method name="_process" qualifiers="virtual"> - <return type="void" /> + <method name="_process" qualifiers="virtual const"> + <return type="float" /> <argument index="0" name="time" type="float" /> <argument index="1" name="seek" type="bool" /> <description> diff --git a/doc/classes/CodeEdit.xml b/doc/classes/CodeEdit.xml index 47078330f3..93f72d45ae 100644 --- a/doc/classes/CodeEdit.xml +++ b/doc/classes/CodeEdit.xml @@ -17,9 +17,9 @@ Override this method to define how the selected entry should be inserted. If [code]replace[/code] is true, any existing text should be replaced. </description> </method> - <method name="_filter_code_completion_candidates" qualifiers="virtual"> + <method name="_filter_code_completion_candidates" qualifiers="virtual const"> <return type="Array" /> - <argument index="0" name="candidates" type="Array" /> + <argument index="0" name="candidates" type="Dictionary[]" /> <description> Override this method to define what items in [code]candidates[/code] should be displayed. Both [code]candidates[/code] and the return is a [Array] of [Dictionary], see [method get_code_completion_option] for [Dictionary] content. diff --git a/doc/classes/Control.xml b/doc/classes/Control.xml index 0834521c91..5392189f6a 100644 --- a/doc/classes/Control.xml +++ b/doc/classes/Control.xml @@ -22,9 +22,9 @@ <link title="All GUI Demos">https://github.com/godotengine/godot-demo-projects/tree/master/gui</link> </tutorials> <methods> - <method name="_can_drop_data" qualifiers="virtual"> + <method name="_can_drop_data" qualifiers="virtual const"> <return type="bool" /> - <argument index="0" name="position" type="Vector2" /> + <argument index="0" name="at_position" type="Vector2" /> <argument index="1" name="data" type="Variant" /> <description> Godot calls this method to test if [code]data[/code] from a control's [method _get_drag_data] can be dropped at [code]position[/code]. [code]position[/code] is local to this control. @@ -49,7 +49,7 @@ </method> <method name="_drop_data" qualifiers="virtual"> <return type="void" /> - <argument index="0" name="position" type="Vector2" /> + <argument index="0" name="at_position" type="Vector2" /> <argument index="1" name="data" type="Variant" /> <description> Godot calls this method to pass you the [code]data[/code] from a control's [method _get_drag_data] result. Godot first calls [method _can_drop_data] to test if [code]data[/code] is allowed to drop at [code]position[/code] where [code]position[/code] is local to this control. @@ -73,9 +73,9 @@ [/codeblocks] </description> </method> - <method name="_get_drag_data" qualifiers="virtual"> + <method name="_get_drag_data" qualifiers="virtual const"> <return type="Variant" /> - <argument index="0" name="position" type="Vector2" /> + <argument index="0" name="at_position" type="Vector2" /> <description> Godot calls this method to get data that can be dragged and dropped onto controls that expect drop data. Returns [code]null[/code] if there is no data to drag. Controls that want to receive drop data should implement [method _can_drop_data] and [method _drop_data]. [code]position[/code] is local to this control. Drag may be forced with [method force_drag]. A preview that will follow the mouse that should represent the data can be set with [method set_drag_preview]. A good time to set the preview is in this method. @@ -97,7 +97,7 @@ [/codeblocks] </description> </method> - <method name="_get_minimum_size" qualifiers="virtual"> + <method name="_get_minimum_size" qualifiers="virtual const"> <return type="Vector2" /> <description> Virtual method to be implemented by the user. Returns the minimum size for this control. Alternative to [member rect_min_size] for controlling minimum size via code. The actual minimum size will be the max value of these two (in each axis separately). @@ -141,15 +141,15 @@ </method> <method name="_has_point" qualifiers="virtual const"> <return type="bool" /> - <argument index="0" name="" type="Vector2" /> + <argument index="0" name="position" type="Vector2" /> <description> Virtual method to be implemented by the user. Returns whether the given [code]point[/code] is inside this control. If not overridden, default behavior is checking if the point is within control's Rect. [b]Note:[/b] If you want to check if a point is inside the control, you can use [code]get_rect().has_point(point)[/code]. </description> </method> - <method name="_make_custom_tooltip" qualifiers="virtual"> - <return type="Control" /> + <method name="_make_custom_tooltip" qualifiers="virtual const"> + <return type="Object" /> <argument index="0" name="for_text" type="String" /> <description> Virtual method to be implemented by the user. Returns a [Control] node that should be used as a tooltip instead of the default one. The [code]for_text[/code] includes the contents of the [member hint_tooltip] property. @@ -193,8 +193,8 @@ [/codeblocks] </description> </method> - <method name="_structured_text_parser" qualifiers="virtual"> - <return type="void" /> + <method name="_structured_text_parser" qualifiers="virtual const"> + <return type="Array" /> <argument index="0" name="args" type="Array" /> <argument index="1" name="text" type="String" /> <description> diff --git a/doc/classes/EditorImportPlugin.xml b/doc/classes/EditorImportPlugin.xml index b379ccc8c6..da6738d6b7 100644 --- a/doc/classes/EditorImportPlugin.xml +++ b/doc/classes/EditorImportPlugin.xml @@ -113,28 +113,28 @@ <link title="Import plugins">https://docs.godotengine.org/en/latest/tutorials/plugins/editor/import_plugins.html</link> </tutorials> <methods> - <method name="_get_import_options" qualifiers="virtual"> + <method name="_get_import_options" qualifiers="virtual const"> <return type="Array" /> - <argument index="0" name="preset" type="int" /> + <argument index="0" name="preset_index" type="int" /> <description> Gets the options and default values for the preset at this index. Returns an Array of Dictionaries with the following keys: [code]name[/code], [code]default_value[/code], [code]property_hint[/code] (optional), [code]hint_string[/code] (optional), [code]usage[/code] (optional). </description> </method> - <method name="_get_import_order" qualifiers="virtual"> + <method name="_get_import_order" qualifiers="virtual const"> <return type="int" /> <description> Gets the order of this importer to be run when importing resources. Importers with [i]lower[/i] import orders will be called first, and higher values will be called later. Use this to ensure the importer runs after the dependencies are already imported. The default import order is [code]0[/code] unless overridden by a specific importer. See [enum ResourceImporter.ImportOrder] for some predefined values. </description> </method> - <method name="_get_importer_name" qualifiers="virtual"> + <method name="_get_importer_name" qualifiers="virtual const"> <return type="String" /> <description> Gets the unique name of the importer. </description> </method> - <method name="_get_option_visibility" qualifiers="virtual"> + <method name="_get_option_visibility" qualifiers="virtual const"> <return type="bool" /> - <argument index="0" name="option" type="String" /> + <argument index="0" name="option_name" type="StringName" /> <argument index="1" name="options" type="Dictionary" /> <description> This method can be overridden to hide specific import options if conditions are met. This is mainly useful for hiding options that depend on others if one of them is disabled. For example: @@ -163,50 +163,50 @@ Return [code]true[/code] to make all options always visible. </description> </method> - <method name="_get_preset_count" qualifiers="virtual"> + <method name="_get_preset_count" qualifiers="virtual const"> <return type="int" /> <description> Gets the number of initial presets defined by the plugin. Use [method _get_import_options] to get the default options for the preset and [method _get_preset_name] to get the name of the preset. </description> </method> - <method name="_get_preset_name" qualifiers="virtual"> + <method name="_get_preset_name" qualifiers="virtual const"> <return type="String" /> - <argument index="0" name="preset" type="int" /> + <argument index="0" name="preset_index" type="int" /> <description> Gets the name of the options preset at this index. </description> </method> - <method name="_get_priority" qualifiers="virtual"> + <method name="_get_priority" qualifiers="virtual const"> <return type="float" /> <description> Gets the priority of this plugin for the recognized extension. Higher priority plugins will be preferred. The default priority is [code]1.0[/code]. </description> </method> - <method name="_get_recognized_extensions" qualifiers="virtual"> - <return type="Array" /> + <method name="_get_recognized_extensions" qualifiers="virtual const"> + <return type="PackedStringArray" /> <description> Gets the list of file extensions to associate with this loader (case-insensitive). e.g. [code]["obj"][/code]. </description> </method> - <method name="_get_resource_type" qualifiers="virtual"> + <method name="_get_resource_type" qualifiers="virtual const"> <return type="String" /> <description> Gets the Godot resource type associated with this loader. e.g. [code]"Mesh"[/code] or [code]"Animation"[/code]. </description> </method> - <method name="_get_save_extension" qualifiers="virtual"> + <method name="_get_save_extension" qualifiers="virtual const"> <return type="String" /> <description> Gets the extension used to save this resource in the [code].godot/imported[/code] directory. </description> </method> - <method name="_get_visible_name" qualifiers="virtual"> + <method name="_get_visible_name" qualifiers="virtual const"> <return type="String" /> <description> Gets the name to display in the import window. You should choose this name as a continuation to "Import as", e.g. "Import as Special Mesh". </description> </method> - <method name="_import" qualifiers="virtual"> + <method name="_import" qualifiers="virtual const"> <return type="int" /> <argument index="0" name="source_file" type="String" /> <argument index="1" name="save_path" type="String" /> diff --git a/doc/classes/EditorInspectorPlugin.xml b/doc/classes/EditorInspectorPlugin.xml index 62fd7a1d6e..ee93379210 100644 --- a/doc/classes/EditorInspectorPlugin.xml +++ b/doc/classes/EditorInspectorPlugin.xml @@ -16,9 +16,9 @@ <link title="Inspector plugins">https://docs.godotengine.org/en/latest/tutorials/plugins/editor/inspector_plugins.html</link> </tutorials> <methods> - <method name="_can_handle" qualifiers="virtual"> + <method name="_can_handle" qualifiers="virtual const"> <return type="bool" /> - <argument index="0" name="object" type="Object" /> + <argument index="0" name="object" type="Variant" /> <description> Returns [code]true[/code] if this object can be handled by this plugin. </description> @@ -31,9 +31,9 @@ </method> <method name="_parse_category" qualifiers="virtual"> <return type="void" /> - <argument index="0" name="category" type="String" /> + <argument index="0" name="object" type="Object" /> + <argument index="1" name="category" type="String" /> <description> - Called to allow adding controls at the beginning of the category. </description> </method> <method name="_parse_end" qualifiers="virtual"> @@ -44,11 +44,13 @@ </method> <method name="_parse_property" qualifiers="virtual"> <return type="bool" /> - <argument index="0" name="type" type="int" /> - <argument index="1" name="path" type="String" /> - <argument index="2" name="hint" type="int" /> - <argument index="3" name="hint_text" type="String" /> - <argument index="4" name="usage" type="int" /> + <argument index="0" name="object" type="Object" /> + <argument index="1" name="type" type="int" /> + <argument index="2" name="name" type="String" /> + <argument index="3" name="hint_type" type="int" /> + <argument index="4" name="hint_string" type="String" /> + <argument index="5" name="usage_flags" type="int" /> + <argument index="6" name="wide" type="bool" /> <description> Called to allow adding property specific editors to the inspector. Usually these inherit [EditorProperty]. Returning [code]true[/code] removes the built-in editor for this property, otherwise allows to insert a custom editor before the built-in one. </description> diff --git a/doc/classes/EditorNode3DGizmo.xml b/doc/classes/EditorNode3DGizmo.xml index 39f6805254..91e024cc1c 100644 --- a/doc/classes/EditorNode3DGizmo.xml +++ b/doc/classes/EditorNode3DGizmo.xml @@ -13,7 +13,7 @@ <return type="void" /> <argument index="0" name="id" type="int" /> <argument index="1" name="restore" type="Variant" /> - <argument index="2" name="cancel" type="bool" default="false" /> + <argument index="2" name="cancel" type="bool" /> <description> Override this method to commit a handle being edited (handles must have been previously added by [method add_handles]). This usually means creating an [UndoRedo] action for the change, using the current handle value as "do" and the [code]restore[/code] argument as "undo". If the [code]cancel[/code] argument is [code]true[/code], the [code]restore[/code] value should be directly set, without any [UndoRedo] action. @@ -22,14 +22,14 @@ <method name="_commit_subgizmos" qualifiers="virtual"> <return type="void" /> <argument index="0" name="ids" type="PackedInt32Array" /> - <argument index="1" name="restore" type="Array" /> - <argument index="2" name="cancel" type="bool" default="false" /> + <argument index="1" name="restores" type="Transform3D[]" /> + <argument index="2" name="cancel" type="bool" /> <description> Override this method to commit a group of subgizmos being edited (see [method _subgizmos_intersect_ray] and [method _subgizmos_intersect_frustum]). This usually means creating an [UndoRedo] action for the change, using the current transforms as "do" and the [code]restore[/code] transforms as "undo". If the [code]cancel[/code] argument is [code]true[/code], the [code]restore[/code] transforms should be directly set, without any [UndoRedo] action. </description> </method> - <method name="_get_handle_name" qualifiers="virtual"> + <method name="_get_handle_name" qualifiers="virtual const"> <return type="String" /> <argument index="0" name="id" type="int" /> <description> @@ -37,21 +37,21 @@ Handles can be named for reference to the user when editing. </description> </method> - <method name="_get_handle_value" qualifiers="virtual"> + <method name="_get_handle_value" qualifiers="virtual const"> <return type="Variant" /> <argument index="0" name="id" type="int" /> <description> Override this method to return the current value of a handle. This value will be requested at the start of an edit and used as the [code]restore[/code] argument in [method _commit_handle]. </description> </method> - <method name="_get_subgizmo_transform" qualifiers="virtual"> + <method name="_get_subgizmo_transform" qualifiers="virtual const"> <return type="Transform3D" /> <argument index="0" name="id" type="int" /> <description> Override this method to return the current transform of a subgizmo. This transform will be requested at the start of an edit and used as the [code]restore[/code] argument in [method _commit_subgizmos]. </description> </method> - <method name="_is_handle_highlighted" qualifiers="virtual"> + <method name="_is_handle_highlighted" qualifiers="virtual const"> <return type="bool" /> <argument index="0" name="id" type="int" /> <description> @@ -81,15 +81,15 @@ Override this method to update the node properties during subgizmo editing (see [method _subgizmos_intersect_ray] and [method _subgizmos_intersect_frustum]). The [code]transform[/code] is given in the Node3D's local coordinate system. </description> </method> - <method name="_subgizmos_intersect_frustum" qualifiers="virtual"> + <method name="_subgizmos_intersect_frustum" qualifiers="virtual const"> <return type="PackedInt32Array" /> <argument index="0" name="camera" type="Camera3D" /> - <argument index="1" name="frustum" type="Array" /> + <argument index="1" name="frustum" type="Plane[]" /> <description> Override this method to allow selecting subgizmos using mouse drag box selection. Given a [code]camera[/code] and a [code]frustum[/code], this method should return which subgizmos are contained within the frustum. The [code]frustum[/code] argument consists of an [code]Array[/code] with all the [code]Plane[/code]s that make up the selection frustum. The returned value should contain a list of unique subgizmo identifiers, which can have any non-negative value and will be used in other virtual methods like [method _get_subgizmo_transform] or [method _commit_subgizmos]. </description> </method> - <method name="_subgizmos_intersect_ray" qualifiers="virtual"> + <method name="_subgizmos_intersect_ray" qualifiers="virtual const"> <return type="int" /> <argument index="0" name="camera" type="Camera3D" /> <argument index="1" name="point" type="Vector2" /> diff --git a/doc/classes/EditorNode3DGizmoPlugin.xml b/doc/classes/EditorNode3DGizmoPlugin.xml index fb72427a7a..4ba455a336 100644 --- a/doc/classes/EditorNode3DGizmoPlugin.xml +++ b/doc/classes/EditorNode3DGizmoPlugin.xml @@ -10,7 +10,7 @@ <link title="Spatial gizmo plugins">https://docs.godotengine.org/en/latest/tutorials/plugins/editor/spatial_gizmos.html</link> </tutorials> <methods> - <method name="_can_be_hidden" qualifiers="virtual"> + <method name="_can_be_hidden" qualifiers="virtual const"> <return type="bool" /> <description> Override this method to define whether the gizmos handled by this plugin can be hidden or not. Returns [code]true[/code] if not overridden. @@ -19,9 +19,9 @@ <method name="_commit_handle" qualifiers="virtual"> <return type="void" /> <argument index="0" name="gizmo" type="EditorNode3DGizmo" /> - <argument index="1" name="id" type="int" /> + <argument index="1" name="handle_id" type="int" /> <argument index="2" name="restore" type="Variant" /> - <argument index="3" name="cancel" type="bool" default="false" /> + <argument index="3" name="cancel" type="bool" /> <description> Override this method to commit a handle being edited (handles must have been previously added by [method EditorNode3DGizmo.add_handles] during [method _redraw]). This usually means creating an [UndoRedo] action for the change, using the current handle value as "do" and the [code]restore[/code] argument as "undo". If the [code]cancel[/code] argument is [code]true[/code], the [code]restore[/code] value should be directly set, without any [UndoRedo] action. Called for this plugin's active gizmos. @@ -31,73 +31,73 @@ <return type="void" /> <argument index="0" name="gizmo" type="EditorNode3DGizmo" /> <argument index="1" name="ids" type="PackedInt32Array" /> - <argument index="2" name="restore" type="Array" /> - <argument index="3" name="cancel" type="bool" default="false" /> + <argument index="2" name="restores" type="Transform3D[]" /> + <argument index="3" name="cancel" type="bool" /> <description> Override this method to commit a group of subgizmos being edited (see [method _subgizmos_intersect_ray] and [method _subgizmos_intersect_frustum]). This usually means creating an [UndoRedo] action for the change, using the current transforms as "do" and the [code]restore[/code] transforms as "undo". If the [code]cancel[/code] argument is [code]true[/code], the [code]restore[/code] transforms should be directly set, without any [UndoRedo] action. As with all subgizmo methods, transforms are given in local space respect to the gizmo's Node3D. Called for this plugin's active gizmos. </description> </method> - <method name="_create_gizmo" qualifiers="virtual"> + <method name="_create_gizmo" qualifiers="virtual const"> <return type="EditorNode3DGizmo" /> - <argument index="0" name="spatial" type="Node3D" /> + <argument index="0" name="for_node_3d" type="Node3D" /> <description> Override this method to return a custom [EditorNode3DGizmo] for the spatial nodes of your choice, return [code]null[/code] for the rest of nodes. See also [method _has_gizmo]. </description> </method> - <method name="_get_gizmo_name" qualifiers="virtual"> + <method name="_get_gizmo_name" qualifiers="virtual const"> <return type="String" /> <description> Override this method to provide the name that will appear in the gizmo visibility menu. </description> </method> - <method name="_get_handle_name" qualifiers="virtual"> + <method name="_get_handle_name" qualifiers="virtual const"> <return type="String" /> <argument index="0" name="gizmo" type="EditorNode3DGizmo" /> - <argument index="1" name="id" type="int" /> + <argument index="1" name="handle_id" type="int" /> <description> Override this method to provide gizmo's handle names. Called for this plugin's active gizmos. </description> </method> - <method name="_get_handle_value" qualifiers="virtual"> + <method name="_get_handle_value" qualifiers="virtual const"> <return type="Variant" /> <argument index="0" name="gizmo" type="EditorNode3DGizmo" /> - <argument index="1" name="id" type="int" /> + <argument index="1" name="handle_id" type="int" /> <description> Override this method to return the current value of a handle. This value will be requested at the start of an edit and used as the [code]restore[/code] argument in [method _commit_handle]. Called for this plugin's active gizmos. </description> </method> - <method name="_get_priority" qualifiers="virtual"> + <method name="_get_priority" qualifiers="virtual const"> <return type="int" /> <description> Override this method to set the gizmo's priority. Gizmos with higher priority will have precedence when processing inputs like handles or subgizmos selection. All built-in editor gizmos return a priority of [code]-1[/code]. If not overridden, this method will return [code]0[/code], which means custom gizmos will automatically get higher priority than built-in gizmos. </description> </method> - <method name="_get_subgizmo_transform" qualifiers="virtual"> + <method name="_get_subgizmo_transform" qualifiers="virtual const"> <return type="Transform3D" /> <argument index="0" name="gizmo" type="EditorNode3DGizmo" /> - <argument index="1" name="id" type="int" /> + <argument index="1" name="subgizmo_id" type="int" /> <description> Override this method to return the current transform of a subgizmo. As with all subgizmo methods, the transform should be in local space respect to the gizmo's Node3D. This transform will be requested at the start of an edit and used in the [code]restore[/code] argument in [method _commit_subgizmos]. Called for this plugin's active gizmos. </description> </method> - <method name="_has_gizmo" qualifiers="virtual"> + <method name="_has_gizmo" qualifiers="virtual const"> <return type="bool" /> - <argument index="0" name="spatial" type="Node3D" /> + <argument index="0" name="for_node_3d" type="Node3D" /> <description> Override this method to define which Node3D nodes have a gizmo from this plugin. Whenever a [Node3D] node is added to a scene this method is called, if it returns [code]true[/code] the node gets a generic [EditorNode3DGizmo] assigned and is added to this plugin's list of active gizmos. </description> </method> - <method name="_is_handle_highlighted" qualifiers="virtual"> + <method name="_is_handle_highlighted" qualifiers="virtual const"> <return type="bool" /> <argument index="0" name="gizmo" type="EditorNode3DGizmo" /> - <argument index="1" name="id" type="int" /> + <argument index="1" name="handle_id" type="int" /> <description> Override this method to return [code]true[/code] whenever to given handle should be highlighted in the editor. Called for this plugin's active gizmos. </description> </method> - <method name="_is_selectable_when_hidden" qualifiers="virtual"> + <method name="_is_selectable_when_hidden" qualifiers="virtual const"> <return type="bool" /> <description> Override this method to define whether Node3D with this gizmo should be selectable even when the gizmo is hidden. @@ -113,9 +113,9 @@ <method name="_set_handle" qualifiers="virtual"> <return type="void" /> <argument index="0" name="gizmo" type="EditorNode3DGizmo" /> - <argument index="1" name="id" type="int" /> + <argument index="1" name="handle_id" type="int" /> <argument index="2" name="camera" type="Camera3D" /> - <argument index="3" name="point" type="Vector2" /> + <argument index="3" name="screen_pos" type="Vector2" /> <description> Override this method to update the node's properties when the user drags a gizmo handle (previously added with [method EditorNode3DGizmo.add_handles]). The provided [code]point[/code] is the mouse position in screen coordinates and the [code]camera[/code] can be used to convert it to raycasts. Called for this plugin's active gizmos. </description> @@ -123,26 +123,26 @@ <method name="_set_subgizmo_transform" qualifiers="virtual"> <return type="void" /> <argument index="0" name="gizmo" type="EditorNode3DGizmo" /> - <argument index="1" name="id" type="int" /> + <argument index="1" name="subgizmo_id" type="int" /> <argument index="2" name="transform" type="Transform3D" /> <description> Override this method to update the node properties during subgizmo editing (see [method _subgizmos_intersect_ray] and [method _subgizmos_intersect_frustum]). The [code]transform[/code] is given in the Node3D's local coordinate system. Called for this plugin's active gizmos. </description> </method> - <method name="_subgizmos_intersect_frustum" qualifiers="virtual"> + <method name="_subgizmos_intersect_frustum" qualifiers="virtual const"> <return type="PackedInt32Array" /> <argument index="0" name="gizmo" type="EditorNode3DGizmo" /> <argument index="1" name="camera" type="Camera3D" /> - <argument index="2" name="frustum" type="Array" /> + <argument index="2" name="frustum_planes" type="Plane[]" /> <description> Override this method to allow selecting subgizmos using mouse drag box selection. Given a [code]camera[/code] and a [code]frustum[/code], this method should return which subgizmos are contained within the frustum. The [code]frustum[/code] argument consists of an [code]Array[/code] with all the [code]Plane[/code]s that make up the selection frustum. The returned value should contain a list of unique subgizmo identifiers, these identifiers can have any non-negative value and will be used in other virtual methods like [method _get_subgizmo_transform] or [method _commit_subgizmos]. Called for this plugin's active gizmos. </description> </method> - <method name="_subgizmos_intersect_ray" qualifiers="virtual"> + <method name="_subgizmos_intersect_ray" qualifiers="virtual const"> <return type="int" /> <argument index="0" name="gizmo" type="EditorNode3DGizmo" /> <argument index="1" name="camera" type="Camera3D" /> - <argument index="2" name="point" type="Vector2" /> + <argument index="2" name="screen_pos" type="Vector2" /> <description> Override this method to allow selecting subgizmos using mouse clicks. Given a [code]camera[/code] and a [code]point[/code] in screen coordinates, this method should return which subgizmo should be selected. The returned value should be a unique subgizmo identifier, which can have any non-negative value and will be used in other virtual methods like [method _get_subgizmo_transform] or [method _commit_subgizmos]. Called for this plugin's active gizmos. </description> diff --git a/doc/classes/EditorPlugin.xml b/doc/classes/EditorPlugin.xml index 37efca7f48..e564e8045c 100644 --- a/doc/classes/EditorPlugin.xml +++ b/doc/classes/EditorPlugin.xml @@ -38,7 +38,7 @@ </method> <method name="_edit" qualifiers="virtual"> <return type="void" /> - <argument index="0" name="object" type="Object" /> + <argument index="0" name="object" type="Variant" /> <description> This function is used for plugins that edit specific object types (nodes or resources). It requests the editor to edit the given object. </description> @@ -49,18 +49,18 @@ Called by the engine when the user enables the [EditorPlugin] in the Plugin tab of the project settings window. </description> </method> - <method name="_forward_canvas_draw_over_viewport" qualifiers="virtual"> + <method name="_forward_3d_draw_over_viewport" qualifiers="virtual"> <return type="void" /> - <argument index="0" name="overlay" type="Control" /> + <argument index="0" name="viewport_control" type="Control" /> <description> - Called by the engine when the 2D editor's viewport is updated. Use the [code]overlay[/code] [Control] for drawing. You can update the viewport manually by calling [method update_overlays]. + Called by the engine when the 3D editor's viewport is updated. Use the [code]overlay[/code] [Control] for drawing. You can update the viewport manually by calling [method update_overlays]. [codeblocks] [gdscript] - func _forward_canvas_draw_over_viewport(overlay): + func _forward_spatial_3d_over_viewport(overlay): # Draw a circle at cursor position. - overlay.draw_circle(overlay.get_local_mouse_position(), 64, Color.white) + overlay.draw_circle(overlay.get_local_mouse_position(), 64) - func _forward_canvas_gui_input(event): + func _forward_spatial_gui_input(camera, event): if event is InputEventMouseMotion: # Redraw viewport when cursor is moved. update_overlays() @@ -68,13 +68,13 @@ return false [/gdscript] [csharp] - public override void ForwardCanvasDrawOverViewport(Godot.Control overlay) + public override void ForwardSpatialDrawOverViewport(Godot.Control overlay) { // Draw a circle at cursor position. overlay.DrawCircle(overlay.GetLocalMousePosition(), 64, Colors.White); } - public override bool ForwardCanvasGuiInput(InputEvent @event) + public override bool ForwardSpatialGuiInput(Godot.Camera3D camera, InputEvent @event) { if (@event is InputEventMouseMotion) { @@ -87,28 +87,29 @@ [/codeblocks] </description> </method> - <method name="_forward_canvas_force_draw_over_viewport" qualifiers="virtual"> + <method name="_forward_3d_force_draw_over_viewport" qualifiers="virtual"> <return type="void" /> - <argument index="0" name="overlay" type="Control" /> + <argument index="0" name="viewport_control" type="Control" /> <description> - This method is the same as [method _forward_canvas_draw_over_viewport], except it draws on top of everything. Useful when you need an extra layer that shows over anything else. + This method is the same as [method _forward_3d_draw_over_viewport], except it draws on top of everything. Useful when you need an extra layer that shows over anything else. You need to enable calling of this method by using [method set_force_draw_over_forwarding_enabled]. </description> </method> - <method name="_forward_canvas_gui_input" qualifiers="virtual"> + <method name="_forward_3d_gui_input" qualifiers="virtual"> <return type="bool" /> - <argument index="0" name="event" type="InputEvent" /> + <argument index="0" name="viewport_camera" type="Camera3D" /> + <argument index="1" name="event" type="InputEvent" /> <description> - Called when there is a root node in the current edited scene, [method _handles] is implemented and an [InputEvent] happens in the 2D viewport. Intercepts the [InputEvent], if [code]return true[/code] [EditorPlugin] consumes the [code]event[/code], otherwise forwards [code]event[/code] to other Editor classes. Example: + Called when there is a root node in the current edited scene, [method _handles] is implemented and an [InputEvent] happens in the 3D viewport. Intercepts the [InputEvent], if [code]return true[/code] [EditorPlugin] consumes the [code]event[/code], otherwise forwards [code]event[/code] to other Editor classes. Example: [codeblocks] [gdscript] - # Prevents the InputEvent to reach other Editor classes - func _forward_canvas_gui_input(event): + # Prevents the InputEvent to reach other Editor classes. + func _forward_spatial_gui_input(camera, event): return true [/gdscript] [csharp] - // Prevents the InputEvent to reach other Editor classes - public override bool ForwardCanvasGuiInput(InputEvent @event) + // Prevents the InputEvent to reach other Editor classes. + public override bool ForwardSpatialGuiInput(Camera3D camera, InputEvent @event) { return true; } @@ -118,12 +119,12 @@ [codeblocks] [gdscript] # Consumes InputEventMouseMotion and forwards other InputEvent types. - func _forward_canvas_gui_input(event): + func _forward_spatial_gui_input(camera, event): return event is InputEventMouseMotion [/gdscript] [csharp] // Consumes InputEventMouseMotion and forwards other InputEvent types. - public override bool ForwardCanvasGuiInput(InputEvent @event) + public override bool ForwardSpatialGuiInput(Camera3D camera, InputEvent @event) { return @event is InputEventMouseMotion; } @@ -131,18 +132,18 @@ [/codeblocks] </description> </method> - <method name="_forward_spatial_draw_over_viewport" qualifiers="virtual"> + <method name="_forward_canvas_draw_over_viewport" qualifiers="virtual"> <return type="void" /> - <argument index="0" name="overlay" type="Control" /> + <argument index="0" name="viewport_control" type="Control" /> <description> - Called by the engine when the 3D editor's viewport is updated. Use the [code]overlay[/code] [Control] for drawing. You can update the viewport manually by calling [method update_overlays]. + Called by the engine when the 2D editor's viewport is updated. Use the [code]overlay[/code] [Control] for drawing. You can update the viewport manually by calling [method update_overlays]. [codeblocks] [gdscript] - func _forward_spatial_draw_over_viewport(overlay): + func _forward_canvas_draw_over_viewport(overlay): # Draw a circle at cursor position. - overlay.draw_circle(overlay.get_local_mouse_position(), 64) + overlay.draw_circle(overlay.get_local_mouse_position(), 64, Color.white) - func _forward_spatial_gui_input(camera, event): + func _forward_canvas_gui_input(event): if event is InputEventMouseMotion: # Redraw viewport when cursor is moved. update_overlays() @@ -150,13 +151,13 @@ return false [/gdscript] [csharp] - public override void ForwardSpatialDrawOverViewport(Godot.Control overlay) + public override void ForwardCanvasDrawOverViewport(Godot.Control overlay) { // Draw a circle at cursor position. overlay.DrawCircle(overlay.GetLocalMousePosition(), 64, Colors.White); } - public override bool ForwardSpatialGuiInput(Godot.Camera3D camera, InputEvent @event) + public override bool ForwardCanvasGuiInput(InputEvent @event) { if (@event is InputEventMouseMotion) { @@ -169,29 +170,28 @@ [/codeblocks] </description> </method> - <method name="_forward_spatial_force_draw_over_viewport" qualifiers="virtual"> + <method name="_forward_canvas_force_draw_over_viewport" qualifiers="virtual"> <return type="void" /> - <argument index="0" name="overlay" type="Control" /> + <argument index="0" name="viewport_control" type="Control" /> <description> - This method is the same as [method _forward_spatial_draw_over_viewport], except it draws on top of everything. Useful when you need an extra layer that shows over anything else. + This method is the same as [method _forward_canvas_draw_over_viewport], except it draws on top of everything. Useful when you need an extra layer that shows over anything else. You need to enable calling of this method by using [method set_force_draw_over_forwarding_enabled]. </description> </method> - <method name="_forward_spatial_gui_input" qualifiers="virtual"> + <method name="_forward_canvas_gui_input" qualifiers="virtual"> <return type="bool" /> - <argument index="0" name="camera" type="Camera3D" /> - <argument index="1" name="event" type="InputEvent" /> + <argument index="0" name="event" type="InputEvent" /> <description> - Called when there is a root node in the current edited scene, [method _handles] is implemented and an [InputEvent] happens in the 3D viewport. Intercepts the [InputEvent], if [code]return true[/code] [EditorPlugin] consumes the [code]event[/code], otherwise forwards [code]event[/code] to other Editor classes. Example: + Called when there is a root node in the current edited scene, [method _handles] is implemented and an [InputEvent] happens in the 2D viewport. Intercepts the [InputEvent], if [code]return true[/code] [EditorPlugin] consumes the [code]event[/code], otherwise forwards [code]event[/code] to other Editor classes. Example: [codeblocks] [gdscript] - # Prevents the InputEvent to reach other Editor classes. - func _forward_spatial_gui_input(camera, event): + # Prevents the InputEvent to reach other Editor classes + func _forward_canvas_gui_input(event): return true [/gdscript] [csharp] - // Prevents the InputEvent to reach other Editor classes. - public override bool ForwardSpatialGuiInput(Camera3D camera, InputEvent @event) + // Prevents the InputEvent to reach other Editor classes + public override bool ForwardCanvasGuiInput(InputEvent @event) { return true; } @@ -201,12 +201,12 @@ [codeblocks] [gdscript] # Consumes InputEventMouseMotion and forwards other InputEvent types. - func _forward_spatial_gui_input(camera, event): + func _forward_canvas_gui_input(event): return event is InputEventMouseMotion [/gdscript] [csharp] // Consumes InputEventMouseMotion and forwards other InputEvent types. - public override bool ForwardSpatialGuiInput(Camera3D camera, InputEvent @event) + public override bool ForwardCanvasGuiInput(InputEvent @event) { return @event is InputEventMouseMotion; } @@ -214,13 +214,13 @@ [/codeblocks] </description> </method> - <method name="_get_breakpoints" qualifiers="virtual"> + <method name="_get_breakpoints" qualifiers="virtual const"> <return type="PackedStringArray" /> <description> This is for editors that edit script-based objects. You can return a list of breakpoints in the format ([code]script:line[/code]), for example: [code]res://path_to_script.gd:25[/code]. </description> </method> - <method name="_get_plugin_icon" qualifiers="virtual"> + <method name="_get_plugin_icon" qualifiers="virtual const"> <return type="Texture2D" /> <description> Override this method in your plugin to return a [Texture2D] in order to give it an icon. @@ -246,14 +246,14 @@ [/codeblocks] </description> </method> - <method name="_get_plugin_name" qualifiers="virtual"> + <method name="_get_plugin_name" qualifiers="virtual const"> <return type="String" /> <description> Override this method in your plugin to provide the name of the plugin when displayed in the Godot editor. For main screen plugins, this appears at the top of the screen, to the right of the "2D", "3D", "Script", and "AssetLib" buttons. </description> </method> - <method name="_get_state" qualifiers="virtual"> + <method name="_get_state" qualifiers="virtual const"> <return type="Dictionary" /> <description> Gets the state of your plugin editor. This is used when saving the scene (so state is kept when opening it again) and for switching tabs (so state can be restored when the tab returns). @@ -261,19 +261,19 @@ </method> <method name="_get_window_layout" qualifiers="virtual"> <return type="void" /> - <argument index="0" name="layout" type="ConfigFile" /> + <argument index="0" name="configuration" type="ConfigFile" /> <description> Gets the GUI layout of the plugin. This is used to save the project's editor layout when [method queue_save_layout] is called or the editor layout was changed(For example changing the position of a dock). </description> </method> - <method name="_handles" qualifiers="virtual"> + <method name="_handles" qualifiers="virtual const"> <return type="bool" /> - <argument index="0" name="object" type="Object" /> + <argument index="0" name="object" type="Variant" /> <description> - Implement this function if your plugin edits a specific type of object (Resource or Node). If you return [code]true[/code], then you will get the functions [method _edit] and [method _make_visible] called when the editor requests them. If you have declared the methods [method _forward_canvas_gui_input] and [method _forward_spatial_gui_input] these will be called too. + Implement this function if your plugin edits a specific type of object (Resource or Node). If you return [code]true[/code], then you will get the functions [method _edit] and [method _make_visible] called when the editor requests them. If you have declared the methods [method _forward_canvas_gui_input] and [method _forward_3d_gui_input] these will be called too. </description> </method> - <method name="_has_main_screen" qualifiers="virtual"> + <method name="_has_main_screen" qualifiers="virtual const"> <return type="bool" /> <description> Returns [code]true[/code] if this is a main screen editor plugin (it goes in the workspace selector together with [b]2D[/b], [b]3D[/b], [b]Script[/b] and [b]AssetLib[/b]). @@ -302,7 +302,7 @@ </method> <method name="_set_window_layout" qualifiers="virtual"> <return type="void" /> - <argument index="0" name="layout" type="ConfigFile" /> + <argument index="0" name="configuration" type="ConfigFile" /> <description> Restore the plugin GUI layout saved by [method _get_window_layout]. </description> @@ -586,19 +586,19 @@ <method name="set_force_draw_over_forwarding_enabled"> <return type="void" /> <description> - Enables calling of [method _forward_canvas_force_draw_over_viewport] for the 2D editor and [method _forward_spatial_force_draw_over_viewport] for the 3D editor when their viewports are updated. You need to call this method only once and it will work permanently for this plugin. + Enables calling of [method _forward_canvas_force_draw_over_viewport] for the 2D editor and [method _forward_3d_force_draw_over_viewport] for the 3D editor when their viewports are updated. You need to call this method only once and it will work permanently for this plugin. </description> </method> <method name="set_input_event_forwarding_always_enabled"> <return type="void" /> <description> - Use this method if you always want to receive inputs from 3D view screen inside [method _forward_spatial_gui_input]. It might be especially usable if your plugin will want to use raycast in the scene. + Use this method if you always want to receive inputs from 3D view screen inside [method _forward_3d_gui_input]. It might be especially usable if your plugin will want to use raycast in the scene. </description> </method> <method name="update_overlays" qualifiers="const"> <return type="int" /> <description> - Updates the overlays of the 2D and 3D editor viewport. Causes methods [method _forward_canvas_draw_over_viewport], [method _forward_canvas_force_draw_over_viewport], [method _forward_spatial_draw_over_viewport] and [method _forward_spatial_force_draw_over_viewport] to be called. + Updates the overlays of the 2D and 3D editor viewport. Causes methods [method _forward_canvas_draw_over_viewport], [method _forward_canvas_force_draw_over_viewport], [method _forward_3d_draw_over_viewport] and [method _forward_3d_force_draw_over_viewport] to be called. </description> </method> </methods> diff --git a/doc/classes/EditorProperty.xml b/doc/classes/EditorProperty.xml index 725b0ba8ff..822bcfd255 100644 --- a/doc/classes/EditorProperty.xml +++ b/doc/classes/EditorProperty.xml @@ -57,6 +57,11 @@ Puts the [code]editor[/code] control below the property label. The control must be previously added using [method Node.add_child]. </description> </method> + <method name="update_property"> + <return type="void" /> + <description> + </description> + </method> </methods> <members> <member name="checkable" type="bool" setter="set_checkable" getter="is_checkable" default="false"> diff --git a/doc/classes/EditorResourceConversionPlugin.xml b/doc/classes/EditorResourceConversionPlugin.xml index 3de508c88d..8543afa4ae 100644 --- a/doc/classes/EditorResourceConversionPlugin.xml +++ b/doc/classes/EditorResourceConversionPlugin.xml @@ -7,17 +7,23 @@ <tutorials> </tutorials> <methods> - <method name="_convert" qualifiers="virtual"> + <method name="_convert" qualifiers="virtual const"> <return type="Resource" /> <argument index="0" name="resource" type="Resource" /> <description> </description> </method> - <method name="_converts_to" qualifiers="virtual"> + <method name="_converts_to" qualifiers="virtual const"> <return type="String" /> <description> </description> </method> + <method name="_handles" qualifiers="virtual const"> + <return type="bool" /> + <argument index="0" name="resource" type="Resource" /> + <description> + </description> + </method> </methods> <constants> </constants> diff --git a/doc/classes/EditorResourcePreviewGenerator.xml b/doc/classes/EditorResourcePreviewGenerator.xml index 7054b1f4d0..033e03c5b5 100644 --- a/doc/classes/EditorResourcePreviewGenerator.xml +++ b/doc/classes/EditorResourcePreviewGenerator.xml @@ -9,41 +9,41 @@ <tutorials> </tutorials> <methods> - <method name="_can_generate_small_preview" qualifiers="virtual"> + <method name="_can_generate_small_preview" qualifiers="virtual const"> <return type="bool" /> <description> If this function returns [code]true[/code], the generator will call [method _generate] or [method _generate_from_path] for small previews as well. By default, it returns [code]false[/code]. </description> </method> - <method name="_generate" qualifiers="virtual"> + <method name="_generate" qualifiers="virtual const"> <return type="Texture2D" /> - <argument index="0" name="from" type="Resource" /> - <argument index="1" name="size" type="Vector2" /> + <argument index="0" name="resource" type="Resource" /> + <argument index="1" name="size" type="Vector2i" /> <description> Generate a preview from a given resource with the specified size. This must always be implemented. Returning an empty texture is an OK way to fail and let another generator take care. Care must be taken because this function is always called from a thread (not the main thread). </description> </method> - <method name="_generate_from_path" qualifiers="virtual"> + <method name="_generate_from_path" qualifiers="virtual const"> <return type="Texture2D" /> <argument index="0" name="path" type="String" /> - <argument index="1" name="size" type="Vector2" /> + <argument index="1" name="size" type="Vector2i" /> <description> Generate a preview directly from a path with the specified size. Implementing this is optional, as default code will load and call [method _generate]. Returning an empty texture is an OK way to fail and let another generator take care. Care must be taken because this function is always called from a thread (not the main thread). </description> </method> - <method name="_generate_small_preview_automatically" qualifiers="virtual"> + <method name="_generate_small_preview_automatically" qualifiers="virtual const"> <return type="bool" /> <description> If this function returns [code]true[/code], the generator will automatically generate the small previews from the normal preview texture generated by the methods [method _generate] or [method _generate_from_path]. By default, it returns [code]false[/code]. </description> </method> - <method name="_handles" qualifiers="virtual"> + <method name="_handles" qualifiers="virtual const"> <return type="bool" /> <argument index="0" name="type" type="String" /> <description> diff --git a/doc/classes/EditorSceneImporter.xml b/doc/classes/EditorSceneImporter.xml index 2e9d6a43d8..a400db551f 100644 --- a/doc/classes/EditorSceneImporter.xml +++ b/doc/classes/EditorSceneImporter.xml @@ -8,12 +8,12 @@ <tutorials> </tutorials> <methods> - <method name="_get_extensions" qualifiers="virtual"> - <return type="Array" /> + <method name="_get_extensions" qualifiers="virtual const"> + <return type="PackedStringArray" /> <description> </description> </method> - <method name="_get_import_flags" qualifiers="virtual"> + <method name="_get_import_flags" qualifiers="virtual const"> <return type="int" /> <description> </description> @@ -27,7 +27,7 @@ </description> </method> <method name="_import_scene" qualifiers="virtual"> - <return type="Node" /> + <return type="Object" /> <argument index="0" name="path" type="String" /> <argument index="1" name="flags" type="int" /> <argument index="2" name="bake_fps" type="int" /> diff --git a/doc/classes/EditorScenePostImport.xml b/doc/classes/EditorScenePostImport.xml index 95b0b42d9f..43ca3db5fa 100644 --- a/doc/classes/EditorScenePostImport.xml +++ b/doc/classes/EditorScenePostImport.xml @@ -57,7 +57,7 @@ <methods> <method name="_post_import" qualifiers="virtual"> <return type="Object" /> - <argument index="0" name="scene" type="Object" /> + <argument index="0" name="scene" type="Node" /> <description> Called after the scene was imported. This method must return the modified version of the scene. </description> diff --git a/doc/classes/EditorSyntaxHighlighter.xml b/doc/classes/EditorSyntaxHighlighter.xml index 37644a8595..394a4ada46 100644 --- a/doc/classes/EditorSyntaxHighlighter.xml +++ b/doc/classes/EditorSyntaxHighlighter.xml @@ -5,24 +5,18 @@ </brief_description> <description> Base syntax highlighter resource all editor syntax highlighters extend from, it is used in the [ScriptEditor]. - Add a syntax highlighter to an individual script by calling [method ScriptEditorBase._add_syntax_highlighter]. To apply to all scripts on open, call [method ScriptEditor.register_syntax_highlighter] + Add a syntax highlighter to an individual script by calling ScriptEditorBase._add_syntax_highlighter (currently not working). To apply to all scripts on open, call [method ScriptEditor.register_syntax_highlighter] </description> <tutorials> </tutorials> <methods> - <method name="_get_name" qualifiers="virtual"> + <method name="_get_name" qualifiers="virtual const"> <return type="String" /> <description> Virtual method which can be overridden to return the syntax highlighter name. </description> </method> - <method name="_get_supported_extentions" qualifiers="virtual"> - <return type="Array" /> - <description> - Virtual method which can be overridden to return the supported file extensions. - </description> - </method> - <method name="_get_supported_languages" qualifiers="virtual"> + <method name="_get_supported_languages" qualifiers="virtual const"> <return type="Array" /> <description> Virtual method which can be overridden to return the supported language names. diff --git a/doc/classes/EditorTranslationParserPlugin.xml b/doc/classes/EditorTranslationParserPlugin.xml index 47da8ec37b..94e96e985f 100644 --- a/doc/classes/EditorTranslationParserPlugin.xml +++ b/doc/classes/EditorTranslationParserPlugin.xml @@ -102,8 +102,8 @@ <tutorials> </tutorials> <methods> - <method name="_get_recognized_extensions" qualifiers="virtual"> - <return type="Array" /> + <method name="_get_recognized_extensions" qualifiers="virtual const"> + <return type="PackedStringArray" /> <description> Gets the list of file extensions to associate with this parser, e.g. [code]["csv"][/code]. </description> diff --git a/doc/classes/Node.xml b/doc/classes/Node.xml index 096fbbf2c0..97e6c71ef9 100644 --- a/doc/classes/Node.xml +++ b/doc/classes/Node.xml @@ -35,6 +35,14 @@ Corresponds to the [constant NOTIFICATION_EXIT_TREE] notification in [method Object._notification] and signal [signal tree_exiting]. To get notified when the node has already left the active tree, connect to the [signal tree_exited]. </description> </method> + <method name="_get_configuration_warnings" qualifiers="virtual const"> + <return type="PackedStringArray" /> + <description> + The elements in the array returned from this method are displayed as warnings in the Scene Dock if the script that overrides it is a [code]tool[/code] script. + Returning an empty array produces no warnings. + Call [method update_configuration_warnings] when the warnings need to be updated for this node. + </description> + </method> <method name="_get_configuration_warnings" qualifiers="virtual"> <return type="String[]" /> <description> diff --git a/doc/classes/Resource.xml b/doc/classes/Resource.xml index 701ecf815c..65dedf5280 100644 --- a/doc/classes/Resource.xml +++ b/doc/classes/Resource.xml @@ -12,12 +12,6 @@ <link title="When and how to avoid using nodes for everything">https://docs.godotengine.org/en/latest/getting_started/workflow/best_practices/node_alternatives.html</link> </tutorials> <methods> - <method name="_setup_local_to_scene" qualifiers="virtual"> - <return type="void" /> - <description> - Virtual function which can be overridden to customize the behavior value of [method setup_local_to_scene]. - </description> - </method> <method name="duplicate" qualifiers="const"> <return type="Resource" /> <argument index="0" name="subresources" type="bool" default="false" /> @@ -54,7 +48,7 @@ <method name="setup_local_to_scene"> <return type="void" /> <description> - This method is called when a resource with [member resource_local_to_scene] enabled is loaded from a [PackedScene] instantiation. Its behavior can be customized by overriding [method _setup_local_to_scene] from script. + This method is called when a resource with [member resource_local_to_scene] enabled is loaded from a [PackedScene] instantiation. Its behavior can be customized by connecting [signal setup_local_to_scene_requested] from script. For most resources, this method performs no base logic. [ViewportTexture] performs custom logic to properly set the proxy texture and flags in the local viewport. </description> </method> @@ -84,6 +78,10 @@ [b]Note:[/b] This signal is not emitted automatically for custom resources, which means that you need to create a setter and emit the signal yourself. </description> </signal> + <signal name="setup_local_to_scene_requested"> + <description> + </description> + </signal> </signals> <constants> </constants> diff --git a/doc/classes/ResourceFormatLoader.xml b/doc/classes/ResourceFormatLoader.xml index bce5785cc1..0c2bb26c02 100644 --- a/doc/classes/ResourceFormatLoader.xml +++ b/doc/classes/ResourceFormatLoader.xml @@ -11,22 +11,28 @@ <tutorials> </tutorials> <methods> - <method name="_get_dependencies" qualifiers="virtual"> - <return type="void" /> + <method name="_exists" qualifiers="virtual const"> + <return type="bool" /> + <argument index="0" name="path" type="String" /> + <description> + </description> + </method> + <method name="_get_dependencies" qualifiers="virtual const"> + <return type="PackedStringArray" /> <argument index="0" name="path" type="String" /> - <argument index="1" name="add_types" type="String" /> + <argument index="1" name="add_types" type="bool" /> <description> If implemented, gets the dependencies of a given resource. If [code]add_types[/code] is [code]true[/code], paths should be appended [code]::TypeName[/code], where [code]TypeName[/code] is the class name of the dependency. [b]Note:[/b] Custom resource types defined by scripts aren't known by the [ClassDB], so you might just return [code]"Resource"[/code] for them. </description> </method> - <method name="_get_recognized_extensions" qualifiers="virtual"> + <method name="_get_recognized_extensions" qualifiers="virtual const"> <return type="PackedStringArray" /> <description> Gets the list of extensions for files this loader is able to read. </description> </method> - <method name="_get_resource_type" qualifiers="virtual"> + <method name="_get_resource_type" qualifiers="virtual const"> <return type="String" /> <argument index="0" name="path" type="String" /> <description> @@ -34,15 +40,21 @@ [b]Note:[/b] Custom resource types defined by scripts aren't known by the [ClassDB], so you might just return [code]"Resource"[/code] for them. </description> </method> - <method name="_handles_type" qualifiers="virtual"> + <method name="_get_resource_uid" qualifiers="virtual const"> + <return type="int" /> + <argument index="0" name="path" type="String" /> + <description> + </description> + </method> + <method name="_handles_type" qualifiers="virtual const"> <return type="bool" /> - <argument index="0" name="typename" type="StringName" /> + <argument index="0" name="type" type="StringName" /> <description> Tells which resource class this loader can load. [b]Note:[/b] Custom resource types defined by scripts aren't known by the [ClassDB], so you might just handle [code]"Resource"[/code] for them. </description> </method> - <method name="_load" qualifiers="virtual"> + <method name="_load" qualifiers="virtual const"> <return type="Variant" /> <argument index="0" name="path" type="String" /> <argument index="1" name="original_path" type="String" /> @@ -53,10 +65,10 @@ The [code]cache_mode[/code] property defines whether and how the cache should be used or updated when loading the resource. See [enum CacheMode] for details. </description> </method> - <method name="_rename_dependencies" qualifiers="virtual"> + <method name="_rename_dependencies" qualifiers="virtual const"> <return type="int" /> <argument index="0" name="path" type="String" /> - <argument index="1" name="renames" type="String" /> + <argument index="1" name="renames" type="Dictionary" /> <description> If implemented, renames dependencies within the given resource and saves it. [code]renames[/code] is a dictionary [code]{ String => String }[/code] mapping old dependency paths to new paths. Returns [constant OK] on success, or an [enum Error] constant in case of failure. diff --git a/doc/classes/ResourceFormatSaver.xml b/doc/classes/ResourceFormatSaver.xml index ef9eebc953..7ee8875321 100644 --- a/doc/classes/ResourceFormatSaver.xml +++ b/doc/classes/ResourceFormatSaver.xml @@ -10,14 +10,14 @@ <tutorials> </tutorials> <methods> - <method name="_get_recognized_extensions" qualifiers="virtual"> + <method name="_get_recognized_extensions" qualifiers="virtual const"> <return type="PackedStringArray" /> <argument index="0" name="resource" type="Resource" /> <description> Returns the list of extensions available for saving the resource object, provided it is recognized (see [method _recognize]). </description> </method> - <method name="_recognize" qualifiers="virtual"> + <method name="_recognize" qualifiers="virtual const"> <return type="bool" /> <argument index="0" name="resource" type="Resource" /> <description> diff --git a/doc/classes/RichTextEffect.xml b/doc/classes/RichTextEffect.xml index 142afbb860..fd93f6be56 100644 --- a/doc/classes/RichTextEffect.xml +++ b/doc/classes/RichTextEffect.xml @@ -23,7 +23,7 @@ <link title="RichTextEffect test project (third-party)">https://github.com/Eoin-ONeill-Yokai/Godot-Rich-Text-Effect-Test-Project</link> </tutorials> <methods> - <method name="_process_custom_fx" qualifiers="virtual"> + <method name="_process_custom_fx" qualifiers="virtual const"> <return type="bool" /> <argument index="0" name="char_fx" type="CharFXTransform" /> <description> diff --git a/doc/classes/ScriptEditorBase.xml b/doc/classes/ScriptEditorBase.xml index 0efcde5638..08baa705e8 100644 --- a/doc/classes/ScriptEditorBase.xml +++ b/doc/classes/ScriptEditorBase.xml @@ -9,13 +9,6 @@ <tutorials> </tutorials> <methods> - <method name="_add_syntax_highlighter" qualifiers="virtual"> - <return type="void" /> - <argument index="0" name="highlighter" type="Object" /> - <description> - Adds a [EditorSyntaxHighlighter] to the open script. - </description> - </method> <method name="get_base_editor" qualifiers="const"> <return type="Control" /> <description> diff --git a/doc/classes/SyntaxHighlighter.xml b/doc/classes/SyntaxHighlighter.xml index ea0d1c27a3..c478cb0eb6 100644 --- a/doc/classes/SyntaxHighlighter.xml +++ b/doc/classes/SyntaxHighlighter.xml @@ -17,7 +17,7 @@ Virtual method which can be overridden to clear any local caches. </description> </method> - <method name="_get_line_syntax_highlighting" qualifiers="virtual"> + <method name="_get_line_syntax_highlighting" qualifiers="virtual const"> <return type="Dictionary" /> <argument index="0" name="line" type="int" /> <description> diff --git a/doc/classes/TextEdit.xml b/doc/classes/TextEdit.xml index 7aa627b7d0..abb4119584 100644 --- a/doc/classes/TextEdit.xml +++ b/doc/classes/TextEdit.xml @@ -30,7 +30,7 @@ </method> <method name="_handle_unicode_input" qualifiers="virtual"> <return type="void" /> - <argument index="0" name="unicode" type="int" /> + <argument index="0" name="unicode_char" type="int" /> <description> Override this method to define what happens when the types in the provided key [code]unicode[/code]. </description> diff --git a/doc/classes/VisualShaderNodeCustom.xml b/doc/classes/VisualShaderNodeCustom.xml index f6dbd2ad43..3a489419c1 100644 --- a/doc/classes/VisualShaderNodeCustom.xml +++ b/doc/classes/VisualShaderNodeCustom.xml @@ -16,17 +16,17 @@ <link title="Visual Shader plugins">https://docs.godotengine.org/en/latest/tutorials/plugins/editor/visual_shader_plugins.html</link> </tutorials> <methods> - <method name="_get_category" qualifiers="virtual"> + <method name="_get_category" qualifiers="virtual const"> <return type="String" /> <description> Override this method to define the path to the associated custom node in the Visual Shader Editor's members dialog. The path may look like [code]"MyGame/MyFunctions/Noise"[/code]. Defining this method is [b]optional[/b]. If not overridden, the node will be filed under the "Addons" category. </description> </method> - <method name="_get_code" qualifiers="virtual"> + <method name="_get_code" qualifiers="virtual const"> <return type="String" /> - <argument index="0" name="input_vars" type="Array" /> - <argument index="1" name="output_vars" type="Array" /> + <argument index="0" name="input_vars" type="PackedStringArray" /> + <argument index="1" name="output_vars" type="String[]" /> <argument index="2" name="mode" type="int" /> <argument index="3" name="type" type="int" /> <description> @@ -37,14 +37,14 @@ Defining this method is [b]required[/b]. </description> </method> - <method name="_get_description" qualifiers="virtual"> + <method name="_get_description" qualifiers="virtual const"> <return type="String" /> <description> Override this method to define the description of the associated custom node in the Visual Shader Editor's members dialog. Defining this method is [b]optional[/b]. </description> </method> - <method name="_get_global_code" qualifiers="virtual"> + <method name="_get_global_code" qualifiers="virtual const"> <return type="String" /> <argument index="0" name="mode" type="int" /> <description> @@ -54,22 +54,22 @@ Defining this method is [b]optional[/b]. </description> </method> - <method name="_get_input_port_count" qualifiers="virtual"> + <method name="_get_input_port_count" qualifiers="virtual const"> <return type="int" /> <description> Override this method to define the amount of input ports of the associated custom node. Defining this method is [b]required[/b]. If not overridden, the node has no input ports. </description> </method> - <method name="_get_input_port_name" qualifiers="virtual"> - <return type="StringName" /> + <method name="_get_input_port_name" qualifiers="virtual const"> + <return type="String" /> <argument index="0" name="port" type="int" /> <description> Override this method to define the names of input ports of the associated custom node. The names are used both for the input slots in the editor and as identifiers in the shader code, and are passed in the [code]input_vars[/code] array in [method _get_code]. Defining this method is [b]optional[/b], but recommended. If not overridden, input ports are named as [code]"in" + str(port)[/code]. </description> </method> - <method name="_get_input_port_type" qualifiers="virtual"> + <method name="_get_input_port_type" qualifiers="virtual const"> <return type="int" /> <argument index="0" name="port" type="int" /> <description> @@ -77,29 +77,29 @@ Defining this method is [b]optional[/b], but recommended. If not overridden, input ports will return the [constant VisualShaderNode.PORT_TYPE_SCALAR] type. </description> </method> - <method name="_get_name" qualifiers="virtual"> + <method name="_get_name" qualifiers="virtual const"> <return type="String" /> <description> Override this method to define the name of the associated custom node in the Visual Shader Editor's members dialog and graph. Defining this method is [b]optional[/b], but recommended. If not overridden, the node will be named as "Unnamed". </description> </method> - <method name="_get_output_port_count" qualifiers="virtual"> + <method name="_get_output_port_count" qualifiers="virtual const"> <return type="int" /> <description> Override this method to define the amount of output ports of the associated custom node. Defining this method is [b]required[/b]. If not overridden, the node has no output ports. </description> </method> - <method name="_get_output_port_name" qualifiers="virtual"> - <return type="StringName" /> + <method name="_get_output_port_name" qualifiers="virtual const"> + <return type="String" /> <argument index="0" name="port" type="int" /> <description> Override this method to define the names of output ports of the associated custom node. The names are used both for the output slots in the editor and as identifiers in the shader code, and are passed in the [code]output_vars[/code] array in [method _get_code]. Defining this method is [b]optional[/b], but recommended. If not overridden, output ports are named as [code]"out" + str(port)[/code]. </description> </method> - <method name="_get_output_port_type" qualifiers="virtual"> + <method name="_get_output_port_type" qualifiers="virtual const"> <return type="int" /> <argument index="0" name="port" type="int" /> <description> @@ -107,14 +107,14 @@ Defining this method is [b]optional[/b], but recommended. If not overridden, output ports will return the [constant VisualShaderNode.PORT_TYPE_SCALAR] type. </description> </method> - <method name="_get_return_icon_type" qualifiers="virtual"> + <method name="_get_return_icon_type" qualifiers="virtual const"> <return type="int" /> <description> Override this method to define the return icon of the associated custom node in the Visual Shader Editor's members dialog. Defining this method is [b]optional[/b]. If not overridden, no return icon is shown. </description> </method> - <method name="_is_highend" qualifiers="virtual"> + <method name="_is_highend" qualifiers="virtual const"> <return type="bool" /> <description> Override this method to enable high-end mark in the Visual Shader Editor's members dialog. diff --git a/editor/editor_export.cpp b/editor/editor_export.cpp index b374f56f6d..91c3c51c4d 100644 --- a/editor/editor_export.cpp +++ b/editor/editor_export.cpp @@ -624,21 +624,15 @@ Vector<String> EditorExportPlugin::get_ios_project_static_libs() const { } void EditorExportPlugin::_export_file_script(const String &p_path, const String &p_type, const Vector<String> &p_features) { - if (get_script_instance()) { - get_script_instance()->call("_export_file", p_path, p_type, p_features); - } + GDVIRTUAL_CALL(_export_file, p_path, p_type, p_features); } void EditorExportPlugin::_export_begin_script(const Vector<String> &p_features, bool p_debug, const String &p_path, int p_flags) { - if (get_script_instance()) { - get_script_instance()->call("_export_begin", p_features, p_debug, p_path, p_flags); - } + GDVIRTUAL_CALL(_export_begin, p_features, p_debug, p_path, p_flags); } void EditorExportPlugin::_export_end_script() { - if (get_script_instance()) { - get_script_instance()->call("_export_end"); - } + GDVIRTUAL_CALL(_export_end); } void EditorExportPlugin::_export_file(const String &p_path, const String &p_type, const Set<String> &p_features) { @@ -663,9 +657,9 @@ void EditorExportPlugin::_bind_methods() { ClassDB::bind_method(D_METHOD("add_ios_cpp_code", "code"), &EditorExportPlugin::add_ios_cpp_code); ClassDB::bind_method(D_METHOD("skip"), &EditorExportPlugin::skip); - BIND_VMETHOD(MethodInfo("_export_file", PropertyInfo(Variant::STRING, "path"), PropertyInfo(Variant::STRING, "type"), PropertyInfo(Variant::PACKED_STRING_ARRAY, "features"))); - BIND_VMETHOD(MethodInfo("_export_begin", PropertyInfo(Variant::PACKED_STRING_ARRAY, "features"), PropertyInfo(Variant::BOOL, "is_debug"), PropertyInfo(Variant::STRING, "path"), PropertyInfo(Variant::INT, "flags"))); - BIND_VMETHOD(MethodInfo("_export_end")); + GDVIRTUAL_BIND(_export_file, "path", "type", "features"); + GDVIRTUAL_BIND(_export_begin, "features", "is_debug", "path", "flags"); + GDVIRTUAL_BIND(_export_end); } EditorExportPlugin::EditorExportPlugin() { diff --git a/editor/editor_export.h b/editor/editor_export.h index c9401df9c2..b681f52330 100644 --- a/editor/editor_export.h +++ b/editor/editor_export.h @@ -349,6 +349,10 @@ protected: static void _bind_methods(); + GDVIRTUAL3(_export_file, String, String, Vector<String>) + GDVIRTUAL4(_export_begin, Vector<String>, bool, String, uint32_t) + GDVIRTUAL0(_export_end) + public: Vector<String> get_ios_frameworks() const; Vector<String> get_ios_embedded_frameworks() const; diff --git a/editor/editor_inspector.cpp b/editor/editor_inspector.cpp index b3ce11028b..8d2edd3000 100644 --- a/editor/editor_inspector.cpp +++ b/editor/editor_inspector.cpp @@ -379,9 +379,7 @@ StringName EditorProperty::get_edited_property() { } void EditorProperty::update_property() { - if (get_script_instance()) { - get_script_instance()->call("_update_property"); - } + GDVIRTUAL_CALL(_update_property); } void EditorProperty::set_read_only(bool p_read_only) { @@ -766,7 +764,7 @@ void EditorProperty::_gui_input(const Ref<InputEvent> &p_event) { call_deferred(SNAME("emit_changed"), property, object->get(property).operator int64_t() + 1, "", false); } - call_deferred(SNAME("_update_property")); + call_deferred(SNAME("update_property")); } } if (delete_rect.has_point(mpos)) { @@ -925,6 +923,7 @@ void EditorProperty::_bind_methods() { ClassDB::bind_method(D_METHOD("_gui_input"), &EditorProperty::_gui_input); ClassDB::bind_method(D_METHOD("get_tooltip_text"), &EditorProperty::get_tooltip_text); + ClassDB::bind_method(D_METHOD("update_property"), &EditorProperty::update_property); ClassDB::bind_method(D_METHOD("add_focusable", "control"), &EditorProperty::add_focusable); ClassDB::bind_method(D_METHOD("set_bottom_editor", "editor"), &EditorProperty::set_bottom_editor); @@ -948,7 +947,7 @@ void EditorProperty::_bind_methods() { ADD_SIGNAL(MethodInfo("object_id_selected", PropertyInfo(Variant::STRING_NAME, "property"), PropertyInfo(Variant::INT, "id"))); ADD_SIGNAL(MethodInfo("selected", PropertyInfo(Variant::STRING, "path"), PropertyInfo(Variant::INT, "focusable_idx"))); - BIND_VMETHOD(MethodInfo("_update_property")); + GDVIRTUAL_BIND(_update_property) } EditorProperty::EditorProperty() { @@ -1003,43 +1002,31 @@ void EditorInspectorPlugin::add_property_editor_for_multiple_properties(const St } bool EditorInspectorPlugin::can_handle(Object *p_object) { - if (get_script_instance()) { - return get_script_instance()->call("_can_handle", p_object); + bool success; + if (GDVIRTUAL_CALL(_can_handle, p_object, success)) { + return success; } return false; } void EditorInspectorPlugin::parse_begin(Object *p_object) { - if (get_script_instance()) { - get_script_instance()->call("_parse_begin", p_object); - } + GDVIRTUAL_CALL(_parse_begin); } void EditorInspectorPlugin::parse_category(Object *p_object, const String &p_parse_category) { - if (get_script_instance()) { - get_script_instance()->call("_parse_category", p_object, p_parse_category); - } + GDVIRTUAL_CALL(_parse_category, p_object, p_parse_category); } bool EditorInspectorPlugin::parse_property(Object *p_object, const Variant::Type p_type, const String &p_path, const PropertyHint p_hint, const String &p_hint_text, const uint32_t p_usage, const bool p_wide) { - if (get_script_instance()) { - Variant arg[6] = { - p_object, p_type, p_path, p_hint, p_hint_text, p_usage - }; - const Variant *argptr[6] = { - &arg[0], &arg[1], &arg[2], &arg[3], &arg[4], &arg[5] - }; - - Callable::CallError err; - return get_script_instance()->call("_parse_property", (const Variant **)&argptr, 6, err); + bool ret; + if (GDVIRTUAL_CALL(_parse_property, p_object, p_type, p_path, p_hint, p_hint_text, p_usage, p_wide, ret)) { + return ret; } return false; } void EditorInspectorPlugin::parse_end() { - if (get_script_instance()) { - get_script_instance()->call("_parse_end"); - } + GDVIRTUAL_CALL(_parse_end); } void EditorInspectorPlugin::_bind_methods() { @@ -1047,11 +1034,11 @@ void EditorInspectorPlugin::_bind_methods() { ClassDB::bind_method(D_METHOD("add_property_editor", "property", "editor"), &EditorInspectorPlugin::add_property_editor); ClassDB::bind_method(D_METHOD("add_property_editor_for_multiple_properties", "label", "properties", "editor"), &EditorInspectorPlugin::add_property_editor_for_multiple_properties); - BIND_VMETHOD(MethodInfo(Variant::BOOL, "_can_handle", PropertyInfo(Variant::OBJECT, "object"))); - BIND_VMETHOD(MethodInfo(Variant::NIL, "_parse_begin")); - BIND_VMETHOD(MethodInfo(Variant::NIL, "_parse_category", PropertyInfo(Variant::STRING, "category"))); - BIND_VMETHOD(MethodInfo(Variant::BOOL, "_parse_property", PropertyInfo(Variant::INT, "type"), PropertyInfo(Variant::STRING, "path"), PropertyInfo(Variant::INT, "hint"), PropertyInfo(Variant::STRING, "hint_text"), PropertyInfo(Variant::INT, "usage"))); - BIND_VMETHOD(MethodInfo(Variant::NIL, "_parse_end")); + GDVIRTUAL_BIND(_can_handle, "object") + GDVIRTUAL_BIND(_parse_begin) + GDVIRTUAL_BIND(_parse_category, "object", "category") + GDVIRTUAL_BIND(_parse_property, "object", "type", "name", "hint_type", "hint_string", "usage_flags", "wide"); + GDVIRTUAL_BIND(_parse_end) } //////////////////////////////////////////////// diff --git a/editor/editor_inspector.h b/editor/editor_inspector.h index 3c9ba9f39d..8cb4f1fbef 100644 --- a/editor/editor_inspector.h +++ b/editor/editor_inspector.h @@ -102,6 +102,7 @@ private: Map<StringName, Variant> cache; + GDVIRTUAL0(_update_property) protected: void _notification(int p_what); static void _bind_methods(); @@ -192,6 +193,12 @@ class EditorInspectorPlugin : public RefCounted { protected: static void _bind_methods(); + GDVIRTUAL1RC(bool, _can_handle, Variant) + GDVIRTUAL0(_parse_begin) + GDVIRTUAL2(_parse_category, Object *, String) + GDVIRTUAL7R(bool, _parse_property, Object *, int, String, int, String, int, bool) + GDVIRTUAL0(_parse_end) + public: void add_custom_control(Control *control); void add_property_editor(const String &p_for_property, Control *p_prop); diff --git a/editor/editor_plugin.cpp b/editor/editor_plugin.cpp index 98b5ec7d56..73ea4fb5ef 100644 --- a/editor/editor_plugin.cpp +++ b/editor/editor_plugin.cpp @@ -558,22 +558,19 @@ void EditorPlugin::notify_resource_saved(const Ref<Resource> &p_resource) { } bool EditorPlugin::forward_canvas_gui_input(const Ref<InputEvent> &p_event) { - if (get_script_instance() && get_script_instance()->has_method("_forward_canvas_gui_input")) { - return get_script_instance()->call("_forward_canvas_gui_input", p_event); + bool success; + if (GDVIRTUAL_CALL(_forward_canvas_gui_input, p_event, success)) { + return success; } return false; } void EditorPlugin::forward_canvas_draw_over_viewport(Control *p_overlay) { - if (get_script_instance() && get_script_instance()->has_method("_forward_canvas_draw_over_viewport")) { - get_script_instance()->call("_forward_canvas_draw_over_viewport", p_overlay); - } + GDVIRTUAL_CALL(_forward_canvas_draw_over_viewport, p_overlay); } void EditorPlugin::forward_canvas_force_draw_over_viewport(Control *p_overlay) { - if (get_script_instance() && get_script_instance()->has_method("_forward_canvas_force_draw_over_viewport")) { - get_script_instance()->call("_forward_canvas_force_draw_over_viewport", p_overlay); - } + GDVIRTUAL_CALL(_forward_canvas_force_draw_over_viewport, p_overlay); } // Updates the overlays of the 2D viewport or, if in 3D mode, of every 3D viewport. @@ -596,110 +593,101 @@ int EditorPlugin::update_overlays() const { } bool EditorPlugin::forward_spatial_gui_input(Camera3D *p_camera, const Ref<InputEvent> &p_event) { - if (get_script_instance() && get_script_instance()->has_method("_forward_spatial_gui_input")) { - return get_script_instance()->call("_forward_spatial_gui_input", p_camera, p_event); + bool success; + + if (GDVIRTUAL_CALL(_forward_3d_gui_input, p_camera, p_event, success)) { + return success; } return false; } void EditorPlugin::forward_spatial_draw_over_viewport(Control *p_overlay) { - if (get_script_instance() && get_script_instance()->has_method("_forward_spatial_draw_over_viewport")) { - get_script_instance()->call("_forward_spatial_draw_over_viewport", p_overlay); - } + GDVIRTUAL_CALL(_forward_3d_draw_over_viewport, p_overlay); } void EditorPlugin::forward_spatial_force_draw_over_viewport(Control *p_overlay) { - if (get_script_instance() && get_script_instance()->has_method("_forward_spatial_force_draw_over_viewport")) { - get_script_instance()->call("_forward_spatial_force_draw_over_viewport", p_overlay); - } + GDVIRTUAL_CALL(_forward_3d_force_draw_over_viewport, p_overlay); } String EditorPlugin::get_name() const { - if (get_script_instance() && get_script_instance()->has_method("_get_plugin_name")) { - return get_script_instance()->call("_get_plugin_name"); + String name; + if (GDVIRTUAL_CALL(_get_plugin_name, name)) { + return name; } return String(); } const Ref<Texture2D> EditorPlugin::get_icon() const { - if (get_script_instance() && get_script_instance()->has_method("_get_plugin_icon")) { - return get_script_instance()->call("_get_plugin_icon"); + Ref<Texture2D> icon; + if (GDVIRTUAL_CALL(_get_plugin_icon, icon)) { + return icon; } return Ref<Texture2D>(); } bool EditorPlugin::has_main_screen() const { - if (get_script_instance() && get_script_instance()->has_method("_has_main_screen")) { - return get_script_instance()->call("_has_main_screen"); + bool success; + if (GDVIRTUAL_CALL(_has_main_screen, success)) { + return success; } return false; } void EditorPlugin::make_visible(bool p_visible) { - if (get_script_instance() && get_script_instance()->has_method("_make_visible")) { - get_script_instance()->call("_make_visible", p_visible); - } + GDVIRTUAL_CALL(_make_visible, p_visible); } void EditorPlugin::edit(Object *p_object) { - if (get_script_instance() && get_script_instance()->has_method("_edit")) { - if (p_object->is_class("Resource")) { - get_script_instance()->call("_edit", Ref<Resource>(Object::cast_to<Resource>(p_object))); - } else { - get_script_instance()->call("_edit", p_object); - } + if (p_object->is_class("Resource")) { + GDVIRTUAL_CALL(_edit, Ref<Resource>(Object::cast_to<Resource>(p_object))); + } else { + GDVIRTUAL_CALL(_edit, p_object); } } bool EditorPlugin::handles(Object *p_object) const { - if (get_script_instance() && get_script_instance()->has_method("_handles")) { - return get_script_instance()->call("_handles", p_object); + bool success; + if (GDVIRTUAL_CALL(_handles, p_object, success)) { + return success; } return false; } Dictionary EditorPlugin::get_state() const { - if (get_script_instance() && get_script_instance()->has_method("_get_state")) { - return get_script_instance()->call("_get_state"); + Dictionary state; + if (GDVIRTUAL_CALL(_get_state, state)) { + return state; } return Dictionary(); } void EditorPlugin::set_state(const Dictionary &p_state) { - if (get_script_instance() && get_script_instance()->has_method("_set_state")) { - get_script_instance()->call("_set_state", p_state); - } + GDVIRTUAL_CALL(_set_state, p_state); } void EditorPlugin::clear() { - if (get_script_instance() && get_script_instance()->has_method("_clear")) { - get_script_instance()->call("_clear"); - } + GDVIRTUAL_CALL(_clear); } // if editor references external resources/scenes, save them void EditorPlugin::save_external_data() { - if (get_script_instance() && get_script_instance()->has_method("_save_external_data")) { - get_script_instance()->call("_save_external_data"); - } + GDVIRTUAL_CALL(_save_external_data); } // if changes are pending in editor, apply them void EditorPlugin::apply_changes() { - if (get_script_instance() && get_script_instance()->has_method("_apply_changes")) { - get_script_instance()->call("_apply_changes"); - } + GDVIRTUAL_CALL(_apply_changes); } void EditorPlugin::get_breakpoints(List<String> *p_breakpoints) { - if (get_script_instance() && get_script_instance()->has_method("_get_breakpoints")) { - PackedStringArray arr = get_script_instance()->call("_get_breakpoints"); + PackedStringArray arr; + if (GDVIRTUAL_CALL(_get_breakpoints, arr)) { for (int i = 0; i < arr.size(); i++) { p_breakpoints->push_back(arr[i]); } @@ -796,37 +784,28 @@ int find(const PackedStringArray &a, const String &v) { void EditorPlugin::enable_plugin() { // Called when the plugin gets enabled in project settings, after it's added to the tree. // You can implement it to register autoloads. - if (get_script_instance() && get_script_instance()->has_method("_enable_plugin")) { - get_script_instance()->call("_enable_plugin"); - } + GDVIRTUAL_CALL(_enable_plugin); } void EditorPlugin::disable_plugin() { // Last function called when the plugin gets disabled in project settings. // Implement it to cleanup things from the project, such as unregister autoloads. - - if (get_script_instance() && get_script_instance()->has_method("_disable_plugin")) { - get_script_instance()->call("_disable_plugin"); - } + GDVIRTUAL_CALL(_disable_plugin); } void EditorPlugin::set_window_layout(Ref<ConfigFile> p_layout) { - if (get_script_instance() && get_script_instance()->has_method("_set_window_layout")) { - get_script_instance()->call("_set_window_layout", p_layout); - } + GDVIRTUAL_CALL(_set_window_layout, p_layout); } void EditorPlugin::get_window_layout(Ref<ConfigFile> p_layout) { - if (get_script_instance() && get_script_instance()->has_method("_get_window_layout")) { - get_script_instance()->call("_get_window_layout", p_layout); - } + GDVIRTUAL_CALL(_get_window_layout, p_layout); } bool EditorPlugin::build() { - if (get_script_instance() && get_script_instance()->has_method("_build")) { - return get_script_instance()->call("_build"); + bool success; + if (GDVIRTUAL_CALL(_build, success)) { + return success; } - return true; } @@ -915,29 +894,29 @@ void EditorPlugin::_bind_methods() { ClassDB::bind_method(D_METHOD("add_debugger_plugin", "script"), &EditorPlugin::add_debugger_plugin); ClassDB::bind_method(D_METHOD("remove_debugger_plugin", "script"), &EditorPlugin::remove_debugger_plugin); - BIND_VMETHOD(MethodInfo(Variant::BOOL, "_forward_canvas_gui_input", PropertyInfo(Variant::OBJECT, "event", PROPERTY_HINT_RESOURCE_TYPE, "InputEvent"))); - BIND_VMETHOD(MethodInfo("_forward_canvas_draw_over_viewport", PropertyInfo(Variant::OBJECT, "overlay", PROPERTY_HINT_RESOURCE_TYPE, "Control"))); - BIND_VMETHOD(MethodInfo("_forward_canvas_force_draw_over_viewport", PropertyInfo(Variant::OBJECT, "overlay", PROPERTY_HINT_RESOURCE_TYPE, "Control"))); - BIND_VMETHOD(MethodInfo(Variant::BOOL, "_forward_spatial_gui_input", PropertyInfo(Variant::OBJECT, "camera", PROPERTY_HINT_RESOURCE_TYPE, "Camera3D"), PropertyInfo(Variant::OBJECT, "event", PROPERTY_HINT_RESOURCE_TYPE, "InputEvent"))); - BIND_VMETHOD(MethodInfo("_forward_spatial_draw_over_viewport", PropertyInfo(Variant::OBJECT, "overlay", PROPERTY_HINT_RESOURCE_TYPE, "Control"))); - BIND_VMETHOD(MethodInfo("_forward_spatial_force_draw_over_viewport", PropertyInfo(Variant::OBJECT, "overlay", PROPERTY_HINT_RESOURCE_TYPE, "Control"))); - BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_plugin_name")); - BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::OBJECT, "icon", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), "_get_plugin_icon")); - BIND_VMETHOD(MethodInfo(Variant::BOOL, "_has_main_screen")); - BIND_VMETHOD(MethodInfo("_make_visible", PropertyInfo(Variant::BOOL, "visible"))); - BIND_VMETHOD(MethodInfo("_edit", PropertyInfo(Variant::OBJECT, "object"))); - BIND_VMETHOD(MethodInfo(Variant::BOOL, "_handles", PropertyInfo(Variant::OBJECT, "object"))); - BIND_VMETHOD(MethodInfo(Variant::DICTIONARY, "_get_state")); - BIND_VMETHOD(MethodInfo("_set_state", PropertyInfo(Variant::DICTIONARY, "state"))); - BIND_VMETHOD(MethodInfo("_clear")); - BIND_VMETHOD(MethodInfo("_save_external_data")); - BIND_VMETHOD(MethodInfo("_apply_changes")); - BIND_VMETHOD(MethodInfo(Variant::PACKED_STRING_ARRAY, "_get_breakpoints")); - BIND_VMETHOD(MethodInfo("_set_window_layout", PropertyInfo(Variant::OBJECT, "layout", PROPERTY_HINT_RESOURCE_TYPE, "ConfigFile"))); - BIND_VMETHOD(MethodInfo("_get_window_layout", PropertyInfo(Variant::OBJECT, "layout", PROPERTY_HINT_RESOURCE_TYPE, "ConfigFile"))); - BIND_VMETHOD(MethodInfo(Variant::BOOL, "_build")); - BIND_VMETHOD(MethodInfo("_enable_plugin")); - BIND_VMETHOD(MethodInfo("_disable_plugin")); + GDVIRTUAL_BIND(_forward_canvas_gui_input, "event"); + GDVIRTUAL_BIND(_forward_canvas_draw_over_viewport, "viewport_control"); + GDVIRTUAL_BIND(_forward_canvas_force_draw_over_viewport, "viewport_control"); + GDVIRTUAL_BIND(_forward_3d_gui_input, "viewport_camera", "event"); + GDVIRTUAL_BIND(_forward_3d_draw_over_viewport, "viewport_control"); + GDVIRTUAL_BIND(_forward_3d_force_draw_over_viewport, "viewport_control"); + GDVIRTUAL_BIND(_get_plugin_name); + GDVIRTUAL_BIND(_get_plugin_icon); + GDVIRTUAL_BIND(_has_main_screen); + GDVIRTUAL_BIND(_make_visible, "visible"); + GDVIRTUAL_BIND(_edit, "object"); + GDVIRTUAL_BIND(_handles, "object"); + GDVIRTUAL_BIND(_get_state); + GDVIRTUAL_BIND(_set_state, "state"); + GDVIRTUAL_BIND(_clear); + GDVIRTUAL_BIND(_save_external_data); + GDVIRTUAL_BIND(_apply_changes); + GDVIRTUAL_BIND(_get_breakpoints); + GDVIRTUAL_BIND(_set_window_layout, "configuration"); + GDVIRTUAL_BIND(_get_window_layout, "configuration"); + GDVIRTUAL_BIND(_build); + GDVIRTUAL_BIND(_enable_plugin); + GDVIRTUAL_BIND(_disable_plugin); ADD_SIGNAL(MethodInfo("scene_changed", PropertyInfo(Variant::OBJECT, "scene_root", PROPERTY_HINT_RESOURCE_TYPE, "Node"))); ADD_SIGNAL(MethodInfo("scene_closed", PropertyInfo(Variant::STRING, "filepath"))); diff --git a/editor/editor_plugin.h b/editor/editor_plugin.h index d665278144..169106d901 100644 --- a/editor/editor_plugin.h +++ b/editor/editor_plugin.h @@ -39,9 +39,9 @@ #include "editor/import/editor_import_plugin.h" #include "editor/import/resource_importer_scene.h" #include "editor/script_create_dialog.h" +#include "scene/3d/camera_3d.h" #include "scene/main/node.h" #include "scene/resources/texture.h" - class EditorNode; class Node3D; class Camera3D; @@ -148,6 +148,30 @@ protected: void add_custom_type(const String &p_type, const String &p_base, const Ref<Script> &p_script, const Ref<Texture2D> &p_icon); void remove_custom_type(const String &p_type); + GDVIRTUAL1R(bool, _forward_canvas_gui_input, Ref<InputEvent>) + GDVIRTUAL1(_forward_canvas_draw_over_viewport, Control *) + GDVIRTUAL1(_forward_canvas_force_draw_over_viewport, Control *) + GDVIRTUAL2R(bool, _forward_3d_gui_input, Camera3D *, Ref<InputEvent>) + GDVIRTUAL1(_forward_3d_draw_over_viewport, Control *) + GDVIRTUAL1(_forward_3d_force_draw_over_viewport, Control *) + GDVIRTUAL0RC(String, _get_plugin_name) + GDVIRTUAL0RC(Ref<Texture2D>, _get_plugin_icon) + GDVIRTUAL0RC(bool, _has_main_screen) + GDVIRTUAL1(_make_visible, bool) + GDVIRTUAL1(_edit, Variant) + GDVIRTUAL1RC(bool, _handles, Variant) + GDVIRTUAL0RC(Dictionary, _get_state) + GDVIRTUAL1(_set_state, Dictionary) + GDVIRTUAL0(_clear) + GDVIRTUAL0(_save_external_data) + GDVIRTUAL0(_apply_changes) + GDVIRTUAL0RC(Vector<String>, _get_breakpoints) + GDVIRTUAL1(_set_window_layout, Ref<ConfigFile>) + GDVIRTUAL1(_get_window_layout, Ref<ConfigFile>) + GDVIRTUAL0R(bool, _build) + GDVIRTUAL0(_enable_plugin) + GDVIRTUAL0(_disable_plugin) + public: enum CustomControlContainer { CONTAINER_TOOLBAR, diff --git a/editor/editor_resource_preview.cpp b/editor/editor_resource_preview.cpp index 7f4ee7848f..8fc1345f3e 100644 --- a/editor/editor_resource_preview.cpp +++ b/editor/editor_resource_preview.cpp @@ -40,22 +40,25 @@ #include "editor_settings.h" bool EditorResourcePreviewGenerator::handles(const String &p_type) const { - if (get_script_instance() && get_script_instance()->has_method("_handles")) { - return get_script_instance()->call("_handles", p_type); + bool success; + if (GDVIRTUAL_CALL(_handles, p_type, success)) { + return success; } ERR_FAIL_V_MSG(false, "EditorResourcePreviewGenerator::_handles needs to be overridden."); } Ref<Texture2D> EditorResourcePreviewGenerator::generate(const RES &p_from, const Size2 &p_size) const { - if (get_script_instance() && get_script_instance()->has_method("_generate")) { - return get_script_instance()->call("_generate", p_from, p_size); + Ref<Texture2D> preview; + if (GDVIRTUAL_CALL(_generate, p_from, p_size, preview)) { + return preview; } ERR_FAIL_V_MSG(Ref<Texture2D>(), "EditorResourcePreviewGenerator::_generate needs to be overridden."); } Ref<Texture2D> EditorResourcePreviewGenerator::generate_from_path(const String &p_path, const Size2 &p_size) const { - if (get_script_instance() && get_script_instance()->has_method("_generate_from_path")) { - return get_script_instance()->call("_generate_from_path", p_path, p_size); + Ref<Texture2D> preview; + if (GDVIRTUAL_CALL(_generate_from_path, p_path, p_size, preview)) { + return preview; } RES res = ResourceLoader::load(p_path); @@ -66,27 +69,29 @@ Ref<Texture2D> EditorResourcePreviewGenerator::generate_from_path(const String & } bool EditorResourcePreviewGenerator::generate_small_preview_automatically() const { - if (get_script_instance() && get_script_instance()->has_method("_generate_small_preview_automatically")) { - return get_script_instance()->call("_generate_small_preview_automatically"); + bool success; + if (GDVIRTUAL_CALL(_generate_small_preview_automatically, success)) { + return success; } return false; } bool EditorResourcePreviewGenerator::can_generate_small_preview() const { - if (get_script_instance() && get_script_instance()->has_method("_can_generate_small_preview")) { - return get_script_instance()->call("_can_generate_small_preview"); + bool success; + if (GDVIRTUAL_CALL(_can_generate_small_preview, success)) { + return success; } return false; } void EditorResourcePreviewGenerator::_bind_methods() { - BIND_VMETHOD(MethodInfo(Variant::BOOL, "_handles", PropertyInfo(Variant::STRING, "type"))); - BIND_VMETHOD(MethodInfo(CLASS_INFO(Texture2D), "_generate", PropertyInfo(Variant::OBJECT, "from", PROPERTY_HINT_RESOURCE_TYPE, "Resource"), PropertyInfo(Variant::VECTOR2, "size"))); - BIND_VMETHOD(MethodInfo(CLASS_INFO(Texture2D), "_generate_from_path", PropertyInfo(Variant::STRING, "path", PROPERTY_HINT_FILE), PropertyInfo(Variant::VECTOR2, "size"))); - BIND_VMETHOD(MethodInfo(Variant::BOOL, "_generate_small_preview_automatically")); - BIND_VMETHOD(MethodInfo(Variant::BOOL, "_can_generate_small_preview")); + GDVIRTUAL_BIND(_handles, "type"); + GDVIRTUAL_BIND(_generate, "resource", "size"); + GDVIRTUAL_BIND(_generate_from_path, "path", "size"); + GDVIRTUAL_BIND(_generate_small_preview_automatically); + GDVIRTUAL_BIND(_can_generate_small_preview); } EditorResourcePreviewGenerator::EditorResourcePreviewGenerator() { diff --git a/editor/editor_resource_preview.h b/editor/editor_resource_preview.h index 67f83220d0..ea16c8fde0 100644 --- a/editor/editor_resource_preview.h +++ b/editor/editor_resource_preview.h @@ -43,6 +43,12 @@ class EditorResourcePreviewGenerator : public RefCounted { protected: static void _bind_methods(); + GDVIRTUAL1RC(bool, _handles, String) + GDVIRTUAL2RC(Ref<Texture2D>, _generate, RES, Vector2i) + GDVIRTUAL2RC(Ref<Texture2D>, _generate_from_path, String, Vector2i) + GDVIRTUAL0RC(bool, _generate_small_preview_automatically) + GDVIRTUAL0RC(bool, _can_generate_small_preview) + public: virtual bool handles(const String &p_type) const; virtual Ref<Texture2D> generate(const RES &p_from, const Size2 &p_size) const; diff --git a/editor/editor_run_script.cpp b/editor/editor_run_script.cpp index 83ce50a9f9..27923ef413 100644 --- a/editor/editor_run_script.cpp +++ b/editor/editor_run_script.cpp @@ -60,18 +60,8 @@ Node *EditorScript::get_scene() { } void EditorScript::_run() { - Ref<Script> s = get_script(); - ERR_FAIL_COND(!s.is_valid()); - if (!get_script_instance()) { - EditorNode::add_io_error(TTR("Couldn't instance script:") + "\n " + s->get_path() + "\n" + TTR("Did you forget the 'tool' keyword?")); - return; - } - - Callable::CallError ce; - ce.error = Callable::CallError::CALL_OK; - get_script_instance()->call("_run", nullptr, 0, ce); - if (ce.error != Callable::CallError::CALL_OK) { - EditorNode::add_io_error(TTR("Couldn't run script:") + "\n " + s->get_path() + "\n" + TTR("Did you forget the '_run' method?")); + if (!GDVIRTUAL_CALL(_run)) { + EditorNode::add_io_error(TTR("Couldn't run editor script, did you forget to override the '_run' method?")); } } @@ -83,7 +73,7 @@ void EditorScript::_bind_methods() { ClassDB::bind_method(D_METHOD("add_root_node", "node"), &EditorScript::add_root_node); ClassDB::bind_method(D_METHOD("get_scene"), &EditorScript::get_scene); ClassDB::bind_method(D_METHOD("get_editor_interface"), &EditorScript::get_editor_interface); - BIND_VMETHOD(MethodInfo("_run")); + GDVIRTUAL_BIND(_run); } EditorScript::EditorScript() { diff --git a/editor/editor_run_script.h b/editor/editor_run_script.h index c8412c3c92..6c7e37774d 100644 --- a/editor/editor_run_script.h +++ b/editor/editor_run_script.h @@ -41,6 +41,7 @@ class EditorScript : public RefCounted { protected: static void _bind_methods(); + GDVIRTUAL0(_run) public: void add_root_node(Node *p_node); diff --git a/editor/editor_translation_parser.cpp b/editor/editor_translation_parser.cpp index 27d428e682..df47b2d988 100644 --- a/editor/editor_translation_parser.cpp +++ b/editor/editor_translation_parser.cpp @@ -38,15 +38,10 @@ EditorTranslationParser *EditorTranslationParser::singleton = nullptr; Error EditorTranslationParserPlugin::parse_file(const String &p_path, Vector<String> *r_ids, Vector<Vector<String>> *r_ids_ctx_plural) { - if (!get_script_instance()) { - return ERR_UNAVAILABLE; - } - - if (get_script_instance()->has_method("_parse_file")) { - Array ids; - Array ids_ctx_plural; - get_script_instance()->call("_parse_file", p_path, ids, ids_ctx_plural); + Array ids; + Array ids_ctx_plural; + if (GDVIRTUAL_CALL(_parse_file, p_path, ids, ids_ctx_plural)) { // Add user's extracted translatable messages. for (int i = 0; i < ids.size(); i++) { r_ids->append(ids[i]); @@ -71,12 +66,8 @@ Error EditorTranslationParserPlugin::parse_file(const String &p_path, Vector<Str } void EditorTranslationParserPlugin::get_recognized_extensions(List<String> *r_extensions) const { - if (!get_script_instance()) { - return; - } - - if (get_script_instance()->has_method("_get_recognized_extensions")) { - Array extensions = get_script_instance()->call("_get_recognized_extensions"); + Vector<String> extensions; + if (GDVIRTUAL_CALL(_get_recognized_extensions, extensions)) { for (int i = 0; i < extensions.size(); i++) { r_extensions->push_back(extensions[i]); } @@ -86,8 +77,8 @@ void EditorTranslationParserPlugin::get_recognized_extensions(List<String> *r_ex } void EditorTranslationParserPlugin::_bind_methods() { - BIND_VMETHOD(MethodInfo(Variant::NIL, "_parse_file", PropertyInfo(Variant::STRING, "path"), PropertyInfo(Variant::ARRAY, "msgids"), PropertyInfo(Variant::ARRAY, "msgids_context_plural"))); - BIND_VMETHOD(MethodInfo(Variant::ARRAY, "_get_recognized_extensions")); + GDVIRTUAL_BIND(_parse_file, "path", "msgids", "msgids_context_plural"); + GDVIRTUAL_BIND(_get_recognized_extensions); } ///////////////////////// diff --git a/editor/editor_translation_parser.h b/editor/editor_translation_parser.h index 7013bbb8c4..242ba33b55 100644 --- a/editor/editor_translation_parser.h +++ b/editor/editor_translation_parser.h @@ -32,7 +32,9 @@ #define EDITOR_TRANSLATION_PARSER_H #include "core/error/error_list.h" +#include "core/object/gdvirtual.gen.inc" #include "core/object/ref_counted.h" +#include "core/object/script_language.h" class EditorTranslationParserPlugin : public RefCounted { GDCLASS(EditorTranslationParserPlugin, RefCounted); @@ -40,6 +42,9 @@ class EditorTranslationParserPlugin : public RefCounted { protected: static void _bind_methods(); + GDVIRTUAL3(_parse_file, String, Array, Array) + GDVIRTUAL0RC(Vector<String>, _get_recognized_extensions) + public: virtual Error parse_file(const String &p_path, Vector<String> *r_ids, Vector<Vector<String>> *r_ids_ctx_plural); virtual void get_recognized_extensions(List<String> *r_extensions) const; diff --git a/editor/import/editor_import_plugin.cpp b/editor/import/editor_import_plugin.cpp index 8660289c40..d219f6e325 100644 --- a/editor/import/editor_import_plugin.cpp +++ b/editor/import/editor_import_plugin.cpp @@ -35,102 +35,131 @@ EditorImportPlugin::EditorImportPlugin() { } String EditorImportPlugin::get_importer_name() const { - ERR_FAIL_COND_V(!(get_script_instance() && get_script_instance()->has_method("_get_importer_name")), ""); - return get_script_instance()->call("_get_importer_name"); + String ret; + if (GDVIRTUAL_CALL(_get_importer_name, ret)) { + return ret; + } + ERR_FAIL_V_MSG(String(), "Unimplemented _get_importer_name in add-on."); } String EditorImportPlugin::get_visible_name() const { - ERR_FAIL_COND_V(!(get_script_instance() && get_script_instance()->has_method("_get_visible_name")), ""); - return get_script_instance()->call("_get_visible_name"); + String ret; + if (GDVIRTUAL_CALL(_get_visible_name, ret)) { + return ret; + } + ERR_FAIL_V_MSG(String(), "Unimplemented _get_visible_name in add-on."); } void EditorImportPlugin::get_recognized_extensions(List<String> *p_extensions) const { - ERR_FAIL_COND(!(get_script_instance() && get_script_instance()->has_method("_get_recognized_extensions"))); - Array extensions = get_script_instance()->call("_get_recognized_extensions"); - for (int i = 0; i < extensions.size(); i++) { - p_extensions->push_back(extensions[i]); + Vector<String> extensions; + + if (GDVIRTUAL_CALL(_get_recognized_extensions, extensions)) { + for (int i = 0; i < extensions.size(); i++) { + p_extensions->push_back(extensions[i]); + } } + ERR_FAIL_MSG("Unimplemented _get_recognized_extensions in add-on."); } String EditorImportPlugin::get_preset_name(int p_idx) const { - ERR_FAIL_COND_V(!(get_script_instance() && get_script_instance()->has_method("_get_preset_name")), ""); - return get_script_instance()->call("_get_preset_name", p_idx); + String ret; + if (GDVIRTUAL_CALL(_get_preset_name, p_idx, ret)) { + return ret; + } + ERR_FAIL_V_MSG(String(), "Unimplemented _get_preset_name in add-on."); } int EditorImportPlugin::get_preset_count() const { - ERR_FAIL_COND_V(!(get_script_instance() && get_script_instance()->has_method("_get_preset_count")), 0); - return get_script_instance()->call("_get_preset_count"); + int ret; + if (GDVIRTUAL_CALL(_get_preset_count, ret)) { + return ret; + } + ERR_FAIL_V_MSG(-1, "Unimplemented _get_preset_count in add-on."); } String EditorImportPlugin::get_save_extension() const { - ERR_FAIL_COND_V(!(get_script_instance() && get_script_instance()->has_method("_get_save_extension")), ""); - return get_script_instance()->call("_get_save_extension"); + String ret; + if (GDVIRTUAL_CALL(_get_save_extension, ret)) { + return ret; + } + ERR_FAIL_V_MSG(String(), "Unimplemented _get_save_extension in add-on."); } String EditorImportPlugin::get_resource_type() const { - ERR_FAIL_COND_V(!(get_script_instance() && get_script_instance()->has_method("_get_resource_type")), ""); - return get_script_instance()->call("_get_resource_type"); + String ret; + if (GDVIRTUAL_CALL(_get_resource_type, ret)) { + return ret; + } + ERR_FAIL_V_MSG(String(), "Unimplemented _get_resource_type in add-on."); } float EditorImportPlugin::get_priority() const { - if (!(get_script_instance() && get_script_instance()->has_method("_get_priority"))) { - return ResourceImporter::get_priority(); + float ret; + if (GDVIRTUAL_CALL(_get_priority, ret)) { + return ret; } - return get_script_instance()->call("_get_priority"); + ERR_FAIL_V_MSG(-1, "Unimplemented _get_priority in add-on."); } int EditorImportPlugin::get_import_order() const { - if (!(get_script_instance() && get_script_instance()->has_method("_get_import_order"))) { - return ResourceImporter::get_import_order(); + int ret; + if (GDVIRTUAL_CALL(_get_import_order, ret)) { + return ret; } - return get_script_instance()->call("_get_import_order"); + ERR_FAIL_V_MSG(-1, "Unimplemented _get_import_order in add-on."); } void EditorImportPlugin::get_import_options(List<ResourceImporter::ImportOption> *r_options, int p_preset) const { - ERR_FAIL_COND(!(get_script_instance() && get_script_instance()->has_method("_get_import_options"))); Array needed; needed.push_back("name"); needed.push_back("default_value"); - Array options = get_script_instance()->call("_get_import_options", p_preset); - for (int i = 0; i < options.size(); i++) { - Dictionary d = options[i]; - ERR_FAIL_COND(!d.has_all(needed)); - String name = d["name"]; - Variant default_value = d["default_value"]; - - PropertyHint hint = PROPERTY_HINT_NONE; - if (d.has("property_hint")) { - hint = (PropertyHint)d["property_hint"].operator int64_t(); - } - - String hint_string; - if (d.has("hint_string")) { - hint_string = d["hint_string"]; + Array options; + if (GDVIRTUAL_CALL(_get_import_options, p_preset, options)) { + for (int i = 0; i < options.size(); i++) { + Dictionary d = options[i]; + ERR_FAIL_COND(!d.has_all(needed)); + String name = d["name"]; + Variant default_value = d["default_value"]; + + PropertyHint hint = PROPERTY_HINT_NONE; + if (d.has("property_hint")) { + hint = (PropertyHint)d["property_hint"].operator int64_t(); + } + + String hint_string; + if (d.has("hint_string")) { + hint_string = d["hint_string"]; + } + + uint32_t usage = PROPERTY_USAGE_DEFAULT; + if (d.has("usage")) { + usage = d["usage"]; + } + + ImportOption option(PropertyInfo(default_value.get_type(), name, hint, hint_string, usage), default_value); + r_options->push_back(option); } - - uint32_t usage = PROPERTY_USAGE_DEFAULT; - if (d.has("usage")) { - usage = d["usage"]; - } - - ImportOption option(PropertyInfo(default_value.get_type(), name, hint, hint_string, usage), default_value); - r_options->push_back(option); } + + ERR_FAIL_MSG("Unimplemented _get_import_options in add-on."); } bool EditorImportPlugin::get_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const { - ERR_FAIL_COND_V(!(get_script_instance() && get_script_instance()->has_method("_get_option_visibility")), true); Dictionary d; Map<StringName, Variant>::Element *E = p_options.front(); while (E) { d[E->key()] = E->get(); E = E->next(); } - return get_script_instance()->call("_get_option_visibility", p_option, d); + bool visible; + if (GDVIRTUAL_CALL(_get_option_visibility, p_option, d, visible)) { + return visible; + } + + ERR_FAIL_V_MSG(false, "Unimplemented _get_option_visibility in add-on."); } Error EditorImportPlugin::import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files, Variant *r_metadata) { - ERR_FAIL_COND_V(!(get_script_instance() && get_script_instance()->has_method("_import")), ERR_UNAVAILABLE); Dictionary options; Array platform_variants, gen_files; @@ -139,28 +168,33 @@ Error EditorImportPlugin::import(const String &p_source_file, const String &p_sa options[E->key()] = E->get(); E = E->next(); } - Error err = (Error)get_script_instance()->call("_import", p_source_file, p_save_path, options, platform_variants, gen_files).operator int64_t(); - for (int i = 0; i < platform_variants.size(); i++) { - r_platform_variants->push_back(platform_variants[i]); - } - for (int i = 0; i < gen_files.size(); i++) { - r_gen_files->push_back(gen_files[i]); + int err; + if (GDVIRTUAL_CALL(_import, p_source_file, p_save_path, options, platform_variants, gen_files, err)) { + Error ret_err = Error(err); + + for (int i = 0; i < platform_variants.size(); i++) { + r_platform_variants->push_back(platform_variants[i]); + } + for (int i = 0; i < gen_files.size(); i++) { + r_gen_files->push_back(gen_files[i]); + } + return ret_err; } - return err; + ERR_FAIL_V_MSG(ERR_METHOD_NOT_FOUND, "Unimplemented _import in add-on."); } void EditorImportPlugin::_bind_methods() { - BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_importer_name")); - BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_visible_name")); - BIND_VMETHOD(MethodInfo(Variant::INT, "_get_preset_count")); - BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_preset_name", PropertyInfo(Variant::INT, "preset"))); - BIND_VMETHOD(MethodInfo(Variant::ARRAY, "_get_recognized_extensions")); - BIND_VMETHOD(MethodInfo(Variant::ARRAY, "_get_import_options", PropertyInfo(Variant::INT, "preset"))); - BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_save_extension")); - BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_resource_type")); - BIND_VMETHOD(MethodInfo(Variant::FLOAT, "_get_priority")); - BIND_VMETHOD(MethodInfo(Variant::INT, "_get_import_order")); - BIND_VMETHOD(MethodInfo(Variant::BOOL, "_get_option_visibility", PropertyInfo(Variant::STRING, "option"), PropertyInfo(Variant::DICTIONARY, "options"))); - BIND_VMETHOD(MethodInfo(Variant::INT, "_import", PropertyInfo(Variant::STRING, "source_file"), PropertyInfo(Variant::STRING, "save_path"), PropertyInfo(Variant::DICTIONARY, "options"), PropertyInfo(Variant::ARRAY, "platform_variants"), PropertyInfo(Variant::ARRAY, "gen_files"))); + GDVIRTUAL_BIND(_get_importer_name) + GDVIRTUAL_BIND(_get_visible_name) + GDVIRTUAL_BIND(_get_preset_count) + GDVIRTUAL_BIND(_get_preset_name, "preset_index") + GDVIRTUAL_BIND(_get_recognized_extensions) + GDVIRTUAL_BIND(_get_import_options, "preset_index") + GDVIRTUAL_BIND(_get_save_extension) + GDVIRTUAL_BIND(_get_resource_type) + GDVIRTUAL_BIND(_get_priority) + GDVIRTUAL_BIND(_get_import_order) + GDVIRTUAL_BIND(_get_option_visibility, "option_name", "options") + GDVIRTUAL_BIND(_import, "source_file", "save_path", "options", "platform_variants", "gen_files"); } diff --git a/editor/import/editor_import_plugin.h b/editor/import/editor_import_plugin.h index 345a40e96d..49c959ab44 100644 --- a/editor/import/editor_import_plugin.h +++ b/editor/import/editor_import_plugin.h @@ -39,6 +39,19 @@ class EditorImportPlugin : public ResourceImporter { protected: static void _bind_methods(); + GDVIRTUAL0RC(String, _get_importer_name) + GDVIRTUAL0RC(String, _get_visible_name) + GDVIRTUAL0RC(int, _get_preset_count) + GDVIRTUAL1RC(String, _get_preset_name, int) + GDVIRTUAL0RC(Vector<String>, _get_recognized_extensions) + GDVIRTUAL1RC(Array, _get_import_options, int) + GDVIRTUAL0RC(String, _get_save_extension) + GDVIRTUAL0RC(String, _get_resource_type) + GDVIRTUAL0RC(float, _get_priority) + GDVIRTUAL0RC(int, _get_import_order) + GDVIRTUAL2RC(bool, _get_option_visibility, StringName, Dictionary) + GDVIRTUAL5RC(int, _import, String, String, Dictionary, Array, Array) + public: EditorImportPlugin(); virtual String get_importer_name() const override; diff --git a/editor/import/resource_importer_scene.cpp b/editor/import/resource_importer_scene.cpp index 492fa3f965..2b03ad928c 100644 --- a/editor/import/resource_importer_scene.cpp +++ b/editor/import/resource_importer_scene.cpp @@ -51,16 +51,17 @@ #include "scene/resources/world_margin_shape_3d.h" uint32_t EditorSceneImporter::get_import_flags() const { - if (get_script_instance()) { - return get_script_instance()->call("_get_import_flags"); + int ret; + if (GDVIRTUAL_CALL(_get_import_flags, ret)) { + return ret; } ERR_FAIL_V(0); } void EditorSceneImporter::get_extensions(List<String> *r_extensions) const { - if (get_script_instance()) { - Array arr = get_script_instance()->call("_get_extensions"); + Vector<String> arr; + if (GDVIRTUAL_CALL(_get_extensions, arr)) { for (int i = 0; i < arr.size(); i++) { r_extensions->push_back(arr[i]); } @@ -71,16 +72,18 @@ void EditorSceneImporter::get_extensions(List<String> *r_extensions) const { } Node *EditorSceneImporter::import_scene(const String &p_path, uint32_t p_flags, int p_bake_fps, List<String> *r_missing_deps, Error *r_err) { - if (get_script_instance()) { - return get_script_instance()->call("_import_scene", p_path, p_flags, p_bake_fps); + Object *ret; + if (GDVIRTUAL_CALL(_import_scene, p_path, p_flags, p_bake_fps, ret)) { + return Object::cast_to<Node>(ret); } ERR_FAIL_V(nullptr); } Ref<Animation> EditorSceneImporter::import_animation(const String &p_path, uint32_t p_flags, int p_bake_fps) { - if (get_script_instance()) { - return get_script_instance()->call("_import_animation", p_path, p_flags); + Ref<Animation> ret; + if (GDVIRTUAL_CALL(_import_animation, p_path, p_flags, p_bake_fps, ret)) { + return ret; } ERR_FAIL_V(nullptr); @@ -101,15 +104,10 @@ void EditorSceneImporter::_bind_methods() { ClassDB::bind_method(D_METHOD("import_scene_from_other_importer", "path", "flags", "bake_fps"), &EditorSceneImporter::import_scene_from_other_importer); ClassDB::bind_method(D_METHOD("import_animation_from_other_importer", "path", "flags", "bake_fps"), &EditorSceneImporter::import_animation_from_other_importer); - BIND_VMETHOD(MethodInfo(Variant::INT, "_get_import_flags")); - BIND_VMETHOD(MethodInfo(Variant::ARRAY, "_get_extensions")); - - MethodInfo mi = MethodInfo(Variant::OBJECT, "_import_scene", PropertyInfo(Variant::STRING, "path"), PropertyInfo(Variant::INT, "flags"), PropertyInfo(Variant::INT, "bake_fps")); - mi.return_val.class_name = "Node"; - BIND_VMETHOD(mi); - mi = MethodInfo(Variant::OBJECT, "_import_animation", PropertyInfo(Variant::STRING, "path"), PropertyInfo(Variant::INT, "flags"), PropertyInfo(Variant::INT, "bake_fps")); - mi.return_val.class_name = "Animation"; - BIND_VMETHOD(mi); + GDVIRTUAL_BIND(_get_import_flags); + GDVIRTUAL_BIND(_get_extensions); + GDVIRTUAL_BIND(_import_scene, "path", "flags", "bake_fps"); + GDVIRTUAL_BIND(_import_animation, "path", "flags", "bake_fps"); BIND_CONSTANT(IMPORT_SCENE); BIND_CONSTANT(IMPORT_ANIMATION); @@ -120,13 +118,14 @@ void EditorSceneImporter::_bind_methods() { ///////////////////////////////// void EditorScenePostImport::_bind_methods() { - BIND_VMETHOD(MethodInfo(Variant::OBJECT, "_post_import", PropertyInfo(Variant::OBJECT, "scene"))); + GDVIRTUAL_BIND(_post_import, "scene") ClassDB::bind_method(D_METHOD("get_source_file"), &EditorScenePostImport::get_source_file); } Node *EditorScenePostImport::post_import(Node *p_scene) { - if (get_script_instance()) { - return get_script_instance()->call("_post_import", p_scene); + Object *ret; + if (GDVIRTUAL_CALL(_post_import, p_scene, ret)) { + return Object::cast_to<Node>(ret); } return p_scene; diff --git a/editor/import/resource_importer_scene.h b/editor/import/resource_importer_scene.h index 781beff689..542959be02 100644 --- a/editor/import/resource_importer_scene.h +++ b/editor/import/resource_importer_scene.h @@ -51,6 +51,11 @@ protected: Node *import_scene_from_other_importer(const String &p_path, uint32_t p_flags, int p_bake_fps); Ref<Animation> import_animation_from_other_importer(const String &p_path, uint32_t p_flags, int p_bake_fps); + GDVIRTUAL0RC(int, _get_import_flags) + GDVIRTUAL0RC(Vector<String>, _get_extensions) + GDVIRTUAL3R(Object *, _import_scene, String, uint32_t, uint32_t) + GDVIRTUAL3R(Ref<Animation>, _import_animation, String, uint32_t, uint32_t) + public: enum ImportFlags { IMPORT_SCENE = 1, @@ -77,6 +82,8 @@ class EditorScenePostImport : public RefCounted { protected: static void _bind_methods(); + GDVIRTUAL1R(Object *, _post_import, Node *) + public: String get_source_file() const; virtual Node *post_import(Node *p_scene); diff --git a/editor/plugins/node_3d_editor_gizmos.cpp b/editor/plugins/node_3d_editor_gizmos.cpp index a42f94ed3d..5d1b4d8ead 100644 --- a/editor/plugins/node_3d_editor_gizmos.cpp +++ b/editor/plugins/node_3d_editor_gizmos.cpp @@ -105,9 +105,7 @@ void EditorNode3DGizmo::clear() { } void EditorNode3DGizmo::redraw() { - if (get_script_instance() && get_script_instance()->has_method("_redraw")) { - get_script_instance()->call("_redraw"); - } else { + if (!GDVIRTUAL_CALL(_redraw)) { ERR_FAIL_COND(!gizmo_plugin); gizmo_plugin->redraw(this); } @@ -118,8 +116,9 @@ void EditorNode3DGizmo::redraw() { } String EditorNode3DGizmo::get_handle_name(int p_id) const { - if (get_script_instance() && get_script_instance()->has_method("_get_handle_name")) { - return get_script_instance()->call("_get_handle_name", p_id); + String ret; + if (GDVIRTUAL_CALL(_get_handle_name, p_id, ret)) { + return ret; } ERR_FAIL_COND_V(!gizmo_plugin, ""); @@ -127,8 +126,9 @@ String EditorNode3DGizmo::get_handle_name(int p_id) const { } bool EditorNode3DGizmo::is_handle_highlighted(int p_id) const { - if (get_script_instance() && get_script_instance()->has_method("_is_handle_highlighted")) { - return get_script_instance()->call("_is_handle_highlighted", p_id); + bool success; + if (GDVIRTUAL_CALL(_is_handle_highlighted, p_id, success)) { + return success; } ERR_FAIL_COND_V(!gizmo_plugin, false); @@ -136,8 +136,9 @@ bool EditorNode3DGizmo::is_handle_highlighted(int p_id) const { } Variant EditorNode3DGizmo::get_handle_value(int p_id) const { - if (get_script_instance() && get_script_instance()->has_method("_get_handle_value")) { - return get_script_instance()->call("_get_handle_value", p_id); + Variant value; + if (GDVIRTUAL_CALL(_get_handle_value, p_id, value)) { + return value; } ERR_FAIL_COND_V(!gizmo_plugin, Variant()); @@ -145,8 +146,7 @@ Variant EditorNode3DGizmo::get_handle_value(int p_id) const { } void EditorNode3DGizmo::set_handle(int p_id, Camera3D *p_camera, const Point2 &p_point) { - if (get_script_instance() && get_script_instance()->has_method("_set_handle")) { - get_script_instance()->call("_set_handle", p_id, p_camera, p_point); + if (GDVIRTUAL_CALL(_set_handle, p_id, p_camera, p_point)) { return; } @@ -155,8 +155,7 @@ void EditorNode3DGizmo::set_handle(int p_id, Camera3D *p_camera, const Point2 &p } void EditorNode3DGizmo::commit_handle(int p_id, const Variant &p_restore, bool p_cancel) { - if (get_script_instance() && get_script_instance()->has_method("_commit_handle")) { - get_script_instance()->call("_commit_handle", p_id, p_restore, p_cancel); + if (GDVIRTUAL_CALL(_commit_handle, p_id, p_restore, p_cancel)) { return; } @@ -165,8 +164,9 @@ void EditorNode3DGizmo::commit_handle(int p_id, const Variant &p_restore, bool p } int EditorNode3DGizmo::subgizmos_intersect_ray(Camera3D *p_camera, const Vector2 &p_point) const { - if (get_script_instance() && get_script_instance()->has_method("_subgizmos_intersect_ray")) { - return get_script_instance()->call("_subgizmos_intersect_ray", p_camera, p_point); + int id; + if (GDVIRTUAL_CALL(_subgizmos_intersect_ray, p_camera, p_point, id)) { + return id; } ERR_FAIL_COND_V(!gizmo_plugin, -1); @@ -174,12 +174,14 @@ int EditorNode3DGizmo::subgizmos_intersect_ray(Camera3D *p_camera, const Vector2 } Vector<int> EditorNode3DGizmo::subgizmos_intersect_frustum(const Camera3D *p_camera, const Vector<Plane> &p_frustum) const { - if (get_script_instance() && get_script_instance()->has_method("_subgizmos_intersect_frustum")) { - Array frustum; - for (int i = 0; i < p_frustum.size(); i++) { - frustum[i] = p_frustum[i]; - } - return get_script_instance()->call("_subgizmos_intersect_frustum", p_camera, frustum); + TypedArray<Plane> frustum; + frustum.resize(p_frustum.size()); + for (int i = 0; i < p_frustum.size(); i++) { + frustum[i] = p_frustum[i]; + } + Vector<int> ret; + if (GDVIRTUAL_CALL(_subgizmos_intersect_frustum, p_camera, frustum, ret)) { + return ret; } ERR_FAIL_COND_V(!gizmo_plugin, Vector<int>()); @@ -187,8 +189,9 @@ Vector<int> EditorNode3DGizmo::subgizmos_intersect_frustum(const Camera3D *p_cam } Transform3D EditorNode3DGizmo::get_subgizmo_transform(int p_id) const { - if (get_script_instance() && get_script_instance()->has_method("_get_subgizmo_transform")) { - return get_script_instance()->call("_get_subgizmo_transform", p_id); + Transform3D ret; + if (GDVIRTUAL_CALL(_get_subgizmo_transform, p_id, ret)) { + return ret; } ERR_FAIL_COND_V(!gizmo_plugin, Transform3D()); @@ -196,8 +199,7 @@ Transform3D EditorNode3DGizmo::get_subgizmo_transform(int p_id) const { } void EditorNode3DGizmo::set_subgizmo_transform(int p_id, Transform3D p_transform) { - if (get_script_instance() && get_script_instance()->has_method("_set_subgizmo_transform")) { - get_script_instance()->call("_set_subgizmo_transform", p_id, p_transform); + if (GDVIRTUAL_CALL(_set_subgizmo_transform, p_id, p_transform)) { return; } @@ -206,18 +208,13 @@ void EditorNode3DGizmo::set_subgizmo_transform(int p_id, Transform3D p_transform } void EditorNode3DGizmo::commit_subgizmos(const Vector<int> &p_ids, const Vector<Transform3D> &p_restore, bool p_cancel) { - if (get_script_instance() && get_script_instance()->has_method("_commit_subgizmos")) { - Array ids; - for (int i = 0; i < p_ids.size(); i++) { - ids[i] = p_ids[i]; - } - - Array restore; - for (int i = 0; i < p_restore.size(); i++) { - restore[i] = p_restore[i]; - } + TypedArray<Transform3D> restore; + restore.resize(p_restore.size()); + for (int i = 0; i < p_restore.size(); i++) { + restore[i] = p_restore[i]; + } - get_script_instance()->call("_commit_subgizmos", ids, restore, p_cancel); + if (GDVIRTUAL_CALL(_commit_subgizmos, p_ids, restore, p_cancel)) { return; } @@ -837,26 +834,19 @@ void EditorNode3DGizmo::_bind_methods() { ClassDB::bind_method(D_METHOD("is_subgizmo_selected"), &EditorNode3DGizmo::is_subgizmo_selected); ClassDB::bind_method(D_METHOD("get_subgizmo_selection"), &EditorNode3DGizmo::get_subgizmo_selection); - BIND_VMETHOD(MethodInfo("_redraw")); - BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_handle_name", PropertyInfo(Variant::INT, "id"))); - BIND_VMETHOD(MethodInfo(Variant::BOOL, "_is_handle_highlighted", PropertyInfo(Variant::INT, "id"))); - - MethodInfo hvget(Variant::NIL, "_get_handle_value", PropertyInfo(Variant::INT, "id")); - hvget.return_val.usage |= PROPERTY_USAGE_NIL_IS_VARIANT; - BIND_VMETHOD(hvget); + GDVIRTUAL_BIND(_redraw); + GDVIRTUAL_BIND(_get_handle_name, "id"); + GDVIRTUAL_BIND(_is_handle_highlighted, "id"); - BIND_VMETHOD(MethodInfo("_set_handle", PropertyInfo(Variant::INT, "id"), PropertyInfo(Variant::OBJECT, "camera", PROPERTY_HINT_RESOURCE_TYPE, "Camera3D"), PropertyInfo(Variant::VECTOR2, "point"))); - MethodInfo cm = MethodInfo("_commit_handle", PropertyInfo(Variant::INT, "id"), PropertyInfo(Variant::NIL, "restore"), PropertyInfo(Variant::BOOL, "cancel")); - cm.default_arguments.push_back(false); - BIND_VMETHOD(cm); + GDVIRTUAL_BIND(_get_handle_value, "id"); + GDVIRTUAL_BIND(_set_handle, "id", "camera", "point"); + GDVIRTUAL_BIND(_commit_handle, "id", "restore", "cancel"); - BIND_VMETHOD(MethodInfo(Variant::INT, "_subgizmos_intersect_ray", PropertyInfo(Variant::OBJECT, "camera", PROPERTY_HINT_RESOURCE_TYPE, "Camera3D"), PropertyInfo(Variant::VECTOR2, "point"))); - BIND_VMETHOD(MethodInfo(Variant::PACKED_INT32_ARRAY, "_subgizmos_intersect_frustum", PropertyInfo(Variant::OBJECT, "camera", PROPERTY_HINT_RESOURCE_TYPE, "Camera3D"), PropertyInfo(Variant::ARRAY, "frustum"))); - BIND_VMETHOD(MethodInfo(Variant::TRANSFORM3D, "_get_subgizmo_transform", PropertyInfo(Variant::INT, "id"))); - BIND_VMETHOD(MethodInfo("_set_subgizmo_transform", PropertyInfo(Variant::INT, "id"), PropertyInfo(Variant::TRANSFORM3D, "transform"))); - MethodInfo cs = MethodInfo("_commit_subgizmos", PropertyInfo(Variant::PACKED_INT32_ARRAY, "ids"), PropertyInfo(Variant::ARRAY, "restore"), PropertyInfo(Variant::BOOL, "cancel")); - cs.default_arguments.push_back(false); - BIND_VMETHOD(cs); + GDVIRTUAL_BIND(_subgizmos_intersect_ray, "camera", "point"); + GDVIRTUAL_BIND(_subgizmos_intersect_frustum, "camera", "frustum"); + GDVIRTUAL_BIND(_set_subgizmo_transform, "id", "transform"); + GDVIRTUAL_BIND(_get_subgizmo_transform, "id"); + GDVIRTUAL_BIND(_commit_subgizmos, "ids", "restores", "cancel"); } EditorNode3DGizmo::EditorNode3DGizmo() { @@ -1042,11 +1032,6 @@ Ref<EditorNode3DGizmo> EditorNode3DGizmoPlugin::get_gizmo(Node3D *p_spatial) { } void EditorNode3DGizmoPlugin::_bind_methods() { -#define GIZMO_REF PropertyInfo(Variant::OBJECT, "gizmo", PROPERTY_HINT_RESOURCE_TYPE, "EditorNode3DGizmo") - - BIND_VMETHOD(MethodInfo(Variant::BOOL, "_has_gizmo", PropertyInfo(Variant::OBJECT, "spatial", PROPERTY_HINT_RESOURCE_TYPE, "Node3D"))); - BIND_VMETHOD(MethodInfo(GIZMO_REF, "_create_gizmo", PropertyInfo(Variant::OBJECT, "spatial", PROPERTY_HINT_RESOURCE_TYPE, "Node3D"))); - ClassDB::bind_method(D_METHOD("create_material", "name", "color", "billboard", "on_top", "use_vertex_color"), &EditorNode3DGizmoPlugin::create_material, DEFVAL(false), DEFVAL(false), DEFVAL(false)); ClassDB::bind_method(D_METHOD("create_icon_material", "name", "texture", "on_top", "color"), &EditorNode3DGizmoPlugin::create_icon_material, DEFVAL(false), DEFVAL(Color(1, 1, 1, 1))); ClassDB::bind_method(D_METHOD("create_handle_material", "name", "billboard", "texture"), &EditorNode3DGizmoPlugin::create_handle_material, DEFVAL(false), DEFVAL(Variant())); @@ -1054,45 +1039,42 @@ void EditorNode3DGizmoPlugin::_bind_methods() { ClassDB::bind_method(D_METHOD("get_material", "name", "gizmo"), &EditorNode3DGizmoPlugin::get_material, DEFVAL(Ref<EditorNode3DGizmo>())); - BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_gizmo_name")); - BIND_VMETHOD(MethodInfo(Variant::INT, "_get_priority")); - BIND_VMETHOD(MethodInfo(Variant::BOOL, "_can_be_hidden")); - BIND_VMETHOD(MethodInfo(Variant::BOOL, "_is_selectable_when_hidden")); - - BIND_VMETHOD(MethodInfo("_redraw", GIZMO_REF)); - BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_handle_name", GIZMO_REF, PropertyInfo(Variant::INT, "id"))); - BIND_VMETHOD(MethodInfo(Variant::BOOL, "_is_handle_highlighted", GIZMO_REF, PropertyInfo(Variant::INT, "id"))); + GDVIRTUAL_BIND(_has_gizmo, "for_node_3d"); + GDVIRTUAL_BIND(_create_gizmo, "for_node_3d"); - MethodInfo hvget(Variant::NIL, "_get_handle_value", GIZMO_REF, PropertyInfo(Variant::INT, "id")); - hvget.return_val.usage |= PROPERTY_USAGE_NIL_IS_VARIANT; - BIND_VMETHOD(hvget); + GDVIRTUAL_BIND(_get_gizmo_name); + GDVIRTUAL_BIND(_get_priority); + GDVIRTUAL_BIND(_can_be_hidden); + GDVIRTUAL_BIND(_is_selectable_when_hidden); - BIND_VMETHOD(MethodInfo("_set_handle", GIZMO_REF, PropertyInfo(Variant::INT, "id"), PropertyInfo(Variant::OBJECT, "camera", PROPERTY_HINT_RESOURCE_TYPE, "Camera3D"), PropertyInfo(Variant::VECTOR2, "point"))); - MethodInfo cm = MethodInfo("_commit_handle", GIZMO_REF, PropertyInfo(Variant::INT, "id"), PropertyInfo(Variant::NIL, "restore"), PropertyInfo(Variant::BOOL, "cancel")); - cm.default_arguments.push_back(false); - BIND_VMETHOD(cm); + GDVIRTUAL_BIND(_redraw, "gizmo"); + GDVIRTUAL_BIND(_get_handle_name, "gizmo", "handle_id"); + GDVIRTUAL_BIND(_is_handle_highlighted, "gizmo", "handle_id"); + GDVIRTUAL_BIND(_get_handle_value, "gizmo", "handle_id"); - BIND_VMETHOD(MethodInfo(Variant::INT, "_subgizmos_intersect_ray", GIZMO_REF, PropertyInfo(Variant::OBJECT, "camera", PROPERTY_HINT_RESOURCE_TYPE, "Camera3D"), PropertyInfo(Variant::VECTOR2, "point"))); - BIND_VMETHOD(MethodInfo(Variant::PACKED_INT32_ARRAY, "_subgizmos_intersect_frustum", GIZMO_REF, PropertyInfo(Variant::OBJECT, "camera", PROPERTY_HINT_RESOURCE_TYPE, "Camera3D"), PropertyInfo(Variant::ARRAY, "frustum"))); - BIND_VMETHOD(MethodInfo(Variant::TRANSFORM3D, "_get_subgizmo_transform", GIZMO_REF, PropertyInfo(Variant::INT, "id"))); - BIND_VMETHOD(MethodInfo("_set_subgizmo_transform", GIZMO_REF, PropertyInfo(Variant::INT, "id"), PropertyInfo(Variant::TRANSFORM3D, "transform"))); - MethodInfo cs = MethodInfo("_commit_subgizmos", GIZMO_REF, PropertyInfo(Variant::PACKED_INT32_ARRAY, "ids"), PropertyInfo(Variant::ARRAY, "restore"), PropertyInfo(Variant::BOOL, "cancel")); - cs.default_arguments.push_back(false); - BIND_VMETHOD(cs); + GDVIRTUAL_BIND(_set_handle, "gizmo", "handle_id", "camera", "screen_pos"); + GDVIRTUAL_BIND(_commit_handle, "gizmo", "handle_id", "restore", "cancel"); -#undef GIZMO_REF + GDVIRTUAL_BIND(_subgizmos_intersect_ray, "gizmo", "camera", "screen_pos"); + GDVIRTUAL_BIND(_subgizmos_intersect_frustum, "gizmo", "camera", "frustum_planes"); + GDVIRTUAL_BIND(_get_subgizmo_transform, "gizmo", "subgizmo_id"); + GDVIRTUAL_BIND(_set_subgizmo_transform, "gizmo", "subgizmo_id", "transform"); + GDVIRTUAL_BIND(_commit_subgizmos, "gizmo", "ids", "restores", "cancel"); + ; } bool EditorNode3DGizmoPlugin::has_gizmo(Node3D *p_spatial) { - if (get_script_instance() && get_script_instance()->has_method("_has_gizmo")) { - return get_script_instance()->call("_has_gizmo", p_spatial); + bool success; + if (GDVIRTUAL_CALL(_has_gizmo, p_spatial, success)) { + return success; } return false; } Ref<EditorNode3DGizmo> EditorNode3DGizmoPlugin::create_gizmo(Node3D *p_spatial) { - if (get_script_instance() && get_script_instance()->has_method("_create_gizmo")) { - return get_script_instance()->call("_create_gizmo", p_spatial); + Ref<EditorNode3DGizmo> ret; + if (GDVIRTUAL_CALL(_create_gizmo, p_spatial, ret)) { + return ret; } Ref<EditorNode3DGizmo> ref; @@ -1103,106 +1085,100 @@ Ref<EditorNode3DGizmo> EditorNode3DGizmoPlugin::create_gizmo(Node3D *p_spatial) } bool EditorNode3DGizmoPlugin::can_be_hidden() const { - if (get_script_instance() && get_script_instance()->has_method("_can_be_hidden")) { - return get_script_instance()->call("_can_be_hidden"); + bool ret; + if (GDVIRTUAL_CALL(_can_be_hidden, ret)) { + return ret; } return true; } bool EditorNode3DGizmoPlugin::is_selectable_when_hidden() const { - if (get_script_instance() && get_script_instance()->has_method("_is_selectable_when_hidden")) { - return get_script_instance()->call("_is_selectable_when_hidden"); + bool ret; + if (GDVIRTUAL_CALL(_is_selectable_when_hidden, ret)) { + return ret; } return false; } void EditorNode3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) { - if (get_script_instance() && get_script_instance()->has_method("_redraw")) { - Ref<EditorNode3DGizmo> ref(p_gizmo); - get_script_instance()->call("_redraw", ref); - } + GDVIRTUAL_CALL(_redraw, p_gizmo); } bool EditorNode3DGizmoPlugin::is_handle_highlighted(const EditorNode3DGizmo *p_gizmo, int p_id) const { - if (get_script_instance() && get_script_instance()->has_method("_is_handle_highlighted")) { - return get_script_instance()->call("_is_handle_highlighted", p_gizmo, p_id); + bool ret; + if (GDVIRTUAL_CALL(_is_handle_highlighted, Ref<EditorNode3DGizmo>(p_gizmo), p_id, ret)) { + return ret; } return false; } String EditorNode3DGizmoPlugin::get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_id) const { - if (get_script_instance() && get_script_instance()->has_method("_get_handle_name")) { - return get_script_instance()->call("_get_handle_name", p_gizmo, p_id); + String ret; + if (GDVIRTUAL_CALL(_get_handle_name, Ref<EditorNode3DGizmo>(p_gizmo), p_id, ret)) { + return ret; } return ""; } Variant EditorNode3DGizmoPlugin::get_handle_value(const EditorNode3DGizmo *p_gizmo, int p_id) const { - if (get_script_instance() && get_script_instance()->has_method("_get_handle_value")) { - return get_script_instance()->call("_get_handle_value", p_gizmo, p_id); + Variant ret; + if (GDVIRTUAL_CALL(_get_handle_value, Ref<EditorNode3DGizmo>(p_gizmo), p_id, ret)) { + return ret; } return Variant(); } void EditorNode3DGizmoPlugin::set_handle(const EditorNode3DGizmo *p_gizmo, int p_id, Camera3D *p_camera, const Point2 &p_point) { - if (get_script_instance() && get_script_instance()->has_method("_set_handle")) { - get_script_instance()->call("_set_handle", p_gizmo, p_id, p_camera, p_point); - } + GDVIRTUAL_CALL(_set_handle, Ref<EditorNode3DGizmo>(p_gizmo), p_id, p_camera, p_point); } void EditorNode3DGizmoPlugin::commit_handle(const EditorNode3DGizmo *p_gizmo, int p_id, const Variant &p_restore, bool p_cancel) { - if (get_script_instance() && get_script_instance()->has_method("_commit_handle")) { - get_script_instance()->call("_commit_handle", p_gizmo, p_id, p_restore, p_cancel); - } + GDVIRTUAL_CALL(_commit_handle, Ref<EditorNode3DGizmo>(p_gizmo), p_id, p_restore, p_cancel); } int EditorNode3DGizmoPlugin::subgizmos_intersect_ray(const EditorNode3DGizmo *p_gizmo, Camera3D *p_camera, const Vector2 &p_point) const { - if (get_script_instance() && get_script_instance()->has_method("_subgizmos_intersect_ray")) { - return get_script_instance()->call("_subgizmos_intersect_ray", p_camera, p_point); + int ret; + if (GDVIRTUAL_CALL(_subgizmos_intersect_ray, Ref<EditorNode3DGizmo>(p_gizmo), p_camera, p_point, ret)) { + return ret; } return -1; } Vector<int> EditorNode3DGizmoPlugin::subgizmos_intersect_frustum(const EditorNode3DGizmo *p_gizmo, const Camera3D *p_camera, const Vector<Plane> &p_frustum) const { - if (get_script_instance() && get_script_instance()->has_method("_subgizmos_intersect_frustum")) { - Array frustum; - for (int i = 0; i < p_frustum.size(); i++) { - frustum[i] = p_frustum[i]; - } - return get_script_instance()->call("_subgizmos_intersect_frustum", p_camera, frustum); + TypedArray<Transform3D> frustum; + frustum.resize(p_frustum.size()); + for (int i = 0; i < p_frustum.size(); i++) { + frustum[i] = p_frustum[i]; + } + Vector<int> ret; + if (GDVIRTUAL_CALL(_subgizmos_intersect_frustum, Ref<EditorNode3DGizmo>(p_gizmo), p_camera, frustum, ret)) { + return ret; } return Vector<int>(); } Transform3D EditorNode3DGizmoPlugin::get_subgizmo_transform(const EditorNode3DGizmo *p_gizmo, int p_id) const { - if (get_script_instance() && get_script_instance()->has_method("_get_subgizmo_transform")) { - return get_script_instance()->call("_get_subgizmo_transform", p_id); + Transform3D ret; + if (GDVIRTUAL_CALL(_get_subgizmo_transform, Ref<EditorNode3DGizmo>(p_gizmo), p_id, ret)) { + return ret; } return Transform3D(); } void EditorNode3DGizmoPlugin::set_subgizmo_transform(const EditorNode3DGizmo *p_gizmo, int p_id, Transform3D p_transform) { - if (get_script_instance() && get_script_instance()->has_method("_set_subgizmo_transform")) { - get_script_instance()->call("_set_subgizmo_transform", p_id, p_transform); - } + GDVIRTUAL_CALL(_set_subgizmo_transform, Ref<EditorNode3DGizmo>(p_gizmo), p_id, p_transform); } void EditorNode3DGizmoPlugin::commit_subgizmos(const EditorNode3DGizmo *p_gizmo, const Vector<int> &p_ids, const Vector<Transform3D> &p_restore, bool p_cancel) { - if (get_script_instance() && get_script_instance()->has_method("_commit_subgizmos")) { - Array ids; - for (int i = 0; i < p_ids.size(); i++) { - ids[i] = p_ids[i]; - } - - Array restore; - for (int i = 0; i < p_restore.size(); i++) { - restore[i] = p_restore[i]; - } - - get_script_instance()->call("_commit_subgizmos", ids, restore, p_cancel); + TypedArray<Transform3D> restore; + restore.resize(p_restore.size()); + for (int i = 0; i < p_restore.size(); i++) { + restore[i] = p_restore[i]; } + + GDVIRTUAL_CALL(_commit_subgizmos, Ref<EditorNode3DGizmo>(p_gizmo), p_ids, restore, p_cancel); } void EditorNode3DGizmoPlugin::set_state(int p_state) { diff --git a/editor/plugins/node_3d_editor_gizmos.h b/editor/plugins/node_3d_editor_gizmos.h index 2cc0951557..415ed5da5c 100644 --- a/editor/plugins/node_3d_editor_gizmos.h +++ b/editor/plugins/node_3d_editor_gizmos.h @@ -33,10 +33,10 @@ #include "core/templates/local_vector.h" #include "core/templates/ordered_hash_map.h" +#include "scene/3d/camera_3d.h" #include "scene/3d/node_3d.h" #include "scene/3d/skeleton_3d.h" -class Camera3D; class Timer; class EditorNode3DGizmoPlugin; @@ -79,6 +79,19 @@ protected: EditorNode3DGizmoPlugin *gizmo_plugin; + GDVIRTUAL0(_redraw) + GDVIRTUAL1RC(String, _get_handle_name, int) + GDVIRTUAL1RC(bool, _is_handle_highlighted, int) + + GDVIRTUAL1RC(Variant, _get_handle_value, int) + GDVIRTUAL3(_set_handle, int, const Camera3D *, Vector2) + GDVIRTUAL3(_commit_handle, int, Variant, bool) + + GDVIRTUAL2RC(int, _subgizmos_intersect_ray, const Camera3D *, Vector2) + GDVIRTUAL2RC(Vector<int>, _subgizmos_intersect_frustum, const Camera3D *, TypedArray<Plane>) + GDVIRTUAL1RC(Transform3D, _get_subgizmo_transform, int) + GDVIRTUAL2(_set_subgizmo_transform, int, Transform3D) + GDVIRTUAL3(_commit_subgizmos, Vector<int>, TypedArray<Transform3D>, bool) public: void add_lines(const Vector<Vector3> &p_lines, const Ref<Material> &p_material, bool p_billboard = false, const Color &p_modulate = Color(1, 1, 1)); void add_vertices(const Vector<Vector3> &p_vertices, const Ref<Material> &p_material, Mesh::PrimitiveType p_primitive_type, bool p_billboard = false, const Color &p_modulate = Color(1, 1, 1)); @@ -145,6 +158,28 @@ protected: virtual bool has_gizmo(Node3D *p_spatial); virtual Ref<EditorNode3DGizmo> create_gizmo(Node3D *p_spatial); + GDVIRTUAL1RC(bool, _has_gizmo, Node3D *) + GDVIRTUAL1RC(Ref<EditorNode3DGizmo>, _create_gizmo, Node3D *) + + GDVIRTUAL0RC(String, _get_gizmo_name) + GDVIRTUAL0RC(int, _get_priority) + GDVIRTUAL0RC(bool, _can_be_hidden) + GDVIRTUAL0RC(bool, _is_selectable_when_hidden) + + GDVIRTUAL1(_redraw, Ref<EditorNode3DGizmo>) + GDVIRTUAL2RC(String, _get_handle_name, Ref<EditorNode3DGizmo>, int) + GDVIRTUAL2RC(bool, _is_handle_highlighted, Ref<EditorNode3DGizmo>, int) + GDVIRTUAL2RC(Variant, _get_handle_value, Ref<EditorNode3DGizmo>, int) + + GDVIRTUAL4(_set_handle, Ref<EditorNode3DGizmo>, int, const Camera3D *, Vector2) + GDVIRTUAL4(_commit_handle, Ref<EditorNode3DGizmo>, int, Variant, bool) + + GDVIRTUAL3RC(int, _subgizmos_intersect_ray, Ref<EditorNode3DGizmo>, const Camera3D *, Vector2) + GDVIRTUAL3RC(Vector<int>, _subgizmos_intersect_frustum, Ref<EditorNode3DGizmo>, const Camera3D *, TypedArray<Plane>) + GDVIRTUAL2RC(Transform3D, _get_subgizmo_transform, Ref<EditorNode3DGizmo>, int) + GDVIRTUAL3(_set_subgizmo_transform, Ref<EditorNode3DGizmo>, int, Transform3D) + GDVIRTUAL4(_commit_subgizmos, Ref<EditorNode3DGizmo>, Vector<int>, TypedArray<Transform3D>, bool) + public: void create_material(const String &p_name, const Color &p_color, bool p_billboard = false, bool p_on_top = false, bool p_use_vertex_color = false); void create_icon_material(const String &p_name, const Ref<Texture2D> &p_texture, bool p_on_top = false, const Color &p_albedo = Color(1, 1, 1, 1)); diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp index 5c1e557286..567cd33305 100644 --- a/editor/plugins/script_editor_plugin.cpp +++ b/editor/plugins/script_editor_plugin.cpp @@ -54,17 +54,17 @@ /*** SYNTAX HIGHLIGHTER ****/ String EditorSyntaxHighlighter::_get_name() const { - ScriptInstance *si = get_script_instance(); - if (si && si->has_method("_get_name")) { - return si->call("_get_name"); + String ret; + if (GDVIRTUAL_CALL(_get_name, ret)) { + return ret; } return "Unnamed"; } Array EditorSyntaxHighlighter::_get_supported_languages() const { - ScriptInstance *si = get_script_instance(); - if (si && si->has_method("_get_supported_languages")) { - return si->call("_get_supported_languages"); + Array ret; + if (GDVIRTUAL_CALL(_get_supported_languages, ret)) { + return ret; } return Array(); } @@ -81,9 +81,8 @@ Ref<EditorSyntaxHighlighter> EditorSyntaxHighlighter::_create() const { void EditorSyntaxHighlighter::_bind_methods() { ClassDB::bind_method(D_METHOD("_get_edited_resource"), &EditorSyntaxHighlighter::_get_edited_resource); - BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_name")); - BIND_VMETHOD(MethodInfo(Variant::ARRAY, "_get_supported_languages")); - BIND_VMETHOD(MethodInfo(Variant::ARRAY, "_get_supported_extentions")); + GDVIRTUAL_BIND(_get_name) + GDVIRTUAL_BIND(_get_supported_languages) } //// @@ -223,8 +222,6 @@ void ScriptEditorBase::_bind_methods() { // TODO: This signal is no use for VisualScript. ADD_SIGNAL(MethodInfo("search_in_files_requested", PropertyInfo(Variant::STRING, "text"))); ADD_SIGNAL(MethodInfo("replace_in_files_requested", PropertyInfo(Variant::STRING, "text"))); - - BIND_VMETHOD(MethodInfo("_add_syntax_highlighter", PropertyInfo(Variant::OBJECT, "highlighter"))); } static bool _is_built_in_script(Script *p_script) { diff --git a/editor/plugins/script_editor_plugin.h b/editor/plugins/script_editor_plugin.h index e322828b6c..a1474c5f66 100644 --- a/editor/plugins/script_editor_plugin.h +++ b/editor/plugins/script_editor_plugin.h @@ -56,6 +56,9 @@ private: protected: static void _bind_methods(); + GDVIRTUAL0RC(String, _get_name) + GDVIRTUAL0RC(Array, _get_supported_languages) + public: virtual String _get_name() const; virtual Array _get_supported_languages() const; @@ -74,7 +77,7 @@ private: public: virtual void _update_cache() override; - virtual Dictionary _get_line_syntax_highlighting(int p_line) override { return highlighter->get_line_syntax_highlighting(p_line); } + virtual Dictionary _get_line_syntax_highlighting_impl(int p_line) override { return highlighter->get_line_syntax_highlighting(p_line); } virtual String _get_name() const override { return TTR("Standard"); } diff --git a/editor/plugins/visual_shader_editor_plugin.cpp b/editor/plugins/visual_shader_editor_plugin.cpp index d84ed4828c..4ed9f712c1 100644 --- a/editor/plugins/visual_shader_editor_plugin.cpp +++ b/editor/plugins/visual_shader_editor_plugin.cpp @@ -70,14 +70,15 @@ const int MAX_FLOAT_CONST_DEFS = sizeof(float_constant_defs) / sizeof(FloatConst /////////////////// Control *VisualShaderNodePlugin::create_editor(const Ref<Resource> &p_parent_resource, const Ref<VisualShaderNode> &p_node) { - if (get_script_instance()) { - return get_script_instance()->call("_create_editor", p_parent_resource, p_node); + Object *ret; + if (GDVIRTUAL_CALL(_create_editor, p_parent_resource, p_node, ret)) { + return Object::cast_to<Control>(ret); } return nullptr; } void VisualShaderNodePlugin::_bind_methods() { - BIND_VMETHOD(MethodInfo(Variant::OBJECT, "_create_editor", PropertyInfo(Variant::OBJECT, "parent_resource", PROPERTY_HINT_RESOURCE_TYPE, "Resource"), PropertyInfo(Variant::OBJECT, "for_node", PROPERTY_HINT_RESOURCE_TYPE, "VisualShaderNode"))); + GDVIRTUAL_BIND(_create_editor, "parent_resource", "visual_shader_node"); } /////////////////// diff --git a/editor/plugins/visual_shader_editor_plugin.h b/editor/plugins/visual_shader_editor_plugin.h index fbfe1197a3..9f24c5af72 100644 --- a/editor/plugins/visual_shader_editor_plugin.h +++ b/editor/plugins/visual_shader_editor_plugin.h @@ -47,6 +47,8 @@ class VisualShaderNodePlugin : public RefCounted { protected: static void _bind_methods(); + GDVIRTUAL2RC(Object *, _create_editor, RES, Ref<VisualShaderNode>) + public: virtual Control *create_editor(const Ref<Resource> &p_parent_resource, const Ref<VisualShaderNode> &p_node); }; diff --git a/editor/property_editor.cpp b/editor/property_editor.cpp index 7338588d56..6ea9b9dfae 100644 --- a/editor/property_editor.cpp +++ b/editor/property_editor.cpp @@ -59,42 +59,33 @@ #include "scene/scene_string_names.h" void EditorResourceConversionPlugin::_bind_methods() { - MethodInfo mi; - mi.name = "_convert"; - mi.return_val.type = Variant::OBJECT; - mi.return_val.class_name = "Resource"; - mi.return_val.hint = PROPERTY_HINT_RESOURCE_TYPE; - mi.return_val.hint_string = "Resource"; - mi.arguments.push_back(mi.return_val); - mi.arguments[0].name = "resource"; - - BIND_VMETHOD(mi) - - mi.name = "_handles"; - mi.return_val = PropertyInfo(Variant::BOOL, ""); - - BIND_VMETHOD(MethodInfo(Variant::STRING, "_converts_to")); + GDVIRTUAL_BIND(_converts_to); + GDVIRTUAL_BIND(_handles, "resource"); + GDVIRTUAL_BIND(_convert, "resource"); } String EditorResourceConversionPlugin::converts_to() const { - if (get_script_instance()) { - return get_script_instance()->call("_converts_to"); + String ret; + if (GDVIRTUAL_CALL(_converts_to, ret)) { + return ret; } return ""; } bool EditorResourceConversionPlugin::handles(const Ref<Resource> &p_resource) const { - if (get_script_instance()) { - return get_script_instance()->call("_handles", p_resource); + bool ret; + if (GDVIRTUAL_CALL(_handles, p_resource, ret)) { + return ret; } return false; } Ref<Resource> EditorResourceConversionPlugin::convert(const Ref<Resource> &p_resource) const { - if (get_script_instance()) { - return get_script_instance()->call("_convert", p_resource); + RES ret; + if (GDVIRTUAL_CALL(_convert, p_resource, ret)) { + return ret; } return Ref<Resource>(); diff --git a/editor/property_editor.h b/editor/property_editor.h index 8a587b50b0..23771b7494 100644 --- a/editor/property_editor.h +++ b/editor/property_editor.h @@ -56,6 +56,10 @@ class EditorResourceConversionPlugin : public RefCounted { protected: static void _bind_methods(); + GDVIRTUAL0RC(String, _converts_to) + GDVIRTUAL1RC(bool, _handles, RES) + GDVIRTUAL1RC(RES, _convert, RES) + public: virtual String converts_to() const; virtual bool handles(const Ref<Resource> &p_resource) const; diff --git a/modules/gdscript/editor/gdscript_highlighter.cpp b/modules/gdscript/editor/gdscript_highlighter.cpp index 0b1cb5d502..8b9bd2659d 100644 --- a/modules/gdscript/editor/gdscript_highlighter.cpp +++ b/modules/gdscript/editor/gdscript_highlighter.cpp @@ -45,7 +45,7 @@ static bool _is_bin_symbol(char32_t c) { return (c == '0' || c == '1'); } -Dictionary GDScriptSyntaxHighlighter::_get_line_syntax_highlighting(int p_line) { +Dictionary GDScriptSyntaxHighlighter::_get_line_syntax_highlighting_impl(int p_line) { Dictionary color_map; Type next_type = NONE; diff --git a/modules/gdscript/editor/gdscript_highlighter.h b/modules/gdscript/editor/gdscript_highlighter.h index d07c182aa6..fabd64dab8 100644 --- a/modules/gdscript/editor/gdscript_highlighter.h +++ b/modules/gdscript/editor/gdscript_highlighter.h @@ -80,7 +80,7 @@ private: public: virtual void _update_cache() override; - virtual Dictionary _get_line_syntax_highlighting(int p_line) override; + virtual Dictionary _get_line_syntax_highlighting_impl(int p_line) override; virtual String _get_name() const override; virtual Array _get_supported_languages() const override; diff --git a/modules/visual_script/doc_classes/VisualScriptCustomNode.xml b/modules/visual_script/doc_classes/VisualScriptCustomNode.xml index 8aa34f8cae..b574576856 100644 --- a/modules/visual_script/doc_classes/VisualScriptCustomNode.xml +++ b/modules/visual_script/doc_classes/VisualScriptCustomNode.xml @@ -9,118 +9,118 @@ <tutorials> </tutorials> <methods> - <method name="_get_caption" qualifiers="virtual"> + <method name="_get_caption" qualifiers="virtual const"> <return type="String" /> <description> Return the node's title. </description> </method> - <method name="_get_category" qualifiers="virtual"> + <method name="_get_category" qualifiers="virtual const"> <return type="String" /> <description> Return the node's category. </description> </method> - <method name="_get_input_value_port_count" qualifiers="virtual"> + <method name="_get_input_value_port_count" qualifiers="virtual const"> <return type="int" /> <description> Return the count of input value ports. </description> </method> - <method name="_get_input_value_port_hint" qualifiers="virtual"> + <method name="_get_input_value_port_hint" qualifiers="virtual const"> <return type="int" /> - <argument index="0" name="idx" type="int" /> + <argument index="0" name="input_idx" type="int" /> <description> Return the specified input port's hint. See the [enum @GlobalScope.PropertyHint] hints. </description> </method> - <method name="_get_input_value_port_hint_string" qualifiers="virtual"> + <method name="_get_input_value_port_hint_string" qualifiers="virtual const"> <return type="String" /> - <argument index="0" name="idx" type="int" /> + <argument index="0" name="input_idx" type="int" /> <description> Return the specified input port's hint string. </description> </method> - <method name="_get_input_value_port_name" qualifiers="virtual"> + <method name="_get_input_value_port_name" qualifiers="virtual const"> <return type="String" /> - <argument index="0" name="idx" type="int" /> + <argument index="0" name="input_idx" type="int" /> <description> Return the specified input port's name. </description> </method> - <method name="_get_input_value_port_type" qualifiers="virtual"> + <method name="_get_input_value_port_type" qualifiers="virtual const"> <return type="int" /> - <argument index="0" name="idx" type="int" /> + <argument index="0" name="input_idx" type="int" /> <description> Return the specified input port's type. See the [enum Variant.Type] values. </description> </method> - <method name="_get_output_sequence_port_count" qualifiers="virtual"> + <method name="_get_output_sequence_port_count" qualifiers="virtual const"> <return type="int" /> <description> Return the amount of output [b]sequence[/b] ports. </description> </method> - <method name="_get_output_sequence_port_text" qualifiers="virtual"> + <method name="_get_output_sequence_port_text" qualifiers="virtual const"> <return type="String" /> - <argument index="0" name="idx" type="int" /> + <argument index="0" name="seq_idx" type="int" /> <description> Return the specified [b]sequence[/b] output's name. </description> </method> - <method name="_get_output_value_port_count" qualifiers="virtual"> + <method name="_get_output_value_port_count" qualifiers="virtual const"> <return type="int" /> <description> Return the amount of output value ports. </description> </method> - <method name="_get_output_value_port_hint" qualifiers="virtual"> + <method name="_get_output_value_port_hint" qualifiers="virtual const"> <return type="int" /> - <argument index="0" name="idx" type="int" /> + <argument index="0" name="output_idx" type="int" /> <description> Return the specified output port's hint. See the [enum @GlobalScope.PropertyHint] hints. </description> </method> - <method name="_get_output_value_port_hint_string" qualifiers="virtual"> + <method name="_get_output_value_port_hint_string" qualifiers="virtual const"> <return type="String" /> - <argument index="0" name="idx" type="int" /> + <argument index="0" name="output_idx" type="int" /> <description> Return the specified output port's hint string. </description> </method> - <method name="_get_output_value_port_name" qualifiers="virtual"> + <method name="_get_output_value_port_name" qualifiers="virtual const"> <return type="String" /> - <argument index="0" name="idx" type="int" /> + <argument index="0" name="output_idx" type="int" /> <description> Return the specified output port's name. </description> </method> - <method name="_get_output_value_port_type" qualifiers="virtual"> + <method name="_get_output_value_port_type" qualifiers="virtual const"> <return type="int" /> - <argument index="0" name="idx" type="int" /> + <argument index="0" name="output_idx" type="int" /> <description> Return the specified output port's type. See the [enum Variant.Type] values. </description> </method> - <method name="_get_text" qualifiers="virtual"> + <method name="_get_text" qualifiers="virtual const"> <return type="String" /> <description> Return the custom node's text, which is shown right next to the input [b]sequence[/b] port (if there is none, on the place that is usually taken by it). </description> </method> - <method name="_get_working_memory_size" qualifiers="virtual"> + <method name="_get_working_memory_size" qualifiers="virtual const"> <return type="int" /> <description> Return the size of the custom node's working memory. See [method _step] for more details. </description> </method> - <method name="_has_input_sequence_port" qualifiers="virtual"> + <method name="_has_input_sequence_port" qualifiers="virtual const"> <return type="bool" /> <description> Return whether the custom node has an input [b]sequence[/b] port. </description> </method> - <method name="_step" qualifiers="virtual"> + <method name="_step" qualifiers="virtual const"> <return type="Variant" /> <argument index="0" name="inputs" type="Array" /> <argument index="1" name="outputs" type="Array" /> diff --git a/modules/visual_script/doc_classes/VisualScriptSubCall.xml b/modules/visual_script/doc_classes/VisualScriptSubCall.xml index 374e7d0f35..f54887b09c 100644 --- a/modules/visual_script/doc_classes/VisualScriptSubCall.xml +++ b/modules/visual_script/doc_classes/VisualScriptSubCall.xml @@ -9,13 +9,6 @@ <tutorials> </tutorials> <methods> - <method name="_subcall" qualifiers="virtual"> - <return type="Variant" /> - <argument index="0" name="arguments" type="Variant" /> - <description> - Called by this node. - </description> - </method> </methods> <constants> </constants> diff --git a/modules/visual_script/visual_script_nodes.cpp b/modules/visual_script/visual_script_nodes.cpp index c517d89aa5..c9e426fa6c 100644 --- a/modules/visual_script/visual_script_nodes.cpp +++ b/modules/visual_script/visual_script_nodes.cpp @@ -2825,36 +2825,41 @@ VisualScriptSelf::VisualScriptSelf() { ////////////////////////////////////////// int VisualScriptCustomNode::get_output_sequence_port_count() const { - if (get_script_instance() && get_script_instance()->has_method("_get_output_sequence_port_count")) { - return get_script_instance()->call("_get_output_sequence_port_count"); + int ret; + if (GDVIRTUAL_CALL(_get_output_sequence_port_count, ret)) { + return ret; } return 0; } bool VisualScriptCustomNode::has_input_sequence_port() const { - if (get_script_instance() && get_script_instance()->has_method("_has_input_sequence_port")) { - return get_script_instance()->call("_has_input_sequence_port"); + bool ret; + if (GDVIRTUAL_CALL(_has_input_sequence_port, ret)) { + return ret; } return false; } int VisualScriptCustomNode::get_input_value_port_count() const { - if (get_script_instance() && get_script_instance()->has_method("_get_input_value_port_count")) { - return get_script_instance()->call("_get_input_value_port_count"); + int ret; + if (GDVIRTUAL_CALL(_get_input_value_port_count, ret)) { + return ret; } return 0; } int VisualScriptCustomNode::get_output_value_port_count() const { - if (get_script_instance() && get_script_instance()->has_method("_get_output_value_port_count")) { - return get_script_instance()->call("_get_output_value_port_count"); + int ret; + if (GDVIRTUAL_CALL(_get_output_value_port_count, ret)) { + return ret; } return 0; } String VisualScriptCustomNode::get_output_sequence_port_text(int p_port) const { - if (get_script_instance() && get_script_instance()->has_method("_get_output_sequence_port_text")) { - return get_script_instance()->call("_get_output_sequence_port_text", p_port); + String ret; + if (GDVIRTUAL_CALL(_get_output_sequence_port_text, p_port, ret)) { + return ret; } return String(); @@ -2862,34 +2867,61 @@ String VisualScriptCustomNode::get_output_sequence_port_text(int p_port) const { PropertyInfo VisualScriptCustomNode::get_input_value_port_info(int p_idx) const { PropertyInfo info; - if (get_script_instance() && get_script_instance()->has_method("_get_input_value_port_type")) { - info.type = Variant::Type(int(get_script_instance()->call("_get_input_value_port_type", p_idx))); + { + int type; + if (GDVIRTUAL_CALL(_get_input_value_port_type, p_idx, type)) { + info.type = Variant::Type(type); + } } - if (get_script_instance() && get_script_instance()->has_method("_get_input_value_port_name")) { - info.name = get_script_instance()->call("_get_input_value_port_name", p_idx); + { + String name; + if (GDVIRTUAL_CALL(_get_input_value_port_name, p_idx, name)) { + info.name = name; + } } - if (get_script_instance() && get_script_instance()->has_method("_get_input_value_port_hint")) { - info.hint = PropertyHint(int(get_script_instance()->call("_get_input_value_port_hint", p_idx))); + { + int hint; + if (GDVIRTUAL_CALL(_get_input_value_port_hint, p_idx, hint)) { + info.hint = PropertyHint(hint); + } } - if (get_script_instance() && get_script_instance()->has_method("_get_input_value_port_hint_string")) { - info.hint_string = get_script_instance()->call("_get_input_value_port_hint_string", p_idx); + + { + String hint_string; + if (GDVIRTUAL_CALL(_get_input_value_port_hint_string, p_idx, hint_string)) { + info.hint_string = hint_string; + } } + return info; } PropertyInfo VisualScriptCustomNode::get_output_value_port_info(int p_idx) const { PropertyInfo info; - if (get_script_instance() && get_script_instance()->has_method("_get_output_value_port_type")) { - info.type = Variant::Type(int(get_script_instance()->call("_get_output_value_port_type", p_idx))); + { + int type; + if (GDVIRTUAL_CALL(_get_output_value_port_type, p_idx, type)) { + info.type = Variant::Type(type); + } } - if (get_script_instance() && get_script_instance()->has_method("_get_output_value_port_name")) { - info.name = get_script_instance()->call("_get_output_value_port_name", p_idx); + { + String name; + if (GDVIRTUAL_CALL(_get_output_value_port_name, p_idx, name)) { + info.name = name; + } } - if (get_script_instance() && get_script_instance()->has_method("_get_output_value_port_hint")) { - info.hint = PropertyHint(int(get_script_instance()->call("_get_output_value_port_hint", p_idx))); + { + int hint; + if (GDVIRTUAL_CALL(_get_output_value_port_hint, p_idx, hint)) { + info.hint = PropertyHint(hint); + } } - if (get_script_instance() && get_script_instance()->has_method("_get_output_value_port_hint_string")) { - info.hint_string = get_script_instance()->call("_get_output_value_port_hint_string", p_idx); + + { + String hint_string; + if (GDVIRTUAL_CALL(_get_output_value_port_hint_string, p_idx, hint_string)) { + info.hint_string = hint_string; + } } return info; } @@ -2911,22 +2943,25 @@ VisualScriptCustomNode::TypeGuess VisualScriptCustomNode::guess_output_type(Type } String VisualScriptCustomNode::get_caption() const { - if (get_script_instance() && get_script_instance()->has_method("_get_caption")) { - return get_script_instance()->call("_get_caption"); + String ret; + if (GDVIRTUAL_CALL(_get_caption, ret)) { + return ret; } return "CustomNode"; } String VisualScriptCustomNode::get_text() const { - if (get_script_instance() && get_script_instance()->has_method("_get_text")) { - return get_script_instance()->call("_get_text"); + String ret; + if (GDVIRTUAL_CALL(_get_text, ret)) { + return ret; } return ""; } String VisualScriptCustomNode::get_category() const { - if (get_script_instance() && get_script_instance()->has_method("_get_category")) { - return get_script_instance()->call("_get_category"); + String ret; + if (GDVIRTUAL_CALL(_get_category, ret)) { + return ret; } return "Custom"; } @@ -2941,14 +2976,7 @@ public: virtual int get_working_memory_size() const { return work_mem_size; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - if (node->get_script_instance()) { -#ifdef DEBUG_ENABLED - if (!node->get_script_instance()->has_method(VisualScriptLanguage::singleton->_step)) { - r_error_str = RTR("Custom node has no _step() method, can't process graph."); - r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD; - return 0; - } -#endif + if (GDVIRTUAL_IS_OVERRIDEN_PTR(node, _step)) { Array in_values; Array out_values; Array work_mem; @@ -2969,7 +2997,8 @@ public: int ret_out; - Variant ret = node->get_script_instance()->call(VisualScriptLanguage::singleton->_step, in_values, out_values, p_start_mode, work_mem); + Variant ret; + GDVIRTUAL_CALL_PTR(node, _step, in_values, out_values, p_start_mode, work_mem, ret); if (ret.get_type() == Variant::STRING) { r_error_str = ret; r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD; @@ -2995,6 +3024,9 @@ public: } return ret_out; + } else { + r_error_str = RTR("Custom node has no _step() method, can't process graph."); + r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD; } return 0; @@ -3008,11 +3040,8 @@ VisualScriptNodeInstance *VisualScriptCustomNode::instantiate(VisualScriptInstan instance->in_count = get_input_value_port_count(); instance->out_count = get_output_value_port_count(); - if (get_script_instance() && get_script_instance()->has_method("_get_working_memory_size")) { - instance->work_mem_size = get_script_instance()->call("_get_working_memory_size"); - } else { - instance->work_mem_size = 0; - } + instance->work_mem_size = 0; + GDVIRTUAL_CALL(_get_working_memory_size, instance->work_mem_size); return instance; } @@ -3022,32 +3051,29 @@ void VisualScriptCustomNode::_script_changed() { } void VisualScriptCustomNode::_bind_methods() { - BIND_VMETHOD(MethodInfo(Variant::INT, "_get_output_sequence_port_count")); - BIND_VMETHOD(MethodInfo(Variant::BOOL, "_has_input_sequence_port")); - - BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_output_sequence_port_text", PropertyInfo(Variant::INT, "idx"))); - BIND_VMETHOD(MethodInfo(Variant::INT, "_get_input_value_port_count")); - BIND_VMETHOD(MethodInfo(Variant::INT, "_get_output_value_port_count")); + GDVIRTUAL_BIND(_get_output_sequence_port_count); + GDVIRTUAL_BIND(_has_input_sequence_port); + GDVIRTUAL_BIND(_get_output_sequence_port_text, "seq_idx"); - BIND_VMETHOD(MethodInfo(Variant::INT, "_get_input_value_port_type", PropertyInfo(Variant::INT, "idx"))); - BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_input_value_port_name", PropertyInfo(Variant::INT, "idx"))); - BIND_VMETHOD(MethodInfo(Variant::INT, "_get_input_value_port_hint", PropertyInfo(Variant::INT, "idx"))); - BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_input_value_port_hint_string", PropertyInfo(Variant::INT, "idx"))); + GDVIRTUAL_BIND(_get_input_value_port_count); + GDVIRTUAL_BIND(_get_input_value_port_type, "input_idx"); + GDVIRTUAL_BIND(_get_input_value_port_name, "input_idx"); + GDVIRTUAL_BIND(_get_input_value_port_hint, "input_idx"); + GDVIRTUAL_BIND(_get_input_value_port_hint_string, "input_idx"); - BIND_VMETHOD(MethodInfo(Variant::INT, "_get_output_value_port_type", PropertyInfo(Variant::INT, "idx"))); - BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_output_value_port_name", PropertyInfo(Variant::INT, "idx"))); - BIND_VMETHOD(MethodInfo(Variant::INT, "_get_output_value_port_hint", PropertyInfo(Variant::INT, "idx"))); - BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_output_value_port_hint_string", PropertyInfo(Variant::INT, "idx"))); + GDVIRTUAL_BIND(_get_output_value_port_count); + GDVIRTUAL_BIND(_get_output_value_port_type, "output_idx"); + GDVIRTUAL_BIND(_get_output_value_port_name, "output_idx"); + GDVIRTUAL_BIND(_get_output_value_port_hint, "output_idx"); + GDVIRTUAL_BIND(_get_output_value_port_hint_string, "output_idx"); - BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_caption")); - BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_text")); - BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_category")); + GDVIRTUAL_BIND(_get_caption); + GDVIRTUAL_BIND(_get_text); + GDVIRTUAL_BIND(_get_category); - BIND_VMETHOD(MethodInfo(Variant::INT, "_get_working_memory_size")); + GDVIRTUAL_BIND(_get_working_memory_size); - MethodInfo stepmi(Variant::NIL, "_step", PropertyInfo(Variant::ARRAY, "inputs"), PropertyInfo(Variant::ARRAY, "outputs"), PropertyInfo(Variant::INT, "start_mode"), PropertyInfo(Variant::ARRAY, "working_mem")); - stepmi.return_val.usage |= PROPERTY_USAGE_NIL_IS_VARIANT; - BIND_VMETHOD(stepmi); + GDVIRTUAL_BIND(_step, "inputs", "outputs", "start_mode", "working_mem"); BIND_ENUM_CONSTANT(START_MODE_BEGIN_SEQUENCE); BIND_ENUM_CONSTANT(START_MODE_CONTINUE_SEQUENCE); @@ -3170,9 +3196,7 @@ VisualScriptNodeInstance *VisualScriptSubCall::instantiate(VisualScriptInstance } void VisualScriptSubCall::_bind_methods() { - MethodInfo scmi(Variant::NIL, "_subcall", PropertyInfo(Variant::NIL, "arguments")); - scmi.return_val.usage |= PROPERTY_USAGE_NIL_IS_VARIANT; - BIND_VMETHOD(scmi); + // Since this is script only, registering virtual function is no longer valid. Will have to go in docs. } VisualScriptSubCall::VisualScriptSubCall() { diff --git a/modules/visual_script/visual_script_nodes.h b/modules/visual_script/visual_script_nodes.h index 2390e5c7bc..35d9b0b4fe 100644 --- a/modules/visual_script/visual_script_nodes.h +++ b/modules/visual_script/visual_script_nodes.h @@ -31,6 +31,8 @@ #ifndef VISUAL_SCRIPT_NODES_H #define VISUAL_SCRIPT_NODES_H +#include "core/object/gdvirtual.gen.inc" +#include "core/object/script_language.h" #include "visual_script.h" class VisualScriptFunction : public VisualScriptNode { @@ -757,6 +759,30 @@ class VisualScriptCustomNode : public VisualScriptNode { protected: static void _bind_methods(); + friend class VisualScriptNodeInstanceCustomNode; + GDVIRTUAL0RC(int, _get_output_sequence_port_count) + GDVIRTUAL0RC(bool, _has_input_sequence_port) + GDVIRTUAL1RC(String, _get_output_sequence_port_text, int) + + GDVIRTUAL0RC(int, _get_input_value_port_count) + GDVIRTUAL1RC(int, _get_input_value_port_type, int) + GDVIRTUAL1RC(String, _get_input_value_port_name, int) + GDVIRTUAL1RC(int, _get_input_value_port_hint, int) + GDVIRTUAL1RC(String, _get_input_value_port_hint_string, int) + + GDVIRTUAL0RC(int, _get_output_value_port_count) + GDVIRTUAL1RC(int, _get_output_value_port_type, int) + GDVIRTUAL1RC(String, _get_output_value_port_name, int) + GDVIRTUAL1RC(int, _get_output_value_port_hint, int) + GDVIRTUAL1RC(String, _get_output_value_port_hint_string, int) + + GDVIRTUAL0RC(String, _get_caption) + GDVIRTUAL0RC(String, _get_text) + GDVIRTUAL0RC(String, _get_category) + + GDVIRTUAL0RC(int, _get_working_memory_size) + + GDVIRTUAL4RC(Variant, _step, Array, Array, int, Array) public: enum StartMode { //replicated for step diff --git a/scene/2d/physics_body_2d.cpp b/scene/2d/physics_body_2d.cpp index 13ed4af04e..a9d4877cbb 100644 --- a/scene/2d/physics_body_2d.cpp +++ b/scene/2d/physics_body_2d.cpp @@ -529,9 +529,9 @@ void RigidBody2D::_direct_state_changed(Object *p_state) { sleeping = state->is_sleeping(); emit_signal(SceneStringNames::get_singleton()->sleeping_state_changed); } - if (get_script_instance()) { - get_script_instance()->call("_integrate_forces", state); - } + + GDVIRTUAL_CALL(_integrate_forces, state); + set_block_transform_notify(false); // want it back if (contact_monitor) { @@ -978,7 +978,7 @@ void RigidBody2D::_bind_methods() { ClassDB::bind_method(D_METHOD("get_colliding_bodies"), &RigidBody2D::get_colliding_bodies); - BIND_VMETHOD(MethodInfo("_integrate_forces", PropertyInfo(Variant::OBJECT, "state", PROPERTY_HINT_RESOURCE_TYPE, "PhysicsDirectBodyState2D"))); + GDVIRTUAL_BIND(_integrate_forces, "state"); ADD_PROPERTY(PropertyInfo(Variant::INT, "mode", PROPERTY_HINT_ENUM, "Dynamic,Static,DynamicLocked,Kinematic"), "set_mode", "get_mode"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "mass", PROPERTY_HINT_RANGE, "0.01,65535,0.01,exp"), "set_mass", "get_mass"); diff --git a/scene/2d/physics_body_2d.h b/scene/2d/physics_body_2d.h index 302a2148be..a999317953 100644 --- a/scene/2d/physics_body_2d.h +++ b/scene/2d/physics_body_2d.h @@ -189,6 +189,8 @@ protected: void _notification(int p_what); static void _bind_methods(); + GDVIRTUAL1(_integrate_forces, PhysicsDirectBodyState2D *) + public: void set_mode(Mode p_mode); Mode get_mode() const; diff --git a/scene/3d/physics_body_3d.cpp b/scene/3d/physics_body_3d.cpp index 092efc55d7..4c36618c99 100644 --- a/scene/3d/physics_body_3d.cpp +++ b/scene/3d/physics_body_3d.cpp @@ -599,9 +599,9 @@ void RigidBody3D::_direct_state_changed(Object *p_state) { sleeping = state->is_sleeping(); emit_signal(SceneStringNames::get_singleton()->sleeping_state_changed); } - if (get_script_instance()) { - get_script_instance()->call("_integrate_forces", state); - } + + GDVIRTUAL_CALL(_integrate_forces, state); + set_ignore_transform_notification(false); _on_transform_changed(); @@ -1022,7 +1022,7 @@ void RigidBody3D::_bind_methods() { ClassDB::bind_method(D_METHOD("get_colliding_bodies"), &RigidBody3D::get_colliding_bodies); - BIND_VMETHOD(MethodInfo("_integrate_forces", PropertyInfo(Variant::OBJECT, "state", PROPERTY_HINT_RESOURCE_TYPE, "PhysicsDirectBodyState3D"))); + GDVIRTUAL_BIND(_integrate_forces, "state"); ADD_PROPERTY(PropertyInfo(Variant::INT, "mode", PROPERTY_HINT_ENUM, "Dynamic,Static,DynamicLocked,Kinematic"), "set_mode", "get_mode"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "mass", PROPERTY_HINT_RANGE, "0.01,65535,0.01,exp"), "set_mass", "get_mass"); diff --git a/scene/3d/physics_body_3d.h b/scene/3d/physics_body_3d.h index 9c40f92f06..26b9a39047 100644 --- a/scene/3d/physics_body_3d.h +++ b/scene/3d/physics_body_3d.h @@ -132,6 +132,8 @@ public: MODE_KINEMATIC, }; + GDVIRTUAL1(_integrate_forces, PhysicsDirectBodyState3D *) + protected: bool can_sleep = true; PhysicsDirectBodyState3D *state = nullptr; diff --git a/scene/animation/animation_tree.cpp b/scene/animation/animation_tree.cpp index 543545b90f..88fb960164 100644 --- a/scene/animation/animation_tree.cpp +++ b/scene/animation/animation_tree.cpp @@ -36,8 +36,9 @@ #include "servers/audio/audio_stream.h" void AnimationNode::get_parameter_list(List<PropertyInfo> *r_list) const { - if (get_script_instance()) { - Array parameters = get_script_instance()->call("_get_parameter_list"); + Array parameters; + + if (GDVIRTUAL_CALL(_get_parameter_list, parameters)) { for (int i = 0; i < parameters.size(); i++) { Dictionary d = parameters[i]; ERR_CONTINUE(d.is_empty()); @@ -47,8 +48,9 @@ void AnimationNode::get_parameter_list(List<PropertyInfo> *r_list) const { } Variant AnimationNode::get_parameter_default_value(const StringName &p_parameter) const { - if (get_script_instance()) { - return get_script_instance()->call("_get_parameter_default_value", p_parameter); + Variant ret; + if (GDVIRTUAL_CALL(_get_parameter_default_value, p_parameter, ret)) { + return ret; } return Variant(); } @@ -72,8 +74,8 @@ Variant AnimationNode::get_parameter(const StringName &p_name) const { } void AnimationNode::get_child_nodes(List<ChildNode> *r_child_nodes) { - if (get_script_instance()) { - Dictionary cn = get_script_instance()->call("_get_child_nodes"); + Dictionary cn; + if (GDVIRTUAL_CALL(_get_child_nodes, cn)) { List<Variant> keys; cn.get_key_list(&keys); for (const Variant &E : keys) { @@ -298,8 +300,9 @@ String AnimationNode::get_input_name(int p_input) { } String AnimationNode::get_caption() const { - if (get_script_instance()) { - return get_script_instance()->call("_get_caption"); + String ret; + if (GDVIRTUAL_CALL(_get_caption, ret)) { + return ret; } return "Node"; @@ -329,8 +332,9 @@ void AnimationNode::remove_input(int p_index) { } double AnimationNode::process(double p_time, bool p_seek) { - if (get_script_instance()) { - return get_script_instance()->call("_process", p_time, p_seek); + double ret; + if (GDVIRTUAL_CALL(_process, p_time, p_seek, ret)) { + return ret; } return 0; @@ -357,8 +361,9 @@ bool AnimationNode::is_path_filtered(const NodePath &p_path) const { } bool AnimationNode::has_filter() const { - if (get_script_instance()) { - return get_script_instance()->call("_has_filter"); + bool ret; + if (GDVIRTUAL_CALL(_has_filter, ret)) { + return ret; } return false; @@ -390,8 +395,9 @@ void AnimationNode::_validate_property(PropertyInfo &property) const { } Ref<AnimationNode> AnimationNode::get_child_by_name(const StringName &p_name) { - if (get_script_instance()) { - return get_script_instance()->call("_get_child_by_name", p_name); + Ref<AnimationNode> ret; + if (GDVIRTUAL_CALL(_get_child_by_name, p_name, ret)) { + return ret; } return Ref<AnimationNode>(); } @@ -422,17 +428,13 @@ void AnimationNode::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "filter_enabled", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_filter_enabled", "is_filter_enabled"); ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "filters", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL), "_set_filters", "_get_filters"); - BIND_VMETHOD(MethodInfo(Variant::DICTIONARY, "_get_child_nodes")); - BIND_VMETHOD(MethodInfo(Variant::ARRAY, "_get_parameter_list")); - BIND_VMETHOD(MethodInfo(Variant::OBJECT, "_get_child_by_name", PropertyInfo(Variant::STRING, "name"))); - { - MethodInfo mi = MethodInfo(Variant::NIL, "_get_parameter_default_value", PropertyInfo(Variant::STRING_NAME, "name")); - mi.return_val.usage = PROPERTY_USAGE_NIL_IS_VARIANT; - BIND_VMETHOD(mi); - } - BIND_VMETHOD(MethodInfo("_process", PropertyInfo(Variant::FLOAT, "time"), PropertyInfo(Variant::BOOL, "seek"))); - BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_caption")); - BIND_VMETHOD(MethodInfo(Variant::BOOL, "_has_filter")); + GDVIRTUAL_BIND(_get_child_nodes); + GDVIRTUAL_BIND(_get_parameter_list); + GDVIRTUAL_BIND(_get_child_by_name, "name"); + GDVIRTUAL_BIND(_get_parameter_default_value, "parameter"); + GDVIRTUAL_BIND(_process, "time", "seek"); + GDVIRTUAL_BIND(_get_caption); + GDVIRTUAL_BIND(_has_filter); ADD_SIGNAL(MethodInfo("removed_from_graph")); diff --git a/scene/animation/animation_tree.h b/scene/animation/animation_tree.h index 59bbc5b4da..1e0267682e 100644 --- a/scene/animation/animation_tree.h +++ b/scene/animation/animation_tree.h @@ -112,6 +112,14 @@ protected: void _set_parent(Object *p_parent); + GDVIRTUAL0RC(Dictionary, _get_child_nodes) + GDVIRTUAL0RC(Array, _get_parameter_list) + GDVIRTUAL1RC(Ref<AnimationNode>, _get_child_by_name, StringName) + GDVIRTUAL1RC(Variant, _get_parameter_default_value, StringName) + GDVIRTUAL2RC(double, _process, double, bool) + GDVIRTUAL0RC(String, _get_caption) + GDVIRTUAL0RC(bool, _has_filter) + public: virtual void get_parameter_list(List<PropertyInfo> *r_list) const; virtual Variant get_parameter_default_value(const StringName &p_parameter) const; diff --git a/scene/gui/base_button.cpp b/scene/gui/base_button.cpp index d252a4507c..03c75b25f4 100644 --- a/scene/gui/base_button.cpp +++ b/scene/gui/base_button.cpp @@ -121,17 +121,13 @@ void BaseButton::_notification(int p_what) { } void BaseButton::_pressed() { - if (get_script_instance()) { - get_script_instance()->call(SceneStringNames::get_singleton()->_pressed); - } + GDVIRTUAL_CALL(_pressed); pressed(); emit_signal(SNAME("pressed")); } void BaseButton::_toggled(bool p_pressed) { - if (get_script_instance()) { - get_script_instance()->call(SceneStringNames::get_singleton()->_toggled, p_pressed); - } + GDVIRTUAL_CALL(_toggled, p_pressed); toggled(p_pressed); emit_signal(SNAME("toggled"), p_pressed); } @@ -440,8 +436,8 @@ void BaseButton::_bind_methods() { ClassDB::bind_method(D_METHOD("set_shortcut_context", "node"), &BaseButton::set_shortcut_context); ClassDB::bind_method(D_METHOD("get_shortcut_context"), &BaseButton::get_shortcut_context); - BIND_VMETHOD(MethodInfo("_pressed")); - BIND_VMETHOD(MethodInfo("_toggled", PropertyInfo(Variant::BOOL, "button_pressed"))); + GDVIRTUAL_BIND(_pressed); + GDVIRTUAL_BIND(_toggled, "button_pressed"); ADD_SIGNAL(MethodInfo("pressed")); ADD_SIGNAL(MethodInfo("button_up")); diff --git a/scene/gui/base_button.h b/scene/gui/base_button.h index d86b35daf0..cf1904344b 100644 --- a/scene/gui/base_button.h +++ b/scene/gui/base_button.h @@ -81,6 +81,9 @@ protected: bool _is_focus_owner_in_shorcut_context() const; + GDVIRTUAL0(_pressed) + GDVIRTUAL1(_toggled, bool) + public: enum DrawMode { DRAW_NORMAL, diff --git a/scene/gui/code_edit.cpp b/scene/gui/code_edit.cpp index 08dd7f28eb..7cc2352353 100644 --- a/scene/gui/code_edit.cpp +++ b/scene/gui/code_edit.cpp @@ -450,7 +450,7 @@ void CodeEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { } if (k->is_action("ui_text_backspace", true)) { backspace(); - _filter_code_completion_candidates(); + _filter_code_completion_candidates_impl(); accept_event(); return; } @@ -522,7 +522,7 @@ void CodeEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { TextEdit::_gui_input(p_gui_input); if (update_code_completion) { - _filter_code_completion_candidates(); + _filter_code_completion_candidates_impl(); } } @@ -557,7 +557,7 @@ Control::CursorShape CodeEdit::get_cursor_shape(const Point2 &p_pos) const { /* Text manipulation */ // Overridable actions -void CodeEdit::_handle_unicode_input(const uint32_t p_unicode) { +void CodeEdit::_handle_unicode_input_internal(const uint32_t p_unicode) { bool had_selection = has_selection(); if (had_selection) { begin_complex_operation(); @@ -609,7 +609,7 @@ void CodeEdit::_handle_unicode_input(const uint32_t p_unicode) { } } -void CodeEdit::_backspace() { +void CodeEdit::_backspace_internal() { if (!is_editable()) { return; } @@ -1739,9 +1739,7 @@ String CodeEdit::get_text_for_code_completion() const { } void CodeEdit::request_code_completion(bool p_force) { - ScriptInstance *si = get_script_instance(); - if (si && si->has_method("_request_code_completion")) { - si->call("_request_code_completion", p_force); + if (GDVIRTUAL_CALL(_request_code_completion, p_force)) { return; } @@ -1798,7 +1796,7 @@ void CodeEdit::update_code_completion_options(bool p_forced) { code_completion_forced = p_forced; code_completion_option_sources = code_completion_option_submitted; code_completion_option_submitted.clear(); - _filter_code_completion_candidates(); + _filter_code_completion_candidates_impl(); } TypedArray<Dictionary> CodeEdit::get_code_completion_options() const { @@ -1855,11 +1853,10 @@ void CodeEdit::confirm_code_completion(bool p_replace) { return; } - ScriptInstance *si = get_script_instance(); - if (si && si->has_method("_confirm_code_completion")) { - si->call("_confirm_code_completion", p_replace); + if (GDVIRTUAL_CALL(_confirm_code_completion, p_replace)) { return; } + begin_complex_operation(); int caret_line = get_caret_line(); @@ -2179,9 +2176,10 @@ void CodeEdit::_bind_methods() { ClassDB::bind_method(D_METHOD("get_code_comletion_prefixes"), &CodeEdit::get_code_completion_prefixes); // Overridable - BIND_VMETHOD(MethodInfo("_confirm_code_completion", PropertyInfo(Variant::BOOL, "replace"))); - BIND_VMETHOD(MethodInfo("_request_code_completion", PropertyInfo(Variant::BOOL, "force"))); - BIND_VMETHOD(MethodInfo(Variant::ARRAY, "_filter_code_completion_candidates", PropertyInfo(Variant::ARRAY, "candidates"))); + + GDVIRTUAL_BIND(_confirm_code_completion, "replace") + GDVIRTUAL_BIND(_request_code_completion, "force") + GDVIRTUAL_BIND(_filter_code_completion_candidates, "candidates") /* Line length guidelines */ ClassDB::bind_method(D_METHOD("set_line_length_guidelines", "guideline_columns"), &CodeEdit::set_line_length_guidelines); @@ -2650,11 +2648,10 @@ TypedArray<String> CodeEdit::_get_delimiters(DelimiterType p_type) const { } /* Code Completion */ -void CodeEdit::_filter_code_completion_candidates() { - ScriptInstance *si = get_script_instance(); +void CodeEdit::_filter_code_completion_candidates_impl() { int line_height = get_line_height(); - if (si && si->has_method("_filter_code_completion_candidates")) { + if (GDVIRTUAL_IS_OVERRIDEN(_filter_code_completion_candidates)) { code_completion_options.clear(); code_completion_base = ""; @@ -2674,7 +2671,9 @@ void CodeEdit::_filter_code_completion_candidates() { i++; } - TypedArray<Dictionary> completion_options = si->call("_filter_code_completion_candidates", completion_options_sources); + Array completion_options; + + GDVIRTUAL_CALL(_filter_code_completion_candidates, completion_options_sources, completion_options); /* No options to complete, cancel. */ if (completion_options.size() == 0) { diff --git a/scene/gui/code_edit.h b/scene/gui/code_edit.h index 76ac15f553..aa62cbdf3c 100644 --- a/scene/gui/code_edit.h +++ b/scene/gui/code_edit.h @@ -219,7 +219,7 @@ private: List<ScriptCodeCompletionOption> code_completion_option_sources; String code_completion_base; - void _filter_code_completion_candidates(); + void _filter_code_completion_candidates_impl(); /* Line length guidelines */ TypedArray<int> line_length_guideline_columns; @@ -256,8 +256,12 @@ protected: /* Text manipulation */ // Overridable actions - virtual void _handle_unicode_input(const uint32_t p_unicode) override; - virtual void _backspace() override; + virtual void _handle_unicode_input_internal(const uint32_t p_unicode) override; + virtual void _backspace_internal() override; + + GDVIRTUAL1(_confirm_code_completion, bool) + GDVIRTUAL1(_request_code_completion, bool) + GDVIRTUAL1RC(Array, _filter_code_completion_candidates, TypedArray<Dictionary>) public: /* General overrides */ diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index f114e06c75..6dba23d3c7 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -730,14 +730,9 @@ Variant Control::get_drag_data(const Point2 &p_point) { } } - if (get_script_instance()) { - Variant v = p_point; - const Variant *p = &v; - Callable::CallError ce; - Variant ret = get_script_instance()->call(SceneStringNames::get_singleton()->_get_drag_data, &p, 1, ce); - if (ce.error == Callable::CallError::CALL_OK) { - return ret; - } + Variant dd; + if (GDVIRTUAL_CALL(_get_drag_data, p_point, dd)) { + return dd; } return Variant(); @@ -752,16 +747,10 @@ bool Control::can_drop_data(const Point2 &p_point, const Variant &p_data) const } } - if (get_script_instance()) { - Variant v = p_point; - const Variant *p[2] = { &v, &p_data }; - Callable::CallError ce; - Variant ret = get_script_instance()->call(SceneStringNames::get_singleton()->_can_drop_data, p, 2, ce); - if (ce.error == Callable::CallError::CALL_OK) { - return ret; - } + bool ret; + if (GDVIRTUAL_CALL(_can_drop_data, p_point, p_data, ret)) { + return ret; } - return false; } @@ -775,15 +764,7 @@ void Control::drop_data(const Point2 &p_point, const Variant &p_data) { } } - if (get_script_instance()) { - Variant v = p_point; - const Variant *p[2] = { &v, &p_data }; - Callable::CallError ce; - Variant ret = get_script_instance()->call(SceneStringNames::get_singleton()->_drop_data, p, 2, ce); - if (ce.error == Callable::CallError::CALL_OK) { - return; - } - } + GDVIRTUAL_CALL(_drop_data, p_point, p_data); } void Control::force_drag(const Variant &p_data, Control *p_control) { @@ -800,15 +781,11 @@ void Control::set_drag_preview(Control *p_control) { } Size2 Control::get_minimum_size() const { - ScriptInstance *si = const_cast<Control *>(this)->get_script_instance(); - if (si) { - Callable::CallError ce; - Variant s = si->call(SceneStringNames::get_singleton()->_get_minimum_size, nullptr, 0, ce); - if (ce.error == Callable::CallError::CALL_OK) { - return s; - } + Vector2 ms; + if (GDVIRTUAL_CALL(_get_minimum_size, ms)) { + return ms; } - return Size2(); + return Vector2(); } template <class T> @@ -2123,8 +2100,9 @@ String Control::get_tooltip(const Point2 &p_pos) const { } Control *Control::make_custom_tooltip(const String &p_text) const { - if (get_script_instance()) { - return const_cast<Control *>(this)->call("_make_custom_tooltip", p_text); + Object *ret = nullptr; + if (GDVIRTUAL_CALL(_make_custom_tooltip, p_text, ret)) { + return Object::cast_to<Control>(ret); } return nullptr; } @@ -2499,14 +2477,11 @@ Vector<Vector2i> Control::structured_text_parser(StructuredTextParser p_theme_ty } } break; case STRUCTURED_TEXT_CUSTOM: { - if (get_script_instance()) { - Variant data = get_script_instance()->call(SceneStringNames::get_singleton()->_structured_text_parser, p_args, p_text); - if (data.get_type() == Variant::ARRAY) { - Array _data = data; - for (int i = 0; i < _data.size(); i++) { - if (_data[i].get_type() == Variant::VECTOR2I) { - ret.push_back(Vector2i(_data[i])); - } + Array r; + if (GDVIRTUAL_CALL(_structured_text_parser, p_args, p_text, r)) { + for (int i = 0; i < r.size(); i++) { + if (r[i].get_type() == Variant::VECTOR2I) { + ret.push_back(Vector2i(r[i])); } } } @@ -2823,20 +2798,7 @@ void Control::_bind_methods() { ClassDB::bind_method(D_METHOD("set_auto_translate", "enable"), &Control::set_auto_translate); ClassDB::bind_method(D_METHOD("is_auto_translating"), &Control::is_auto_translating); - BIND_VMETHOD(MethodInfo("_structured_text_parser", PropertyInfo(Variant::ARRAY, "args"), PropertyInfo(Variant::STRING, "text"))); - BIND_VMETHOD(MethodInfo("_gui_input", PropertyInfo(Variant::OBJECT, "event", PROPERTY_HINT_RESOURCE_TYPE, "InputEvent"))); - BIND_VMETHOD(MethodInfo(Variant::VECTOR2, "_get_minimum_size")); - - MethodInfo get_drag_data = MethodInfo("_get_drag_data", PropertyInfo(Variant::VECTOR2, "position")); - get_drag_data.return_val.usage |= PROPERTY_USAGE_NIL_IS_VARIANT; - BIND_VMETHOD(get_drag_data); - - BIND_VMETHOD(MethodInfo(Variant::BOOL, "_can_drop_data", PropertyInfo(Variant::VECTOR2, "position"), PropertyInfo(Variant::NIL, "data"))); - BIND_VMETHOD(MethodInfo("_drop_data", PropertyInfo(Variant::VECTOR2, "position"), PropertyInfo(Variant::NIL, "data"))); - BIND_VMETHOD(MethodInfo( - PropertyInfo(Variant::OBJECT, "control", PROPERTY_HINT_RESOURCE_TYPE, "Control"), - "_make_custom_tooltip", PropertyInfo(Variant::STRING, "for_text"))); ADD_GROUP("Anchor", "anchor_"); ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "anchor_left", PROPERTY_HINT_RANGE, "0,1,0.001,or_lesser,or_greater"), "_set_anchor", "get_anchor", SIDE_LEFT); @@ -2994,5 +2956,12 @@ void Control::_bind_methods() { ADD_SIGNAL(MethodInfo("minimum_size_changed")); ADD_SIGNAL(MethodInfo("theme_changed")); - GDVIRTUAL_BIND(_has_point); + GDVIRTUAL_BIND(_has_point, "position"); + GDVIRTUAL_BIND(_structured_text_parser, "args", "text"); + GDVIRTUAL_BIND(_get_minimum_size); + + GDVIRTUAL_BIND(_get_drag_data, "at_position") + GDVIRTUAL_BIND(_can_drop_data, "at_position", "data") + GDVIRTUAL_BIND(_drop_data, "at_position", "data") + GDVIRTUAL_BIND(_make_custom_tooltip, "for_text") } diff --git a/scene/gui/control.h b/scene/gui/control.h index a871a8e9fb..0d7a3b8de0 100644 --- a/scene/gui/control.h +++ b/scene/gui/control.h @@ -273,6 +273,16 @@ private: _FORCE_INLINE_ void _get_theme_type_dependencies(const StringName &p_theme_type, List<StringName> *p_list) const; GDVIRTUAL1RC(bool, _has_point, Vector2) + GDVIRTUAL2RC(Array, _structured_text_parser, Array, String) + GDVIRTUAL0RC(Vector2, _get_minimum_size) + + GDVIRTUAL1RC(Variant, _get_drag_data, Vector2) + GDVIRTUAL2RC(bool, _can_drop_data, Vector2, Variant) + GDVIRTUAL2(_drop_data, Vector2, Variant) + GDVIRTUAL1RC(Object *, _make_custom_tooltip, String) + + //GDVIRTUAL1(_gui_input, Ref<InputEvent>) + protected: virtual void add_child_notify(Node *p_child) override; virtual void remove_child_notify(Node *p_child) override; diff --git a/scene/gui/rich_text_effect.cpp b/scene/gui/rich_text_effect.cpp index 39718a269a..236d106af8 100644 --- a/scene/gui/rich_text_effect.cpp +++ b/scene/gui/rich_text_effect.cpp @@ -32,8 +32,15 @@ #include "core/object/script_language.h" -void RichTextEffect::_bind_methods() { - BIND_VMETHOD(MethodInfo(Variant::BOOL, "_process_custom_fx", PropertyInfo(Variant::OBJECT, "char_fx", PROPERTY_HINT_RESOURCE_TYPE, "CharFXTransform"))); +CharFXTransform::CharFXTransform() { +} + +CharFXTransform::~CharFXTransform() { + environment.clear(); +} + +void RichTextEffect::_bind_methods(){ + GDVIRTUAL_BIND(_process_custom_fx, "char_fx") } Variant RichTextEffect::get_bbcode() const { @@ -49,15 +56,10 @@ Variant RichTextEffect::get_bbcode() const { bool RichTextEffect::_process_effect_impl(Ref<CharFXTransform> p_cfx) { bool return_value = false; - if (get_script_instance()) { - Variant v = get_script_instance()->call("_process_custom_fx", p_cfx); - if (v.get_type() != Variant::BOOL) { - return_value = false; - } else { - return_value = (bool)v; - } + if (GDVIRTUAL_CALL(_process_custom_fx, p_cfx, return_value)) { + return return_value; } - return return_value; + return false; } RichTextEffect::RichTextEffect() { @@ -101,10 +103,3 @@ void CharFXTransform::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::INT, "glyph_index"), "set_glyph_index", "get_glyph_index"); ADD_PROPERTY(PropertyInfo(Variant::RID, "font"), "set_font", "get_font"); } - -CharFXTransform::CharFXTransform() { -} - -CharFXTransform::~CharFXTransform() { - environment.clear(); -} diff --git a/scene/gui/rich_text_effect.h b/scene/gui/rich_text_effect.h index 67323e7f93..e674b2f62f 100644 --- a/scene/gui/rich_text_effect.h +++ b/scene/gui/rich_text_effect.h @@ -32,20 +32,8 @@ #define RICH_TEXT_EFFECT_H #include "core/io/resource.h" - -class RichTextEffect : public Resource { - GDCLASS(RichTextEffect, Resource); - OBJ_SAVE_TYPE(RichTextEffect); - -protected: - static void _bind_methods(); - -public: - Variant get_bbcode() const; - bool _process_effect_impl(Ref<class CharFXTransform> p_cfx); - - RichTextEffect(); -}; +#include "core/object/gdvirtual.gen.inc" +#include "core/object/script_language.h" class CharFXTransform : public RefCounted { GDCLASS(CharFXTransform, RefCounted); @@ -89,4 +77,20 @@ public: void set_environment(Dictionary p_environment) { environment = p_environment; } }; +class RichTextEffect : public Resource { + GDCLASS(RichTextEffect, Resource); + OBJ_SAVE_TYPE(RichTextEffect); + +protected: + static void _bind_methods(); + + GDVIRTUAL1RC(bool, _process_custom_fx, Ref<CharFXTransform>) + +public: + Variant get_bbcode() const; + bool _process_effect_impl(Ref<class CharFXTransform> p_cfx); + + RichTextEffect(); +}; + #endif // RICH_TEXT_EFFECT_H diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index 87f06445ac..a65abd5f49 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -2768,48 +2768,38 @@ Point2i TextEdit::get_next_visible_line_index_offset_from(int p_line_from, int p // Overridable actions void TextEdit::handle_unicode_input(const uint32_t p_unicode) { - ScriptInstance *si = get_script_instance(); - if (si && si->has_method("_handle_unicode_input")) { - si->call("_handle_unicode_input", p_unicode); + if (GDVIRTUAL_CALL(_handle_unicode_input, p_unicode)) { return; } - _handle_unicode_input(p_unicode); + _handle_unicode_input_internal(p_unicode); } void TextEdit::backspace() { - ScriptInstance *si = get_script_instance(); - if (si && si->has_method("_backspace")) { - si->call("_backspace"); + if (GDVIRTUAL_CALL(_backspace)) { return; } - _backspace(); + _backspace_internal(); } void TextEdit::cut() { - ScriptInstance *si = get_script_instance(); - if (si && si->has_method("_cut")) { - si->call("_cut"); + if (GDVIRTUAL_CALL(_cut)) { return; } - _cut(); + _cut_internal(); } void TextEdit::copy() { - ScriptInstance *si = get_script_instance(); - if (si && si->has_method("_copy")) { - si->call("_copy"); + if (GDVIRTUAL_CALL(_copy)) { return; } - _copy(); + _copy_internal(); } void TextEdit::paste() { - ScriptInstance *si = get_script_instance(); - if (si && si->has_method("_paste")) { - si->call("_paste"); + if (GDVIRTUAL_CALL(_paste)) { return; } - _paste(); + _paste_internal(); } // Context menu. @@ -4452,12 +4442,11 @@ void TextEdit::_bind_methods() { ClassDB::bind_method(D_METHOD("copy"), &TextEdit::copy); ClassDB::bind_method(D_METHOD("paste"), &TextEdit::paste); - BIND_VMETHOD(MethodInfo("_handle_unicode_input", PropertyInfo(Variant::INT, "unicode"))) - BIND_VMETHOD(MethodInfo("_backspace")); - - BIND_VMETHOD(MethodInfo("_cut")); - BIND_VMETHOD(MethodInfo("_copy")); - BIND_VMETHOD(MethodInfo("_paste")); + GDVIRTUAL_BIND(_handle_unicode_input, "unicode_char") + GDVIRTUAL_BIND(_backspace) + GDVIRTUAL_BIND(_cut) + GDVIRTUAL_BIND(_copy) + GDVIRTUAL_BIND(_paste) // Context Menu BIND_ENUM_CONSTANT(MENU_CUT); @@ -4884,7 +4873,7 @@ void TextEdit::_set_symbol_lookup_word(const String &p_symbol) { /* Text manipulation */ // Overridable actions -void TextEdit::_handle_unicode_input(const uint32_t p_unicode) { +void TextEdit::_handle_unicode_input_internal(const uint32_t p_unicode) { if (!editable) { return; } @@ -4915,7 +4904,7 @@ void TextEdit::_handle_unicode_input(const uint32_t p_unicode) { } } -void TextEdit::_backspace() { +void TextEdit::_backspace_internal() { if (!editable) { return; } @@ -4946,7 +4935,7 @@ void TextEdit::_backspace() { set_caret_column(prev_column); } -void TextEdit::_cut() { +void TextEdit::_cut_internal() { if (!editable) { return; } @@ -4976,7 +4965,7 @@ void TextEdit::_cut() { cut_copy_line = clipboard; } -void TextEdit::_copy() { +void TextEdit::_copy_internal() { if (has_selection()) { DisplayServer::get_singleton()->clipboard_set(get_selected_text()); cut_copy_line = ""; @@ -4991,7 +4980,7 @@ void TextEdit::_copy() { } } -void TextEdit::_paste() { +void TextEdit::_paste_internal() { if (!editable) { return; } diff --git a/scene/gui/text_edit.h b/scene/gui/text_edit.h index 69468978ab..7d00ce14af 100644 --- a/scene/gui/text_edit.h +++ b/scene/gui/text_edit.h @@ -562,12 +562,18 @@ protected: /* Text manipulation */ // Overridable actions - virtual void _handle_unicode_input(const uint32_t p_unicode); - virtual void _backspace(); - - virtual void _cut(); - virtual void _copy(); - virtual void _paste(); + virtual void _handle_unicode_input_internal(const uint32_t p_unicode); + virtual void _backspace_internal(); + + virtual void _cut_internal(); + virtual void _copy_internal(); + virtual void _paste_internal(); + + GDVIRTUAL1(_handle_unicode_input, int) + GDVIRTUAL0(_backspace) + GDVIRTUAL0(_cut) + GDVIRTUAL0(_copy) + GDVIRTUAL0(_paste) public: /* General overrides. */ diff --git a/scene/main/canvas_item.cpp b/scene/main/canvas_item.cpp index f2415eaf71..f329332725 100644 --- a/scene/main/canvas_item.cpp +++ b/scene/main/canvas_item.cpp @@ -151,9 +151,7 @@ void CanvasItem::_update_callback() { current_item_drawn = this; notification(NOTIFICATION_DRAW); emit_signal(SceneStringNames::get_singleton()->draw); - if (get_script_instance()) { - get_script_instance()->call(SceneStringNames::get_singleton()->_draw); - } + GDVIRTUAL_CALL(_draw); current_item_drawn = nullptr; drawing = false; } @@ -934,7 +932,7 @@ void CanvasItem::_bind_methods() { ClassDB::bind_method(D_METHOD("set_clip_children", "enable"), &CanvasItem::set_clip_children); ClassDB::bind_method(D_METHOD("is_clipping_children"), &CanvasItem::is_clipping_children); - BIND_VMETHOD(MethodInfo("_draw")); + GDVIRTUAL_BIND(_draw); ADD_GROUP("Visibility", ""); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "visible"), "set_visible", "is_visible"); diff --git a/scene/main/canvas_item.h b/scene/main/canvas_item.h index dc7ad2bf5d..a591cab485 100644 --- a/scene/main/canvas_item.h +++ b/scene/main/canvas_item.h @@ -142,6 +142,7 @@ protected: void _notification(int p_what); static void _bind_methods(); + GDVIRTUAL0(_draw) public: enum { NOTIFICATION_TRANSFORM_CHANGED = SceneTree::NOTIFICATION_TRANSFORM_CHANGED, //unique diff --git a/scene/main/node.cpp b/scene/main/node.cpp index 155af30a6d..1d617d1ff7 100644 --- a/scene/main/node.cpp +++ b/scene/main/node.cpp @@ -54,16 +54,11 @@ int Node::orphan_node_count = 0; void Node::_notification(int p_notification) { switch (p_notification) { case NOTIFICATION_PROCESS: { - if (get_script_instance()) { - Variant time = get_process_delta_time(); - get_script_instance()->call(SceneStringNames::get_singleton()->_process, time); - } + GDVIRTUAL_CALL(_process, get_process_delta_time()); + } break; case NOTIFICATION_PHYSICS_PROCESS: { - if (get_script_instance()) { - Variant time = get_physics_process_delta_time(); - get_script_instance()->call(SceneStringNames::get_singleton()->_physics_process, time); - } + GDVIRTUAL_CALL(_physics_process, get_process_delta_time()); } break; case NOTIFICATION_ENTER_TREE: { @@ -140,15 +135,14 @@ void Node::_notification(int p_notification) { set_process_unhandled_key_input(true); } - if (get_script_instance()->has_method(SceneStringNames::get_singleton()->_process)) { + if (GDVIRTUAL_IS_OVERRIDEN(_process)) { set_process(true); } - - if (get_script_instance()->has_method(SceneStringNames::get_singleton()->_physics_process)) { + if (GDVIRTUAL_IS_OVERRIDEN(_physics_process)) { set_physics_process(true); } - get_script_instance()->call(SceneStringNames::get_singleton()->_ready); + GDVIRTUAL_CALL(_ready); } if (data.filename.length()) { ERR_FAIL_COND(!is_inside_tree()); @@ -221,9 +215,7 @@ void Node::_propagate_enter_tree() { notification(NOTIFICATION_ENTER_TREE); - if (get_script_instance()) { - get_script_instance()->call(SceneStringNames::get_singleton()->_enter_tree); - } + GDVIRTUAL_CALL(_enter_tree); emit_signal(SceneStringNames::get_singleton()->tree_entered); @@ -269,9 +261,8 @@ void Node::_propagate_exit_tree() { data.blocked--; - if (get_script_instance()) { - get_script_instance()->call(SceneStringNames::get_singleton()->_exit_tree); - } + GDVIRTUAL_CALL(_exit_tree); + emit_signal(SceneStringNames::get_singleton()->tree_exiting); notification(NOTIFICATION_EXIT_TREE, true); @@ -2737,11 +2728,13 @@ void Node::_bind_methods() { ADD_GROUP("Editor Description", "editor_"); ADD_PROPERTY(PropertyInfo(Variant::STRING, "editor_description", PROPERTY_HINT_MULTILINE_TEXT, "", PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_INTERNAL), "set_editor_description", "get_editor_description"); - BIND_VMETHOD(MethodInfo("_process", PropertyInfo(Variant::FLOAT, "delta"))); - BIND_VMETHOD(MethodInfo("_physics_process", PropertyInfo(Variant::FLOAT, "delta"))); - BIND_VMETHOD(MethodInfo("_enter_tree")); - BIND_VMETHOD(MethodInfo("_exit_tree")); - BIND_VMETHOD(MethodInfo("_ready")); + GDVIRTUAL_BIND(_process, "delta"); + GDVIRTUAL_BIND(_physics_process, "delta"); + GDVIRTUAL_BIND(_enter_tree); + GDVIRTUAL_BIND(_exit_tree); + GDVIRTUAL_BIND(_ready); + GDVIRTUAL_BIND(_get_configuration_warnings); + BIND_VMETHOD(MethodInfo("_input", PropertyInfo(Variant::OBJECT, "event", PROPERTY_HINT_RESOURCE_TYPE, "InputEvent"))); BIND_VMETHOD(MethodInfo("_unhandled_input", PropertyInfo(Variant::OBJECT, "event", PROPERTY_HINT_RESOURCE_TYPE, "InputEvent"))); BIND_VMETHOD(MethodInfo("_unhandled_key_input", PropertyInfo(Variant::OBJECT, "event", PROPERTY_HINT_RESOURCE_TYPE, "InputEventKey"))); diff --git a/scene/main/node.h b/scene/main/node.h index 6616524866..8aa56aa97f 100644 --- a/scene/main/node.h +++ b/scene/main/node.h @@ -208,6 +208,12 @@ protected: void _set_owner_nocheck(Node *p_owner); void _set_name_nocheck(const StringName &p_name); + GDVIRTUAL1(_process, double) + GDVIRTUAL1(_physics_process, double) + GDVIRTUAL0(_enter_tree) + GDVIRTUAL0(_exit_tree) + GDVIRTUAL0(_ready) + GDVIRTUAL0RC(Vector<String>, _get_configuration_warnings) public: enum { // you can make your own, but don't use the same numbers as other notifications in other nodes diff --git a/scene/resources/skeleton_modification_2d.cpp b/scene/resources/skeleton_modification_2d.cpp index 2d5b42ddf4..e533fb054a 100644 --- a/scene/resources/skeleton_modification_2d.cpp +++ b/scene/resources/skeleton_modification_2d.cpp @@ -44,7 +44,7 @@ /////////////////////////////////////// void SkeletonModification2D::_execute(float p_delta) { - call("_execute", p_delta); + GDVIRTUAL_CALL(_execute, p_delta); if (!enabled) { return; @@ -59,11 +59,11 @@ void SkeletonModification2D::_setup_modification(SkeletonModificationStack2D *p_ WARN_PRINT("Could not setup modification with name " + get_name()); } - call("_setup_modification", p_stack); + GDVIRTUAL_CALL(_setup_modification, Ref<SkeletonModificationStack2D>(p_stack)); } void SkeletonModification2D::_draw_editor_gizmo() { - call("_draw_editor_gizmo"); + GDVIRTUAL_CALL(_draw_editor_gizmo); } void SkeletonModification2D::set_enabled(bool p_enabled) { @@ -228,9 +228,9 @@ bool SkeletonModification2D::get_editor_draw_gizmo() const { } void SkeletonModification2D::_bind_methods() { - BIND_VMETHOD(MethodInfo("_execute", PropertyInfo(Variant::FLOAT, "delta"))); - BIND_VMETHOD(MethodInfo("_setup_modification", PropertyInfo(Variant::OBJECT, "modification_stack", PROPERTY_HINT_RESOURCE_TYPE, "SkeletonModificationStack2D"))); - BIND_VMETHOD(MethodInfo("_draw_editor_gizmo")); + GDVIRTUAL_BIND(_execute, "delta"); + GDVIRTUAL_BIND(_setup_modification, "modification_stack") + GDVIRTUAL_BIND(_draw_editor_gizmo) ClassDB::bind_method(D_METHOD("set_enabled", "enabled"), &SkeletonModification2D::set_enabled); ClassDB::bind_method(D_METHOD("get_enabled"), &SkeletonModification2D::get_enabled); diff --git a/scene/resources/skeleton_modification_2d.h b/scene/resources/skeleton_modification_2d.h index 18633e55cb..aaddb9136e 100644 --- a/scene/resources/skeleton_modification_2d.h +++ b/scene/resources/skeleton_modification_2d.h @@ -57,6 +57,10 @@ protected: bool _print_execution_error(bool p_condition, String p_message); + GDVIRTUAL1(_execute, double) + GDVIRTUAL1(_setup_modification, Ref<SkeletonModificationStack2D>) + GDVIRTUAL0(_draw_editor_gizmo) + public: virtual void _execute(float _delta); virtual void _setup_modification(SkeletonModificationStack2D *p_stack); diff --git a/scene/resources/skeleton_modification_3d.cpp b/scene/resources/skeleton_modification_3d.cpp index 9306ee14cd..ee02ede2d5 100644 --- a/scene/resources/skeleton_modification_3d.cpp +++ b/scene/resources/skeleton_modification_3d.cpp @@ -32,11 +32,7 @@ #include "scene/3d/skeleton_3d.h" void SkeletonModification3D::_execute(real_t p_delta) { - if (get_script_instance()) { - if (get_script_instance()->has_method("execute")) { - get_script_instance()->call("execute", p_delta); - } - } + GDVIRTUAL_CALL(_execute, p_delta); if (!enabled) return; @@ -50,11 +46,7 @@ void SkeletonModification3D::_setup_modification(SkeletonModificationStack3D *p_ WARN_PRINT("Could not setup modification with name " + this->get_name()); } - if (get_script_instance()) { - if (get_script_instance()->has_method("setup_modification")) { - get_script_instance()->call("setup_modification", p_stack); - } - } + GDVIRTUAL_CALL(_setup_modification, Ref<SkeletonModificationStack3D>(p_stack)); } void SkeletonModification3D::set_enabled(bool p_enabled) { @@ -148,8 +140,8 @@ int SkeletonModification3D::get_execution_mode() const { } void SkeletonModification3D::_bind_methods() { - BIND_VMETHOD(MethodInfo("_execute", PropertyInfo(Variant::FLOAT, "delta"))); - BIND_VMETHOD(MethodInfo("_setup_modification", PropertyInfo(Variant::OBJECT, "modification_stack", PROPERTY_HINT_RESOURCE_TYPE, "SkeletonModificationStack3D"))); + GDVIRTUAL_BIND(_execute, "delta"); + GDVIRTUAL_BIND(_setup_modification, "modification_stack") ClassDB::bind_method(D_METHOD("set_enabled", "enabled"), &SkeletonModification3D::set_enabled); ClassDB::bind_method(D_METHOD("get_enabled"), &SkeletonModification3D::get_enabled); diff --git a/scene/resources/skeleton_modification_3d.h b/scene/resources/skeleton_modification_3d.h index 94ab0bf32c..fb1f3d33d1 100644 --- a/scene/resources/skeleton_modification_3d.h +++ b/scene/resources/skeleton_modification_3d.h @@ -53,6 +53,9 @@ protected: bool _print_execution_error(bool p_condition, String p_message); + GDVIRTUAL1(_execute, double) + GDVIRTUAL1(_setup_modification, Ref<SkeletonModificationStack3D>) + public: virtual void _execute(real_t p_delta); virtual void _setup_modification(SkeletonModificationStack3D *p_stack); diff --git a/scene/resources/syntax_highlighter.cpp b/scene/resources/syntax_highlighter.cpp index 173ce2adce..e1c5ebb005 100644 --- a/scene/resources/syntax_highlighter.cpp +++ b/scene/resources/syntax_highlighter.cpp @@ -43,12 +43,8 @@ Dictionary SyntaxHighlighter::get_line_syntax_highlighting(int p_line) { return color_map; } - ScriptInstance *si = get_script_instance(); - if (si && si->has_method("_get_line_syntax_highlighting")) { - color_map = si->call("_get_line_syntax_highlighting", p_line); - } else { - color_map = _get_line_syntax_highlighting(p_line); - } + GDVIRTUAL_CALL(_get_line_syntax_highlighting, p_line, color_map); + highlighting_cache[p_line] = color_map; return color_map; } @@ -69,9 +65,7 @@ void SyntaxHighlighter::_lines_edited_from(int p_from_line, int p_to_line) { void SyntaxHighlighter::clear_highlighting_cache() { highlighting_cache.clear(); - ScriptInstance *si = get_script_instance(); - if (si && si->has_method("_clear_highlighting_cache")) { - si->call("_clear_highlighting_cache"); + if (GDVIRTUAL_CALL(_clear_highlighting_cache)) { return; } _clear_highlighting_cache(); @@ -83,9 +77,7 @@ void SyntaxHighlighter::update_cache() { if (text_edit == nullptr) { return; } - ScriptInstance *si = get_script_instance(); - if (si && si->has_method("_update_cache")) { - si->call("_update_cache"); + if (GDVIRTUAL_CALL(_update_cache)) { return; } _update_cache(); @@ -115,9 +107,9 @@ void SyntaxHighlighter::_bind_methods() { ClassDB::bind_method(D_METHOD("clear_highlighting_cache"), &SyntaxHighlighter::clear_highlighting_cache); ClassDB::bind_method(D_METHOD("get_text_edit"), &SyntaxHighlighter::get_text_edit); - BIND_VMETHOD(MethodInfo(Variant::DICTIONARY, "_get_line_syntax_highlighting", PropertyInfo(Variant::INT, "line"))); - BIND_VMETHOD(MethodInfo("_clear_highlighting_cache")); - BIND_VMETHOD(MethodInfo("_update_cache")); + GDVIRTUAL_BIND(_get_line_syntax_highlighting, "line") + GDVIRTUAL_BIND(_clear_highlighting_cache) + GDVIRTUAL_BIND(_update_cache) } //////////////////////////////////////////////////////////////////////////////// @@ -130,7 +122,7 @@ static bool _is_hex_symbol(char32_t c) { return ((c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F')); } -Dictionary CodeHighlighter::_get_line_syntax_highlighting(int p_line) { +Dictionary CodeHighlighter::_get_line_syntax_highlighting_impl(int p_line) { Dictionary color_map; bool prev_is_char = false; diff --git a/scene/resources/syntax_highlighter.h b/scene/resources/syntax_highlighter.h index f3964b0c8f..0fe39ccff6 100644 --- a/scene/resources/syntax_highlighter.h +++ b/scene/resources/syntax_highlighter.h @@ -32,6 +32,8 @@ #define SYNTAX_HIGHLIGHTER_H #include "core/io/resource.h" +#include "core/object/gdvirtual.gen.inc" +#include "core/object/script_language.h" class TextEdit; @@ -48,9 +50,12 @@ protected: static void _bind_methods(); + GDVIRTUAL1RC(Dictionary, _get_line_syntax_highlighting, int) + GDVIRTUAL0(_clear_highlighting_cache) + GDVIRTUAL0(_update_cache) public: Dictionary get_line_syntax_highlighting(int p_line); - virtual Dictionary _get_line_syntax_highlighting(int p_line) { return Dictionary(); } + virtual Dictionary _get_line_syntax_highlighting_impl(int p_line) { return Dictionary(); } void clear_highlighting_cache(); virtual void _clear_highlighting_cache() {} @@ -93,7 +98,7 @@ protected: static void _bind_methods(); public: - virtual Dictionary _get_line_syntax_highlighting(int p_line) override; + virtual Dictionary _get_line_syntax_highlighting_impl(int p_line) override; virtual void _clear_highlighting_cache() override; virtual void _update_cache() override; diff --git a/scene/resources/visual_shader.cpp b/scene/resources/visual_shader.cpp index b00dcca004..a7f99a2113 100644 --- a/scene/resources/visual_shader.cpp +++ b/scene/resources/visual_shader.cpp @@ -261,54 +261,47 @@ VisualShaderNode::VisualShaderNode() { ///////////////////////////////////////////////////////// void VisualShaderNodeCustom::update_ports() { - ERR_FAIL_COND(!get_script_instance()); + { + input_ports.clear(); + int input_port_count; + if (GDVIRTUAL_CALL(_get_input_port_count, input_port_count)) { + for (int i = 0; i < input_port_count; i++) { + Port port; + if (!GDVIRTUAL_CALL(_get_input_port_name, i, port.name)) { + port.name = "in" + itos(i); + } + if (!GDVIRTUAL_CALL(_get_input_port_type, i, port.type)) { + port.type = (int)PortType::PORT_TYPE_SCALAR; + } - input_ports.clear(); - if (get_script_instance()->has_method("_get_input_port_count")) { - int input_port_count = (int)get_script_instance()->call("_get_input_port_count"); - bool has_name = get_script_instance()->has_method("_get_input_port_name"); - bool has_type = get_script_instance()->has_method("_get_input_port_type"); - for (int i = 0; i < input_port_count; i++) { - Port port; - if (has_name) { - port.name = (String)get_script_instance()->call("_get_input_port_name", i); - } else { - port.name = "in" + itos(i); + input_ports.push_back(port); } - if (has_type) { - port.type = (int)get_script_instance()->call("_get_input_port_type", i); - } else { - port.type = (int)PortType::PORT_TYPE_SCALAR; - } - input_ports.push_back(port); } } - output_ports.clear(); - if (get_script_instance()->has_method("_get_output_port_count")) { - int output_port_count = (int)get_script_instance()->call("_get_output_port_count"); - bool has_name = get_script_instance()->has_method("_get_output_port_name"); - bool has_type = get_script_instance()->has_method("_get_output_port_type"); - for (int i = 0; i < output_port_count; i++) { - Port port; - if (has_name) { - port.name = (String)get_script_instance()->call("_get_output_port_name", i); - } else { - port.name = "out" + itos(i); - } - if (has_type) { - port.type = (int)get_script_instance()->call("_get_output_port_type", i); - } else { - port.type = (int)PortType::PORT_TYPE_SCALAR; + + { + output_ports.clear(); + int output_port_count; + if (GDVIRTUAL_CALL(_get_output_port_count, output_port_count)) { + for (int i = 0; i < output_port_count; i++) { + Port port; + if (!GDVIRTUAL_CALL(_get_output_port_name, i, port.name)) { + port.name = "out" + itos(i); + } + if (!GDVIRTUAL_CALL(_get_output_port_type, i, port.type)) { + port.type = (int)PortType::PORT_TYPE_SCALAR; + } + + output_ports.push_back(port); } - output_ports.push_back(port); } } } String VisualShaderNodeCustom::get_caption() const { - ERR_FAIL_COND_V(!get_script_instance(), ""); - if (get_script_instance()->has_method("_get_name")) { - return (String)get_script_instance()->call("_get_name"); + String ret; + if (GDVIRTUAL_CALL(_get_name, ret)) { + return ret; } return "Unnamed"; } @@ -342,9 +335,8 @@ String VisualShaderNodeCustom::get_output_port_name(int p_port) const { } String VisualShaderNodeCustom::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const { - ERR_FAIL_COND_V(!get_script_instance(), ""); - ERR_FAIL_COND_V(!get_script_instance()->has_method("_get_code"), ""); - Array input_vars; + ERR_FAIL_COND_V(!GDVIRTUAL_IS_OVERRIDEN(_get_code), ""); + Vector<String> input_vars; for (int i = 0; i < get_input_port_count(); i++) { input_vars.push_back(p_input_vars[i]); } @@ -353,7 +345,8 @@ String VisualShaderNodeCustom::generate_code(Shader::Mode p_mode, VisualShader:: output_vars.push_back(p_output_vars[i]); } String code = " {\n"; - String _code = (String)get_script_instance()->call("_get_code", input_vars, output_vars, (int)p_mode, (int)p_type); + String _code; + GDVIRTUAL_CALL(_get_code, input_vars, output_vars, (int)p_mode, (int)p_type, _code); bool nend = _code.ends_with("\n"); _code = _code.insert(0, " "); _code = _code.replace("\n", "\n "); @@ -369,10 +362,10 @@ String VisualShaderNodeCustom::generate_code(Shader::Mode p_mode, VisualShader:: } String VisualShaderNodeCustom::generate_global_per_node(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const { - ERR_FAIL_COND_V(!get_script_instance(), ""); - if (get_script_instance()->has_method("_get_global_code")) { + String ret; + if (GDVIRTUAL_CALL(_get_global_code, (int)p_mode, ret)) { String code = "// " + get_caption() + "\n"; - code += (String)get_script_instance()->call("_get_global_code", (int)p_mode); + code += ret; code += "\n"; return code; } @@ -416,19 +409,19 @@ void VisualShaderNodeCustom::_set_initialized(bool p_enabled) { } void VisualShaderNodeCustom::_bind_methods() { - BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_name")); - BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_description")); - BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_category")); - BIND_VMETHOD(MethodInfo(Variant::INT, "_get_return_icon_type")); - BIND_VMETHOD(MethodInfo(Variant::INT, "_get_input_port_count")); - BIND_VMETHOD(MethodInfo(Variant::INT, "_get_input_port_type", PropertyInfo(Variant::INT, "port"))); - BIND_VMETHOD(MethodInfo(Variant::STRING_NAME, "_get_input_port_name", PropertyInfo(Variant::INT, "port"))); - BIND_VMETHOD(MethodInfo(Variant::INT, "_get_output_port_count")); - BIND_VMETHOD(MethodInfo(Variant::INT, "_get_output_port_type", PropertyInfo(Variant::INT, "port"))); - BIND_VMETHOD(MethodInfo(Variant::STRING_NAME, "_get_output_port_name", PropertyInfo(Variant::INT, "port"))); - BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_code", PropertyInfo(Variant::ARRAY, "input_vars"), PropertyInfo(Variant::ARRAY, "output_vars"), PropertyInfo(Variant::INT, "mode"), PropertyInfo(Variant::INT, "type"))); - BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_global_code", PropertyInfo(Variant::INT, "mode"))); - BIND_VMETHOD(MethodInfo(Variant::BOOL, "_is_highend")); + GDVIRTUAL_BIND(_get_name); + GDVIRTUAL_BIND(_get_description); + GDVIRTUAL_BIND(_get_category); + GDVIRTUAL_BIND(_get_return_icon_type); + GDVIRTUAL_BIND(_get_input_port_count); + GDVIRTUAL_BIND(_get_input_port_type, "port"); + GDVIRTUAL_BIND(_get_input_port_name, "port"); + GDVIRTUAL_BIND(_get_output_port_count); + GDVIRTUAL_BIND(_get_output_port_type, "port"); + GDVIRTUAL_BIND(_get_output_port_name, "port"); + GDVIRTUAL_BIND(_get_code, "input_vars", "output_vars", "mode", "type"); + GDVIRTUAL_BIND(_get_global_code, "mode"); + GDVIRTUAL_BIND(_is_highend); ClassDB::bind_method(D_METHOD("_set_initialized", "enabled"), &VisualShaderNodeCustom::_set_initialized); ClassDB::bind_method(D_METHOD("_is_initialized"), &VisualShaderNodeCustom::_is_initialized); diff --git a/scene/resources/visual_shader.h b/scene/resources/visual_shader.h index 31651318ae..b3efac02aa 100644 --- a/scene/resources/visual_shader.h +++ b/scene/resources/visual_shader.h @@ -314,6 +314,20 @@ protected: virtual void remove_input_port_default_value(int p_port) override; virtual void clear_default_input_values() override; + GDVIRTUAL0RC(String, _get_name) + GDVIRTUAL0RC(String, _get_description) + GDVIRTUAL0RC(String, _get_category) + GDVIRTUAL0RC(int, _get_return_icon_type) + GDVIRTUAL0RC(int, _get_input_port_count) + GDVIRTUAL1RC(int, _get_input_port_type, int) + GDVIRTUAL1RC(String, _get_input_port_name, int) + GDVIRTUAL0RC(int, _get_output_port_count) + GDVIRTUAL1RC(int, _get_output_port_type, int) + GDVIRTUAL1RC(String, _get_output_port_name, int) + GDVIRTUAL4RC(String, _get_code, Vector<String>, TypedArray<String>, int, int) + GDVIRTUAL1RC(String, _get_global_code, int) + GDVIRTUAL0RC(bool, _is_highend) + protected: void _set_input_port_default_value(int p_port, const Variant &p_value); |