diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/bind/core_bind.cpp | 2 | ||||
-rw-r--r-- | core/class_db.cpp | 29 | ||||
-rw-r--r-- | core/class_db.h | 2 | ||||
-rw-r--r-- | core/global_constants.cpp | 14 | ||||
-rw-r--r-- | core/image.cpp | 6 | ||||
-rw-r--r-- | core/image.h | 1 | ||||
-rw-r--r-- | core/io/marshalls.cpp | 4 | ||||
-rw-r--r-- | core/io/resource_format_binary.cpp | 23 | ||||
-rw-r--r-- | core/make_binders.py | 24 | ||||
-rw-r--r-- | core/method_bind.cpp | 46 | ||||
-rw-r--r-- | core/method_bind.h | 52 | ||||
-rw-r--r-- | core/object.cpp | 10 | ||||
-rw-r--r-- | core/object.h | 64 | ||||
-rw-r--r-- | core/os/input_event.cpp | 77 | ||||
-rw-r--r-- | core/os/input_event.h | 7 | ||||
-rw-r--r-- | core/os/os.cpp | 2 | ||||
-rw-r--r-- | core/ref_ptr.cpp | 2 | ||||
-rw-r--r-- | core/reference.cpp | 2 | ||||
-rw-r--r-- | core/reference.h | 20 | ||||
-rw-r--r-- | core/script_language.h | 2 | ||||
-rw-r--r-- | core/type_info.h | 85 | ||||
-rw-r--r-- | core/undo_redo.cpp | 28 | ||||
-rw-r--r-- | core/variant.cpp | 4 | ||||
-rw-r--r-- | core/variant_parser.cpp | 2 |
24 files changed, 313 insertions, 195 deletions
diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp index 5f534f63a8..7f4a83ed49 100644 --- a/core/bind/core_bind.cpp +++ b/core/bind/core_bind.cpp @@ -2354,7 +2354,7 @@ Variant _ClassDB::instance(const StringName &p_class) const { if (!obj) return Variant(); - Reference *r = obj->cast_to<Reference>(); + Reference *r = Object::cast_to<Reference>(obj); if (r) { return REF(r); } else { diff --git a/core/class_db.cpp b/core/class_db.cpp index 6cd7586a54..cd55219b53 100644 --- a/core/class_db.cpp +++ b/core/class_db.cpp @@ -538,9 +538,7 @@ void ClassDB::get_method_list(StringName p_class, List<MethodInfo> *p_methods, b minfo.arguments.push_back(method->get_argument_info(i)); } - if (method->get_argument_type(-1) != Variant::NIL) { - minfo.return_val = method->get_argument_info(-1); - } + minfo.return_val = method->get_return_info(); minfo.flags = method->get_hint_flags(); p_methods->push_back(minfo); @@ -600,14 +598,23 @@ void ClassDB::bind_integer_constant(const StringName &p_class, const StringName type->constant_map[p_name] = p_constant; #ifdef DEBUG_METHODS_ENABLED - List<StringName> *constants_list = type->enum_map.getptr(p_enum); - if (constants_list) { - constants_list->push_back(p_name); - } else { - List<StringName> new_list; - new_list.push_back(p_name); - type->enum_map[p_enum] = new_list; + String enum_name = p_enum; + if (enum_name!=String()) { + if (enum_name.find(".")!=-1) { + enum_name=enum_name.get_slicec('.',1); + } + + List<StringName> *constants_list = type->enum_map.getptr(enum_name); + + if (constants_list) { + constants_list->push_back(p_name); + } else { + List<StringName> new_list; + new_list.push_back(p_name); + type->enum_map[enum_name] = new_list; + } + } type->constant_order.push_back(p_name); @@ -680,7 +687,7 @@ StringName ClassDB::get_integer_constant_enum(const StringName &p_class, const S List<StringName> &constants_list = type->enum_map.get(*k); const List<StringName>::Element *found = constants_list.find(p_name); if (found) - return found->get(); + return *k; } if (p_no_inheritance) diff --git a/core/class_db.h b/core/class_db.h index 8d9192adcc..0943cd36cc 100644 --- a/core/class_db.h +++ b/core/class_db.h @@ -457,7 +457,7 @@ public: } type->method_map[p_name] = bind; #ifdef DEBUG_METHODS_ENABLED - bind->set_return_type("Variant"); +// bind->set_return_type("Variant"); type->method_order.push_back(p_name); #endif diff --git a/core/global_constants.cpp b/core/global_constants.cpp index d296b678b9..cd9a302ba6 100644 --- a/core/global_constants.cpp +++ b/core/global_constants.cpp @@ -45,15 +45,15 @@ struct _GlobalConstant { _GlobalConstant() {} #ifdef DEBUG_METHODS_ENABLED - _GlobalConstant(const StringName &p_enum_name, const char *p_name, int p_value) { - enum_name = p_enum_name; - name = p_name; - value = p_value; + _GlobalConstant(const StringName &p_enum_name, const char *p_name, int p_value) + : enum_name(p_enum_name), + name(p_name), + value(p_value) { } #else - _GlobalConstant(const char *p_name, int p_value) { - name = p_name; - value = p_value; + _GlobalConstant(const char *p_name, int p_value) + : name(p_name), + value(p_value) { } #endif }; diff --git a/core/image.cpp b/core/image.cpp index 91572e44e4..0f09fbc0c1 100644 --- a/core/image.cpp +++ b/core/image.cpp @@ -343,6 +343,11 @@ int Image::get_height() const { return height; } +Vector2 Image::get_size() const { + + return Vector2(width, height); +} + bool Image::has_mipmaps() const { return mipmaps; @@ -2215,6 +2220,7 @@ void Image::_bind_methods() { ClassDB::bind_method(D_METHOD("get_width"), &Image::get_width); ClassDB::bind_method(D_METHOD("get_height"), &Image::get_height); + ClassDB::bind_method(D_METHOD("get_size"), &Image::get_size); ClassDB::bind_method(D_METHOD("has_mipmaps"), &Image::has_mipmaps); ClassDB::bind_method(D_METHOD("get_format"), &Image::get_format); ClassDB::bind_method(D_METHOD("get_data"), &Image::get_data); diff --git a/core/image.h b/core/image.h index 7acc4744e9..2d61032896 100644 --- a/core/image.h +++ b/core/image.h @@ -177,6 +177,7 @@ private: public: int get_width() const; ///< Get image width int get_height() const; ///< Get image height + Vector2 get_size() const; bool has_mipmaps() const; int get_mipmap_count() const; diff --git a/core/io/marshalls.cpp b/core/io/marshalls.cpp index e701a89c78..93002e5446 100644 --- a/core/io/marshalls.cpp +++ b/core/io/marshalls.cpp @@ -463,8 +463,8 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int obj->set(str, value); } - if (obj->cast_to<Reference>()) { - REF ref = REF(obj->cast_to<Reference>()); + if (Object::cast_to<Reference>(obj)) { + REF ref = REF(Object::cast_to<Reference>(obj)); r_variant = ref; } else { r_variant = obj; diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp index fd8928b8a0..0977b03e2f 100644 --- a/core/io/resource_format_binary.cpp +++ b/core/io/resource_format_binary.cpp @@ -28,12 +28,14 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "resource_format_binary.h" -#include "image.h" -#include "io/file_access_compressed.h" -#include "io/marshalls.h" -#include "os/dir_access.h" -#include "project_settings.h" -#include "version.h" + +#include "core/image.h" +#include "core/io/file_access_compressed.h" +#include "core/io/marshalls.h" +#include "core/os/dir_access.h" +#include "core/project_settings.h" +#include "core/version.h" + //#define print_bl(m_what) print_line(m_what) #define print_bl(m_what) @@ -713,7 +715,7 @@ Error ResourceInteractiveLoaderBinary::poll() { } ERR_FAIL_COND_V(!obj, ERR_FILE_CORRUPT); - Resource *r = obj->cast_to<Resource>(); + Resource *r = Object::cast_to<Resource>(obj); if (!r) { error = ERR_FILE_CORRUPT; memdelete(obj); //bye @@ -1798,7 +1800,6 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const RES &p } ERR_FAIL_COND_V(err, err); - FileAccessRef _fref(f); relative_paths = p_flags & ResourceSaver::FLAG_RELATIVE_PATHS; skip_editor = p_flags & ResourceSaver::FLAG_OMIT_EDITOR_PROPERTIES; @@ -1810,7 +1811,6 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const RES &p takeover_paths = false; local_path = p_path.get_base_dir(); - //bin_meta_idx = get_string_index("__bin_meta__"); //is often used, so create _find_resources(p_resource, true); @@ -1836,7 +1836,6 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const RES &p return ERR_CANT_CREATE; } - //f->store_32(saved_resources.size()+external_resources.size()); // load steps -not needed save_unicode_string(p_resource->get_class()); uint64_t md_at = f->get_pos(); f->store_64(0); //offset to impoty metadata @@ -1875,7 +1874,6 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const RES &p f->store_32(strings.size()); //string table size for (int i = 0; i < strings.size(); i++) { - //print_bl("saving string: "+strings[i]); save_unicode_string(strings[i]); } @@ -1944,9 +1942,8 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const RES &p } Vector<uint64_t> ofs_table; - //int saved_idx=0; - //now actually save the resources + //now actually save the resources for (List<ResourceData>::Element *E = resources.front(); E; E = E->next()) { ResourceData &rd = E->get(); diff --git a/core/make_binders.py b/core/make_binders.py index a5cdb78443..6468c029f0 100644 --- a/core/make_binders.py +++ b/core/make_binders.py @@ -16,12 +16,11 @@ public: $ return Variant::NIL; } - virtual StringName _gen_argument_type_name(int p_arg) const { return _gen_argument_type_hint(p_arg); } - StringName _gen_argument_type_hint(int p_argument) const { - $ifret if (p_argument==-1) return GetTypeInfo<R>::get_class_name();$ - $arg if (p_argument==(@-1)) return GetTypeInfo<P@>::get_class_name(); + virtual PropertyInfo _gen_argument_type_info(int p_argument) const { + $ifret if (p_argument==-1) return GetTypeInfo<R>::get_class_info();$ + $arg if (p_argument==(@-1)) return GetTypeInfo<P@>::get_class_info(); $ - return StringName(); + return PropertyInfo(); } #endif virtual String get_instance_class() const { @@ -30,7 +29,7 @@ public: virtual Variant call(Object* p_object,const Variant** p_args,int p_arg_count, Variant::CallError& r_error) { - T *instance=p_object->cast_to<T>(); + T *instance=Object::cast_to<T>(p_object); r_error.error=Variant::CallError::CALL_OK; #ifdef DEBUG_METHODS_ENABLED @@ -58,7 +57,7 @@ public: #ifdef PTRCALL_ENABLED virtual void ptrcall(Object*p_object,const void** p_args,void *r_ret) { - T *instance=p_object->cast_to<T>(); + T *instance=Object::cast_to<T>(p_object); $ifret PtrToArg<R>::encode( $ (instance->*method)($arg, PtrToArg<P@>::convert(p_args[@-1])$) $ifret ,r_ret)$ ; } #endif @@ -104,14 +103,13 @@ public: return Variant::NIL; } - virtual StringName _gen_argument_type_name(int p_arg) const { return _gen_argument_type_hint(p_arg); } - - StringName _gen_argument_type_hint(int p_argument) const { - $ifret if (p_argument==-1) return GetTypeInfo<R>::get_class_name();$ - $arg if (p_argument==(@-1)) return GetTypeInfo<P@>::get_class_name(); + virtual PropertyInfo _gen_argument_type_info(int p_argument) const { + $ifret if (p_argument==-1) return GetTypeInfo<R>::get_class_info();$ + $arg if (p_argument==(@-1)) return GetTypeInfo<P@>::get_class_info(); $ - return StringName(); + return PropertyInfo(); } + #endif virtual String get_instance_class() const { return type_name; diff --git a/core/method_bind.cpp b/core/method_bind.cpp index 6792b62703..660350b899 100644 --- a/core/method_bind.cpp +++ b/core/method_bind.cpp @@ -36,31 +36,16 @@ #ifdef DEBUG_METHODS_ENABLED PropertyInfo MethodBind::get_argument_info(int p_argument) const { - if (p_argument >= 0) { + ERR_FAIL_INDEX_V(p_argument, get_argument_count(), PropertyInfo()); - String name = p_argument < arg_names.size() ? String(arg_names[p_argument]) : String("arg" + itos(p_argument)); - PropertyInfo pi(get_argument_type(p_argument), name); - - if (!is_vararg() && pi.type == Variant::OBJECT) { - StringName type_hint = arg_type_hints[p_argument]; - - if (type_hint != StringName()) { - pi.hint = PROPERTY_HINT_RESOURCE_TYPE; - pi.hint_string = type_hint.operator String(); - } - } - return pi; + PropertyInfo info = _gen_argument_type_info(p_argument); + info.name = p_argument < arg_names.size() ? String(arg_names[p_argument]) : String("arg" + itos(p_argument)); + return info; +} - } else { +PropertyInfo MethodBind::get_return_info() const { - Variant::Type at = get_argument_type(-1); - if (at == Variant::OBJECT && ret_type) - return PropertyInfo(at, "ret", PROPERTY_HINT_RESOURCE_TYPE, ret_type); - else - return PropertyInfo(at, "ret"); - } - - return PropertyInfo(); + return _gen_argument_type_info(-1); } #endif @@ -91,16 +76,6 @@ Vector<StringName> MethodBind::get_argument_names() const { return arg_names; } -void MethodBind::set_argument_type_hints(const Vector<StringName> &p_type_hints) { - - arg_type_hints = p_type_hints; -} - -Vector<StringName> MethodBind::get_argument_type_hints() const { - - return arg_type_hints; -} - #endif void MethodBind::set_default_arguments(const Vector<Variant> &p_defargs) { @@ -114,18 +89,13 @@ void MethodBind::_generate_argument_types(int p_count) { set_argument_count(p_count); Variant::Type *argt = memnew_arr(Variant::Type, p_count + 1); - - arg_type_hints.resize(p_count); - argt[0] = _gen_argument_type(-1); // return type - set_return_type(_gen_argument_type_hint(-1)); for (int i = 0; i < p_count; i++) { argt[i + 1] = _gen_argument_type(i); - arg_type_hints[i] = _gen_argument_type_hint(i); } - set_argument_types(argt); + argument_types = argt; } #endif diff --git a/core/method_bind.h b/core/method_bind.h index 157a67ca20..1f4c3ff66b 100644 --- a/core/method_bind.h +++ b/core/method_bind.h @@ -188,23 +188,22 @@ class MethodBind { Vector<Variant> default_arguments; int default_argument_count; int argument_count; -#ifdef DEBUG_METHODS_ENABLED - Vector<StringName> arg_names; - Vector<StringName> arg_type_hints; - Variant::Type *argument_types; - StringName ret_type; -#endif + bool _const; bool _returns; protected: +#ifdef DEBUG_METHODS_ENABLED + Variant::Type *argument_types; + Vector<StringName> arg_names; +#endif void _set_const(bool p_const); void _set_returns(bool p_returns); #ifdef DEBUG_METHODS_ENABLED virtual Variant::Type _gen_argument_type(int p_arg) const = 0; - virtual StringName _gen_argument_type_hint(int p_arg) const = 0; + virtual PropertyInfo _gen_argument_type_info(int p_arg) const = 0; void _generate_argument_types(int p_count); - void set_argument_types(Variant::Type *p_types) { argument_types = p_types; } + #endif void set_argument_count(int p_count) { argument_count = p_count; } @@ -234,9 +233,6 @@ public: #ifdef DEBUG_METHODS_ENABLED - _FORCE_INLINE_ void set_return_type(const StringName &p_type) { ret_type = p_type; } - _FORCE_INLINE_ StringName get_return_type() const { return ret_type; } - _FORCE_INLINE_ Variant::Type get_argument_type(int p_argument) const { ERR_FAIL_COND_V(p_argument < -1 || p_argument > argument_count, Variant::NIL); @@ -244,12 +240,11 @@ public: } PropertyInfo get_argument_info(int p_argument) const; + PropertyInfo get_return_info() const; - void set_argument_names(const Vector<StringName> &p_names); + void set_argument_names(const Vector<StringName> &p_names); //set by class, db, cant be inferred otherwise Vector<StringName> get_argument_names() const; - void set_argument_type_hints(const Vector<StringName> &p_type_hints); - Vector<StringName> get_argument_type_hints() const; #endif void set_hint_flags(uint32_t p_hint) { hint_flags = p_hint; } uint32_t get_hint_flags() const { return hint_flags | (is_const() ? METHOD_FLAG_CONST : 0) | (is_vararg() ? METHOD_FLAG_VARARG : 0); } @@ -305,18 +300,36 @@ public: protected: NativeCall call_method; +#ifdef DEBUG_METHODS_ENABLED + + MethodInfo arguments; +#endif public: - virtual Variant::Type _gen_argument_type(int p_arg) const { +#ifdef DEBUG_METHODS_ENABLED - return Variant::NIL; + 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]; + } else { + return PropertyInfo(Variant::NIL, "arg_" + itos(p_arg), PROPERTY_HINT_NONE, String(), PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_NIL_IS_VARIANT); + } } - virtual StringName _gen_argument_type_hint(int p_arg) const { + virtual Variant::Type _gen_argument_type(int p_arg) const { + return _gen_argument_type_info(p_arg).type; + } + +#else - return "Variant"; + virtual Variant::Type _gen_argument_type(int p_arg) const { + return Variant::NIL; } +#endif virtual Variant call(Object *p_object, const Variant **p_args, int p_arg_count, Variant::CallError &r_error) { T *instance = static_cast<T *>(p_object); @@ -341,7 +354,8 @@ public: set_argument_names(names); } - set_argument_types(at); + argument_types = at; + arguments = p_info; #endif } diff --git a/core/object.cpp b/core/object.cpp index a43a9c85b1..cd084a0c4a 100644 --- a/core/object.cpp +++ b/core/object.cpp @@ -65,6 +65,7 @@ PropertyInfo::operator Dictionary() const { Dictionary d; d["name"] = name; + d["class_name"] = class_name; d["type"] = type; d["hint"] = hint; d["hint_string"] = hint_string; @@ -82,6 +83,9 @@ PropertyInfo PropertyInfo::from_dict(const Dictionary &p_dict) { if (p_dict.has("name")) pi.name = p_dict["name"]; + if (p_dict.has("class_name")) + pi.class_name = p_dict["class_name"]; + if (p_dict.has("hint")) pi.hint = PropertyHint(int(p_dict["hint"])); @@ -650,7 +654,7 @@ void Object::call_multilevel(const StringName &p_method, const Variant **p_args, if (p_method == CoreStringNames::get_singleton()->_free) { #ifdef DEBUG_ENABLED - if (cast_to<Reference>()) { + if (Object::cast_to<Reference>(this)) { ERR_EXPLAIN("Can't 'free' a reference."); ERR_FAIL(); return; @@ -896,7 +900,7 @@ Variant Object::call(const StringName &p_method, const Variant **p_args, int p_a r_error.error = Variant::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS; return Variant(); } - if (cast_to<Reference>()) { + if (Object::cast_to<Reference>(this)) { r_error.argument = 0; r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD; ERR_EXPLAIN("Can't 'free' a reference."); @@ -1468,7 +1472,7 @@ Error Object::connect(const StringName &p_signal, Object *p_to_object, const Str Signal::Target target(p_to_object->get_instance_id(), p_to_method); if (s->slot_map.has(target)) { - ERR_EXPLAIN("Signal '" + p_signal + "'' already connected to given method '" + p_to_method + "' in that object."); + ERR_EXPLAIN("Signal '" + p_signal + "' is already connected to given method '" + p_to_method + "' in that object."); ERR_FAIL_COND_V(s->slot_map.has(target), ERR_INVALID_PARAMETER); } diff --git a/core/object.h b/core/object.h index 8a858b5b00..746450ef6a 100644 --- a/core/object.h +++ b/core/object.h @@ -107,6 +107,8 @@ enum PropertyUsageFlags { PROPERTY_USAGE_ANIMATE_AS_TRIGGER = 32768, PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED = 65536, PROPERTY_USAGE_SCRIPT_DEFAULT_VALUE = 1 << 17, + PROPERTY_USAGE_CLASS_IS_ENUM = 1 << 18, + PROPERTY_USAGE_NIL_IS_VARIANT = 1 << 19, PROPERTY_USAGE_DEFAULT = PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_NETWORK, PROPERTY_USAGE_DEFAULT_INTL = PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_NETWORK | PROPERTY_USAGE_INTERNATIONALIZED, @@ -126,6 +128,7 @@ struct PropertyInfo { Variant::Type type; String name; + StringName class_name; //for classes PropertyHint hint; String hint_string; uint32_t usage; @@ -145,13 +148,27 @@ struct PropertyInfo { hint(PROPERTY_HINT_NONE), usage(PROPERTY_USAGE_DEFAULT) { } - PropertyInfo(Variant::Type p_type, const String p_name, PropertyHint p_hint = PROPERTY_HINT_NONE, const String &p_hint_string = "", uint32_t p_usage = PROPERTY_USAGE_DEFAULT) + PropertyInfo(Variant::Type p_type, const String p_name, PropertyHint p_hint = PROPERTY_HINT_NONE, const String &p_hint_string = "", uint32_t p_usage = PROPERTY_USAGE_DEFAULT, const StringName &p_class_name = StringName()) : type(p_type), name(p_name), hint(p_hint), hint_string(p_hint_string), usage(p_usage) { + + if (hint == PROPERTY_HINT_RESOURCE_TYPE) { + class_name = hint_string; + } else { + class_name = p_class_name; + } } + PropertyInfo(const StringName &p_class_name) + : type(Variant::OBJECT), + hint(PROPERTY_HINT_NONE), + usage(PROPERTY_USAGE_DEFAULT) { + + class_name = p_class_name; + } + bool operator<(const PropertyInfo &p_info) const { return name < p_info.name; } @@ -168,6 +185,7 @@ struct MethodInfo { uint32_t flags; int id; + inline bool operator==(const MethodInfo &p_method) const { return id == p_method.id; } inline bool operator<(const MethodInfo &p_method) const { return id == p_method.id ? (name < p_method.name) : (id < p_method.id); } operator Dictionary() const; @@ -541,46 +559,46 @@ public: void add_change_receptor(Object *p_receptor); void remove_change_receptor(Object *p_receptor); -// TODO: ensure 'this' is never NULL since it's UB, but by now, avoid warning flood -#ifdef __clang__ -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wundefined-bool-conversion" -#endif - template <class T> - T *cast_to() { - + static T *cast_to(Object *p_object) { +#ifdef DEBUG_ENABLED + // TODO there are some legitimate reasons to pass NULL as p_object. + // we need to figure out how to deal with that in debug mode. + // This code will return NULL for a NULL input in release mode also. + ERR_FAIL_COND_V(p_object == NULL, NULL); +#endif #ifndef NO_SAFE_CAST - return SAFE_CAST<T *>(this); + return dynamic_cast<T *>(p_object); #else - if (!this) + if (!p_object) return NULL; - if (is_class_ptr(T::get_class_ptr_static())) - return static_cast<T *>(this); + if (p_object->is_class_ptr(T::get_class_ptr_static())) + return static_cast<T *>(p_object); else return NULL; #endif } template <class T> - const T *cast_to() const { - + static const T *cast_to(const Object *p_object) { +#ifdef DEBUG_ENABLED + // TODO there are some legitimate reasons to pass NULL as p_object. + // we need to figure out how to deal with that in debug mode. + // This code will return NULL for a NULL input in release mode also. + ERR_FAIL_COND_V(p_object == NULL, NULL); +#endif #ifndef NO_SAFE_CAST - return SAFE_CAST<const T *>(this); + return dynamic_cast<const T *>(p_object); #else - if (!this) + if (!p_object) return NULL; - if (is_class_ptr(T::get_class_ptr_static())) - return static_cast<const T *>(this); + if (p_object->is_class_ptr(T::get_class_ptr_static())) + return static_cast<const T *>(p_object); else return NULL; #endif } -#ifdef __clang__ -#pragma clang diagnostic pop -#endif - enum { NOTIFICATION_POSTINITIALIZE = 0, diff --git a/core/os/input_event.cpp b/core/os/input_event.cpp index cb38eb67b6..c5f787b6c7 100644 --- a/core/os/input_event.cpp +++ b/core/os/input_event.cpp @@ -483,6 +483,38 @@ bool InputEventMouseButton::action_match(const Ref<InputEvent> &p_event) const { return mb->button_index == button_index; } +String InputEventMouseButton::as_text() const { + + String button_index_string = ""; + switch (get_button_index()) { + case BUTTON_LEFT: + button_index_string = "BUTTON_LEFT"; + break; + case BUTTON_RIGHT: + button_index_string = "BUTTON_RIGHT"; + break; + case BUTTON_MIDDLE: + button_index_string = "BUTTON_MIDDLE"; + break; + case BUTTON_WHEEL_UP: + button_index_string = "BUTTON_WHEEL_UP"; + break; + case BUTTON_WHEEL_DOWN: + button_index_string = "BUTTON_WHEEL_DOWN"; + break; + case BUTTON_WHEEL_LEFT: + button_index_string = "BUTTON_WHEEL_LEFT"; + break; + case BUTTON_WHEEL_RIGHT: + button_index_string = "BUTTON_WHEEL_RIGHT"; + break; + default: + button_index_string = itos(get_button_index()); + break; + } + return "InputEventMouseButton : button_index=" + button_index_string + ", pressed=" + (pressed ? "true" : "false") + ", position=(" + String(get_position()) + "), button_mask=" + itos(get_button_mask()) + ", doubleclick=" + (doubleclick ? "true" : "false"); +} + void InputEventMouseButton::_bind_methods() { ClassDB::bind_method(D_METHOD("set_factor", "factor"), &InputEventMouseButton::set_factor); @@ -559,6 +591,26 @@ Ref<InputEvent> InputEventMouseMotion::xformed_by(const Transform2D &p_xform, co return mm; } +String InputEventMouseMotion::as_text() const { + + String button_mask_string = ""; + switch (get_button_mask()) { + case BUTTON_MASK_LEFT: + button_mask_string = "BUTTON_MASK_LEFT"; + break; + case BUTTON_MASK_MIDDLE: + button_mask_string = "BUTTON_MASK_MIDDLE"; + break; + case BUTTON_MASK_RIGHT: + button_mask_string = "BUTTON_MASK_RIGHT"; + break; + default: + button_mask_string = itos(get_button_mask()); + break; + } + return "InputEventMouseMotion : button_mask=" + button_mask_string + ", position=(" + String(get_position()) + "), relative=(" + String(get_relative()) + "), speed=(" + String(get_speed()) + ")"; +} + void InputEventMouseMotion::_bind_methods() { ClassDB::bind_method(D_METHOD("set_relative", "relative"), &InputEventMouseMotion::set_relative); @@ -609,6 +661,11 @@ bool InputEventJoypadMotion::action_match(const Ref<InputEvent> &p_event) const return (axis == jm->axis && (axis_value < 0) == (jm->axis_value < 0)); } +String InputEventJoypadMotion::as_text() const { + + return "InputEventJoypadMotion : axis=" + itos(axis) + ", axis_value=" + String(Variant(axis_value)); +} + void InputEventJoypadMotion::_bind_methods() { ClassDB::bind_method(D_METHOD("set_axis", "axis"), &InputEventJoypadMotion::set_axis); @@ -665,6 +722,11 @@ bool InputEventJoypadButton::action_match(const Ref<InputEvent> &p_event) const return button_index == jb->button_index; } +String InputEventJoypadButton::as_text() const { + + return "InputEventJoypadButton : button_index=" + itos(button_index) + ", pressed=" + (pressed ? "true" : "false") + ", pressure=" + String(Variant(pressure)); +} + void InputEventJoypadButton::_bind_methods() { ClassDB::bind_method(D_METHOD("set_button_index", "button_index"), &InputEventJoypadButton::set_button_index); @@ -730,6 +792,11 @@ Ref<InputEvent> InputEventScreenTouch::xformed_by(const Transform2D &p_xform, co return st; } +String InputEventScreenTouch::as_text() const { + + return "InputEventScreenTouch : index=" + itos(index) + ", pressed=" + (pressed ? "true" : "false") + ", position=(" + String(get_position()) + ")"; +} + void InputEventScreenTouch::_bind_methods() { ClassDB::bind_method(D_METHOD("set_index", "index"), &InputEventScreenTouch::set_index); @@ -808,6 +875,11 @@ Ref<InputEvent> InputEventScreenDrag::xformed_by(const Transform2D &p_xform, con return sd; } +String InputEventScreenDrag::as_text() const { + + return "InputEventScreenDrag : index=" + itos(index) + ", position=(" + String(get_position()) + "), relative=(" + String(get_relative()) + "), speed=(" + String(get_speed()) + ")"; +} + void InputEventScreenDrag::_bind_methods() { ClassDB::bind_method(D_METHOD("set_index", "index"), &InputEventScreenDrag::set_index); @@ -857,6 +929,11 @@ bool InputEventAction::is_action(const StringName &p_action) const { return action == p_action; } +String InputEventAction::as_text() const { + + return "InputEventAction : action=" + action + ", pressed=(" + (pressed ? "true" : "false"); +} + void InputEventAction::_bind_methods() { ClassDB::bind_method(D_METHOD("set_action", "action"), &InputEventAction::set_action); diff --git a/core/os/input_event.h b/core/os/input_event.h index d1fd7cc90f..06d157b2b2 100644 --- a/core/os/input_event.h +++ b/core/os/input_event.h @@ -307,6 +307,7 @@ public: virtual bool action_match(const Ref<InputEvent> &p_event) const; virtual bool is_action_type() const { return true; } + virtual String as_text() const; InputEventMouseButton(); }; @@ -328,6 +329,7 @@ public: Vector2 get_speed() const; virtual Ref<InputEvent> xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs = Vector2()) const; + virtual String as_text() const; InputEventMouseMotion(); }; @@ -352,6 +354,7 @@ public: virtual bool action_match(const Ref<InputEvent> &p_event) const; virtual bool is_action_type() const { return true; } + virtual String as_text() const; InputEventJoypadMotion(); }; @@ -378,6 +381,7 @@ public: virtual bool action_match(const Ref<InputEvent> &p_event) const; virtual bool is_action_type() const { return true; } + virtual String as_text() const; InputEventJoypadButton(); }; @@ -402,6 +406,7 @@ public: virtual bool is_pressed() const; virtual Ref<InputEvent> xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs = Vector2()) const; + virtual String as_text() const; InputEventScreenTouch(); }; @@ -431,6 +436,7 @@ public: Vector2 get_speed() const; virtual Ref<InputEvent> xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs = Vector2()) const; + virtual String as_text() const; InputEventScreenDrag(); }; @@ -455,6 +461,7 @@ public: virtual bool is_action(const StringName &p_action) const; virtual bool is_action_type() const { return true; } + virtual String as_text() const; InputEventAction(); }; diff --git a/core/os/os.cpp b/core/os/os.cpp index 3a06a3fa8f..c49ab6f706 100644 --- a/core/os/os.cpp +++ b/core/os/os.cpp @@ -171,7 +171,7 @@ static FileAccess *_OSPRF = NULL; static void _OS_printres(Object *p_obj) { - Resource *res = p_obj->cast_to<Resource>(); + Resource *res = Object::cast_to<Resource>(p_obj); if (!res) return; diff --git a/core/ref_ptr.cpp b/core/ref_ptr.cpp index c2128fd45d..7bd8523292 100644 --- a/core/ref_ptr.cpp +++ b/core/ref_ptr.cpp @@ -69,7 +69,7 @@ RID RefPtr::get_rid() const { Ref<Reference> *ref = reinterpret_cast<Ref<Reference> *>(&data[0]); if (ref->is_null()) return RID(); - Resource *res = (*ref)->cast_to<Resource>(); + Resource *res = Object::cast_to<Resource>(ref->ptr()); if (res) return res->get_rid(); return RID(); diff --git a/core/reference.cpp b/core/reference.cpp index e9629ee7c0..1380dbd56e 100644 --- a/core/reference.cpp +++ b/core/reference.cpp @@ -98,7 +98,7 @@ Variant WeakRef::get_ref() const { Object *obj = ObjectDB::get_instance(ref); if (!obj) return Variant(); - Reference *r = obj->cast_to<Reference>(); + Reference *r = cast_to<Reference>(obj); if (r) { return REF(r); diff --git a/core/reference.h b/core/reference.h index 69250a4701..a8034a73c6 100644 --- a/core/reference.h +++ b/core/reference.h @@ -180,7 +180,7 @@ public: return; } Ref r; - r.reference = refb->cast_to<T>(); + r.reference = Object::cast_to<T>(refb); ref(r); r.reference = NULL; } @@ -194,7 +194,7 @@ public: return; } Ref r; - r.reference = refb->cast_to<T>(); + r.reference = Object::cast_to<T>(refb); ref(r); r.reference = NULL; } @@ -209,7 +209,7 @@ public: return; } Ref r; - r.reference = refb->cast_to<T>(); + r.reference = Object::cast_to<T>(refb); ref(r); r.reference = NULL; } @@ -230,7 +230,7 @@ public: return; } Ref r; - r.reference = refb->cast_to<T>(); + r.reference = Object::cast_to<T>(refb); ref(r); r.reference = NULL; } @@ -254,7 +254,7 @@ public: return; } Ref r; - r.reference = refb->cast_to<T>(); + r.reference = Object::cast_to<T>(refb); ref(r); r.reference = NULL; } @@ -269,7 +269,7 @@ public: return; } Ref r; - r.reference = refb->cast_to<T>(); + r.reference = Object::cast_to<T>(refb); ref(r); r.reference = NULL; } @@ -382,8 +382,8 @@ template <class T> struct GetTypeInfo<Ref<T> > { enum { VARIANT_TYPE = Variant::OBJECT }; - static inline StringName get_class_name() { - return T::get_class_static(); + static inline PropertyInfo get_class_info() { + return PropertyInfo(Variant::OBJECT, String(), PROPERTY_HINT_RESOURCE_TYPE, T::get_class_static()); } }; @@ -391,8 +391,8 @@ template <class T> struct GetTypeInfo<const Ref<T> &> { enum { VARIANT_TYPE = Variant::OBJECT }; - static inline StringName get_class_name() { - return T::get_class_static(); + static inline PropertyInfo get_class_info() { + return PropertyInfo(Variant::OBJECT, String(), PROPERTY_HINT_RESOURCE_TYPE, T::get_class_static()); } }; diff --git a/core/script_language.h b/core/script_language.h index 7aba3ec0f1..5baf2e6f80 100644 --- a/core/script_language.h +++ b/core/script_language.h @@ -207,7 +207,7 @@ public: virtual String make_function(const String &p_class, const String &p_name, const PoolStringArray &p_args) const = 0; virtual Error open_in_external_editor(const Ref<Script> &p_script, int p_line, int p_col) { return ERR_UNAVAILABLE; } - virtual Error complete_code(const String &p_code, const String &p_base_path, Object *p_owner, List<String> *r_options, String &r_call_hint) { return ERR_UNAVAILABLE; } + virtual Error complete_code(const String &p_code, const String &p_base_path, Object *p_owner, List<String> *r_options, bool &r_force, String &r_call_hint) { return ERR_UNAVAILABLE; } struct LookupResult { enum Type { diff --git a/core/type_info.h b/core/type_info.h index 0603126996..a7d3fa20c8 100644 --- a/core/type_info.h +++ b/core/type_info.h @@ -41,9 +41,9 @@ template <class T, typename = void> struct GetTypeInfo { enum { VARIANT_TYPE = Variant::NIL }; - static inline StringName get_class_name() { + static inline PropertyInfo get_class_info() { ERR_PRINT("GetTypeInfo fallback. Bug!"); - return StringName(); // Not "Nil", this is an error + return PropertyInfo(); // Not "Nil", this is an error } }; @@ -51,15 +51,15 @@ struct GetTypeInfo { template <> \ struct GetTypeInfo<m_type> { \ enum { VARIANT_TYPE = m_var_type }; \ - static inline StringName get_class_name() { \ - return Variant::get_type_name((Variant::Type)VARIANT_TYPE); \ + static inline PropertyInfo get_class_info() { \ + return PropertyInfo((Variant::Type)VARIANT_TYPE,String()); \ } \ }; \ template <> \ struct GetTypeInfo<const m_type &> { \ enum { VARIANT_TYPE = m_var_type }; \ - static inline StringName get_class_name() { \ - return Variant::get_type_name((Variant::Type)VARIANT_TYPE); \ + static inline PropertyInfo get_class_info() { \ + return PropertyInfo((Variant::Type)VARIANT_TYPE,String()); \ } \ }; @@ -105,38 +105,54 @@ MAKE_TYPE_INFO(IP_Address, Variant::STRING) class BSP_Tree; MAKE_TYPE_INFO(BSP_Tree, Variant::DICTIONARY) -#define MAKE_TYPE_INFO_WITH_NAME(m_type, m_var_type, m_class_name) \ - template <> \ - struct GetTypeInfo<m_type> { \ - enum { VARIANT_TYPE = m_var_type }; \ - static inline StringName get_class_name() { \ - return m_class_name; \ - } \ - }; \ - template <> \ - struct GetTypeInfo<const m_type &> { \ - enum { VARIANT_TYPE = m_var_type }; \ - static inline StringName get_class_name() { \ - return m_class_name; \ - } \ - }; +//for RefPtr +template <> +struct GetTypeInfo<RefPtr> { + enum { VARIANT_TYPE = Variant::OBJECT }; + static inline PropertyInfo get_class_info() { + return PropertyInfo(Variant::OBJECT,String(),PROPERTY_HINT_RESOURCE_TYPE,"Reference"); + } +}; +template <> +struct GetTypeInfo<const RefPtr &> { + enum { VARIANT_TYPE = Variant::OBJECT }; + static inline PropertyInfo get_class_info() { + return PropertyInfo(Variant::OBJECT,String(),PROPERTY_HINT_RESOURCE_TYPE,"Reference"); + } +}; + + +//for variant +template<> +struct GetTypeInfo<Variant> { + enum { VARIANT_TYPE = Variant::NIL }; + static inline PropertyInfo get_class_info() { + return PropertyInfo(Variant::NIL,String(),PROPERTY_HINT_NONE,String(),PROPERTY_USAGE_DEFAULT|PROPERTY_USAGE_NIL_IS_VARIANT); + } +}; + +template<> +struct GetTypeInfo<const Variant&> { + enum { VARIANT_TYPE = Variant::NIL }; + static inline PropertyInfo get_class_info() { + return PropertyInfo(Variant::NIL,String(),PROPERTY_HINT_NONE,String(),PROPERTY_USAGE_DEFAULT|PROPERTY_USAGE_NIL_IS_VARIANT); + } +}; -MAKE_TYPE_INFO_WITH_NAME(RefPtr, Variant::OBJECT, "Reference") -MAKE_TYPE_INFO_WITH_NAME(Variant, Variant::NIL, "Variant") #define MAKE_TEMPLATE_TYPE_INFO(m_template, m_type, m_var_type) \ template <> \ struct GetTypeInfo<m_template<m_type> > { \ enum { VARIANT_TYPE = m_var_type }; \ - static inline StringName get_class_name() { \ - return Variant::get_type_name((Variant::Type)VARIANT_TYPE); \ + static inline PropertyInfo get_class_info() { \ + return PropertyInfo((Variant::Type)VARIANT_TYPE,String()); \ } \ }; \ template <> \ struct GetTypeInfo<const m_template<m_type> &> { \ enum { VARIANT_TYPE = m_var_type }; \ - static inline StringName get_class_name() { \ - return Variant::get_type_name((Variant::Type)VARIANT_TYPE); \ + static inline PropertyInfo get_class_info() { \ + return PropertyInfo((Variant::Type)VARIANT_TYPE,String()); \ } \ }; @@ -159,17 +175,18 @@ template <typename T> struct GetTypeInfo<T *, typename EnableIf<TypeInherits<Object, T>::value>::type> { enum { VARIANT_TYPE = Variant::OBJECT }; - static inline StringName get_class_name() { - return T::get_class_static(); + static inline PropertyInfo get_class_info() { + return PropertyInfo(StringName(T::get_class_static())); } + }; template <typename T> struct GetTypeInfo<const T *, typename EnableIf<TypeInherits<Object, T>::value>::type> { enum { VARIANT_TYPE = Variant::OBJECT }; - static inline StringName get_class_name() { - return T::get_class_static(); + static inline PropertyInfo get_class_info() { + return PropertyInfo(StringName(T::get_class_static())); } }; @@ -177,7 +194,9 @@ struct GetTypeInfo<const T *, typename EnableIf<TypeInherits<Object, T>::value>: template <> \ struct GetTypeInfo<m_impl> { \ enum { VARIANT_TYPE = Variant::INT }; \ - static inline StringName get_class_name() { return "enum." #m_enum; } \ + static inline PropertyInfo get_class_info() { \ + return PropertyInfo(Variant::INT,String(),PROPERTY_HINT_NONE,String(),PROPERTY_USAGE_DEFAULT|PROPERTY_USAGE_CLASS_IS_ENUM,String(#m_enum).replace("::",".")); \ + } \ }; #define MAKE_ENUM_TYPE_INFO(m_enum) \ @@ -190,7 +209,7 @@ template <typename T> inline StringName __constant_get_enum_name(T param, const String &p_constant) { if (GetTypeInfo<T>::VARIANT_TYPE == Variant::NIL) ERR_PRINTS("Missing VARIANT_ENUM_CAST for constant's enum: " + p_constant); - return GetTypeInfo<T>::get_class_name(); + return GetTypeInfo<T>::get_class_info().class_name; } #else diff --git a/core/undo_redo.cpp b/core/undo_redo.cpp index bb70146396..00a468816a 100644 --- a/core/undo_redo.cpp +++ b/core/undo_redo.cpp @@ -111,8 +111,8 @@ void UndoRedo::add_do_method(Object *p_object, const String &p_method, VARIANT_A ERR_FAIL_COND((current_action + 1) >= actions.size()); Operation do_op; do_op.object = p_object->get_instance_id(); - if (p_object->cast_to<Resource>()) - do_op.resref = Ref<Resource>(p_object->cast_to<Resource>()); + if (Object::cast_to<Resource>(p_object)) + do_op.resref = Ref<Resource>(Object::cast_to<Resource>(p_object)); do_op.type = Operation::TYPE_METHOD; do_op.name = p_method; @@ -135,8 +135,8 @@ void UndoRedo::add_undo_method(Object *p_object, const String &p_method, VARIANT Operation undo_op; undo_op.object = p_object->get_instance_id(); - if (p_object->cast_to<Resource>()) - undo_op.resref = Ref<Resource>(p_object->cast_to<Resource>()); + if (Object::cast_to<Resource>(p_object)) + undo_op.resref = Ref<Resource>(Object::cast_to<Resource>(p_object)); undo_op.type = Operation::TYPE_METHOD; undo_op.name = p_method; @@ -152,8 +152,8 @@ void UndoRedo::add_do_property(Object *p_object, const String &p_property, const ERR_FAIL_COND((current_action + 1) >= actions.size()); Operation do_op; do_op.object = p_object->get_instance_id(); - if (p_object->cast_to<Resource>()) - do_op.resref = Ref<Resource>(p_object->cast_to<Resource>()); + if (Object::cast_to<Resource>(p_object)) + do_op.resref = Ref<Resource>(Object::cast_to<Resource>(p_object)); do_op.type = Operation::TYPE_PROPERTY; do_op.name = p_property; @@ -171,8 +171,8 @@ void UndoRedo::add_undo_property(Object *p_object, const String &p_property, con Operation undo_op; undo_op.object = p_object->get_instance_id(); - if (p_object->cast_to<Resource>()) - undo_op.resref = Ref<Resource>(p_object->cast_to<Resource>()); + if (Object::cast_to<Resource>(p_object)) + undo_op.resref = Ref<Resource>(Object::cast_to<Resource>(p_object)); undo_op.type = Operation::TYPE_PROPERTY; undo_op.name = p_property; @@ -185,8 +185,8 @@ void UndoRedo::add_do_reference(Object *p_object) { ERR_FAIL_COND((current_action + 1) >= actions.size()); Operation do_op; do_op.object = p_object->get_instance_id(); - if (p_object->cast_to<Resource>()) - do_op.resref = Ref<Resource>(p_object->cast_to<Resource>()); + if (Object::cast_to<Resource>(p_object)) + do_op.resref = Ref<Resource>(Object::cast_to<Resource>(p_object)); do_op.type = Operation::TYPE_REFERENCE; actions[current_action + 1].do_ops.push_back(do_op); @@ -202,8 +202,8 @@ void UndoRedo::add_undo_reference(Object *p_object) { Operation undo_op; undo_op.object = p_object->get_instance_id(); - if (p_object->cast_to<Resource>()) - undo_op.resref = Ref<Resource>(p_object->cast_to<Resource>()); + if (Object::cast_to<Resource>(p_object)) + undo_op.resref = Ref<Resource>(Object::cast_to<Resource>(p_object)); undo_op.type = Operation::TYPE_REFERENCE; actions[current_action + 1].undo_ops.push_back(undo_op); @@ -270,7 +270,7 @@ void UndoRedo::_process_operation_list(List<Operation>::Element *E) { obj->call(op.name, VARIANT_ARGS_FROM_ARRAY(op.args)); #ifdef TOOLS_ENABLED - Resource *res = obj->cast_to<Resource>(); + Resource *res = Object::cast_to<Resource>(obj); if (res) res->set_edited(true); @@ -284,7 +284,7 @@ void UndoRedo::_process_operation_list(List<Operation>::Element *E) { obj->set(op.name, op.args[0]); #ifdef TOOLS_ENABLED - Resource *res = obj->cast_to<Resource>(); + Resource *res = Object::cast_to<Resource>(obj); if (res) res->set_edited(true); #endif diff --git a/core/variant.cpp b/core/variant.cpp index 51c4b70bdc..e6a69edd08 100644 --- a/core/variant.cpp +++ b/core/variant.cpp @@ -1764,14 +1764,14 @@ Variant::operator Object *() const { Variant::operator Node *() const { if (type == OBJECT) - return _get_obj().obj ? _get_obj().obj->cast_to<Node>() : NULL; + return Object::cast_to<Node>(_get_obj().obj); else return NULL; } Variant::operator Control *() const { if (type == OBJECT) - return _get_obj().obj ? _get_obj().obj->cast_to<Control>() : NULL; + return Object::cast_to<Control>(_get_obj().obj); else return NULL; } diff --git a/core/variant_parser.cpp b/core/variant_parser.cpp index 5aa71f6704..a1b168621c 100644 --- a/core/variant_parser.cpp +++ b/core/variant_parser.cpp @@ -742,7 +742,7 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, return err; if (token.type == TK_PARENTHESIS_CLOSE) { - Reference *reference = obj->cast_to<Reference>(); + Reference *reference = Object::cast_to<Reference>(obj); if (reference) { value = REF(reference); } else { |