diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/error_macros.h | 5 | ||||
-rw-r--r-- | core/io/resource_format_binary.cpp | 2 | ||||
-rw-r--r-- | core/object.cpp | 27 | ||||
-rw-r--r-- | core/object.h | 2 | ||||
-rw-r--r-- | core/object_type_db.cpp | 39 | ||||
-rw-r--r-- | core/object_type_db.h | 4 | ||||
-rw-r--r-- | core/ring_buffer.h | 6 | ||||
-rw-r--r-- | core/script_language.cpp | 14 | ||||
-rw-r--r-- | core/script_language.h | 3 | ||||
-rw-r--r-- | core/variant.h | 2 | ||||
-rw-r--r-- | core/variant_call.cpp | 11 | ||||
-rw-r--r-- | core/vector.h | 38 |
12 files changed, 123 insertions, 30 deletions
diff --git a/core/error_macros.h b/core/error_macros.h index 76da88287b..cc88686301 100644 --- a/core/error_macros.h +++ b/core/error_macros.h @@ -207,6 +207,11 @@ extern bool _err_error_exists; _err_error_exists=false;\ } \ +#define ERR_PRINTS(m_string) \ + { \ + _err_print_error(FUNCTION_STR,__FILE__,__LINE__,String(m_string).utf8().get_data()); \ + _err_error_exists=false;\ + } \ /** Print a warning string. */ diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp index 1a0552e8d1..4cd3cd595f 100644 --- a/core/io/resource_format_binary.cpp +++ b/core/io/resource_format_binary.cpp @@ -905,7 +905,7 @@ void ResourceInteractiveLoaderBinary::open(FileAccess *p_f) { error=ERR_FILE_UNRECOGNIZED; ERR_EXPLAIN("Unrecognized binary resource file: "+local_path); - ERR_FAIL_V(); + ERR_FAIL(); } bool big_endian = f->get_32(); diff --git a/core/object.cpp b/core/object.cpp index 3a4c06e7e7..96f0c86832 100644 --- a/core/object.cpp +++ b/core/object.cpp @@ -314,6 +314,7 @@ void Object::set(const StringName& p_name, const Variant& p_value, bool *r_valid _edited=true; #endif + if (script_instance) { if (script_instance->set(p_name,p_value)) { @@ -326,9 +327,9 @@ void Object::set(const StringName& p_name, const Variant& p_value, bool *r_valid //try built-in setgetter { - if (ObjectTypeDB::set_property(this,p_name,p_value)) { - if (r_valid) - *r_valid=true; + if (ObjectTypeDB::set_property(this,p_name,p_value,r_valid)) { + //if (r_valid) + // *r_valid=true; return; } } @@ -1694,6 +1695,26 @@ void Object::get_translatable_strings(List<String> *p_strings) const { } +Variant::Type Object::get_static_property_type(const StringName& p_property, bool *r_valid) const { + + bool valid; + Variant::Type t = ObjectTypeDB::get_property_type(get_type_name(),p_property,&valid); + if (valid) { + if (r_valid) + *r_valid=true; + return t; + } + + if (get_script_instance()) { + return get_script_instance()->get_property_type(p_property,r_valid); + } + if (r_valid) + *r_valid=false; + + return Variant::NIL; + +} + bool Object::is_queued_for_deletion() const { return _is_queued_for_deletion; } diff --git a/core/object.h b/core/object.h index 981a83958c..5b6361796f 100644 --- a/core/object.h +++ b/core/object.h @@ -606,6 +606,8 @@ public: void set_block_signals(bool p_block); bool is_blocking_signals() const; + Variant::Type get_static_property_type(const StringName& p_property,bool *r_valid=NULL) const; + virtual void get_translatable_strings(List<String> *p_strings) const; virtual void get_argument_options(const StringName& p_function,int p_idx,List<String>*r_options) const; diff --git a/core/object_type_db.cpp b/core/object_type_db.cpp index a64b3d2715..f8ba0a9b15 100644 --- a/core/object_type_db.cpp +++ b/core/object_type_db.cpp @@ -612,6 +612,7 @@ void ObjectTypeDB::add_property(StringName p_type,const PropertyInfo& p_pinfo, c psg._setptr=mb_set; psg._getptr=mb_get; psg.index=p_index; + psg.type=p_pinfo.type; type->property_setget[p_pinfo.name]=psg; @@ -634,7 +635,7 @@ void ObjectTypeDB::get_property_list(StringName p_type,List<PropertyInfo> *p_lis } } -bool ObjectTypeDB::set_property(Object* p_object,const StringName& p_property, const Variant& p_value) { +bool ObjectTypeDB::set_property(Object* p_object,const StringName& p_property, const Variant& p_value,bool *r_valid) { TypeInfo *type=types.getptr(p_object->get_type_name()); @@ -643,13 +644,17 @@ bool ObjectTypeDB::set_property(Object* p_object,const StringName& p_property, c const PropertySetGet *psg = check->property_setget.getptr(p_property); if (psg) { - if (!psg->setter) + if (!psg->setter) { + if (r_valid) + *r_valid=false; return true; //return true but do nothing + } + + Variant::CallError ce; if (psg->index>=0) { Variant index=psg->index; const Variant* arg[2]={&index,&p_value}; - Variant::CallError ce; // p_object->call(psg->setter,arg,2,ce); if (psg->_setptr) { psg->_setptr->call(p_object,arg,2,ce); @@ -660,13 +665,16 @@ bool ObjectTypeDB::set_property(Object* p_object,const StringName& p_property, c } else { const Variant* arg[1]={&p_value}; - Variant::CallError ce; if (psg->_setptr) { psg->_setptr->call(p_object,arg,1,ce); } else { p_object->call(psg->setter,arg,1,ce); } } + + if (r_valid) + *r_valid=ce.error==Variant::CallError::CALL_OK; + return true; } @@ -718,6 +726,29 @@ bool ObjectTypeDB::get_property(Object* p_object,const StringName& p_property, V return false; } +Variant::Type ObjectTypeDB::get_property_type(const StringName& p_type, const StringName& p_property,bool *r_is_valid) { + + TypeInfo *type=types.getptr(p_type); + TypeInfo *check=type; + while(check) { + const PropertySetGet *psg = check->property_setget.getptr(p_property); + if (psg) { + + if (r_is_valid) + *r_is_valid=true; + + return psg->type; + } + + check=check->inherits_ptr; + } + if (r_is_valid) + *r_is_valid=false; + + return Variant::NIL; + +} + void ObjectTypeDB::set_method_flags(StringName p_type,StringName p_method,int p_flags) { diff --git a/core/object_type_db.h b/core/object_type_db.h index bfa0f921e5..319e3ec02c 100644 --- a/core/object_type_db.h +++ b/core/object_type_db.h @@ -117,6 +117,7 @@ class ObjectTypeDB { StringName getter; MethodBind *_setptr; MethodBind *_getptr; + Variant::Type type; }; struct TypeInfo { @@ -456,8 +457,9 @@ public: static void add_property(StringName p_type,const PropertyInfo& p_pinfo, const StringName& p_setter, const StringName& p_getter, int p_index=-1); static void get_property_list(StringName p_type,List<PropertyInfo> *p_list,bool p_no_inheritance=false); - static bool set_property(Object* p_object,const StringName& p_property, const Variant& p_value); + static bool set_property(Object* p_object, const StringName& p_property, const Variant& p_value, bool *r_valid=NULL); static bool get_property(Object* p_object,const StringName& p_property, Variant& r_value); + static Variant::Type get_property_type(const StringName& p_type, const StringName& p_property,bool *r_is_valid=NULL); diff --git a/core/ring_buffer.h b/core/ring_buffer.h index 3cf9cf9064..5cbd261ec8 100644 --- a/core/ring_buffer.h +++ b/core/ring_buffer.h @@ -155,6 +155,12 @@ public: inline int size() { return data.size(); }; + + inline void clear() { + read_pos = 0; + write_pos = 0; + + } void resize(int p_power) { int old_size = size(); diff --git a/core/script_language.cpp b/core/script_language.cpp index 35c50b1022..b7a0f579f4 100644 --- a/core/script_language.cpp +++ b/core/script_language.cpp @@ -267,6 +267,20 @@ void PlaceHolderScriptInstance::get_property_list(List<PropertyInfo> *p_properti } } +Variant::Type PlaceHolderScriptInstance::get_property_type(const StringName& p_name,bool *r_is_valid) const { + + if (values.has(p_name)) { + if (r_is_valid) + *r_is_valid=true; + return values[p_name].get_type(); + } + if (r_is_valid) + *r_is_valid=false; + + return Variant::NIL; +} + + void PlaceHolderScriptInstance::update(const List<PropertyInfo> &p_properties,const Map<StringName,Variant>& p_values) { diff --git a/core/script_language.h b/core/script_language.h index 5a0f673b94..9660f141c7 100644 --- a/core/script_language.h +++ b/core/script_language.h @@ -82,6 +82,7 @@ public: virtual StringName get_instance_base_type() const=0; // this may not work in all scripts, will return empty if so virtual ScriptInstance* instance_create(Object *p_this)=0; virtual bool instance_has(const Object *p_this) const=0; + virtual bool has_source_code() const=0; virtual String get_source_code() const=0; @@ -109,6 +110,7 @@ public: virtual bool set(const StringName& p_name, const Variant& p_value)=0; virtual bool get(const StringName& p_name, Variant &r_ret) const=0; virtual void get_property_list(List<PropertyInfo> *p_properties) const=0; + virtual Variant::Type get_property_type(const StringName& p_name,bool *r_is_valid=NULL) const=0; virtual void get_method_list(List<MethodInfo> *p_list) const=0; virtual bool has_method(const StringName& p_method) const=0; @@ -208,6 +210,7 @@ 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=NULL) const; virtual void get_method_list(List<MethodInfo> *p_list) const {} virtual bool has_method(const StringName& p_method) const { return false; } diff --git a/core/variant.h b/core/variant.h index 8fd9662c36..e75a2b1c92 100644 --- a/core/variant.h +++ b/core/variant.h @@ -390,7 +390,7 @@ public: Variant call(const StringName& p_method,const Variant** p_args,int p_argcount,CallError &r_error); Variant call(const StringName& p_method,const Variant& p_arg1=Variant(),const Variant& p_arg2=Variant(),const Variant& p_arg3=Variant(),const Variant& p_arg4=Variant(),const Variant& p_arg5=Variant()); - static Variant construct(const Variant::Type,const Variant** p_args,int p_argcount,CallError &r_error); + static Variant construct(const Variant::Type,const Variant** p_args,int p_argcount,CallError &r_error,bool p_strict=true); void get_method_list(List<MethodInfo> *p_list) const; bool has_method(const StringName& p_method) const; diff --git a/core/variant_call.cpp b/core/variant_call.cpp index 48c38f05f9..2d10cf4d44 100644 --- a/core/variant_call.cpp +++ b/core/variant_call.cpp @@ -858,6 +858,11 @@ static void _call_##m_type##_##m_method(Variant& r_ret,Variant& p_self,const Var r_ret=Transform(p_args[0]->operator Matrix3(),p_args[1]->operator Vector3()); } + static void Image_init1(Variant& r_ret, const Variant** p_args) { + + r_ret=Image(*p_args[0],*p_args[1],*p_args[2],Image::Format(p_args[3]->operator int())); + } + static void add_constructor(VariantConstructFunc p_func,const Variant::Type p_type, const String& p_name1="", const Variant::Type p_type1=Variant::NIL, const String& p_name2="", const Variant::Type p_type2=Variant::NIL, @@ -959,7 +964,7 @@ Variant Variant::call(const StringName& p_method,const Variant** p_args,int p_ar #define VCALL(m_type,m_method) _VariantCall::_call_##m_type##_##m_method -Variant Variant::construct(const Variant::Type p_type,const Variant** p_args,int p_argcount,CallError &r_error) { +Variant Variant::construct(const Variant::Type p_type, const Variant** p_args, int p_argcount, CallError &r_error, bool p_strict) { r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD; ERR_FAIL_INDEX_V(p_type,VARIANT_MAX,Variant()); @@ -1035,7 +1040,7 @@ Variant Variant::construct(const Variant::Type p_type,const Variant** p_args,int } else if (p_argcount==1 && p_args[0]->type==p_type) { return *p_args[0]; //copy construct - } else if (p_argcount==1 && Variant::can_convert(p_args[0]->type,p_type)) { + } else if (p_argcount==1 && (!p_strict || Variant::can_convert(p_args[0]->type,p_type))) { //near match construct switch(p_type) { @@ -1583,6 +1588,8 @@ _VariantCall::addfunc(Variant::m_vtype,Variant::m_ret,_SCS(#m_method),VCALL(m_cl _VariantCall::add_constructor(_VariantCall::Transform_init1,Variant::TRANSFORM,"x_axis",Variant::VECTOR3,"y_axis",Variant::VECTOR3,"z_axis",Variant::VECTOR3,"origin",Variant::VECTOR3); _VariantCall::add_constructor(_VariantCall::Transform_init2,Variant::TRANSFORM,"basis",Variant::MATRIX3,"origin",Variant::VECTOR3); + _VariantCall::add_constructor(_VariantCall::Image_init1,Variant::IMAGE,"width",Variant::INT,"height",Variant::INT,"mipmaps",Variant::BOOL,"format",Variant::INT); + /* REGISTER CONSTANTS */ _VariantCall::constant_data[Variant::VECTOR3].value["AXIS_X"]=Vector3::AXIS_X; diff --git a/core/vector.h b/core/vector.h index d103400622..78dff5eadb 100644 --- a/core/vector.h +++ b/core/vector.h @@ -42,7 +42,7 @@ template<class T> class Vector { - mutable void* _ptr; + mutable T* _ptr; // internal helpers @@ -51,21 +51,21 @@ class Vector { if (!_ptr) return NULL; - return reinterpret_cast<SafeRefCount*>(_ptr); + return reinterpret_cast<SafeRefCount*>((uint8_t*)_ptr-sizeof(int)-sizeof(SafeRefCount)); } _FORCE_INLINE_ int* _get_size() const { if (!_ptr) return NULL; - return reinterpret_cast<int*>(((uint8_t*)(_ptr))+sizeof(SafeRefCount)); + return reinterpret_cast<int*>((uint8_t*)_ptr-sizeof(int)); } _FORCE_INLINE_ T* _get_data() const { if (!_ptr) return NULL; - return reinterpret_cast<T*>(((uint8_t*)(_ptr))+sizeof(SafeRefCount)+sizeof(int)); + return reinterpret_cast<T*>(_ptr); } @@ -88,11 +88,11 @@ public: _FORCE_INLINE_ void clear() { resize(0); } _FORCE_INLINE_ int size() const { - - if (!_ptr) - return 0; + int* size = _get_size(); + if (size) + return *size; else - return *reinterpret_cast<int*>(((uint8_t*)(_ptr))+sizeof(SafeRefCount)); + return 0; } _FORCE_INLINE_ bool empty() const { return _ptr == 0; } Error resize(int p_size); @@ -174,7 +174,7 @@ void Vector<T>::_unref(void *p_data) { if (!p_data) return; - SafeRefCount *src = reinterpret_cast<SafeRefCount*>(p_data); + SafeRefCount *src = reinterpret_cast<SafeRefCount*>((uint8_t*)p_data-sizeof(int)-sizeof(SafeRefCount)); if (!src->unref()) return; // still in use @@ -189,7 +189,7 @@ void Vector<T>::_unref(void *p_data) { } // free mem - memfree(p_data); + memfree((uint8_t*)p_data-sizeof(int)-sizeof(SafeRefCount)); } @@ -201,7 +201,8 @@ void Vector<T>::_copy_on_write() { if (_get_refcount()->get() > 1 ) { /* in use by more than me */ - SafeRefCount *src_new=(SafeRefCount *)memalloc(_get_alloc_size(*_get_size())); + void* mem_new = memalloc(_get_alloc_size(*_get_size())); + SafeRefCount *src_new=(SafeRefCount *)mem_new; src_new->init(); int * _size = (int*)(src_new+1); *_size=*_get_size(); @@ -215,7 +216,7 @@ void Vector<T>::_copy_on_write() { } _unref(_ptr); - _ptr=src_new; + _ptr=_data; } } @@ -260,16 +261,17 @@ Error Vector<T>::resize(int p_size) { if (size()==0) { // alloc from scratch - _ptr = (T*)memalloc(_get_alloc_size(p_size)); - ERR_FAIL_COND_V( !_ptr ,ERR_OUT_OF_MEMORY); + void* ptr=memalloc(_get_alloc_size(p_size)); + ERR_FAIL_COND_V( !ptr ,ERR_OUT_OF_MEMORY); + _ptr=(T*)((uint8_t*)ptr+sizeof(int)+sizeof(SafeRefCount)); _get_refcount()->init(); // init refcount *_get_size()=0; // init size (currently, none) } else { - void *_ptrnew = (T*)memrealloc(_ptr,_get_alloc_size(p_size)); + void *_ptrnew = (T*)memrealloc((uint8_t*)_ptr-sizeof(int)-sizeof(SafeRefCount),_get_alloc_size(p_size)); ERR_FAIL_COND_V( !_ptrnew ,ERR_OUT_OF_MEMORY); - _ptr=_ptrnew; + _ptr=(T*)((uint8_t*)_ptrnew+sizeof(int)+sizeof(SafeRefCount)); } // construct the newly created elements @@ -291,10 +293,10 @@ Error Vector<T>::resize(int p_size) { t->~T(); } - void *_ptrnew = (T*)memrealloc(_ptr,_get_alloc_size(p_size)); + void *_ptrnew = (T*)memrealloc((uint8_t*)_ptr-sizeof(int)-sizeof(SafeRefCount),_get_alloc_size(p_size)); ERR_FAIL_COND_V( !_ptrnew ,ERR_OUT_OF_MEMORY); - _ptr=_ptrnew; + _ptr=(T*)((uint8_t*)_ptrnew+sizeof(int)+sizeof(SafeRefCount)); *_get_size()=p_size; |