diff options
Diffstat (limited to 'core/object')
-rw-r--r-- | core/object/callable_method_pointer.h | 2 | ||||
-rw-r--r-- | core/object/class_db.h | 4 | ||||
-rw-r--r-- | core/object/make_virtuals.py | 2 | ||||
-rw-r--r-- | core/object/message_queue.h | 4 | ||||
-rw-r--r-- | core/object/method_bind.h | 121 | ||||
-rw-r--r-- | core/object/object.cpp | 10 | ||||
-rw-r--r-- | core/object/object.h | 8 | ||||
-rw-r--r-- | core/object/ref_counted.h | 2 | ||||
-rw-r--r-- | core/object/script_language.cpp | 2 | ||||
-rw-r--r-- | core/object/script_language.h | 47 | ||||
-rw-r--r-- | core/object/script_language_extension.cpp | 5 | ||||
-rw-r--r-- | core/object/script_language_extension.h | 3 | ||||
-rw-r--r-- | core/object/undo_redo.cpp | 18 | ||||
-rw-r--r-- | core/object/undo_redo.h | 4 |
14 files changed, 148 insertions, 84 deletions
diff --git a/core/object/callable_method_pointer.h b/core/object/callable_method_pointer.h index 3cd9ad3819..577d4b9fbd 100644 --- a/core/object/callable_method_pointer.h +++ b/core/object/callable_method_pointer.h @@ -38,7 +38,7 @@ #include "core/variant/callable.h" class CallableCustomMethodPointerBase : public CallableCustom { - uint32_t *comp_ptr; + uint32_t *comp_ptr = nullptr; uint32_t comp_size; uint32_t h; #ifdef DEBUG_METHODS_ENABLED diff --git a/core/object/class_db.h b/core/object/class_db.h index b8a4b3ea2b..5da8523743 100644 --- a/core/object/class_db.h +++ b/core/object/class_db.h @@ -85,8 +85,8 @@ public: int index; StringName setter; StringName getter; - MethodBind *_setptr; - MethodBind *_getptr; + MethodBind *_setptr = nullptr; + MethodBind *_getptr = nullptr; Variant::Type type; }; diff --git a/core/object/make_virtuals.py b/core/object/make_virtuals.py index 64ee5940b0..c18d70d9f6 100644 --- a/core/object/make_virtuals.py +++ b/core/object/make_virtuals.py @@ -28,7 +28,7 @@ _FORCE_INLINE_ bool _gdvirtual_##m_name##_call($CALLARGS) $CONST { \\ }\\ \\ if (required) {\\ - ERR_PRINT_ONCE("Required virtual method: "+get_class()+"::" + #m_name + " must be overriden before calling.");\\ + ERR_PRINT_ONCE("Required virtual method " + get_class() + "::" + #m_name + " must be overridden before calling.");\\ $RVOID\\ }\\ \\ diff --git a/core/object/message_queue.h b/core/object/message_queue.h index eaab01d0aa..2219cdb8f6 100644 --- a/core/object/message_queue.h +++ b/core/object/message_queue.h @@ -62,10 +62,10 @@ class MessageQueue { }; }; - uint8_t *buffer; + uint8_t *buffer = nullptr; uint32_t buffer_end = 0; uint32_t buffer_max_used = 0; - uint32_t buffer_size; + uint32_t buffer_size = 0; void _call_function(const Callable &p_callable, const Variant *p_args, int p_argcount, bool p_show_error); diff --git a/core/object/method_bind.h b/core/object/method_bind.h index 1518c8d793..bde6cba199 100644 --- a/core/object/method_bind.h +++ b/core/object/method_bind.h @@ -143,21 +143,20 @@ public: virtual ~MethodBind(); }; -template <class T> -class MethodBindVarArg : public MethodBind { -public: - typedef Variant (T::*NativeCall)(const Variant **, int, Callable::CallError &); - +// MethodBindVarArg base CRTP +template <class Derived, class T, class R, bool should_returns> +class MethodBindVarArgBase : public MethodBind { protected: - NativeCall call_method = nullptr; - MethodInfo arguments; + R(T::*method) + (const Variant **, int, Callable::CallError &); + MethodInfo method_info; public: virtual PropertyInfo _gen_argument_type_info(int p_arg) const { if (p_arg < 0) { - return arguments.return_val; - } else if (p_arg < arguments.arguments.size()) { - return arguments.arguments[p_arg]; + return _gen_return_type_info(); + } else if (p_arg < method_info.arguments.size()) { + return method_info.arguments[p_arg]; } else { return PropertyInfo(Variant::NIL, "arg_" + itos(p_arg), PROPERTY_HINT_NONE, String(), PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_NIL_IS_VARIANT); } @@ -173,24 +172,31 @@ public: } #endif - virtual Variant call(Object *p_object, const Variant **p_args, int p_arg_count, Callable::CallError &r_error) { - T *instance = static_cast<T *>(p_object); - return (instance->*call_method)(p_args, p_arg_count, r_error); + virtual void ptrcall(Object *p_object, const void **p_args, void *r_ret) { + ERR_FAIL(); // Can't call. } - void set_method_info(const MethodInfo &p_info, bool p_return_nil_is_variant) { - set_argument_count(p_info.arguments.size()); - Variant::Type *at = memnew_arr(Variant::Type, p_info.arguments.size() + 1); - at[0] = p_info.return_val.type; - if (p_info.arguments.size()) { + virtual bool is_const() const { return false; } + + virtual bool is_vararg() const { return true; } + + MethodBindVarArgBase( + R (T::*p_method)(const Variant **, int, Callable::CallError &), + const MethodInfo &p_method_info, + bool p_return_nil_is_variant) : + method(p_method), method_info(p_method_info) { + set_argument_count(method_info.arguments.size()); + Variant::Type *at = memnew_arr(Variant::Type, method_info.arguments.size() + 1); + at[0] = _gen_return_type_info().type; + if (method_info.arguments.size()) { #ifdef DEBUG_METHODS_ENABLED Vector<StringName> names; - names.resize(p_info.arguments.size()); + names.resize(method_info.arguments.size()); #endif - for (int i = 0; i < p_info.arguments.size(); i++) { - at[i + 1] = p_info.arguments[i].type; + for (int i = 0; i < method_info.arguments.size(); i++) { + at[i + 1] = method_info.arguments[i].type; #ifdef DEBUG_METHODS_ENABLED - names.write[i] = p_info.arguments[i].name; + names.write[i] = method_info.arguments[i].name; #endif } @@ -199,31 +205,76 @@ public: #endif } argument_types = at; - arguments = p_info; if (p_return_nil_is_variant) { - arguments.return_val.usage |= PROPERTY_USAGE_NIL_IS_VARIANT; + method_info.return_val.usage |= PROPERTY_USAGE_NIL_IS_VARIANT; } + + _set_returns(should_returns); } - virtual void ptrcall(Object *p_object, const void **p_args, void *r_ret) { - ERR_FAIL(); // Can't call. +private: + PropertyInfo _gen_return_type_info() const { + return Derived::_gen_return_type_info_impl(); } +}; - void set_method(NativeCall p_method) { call_method = p_method; } - virtual bool is_const() const { return false; } +// variadic, no return +template <class T> +class MethodBindVarArgT : public MethodBindVarArgBase<MethodBindVarArgT<T>, T, void, false> { + friend class MethodBindVarArgBase<MethodBindVarArgT<T>, T, void, false>; - virtual bool is_vararg() const { return true; } +public: + virtual Variant call(Object *p_object, const Variant **p_args, int p_arg_count, Callable::CallError &r_error) { + (static_cast<T *>(p_object)->*MethodBindVarArgBase<MethodBindVarArgT<T>, T, void, false>::method)(p_args, p_arg_count, r_error); + return {}; + } - MethodBindVarArg() { - _set_returns(true); + MethodBindVarArgT( + void (T::*p_method)(const Variant **, int, Callable::CallError &), + const MethodInfo &p_method_info, + bool p_return_nil_is_variant) : + MethodBindVarArgBase<MethodBindVarArgT<T>, T, void, false>(p_method, p_method_info, p_return_nil_is_variant) { + } + +private: + static PropertyInfo _gen_return_type_info_impl() { + return {}; } }; template <class T> -MethodBind *create_vararg_method_bind(Variant (T::*p_method)(const Variant **, int, Callable::CallError &), const MethodInfo &p_info, bool p_return_nil_is_variant) { - MethodBindVarArg<T> *a = memnew((MethodBindVarArg<T>)); - a->set_method(p_method); - a->set_method_info(p_info, p_return_nil_is_variant); +MethodBind *create_vararg_method_bind(void (T::*p_method)(const Variant **, int, Callable::CallError &), const MethodInfo &p_info, bool p_return_nil_is_variant) { + MethodBind *a = memnew((MethodBindVarArgT<T>)(p_method, p_info, p_return_nil_is_variant)); + a->set_instance_class(T::get_class_static()); + return a; +} + +// variadic, return +template <class T, class R> +class MethodBindVarArgTR : public MethodBindVarArgBase<MethodBindVarArgTR<T, R>, T, R, true> { + friend class MethodBindVarArgBase<MethodBindVarArgTR<T, R>, T, R, true>; + +public: + virtual Variant call(Object *p_object, const Variant **p_args, int p_arg_count, Callable::CallError &r_error) { + return (static_cast<T *>(p_object)->*MethodBindVarArgBase<MethodBindVarArgTR<T, R>, T, R, true>::method)(p_args, p_arg_count, r_error); + } + + MethodBindVarArgTR( + R (T::*p_method)(const Variant **, int, Callable::CallError &), + const MethodInfo &p_info, + bool p_return_nil_is_variant) : + MethodBindVarArgBase<MethodBindVarArgTR<T, R>, T, R, true>(p_method, p_info, p_return_nil_is_variant) { + } + +private: + static PropertyInfo _gen_return_type_info_impl() { + return GetTypeInfo<R>::get_class_info(); + } +}; + +template <class T, class R> +MethodBind *create_vararg_method_bind(R (T::*p_method)(const Variant **, int, Callable::CallError &), const MethodInfo &p_info, bool p_return_nil_is_variant) { + MethodBind *a = memnew((MethodBindVarArgTR<T, R>)(p_method, p_info, p_return_nil_is_variant)); a->set_instance_class(T::get_class_static()); return a; } diff --git a/core/object/object.cpp b/core/object/object.cpp index 0a7879c774..c2cd42ff91 100644 --- a/core/object/object.cpp +++ b/core/object/object.cpp @@ -1028,15 +1028,15 @@ struct _ObjectSignalDisconnectData { Callable callable; }; -Variant Object::_emit_signal(const Variant **p_args, int p_argcount, Callable::CallError &r_error) { +Error Object::_emit_signal(const Variant **p_args, int p_argcount, Callable::CallError &r_error) { r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; - ERR_FAIL_COND_V(p_argcount < 1, Variant()); + ERR_FAIL_COND_V(p_argcount < 1, Error::ERR_INVALID_PARAMETER); if (p_args[0]->get_type() != Variant::STRING_NAME && p_args[0]->get_type() != Variant::STRING) { r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; r_error.argument = 0; r_error.expected = Variant::STRING_NAME; - ERR_FAIL_COND_V(p_args[0]->get_type() != Variant::STRING_NAME && p_args[0]->get_type() != Variant::STRING, Variant()); + ERR_FAIL_COND_V(p_args[0]->get_type() != Variant::STRING_NAME && p_args[0]->get_type() != Variant::STRING, Error::ERR_INVALID_PARAMETER); } r_error.error = Callable::CallError::CALL_OK; @@ -1050,9 +1050,7 @@ Variant Object::_emit_signal(const Variant **p_args, int p_argcount, Callable::C args = &p_args[1]; } - emit_signalp(signal, args, argc); - - return Variant(); + return emit_signalp(signal, args, argc); } Error Object::emit_signalp(const StringName &p_name, const Variant **p_args, int p_argcount) { diff --git a/core/object/object.h b/core/object/object.h index f58a79b49c..eeef03dcb9 100644 --- a/core/object/object.h +++ b/core/object/object.h @@ -522,7 +522,7 @@ private: void _add_user_signal(const String &p_name, const Array &p_args = Array()); bool _has_user_signal(const StringName &p_name) const; - Variant _emit_signal(const Variant **p_args, int p_argcount, Callable::CallError &r_error); + Error _emit_signal(const Variant **p_args, int p_argcount, Callable::CallError &r_error); Array _get_signal_list() const; Array _get_signal_connection_list(const String &p_signal) const; Array _get_incoming_connections() const; @@ -538,8 +538,8 @@ private: std::mutex _instance_binding_mutex; struct InstanceBinding { - void *binding; - void *token; + void *binding = nullptr; + void *token = nullptr; GDNativeInstanceBindingFreeCallback free_callback = nullptr; GDNativeInstanceBindingReferenceCallback reference_callback = nullptr; }; @@ -849,7 +849,7 @@ class ObjectDB { uint64_t validator : OBJECTDB_VALIDATOR_BITS; uint64_t next_free : OBJECTDB_SLOT_MAX_COUNT_BITS; uint64_t is_ref_counted : 1; - Object *object; + Object *object = nullptr; }; static SpinLock spin_lock; diff --git a/core/object/ref_counted.h b/core/object/ref_counted.h index 8eb1c97cce..dcacf19890 100644 --- a/core/object/ref_counted.h +++ b/core/object/ref_counted.h @@ -261,7 +261,7 @@ struct PtrToArg<Ref<T>> { typedef Ref<T> EncodeT; _FORCE_INLINE_ static void encode(Ref<T> p_val, const void *p_ptr) { - *(Ref<RefCounted> *)p_ptr = p_val; + *(const_cast<Ref<RefCounted> *>(reinterpret_cast<const Ref<RefCounted> *>(p_ptr))) = p_val; } }; diff --git a/core/object/script_language.cpp b/core/object/script_language.cpp index 11440c37fe..a5d25bf533 100644 --- a/core/object/script_language.cpp +++ b/core/object/script_language.cpp @@ -144,7 +144,7 @@ void ScriptServer::register_language(ScriptLanguage *p_language) { _languages[_language_count++] = p_language; } -void ScriptServer::unregister_language(ScriptLanguage *p_language) { +void ScriptServer::unregister_language(const ScriptLanguage *p_language) { for (int i = 0; i < _language_count; i++) { if (_languages[i] == p_language) { _language_count--; diff --git a/core/object/script_language.h b/core/object/script_language.h index 6161a0fc0f..69002c81f4 100644 --- a/core/object/script_language.h +++ b/core/object/script_language.h @@ -68,7 +68,7 @@ public: _FORCE_INLINE_ static int get_language_count() { return _language_count; } static ScriptLanguage *get_language(int p_idx); static void register_language(ScriptLanguage *p_language); - static void unregister_language(ScriptLanguage *p_language); + static void unregister_language(const ScriptLanguage *p_language); static void set_reload_scripts_on_save(bool p_enable); static bool is_reload_scripts_on_save_enabled(); @@ -311,6 +311,13 @@ public: CODE_COMPLETION_KIND_MAX }; + enum CodeCompletionLocation { + LOCATION_LOCAL = 0, + LOCATION_PARENT_MASK = 1 << 8, + LOCATION_OTHER_USER_CODE = 1 << 9, + LOCATION_OTHER = 1 << 10, + }; + struct CodeCompletionOption { CodeCompletionKind kind = CODE_COMPLETION_KIND_PLAIN_TEXT; String display; @@ -319,13 +326,15 @@ public: RES icon; Variant default_value; Vector<Pair<int, int>> matches; + int location = LOCATION_OTHER; CodeCompletionOption() {} - CodeCompletionOption(const String &p_text, CodeCompletionKind p_kind) { + CodeCompletionOption(const String &p_text, CodeCompletionKind p_kind, int p_location = LOCATION_OTHER) { display = p_text; insert_text = p_text; kind = p_kind; + location = p_location; } }; @@ -421,42 +430,42 @@ public: extern uint8_t script_encryption_key[32]; class PlaceHolderScriptInstance : public ScriptInstance { - Object *owner; + Object *owner = nullptr; List<PropertyInfo> properties; Map<StringName, Variant> values; Map<StringName, Variant> constants; - ScriptLanguage *language; + ScriptLanguage *language = nullptr; Ref<Script> script; public: - virtual bool set(const StringName &p_name, const Variant &p_value); - virtual bool get(const StringName &p_name, Variant &r_ret) const; - virtual void get_property_list(List<PropertyInfo> *p_properties) const; - virtual Variant::Type get_property_type(const StringName &p_name, bool *r_is_valid = nullptr) const; + virtual bool set(const StringName &p_name, const Variant &p_value) override; + virtual bool get(const StringName &p_name, Variant &r_ret) const override; + virtual void get_property_list(List<PropertyInfo> *p_properties) const override; + virtual Variant::Type get_property_type(const StringName &p_name, bool *r_is_valid = nullptr) const override; - virtual void get_method_list(List<MethodInfo> *p_list) const; - virtual bool has_method(const StringName &p_method) const; + virtual void get_method_list(List<MethodInfo> *p_list) const override; + virtual bool has_method(const StringName &p_method) const override; - virtual Variant callp(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error) { + virtual Variant callp(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error) override { r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD; return Variant(); } - virtual void notification(int p_notification) {} + virtual void notification(int p_notification) override {} - virtual Ref<Script> get_script() const { return script; } + virtual Ref<Script> get_script() const override { return script; } - virtual ScriptLanguage *get_language() { return language; } + virtual ScriptLanguage *get_language() override { return language; } - Object *get_owner() { return owner; } + Object *get_owner() override { return owner; } void update(const List<PropertyInfo> &p_properties, const Map<StringName, Variant> &p_values); //likely changed in editor - virtual bool is_placeholder() const { return true; } + virtual bool is_placeholder() const override { return true; } - virtual void property_set_fallback(const StringName &p_name, const Variant &p_value, bool *r_valid = nullptr); - virtual Variant property_get_fallback(const StringName &p_name, bool *r_valid = nullptr); + virtual void property_set_fallback(const StringName &p_name, const Variant &p_value, bool *r_valid = nullptr) override; + virtual Variant property_get_fallback(const StringName &p_name, bool *r_valid = nullptr) override; - virtual const Vector<Multiplayer::RPCConfig> get_rpc_methods() const { return Vector<Multiplayer::RPCConfig>(); } + virtual const Vector<Multiplayer::RPCConfig> get_rpc_methods() const override { return Vector<Multiplayer::RPCConfig>(); } PlaceHolderScriptInstance(ScriptLanguage *p_language, Ref<Script> p_script, Object *p_owner); ~PlaceHolderScriptInstance(); diff --git a/core/object/script_language_extension.cpp b/core/object/script_language_extension.cpp index bf0966c803..21d7685674 100644 --- a/core/object/script_language_extension.cpp +++ b/core/object/script_language_extension.cpp @@ -161,6 +161,11 @@ void ScriptLanguageExtension::_bind_methods() { BIND_ENUM_CONSTANT(LOOKUP_RESULT_CLASS_TBD_GLOBALSCOPE); BIND_ENUM_CONSTANT(LOOKUP_RESULT_MAX); + BIND_ENUM_CONSTANT(LOCATION_LOCAL); + BIND_ENUM_CONSTANT(LOCATION_PARENT_MASK); + BIND_ENUM_CONSTANT(LOCATION_OTHER_USER_CODE); + BIND_ENUM_CONSTANT(LOCATION_OTHER); + BIND_ENUM_CONSTANT(CODE_COMPLETION_KIND_CLASS); BIND_ENUM_CONSTANT(CODE_COMPLETION_KIND_FUNCTION); BIND_ENUM_CONSTANT(CODE_COMPLETION_KIND_SIGNAL); diff --git a/core/object/script_language_extension.h b/core/object/script_language_extension.h index b9ec79da26..40f18ab30d 100644 --- a/core/object/script_language_extension.h +++ b/core/object/script_language_extension.h @@ -387,6 +387,8 @@ public: option.icon = op["icon"]; ERR_CONTINUE(!op.has("default_value")); option.default_value = op["default_value"]; + ERR_CONTINUE(!op.has("location")); + option.location = op["location"]; if (op.has("matches")) { PackedInt32Array matches = op["matches"]; ERR_CONTINUE(matches.size() & 1); @@ -639,6 +641,7 @@ public: VARIANT_ENUM_CAST(ScriptLanguageExtension::LookupResultType) VARIANT_ENUM_CAST(ScriptLanguageExtension::CodeCompletionKind) +VARIANT_ENUM_CAST(ScriptLanguageExtension::CodeCompletionLocation) class ScriptInstanceExtension : public ScriptInstance { public: diff --git a/core/object/undo_redo.cpp b/core/object/undo_redo.cpp index ee8eb97a93..d3c48853f1 100644 --- a/core/object/undo_redo.cpp +++ b/core/object/undo_redo.cpp @@ -444,25 +444,25 @@ UndoRedo::~UndoRedo() { clear_history(); } -Variant UndoRedo::_add_do_method(const Variant **p_args, int p_argcount, Callable::CallError &r_error) { +void UndoRedo::_add_do_method(const Variant **p_args, int p_argcount, Callable::CallError &r_error) { if (p_argcount < 2) { r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; r_error.argument = 0; - return Variant(); + return; } if (p_args[0]->get_type() != Variant::OBJECT) { r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; r_error.argument = 0; r_error.expected = Variant::OBJECT; - return Variant(); + return; } if (p_args[1]->get_type() != Variant::STRING_NAME && p_args[1]->get_type() != Variant::STRING) { r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; r_error.argument = 1; r_error.expected = Variant::STRING_NAME; - return Variant(); + return; } r_error.error = Callable::CallError::CALL_OK; @@ -471,28 +471,27 @@ Variant UndoRedo::_add_do_method(const Variant **p_args, int p_argcount, Callabl StringName method = *p_args[1]; add_do_methodp(object, method, p_args + 2, p_argcount - 2); - return Variant(); } -Variant UndoRedo::_add_undo_method(const Variant **p_args, int p_argcount, Callable::CallError &r_error) { +void UndoRedo::_add_undo_method(const Variant **p_args, int p_argcount, Callable::CallError &r_error) { if (p_argcount < 2) { r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; r_error.argument = 0; - return Variant(); + return; } if (p_args[0]->get_type() != Variant::OBJECT) { r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; r_error.argument = 0; r_error.expected = Variant::OBJECT; - return Variant(); + return; } if (p_args[1]->get_type() != Variant::STRING_NAME && p_args[1]->get_type() != Variant::STRING) { r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; r_error.argument = 1; r_error.expected = Variant::STRING_NAME; - return Variant(); + return; } r_error.error = Callable::CallError::CALL_OK; @@ -501,7 +500,6 @@ Variant UndoRedo::_add_undo_method(const Variant **p_args, int p_argcount, Calla StringName method = *p_args[1]; add_undo_methodp(object, method, p_args + 2, p_argcount - 2); - return Variant(); } void UndoRedo::_bind_methods() { diff --git a/core/object/undo_redo.h b/core/object/undo_redo.h index ecd7a21167..63cf3e5cbe 100644 --- a/core/object/undo_redo.h +++ b/core/object/undo_redo.h @@ -46,8 +46,8 @@ public: }; typedef void (*CommitNotifyCallback)(void *p_ud, const String &p_name); - Variant _add_do_method(const Variant **p_args, int p_argcount, Callable::CallError &r_error); - Variant _add_undo_method(const Variant **p_args, int p_argcount, Callable::CallError &r_error); + void _add_do_method(const Variant **p_args, int p_argcount, Callable::CallError &r_error); + void _add_undo_method(const Variant **p_args, int p_argcount, Callable::CallError &r_error); typedef void (*MethodNotifyCallback)(void *p_ud, Object *p_base, const StringName &p_name, const Variant **p_args, int p_argcount); typedef void (*PropertyNotifyCallback)(void *p_ud, Object *p_base, const StringName &p_property, const Variant &p_value); |