diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/bind/core_bind.cpp | 2 | ||||
-rw-r--r-- | core/globals.cpp | 11 | ||||
-rw-r--r-- | core/globals.h | 1 | ||||
-rw-r--r-- | core/image.cpp | 8 | ||||
-rw-r--r-- | core/io/file_access_encrypted.cpp | 4 | ||||
-rw-r--r-- | core/io/http_client.cpp | 2 | ||||
-rw-r--r-- | core/io/ip_address.cpp | 2 | ||||
-rw-r--r-- | core/io/resource_format_binary.cpp | 2 | ||||
-rw-r--r-- | core/io/resource_format_xml.cpp | 75 | ||||
-rw-r--r-- | core/method_bind.cpp | 4 | ||||
-rw-r--r-- | core/object.cpp | 7 | ||||
-rw-r--r-- | core/object.h | 29 | ||||
-rw-r--r-- | core/object_type_db.cpp | 22 | ||||
-rw-r--r-- | core/object_type_db.h | 14 | ||||
-rw-r--r-- | core/print_string.cpp | 1 | ||||
-rw-r--r-- | core/print_string.h | 1 | ||||
-rw-r--r-- | core/script_debugger_local.cpp | 16 | ||||
-rw-r--r-- | core/string_db.cpp | 4 | ||||
-rw-r--r-- | core/string_db.h | 12 | ||||
-rw-r--r-- | core/ustring.cpp | 50 | ||||
-rw-r--r-- | core/ustring.h | 1 | ||||
-rw-r--r-- | core/variant.cpp | 57 | ||||
-rw-r--r-- | core/variant.h | 1 | ||||
-rw-r--r-- | core/vector.h | 8 |
24 files changed, 244 insertions, 90 deletions
diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp index 26b1dac6f1..120cb0000b 100644 --- a/core/bind/core_bind.cpp +++ b/core/bind/core_bind.cpp @@ -1772,6 +1772,7 @@ void _Thread::_start_func(void *ud) { memdelete(tud); Variant::CallError ce; const Variant* arg[1]={&t->userdata}; + t->ret=t->target_instance->call(t->target_method,arg,1,ce); if (ce.error!=Variant::CallError::CALL_OK) { @@ -1796,6 +1797,7 @@ void _Thread::_start_func(void *ud) { default: {} } + ERR_EXPLAIN("Could not call function '"+t->target_method.operator String()+"'' starting thread ID: "+t->get_id()+" Reason: "+reason); ERR_FAIL(); } diff --git a/core/globals.cpp b/core/globals.cpp index 8a7d66b68a..731c5b7dff 100644 --- a/core/globals.cpp +++ b/core/globals.cpp @@ -1149,6 +1149,12 @@ Error Globals::_save_settings_text(const String& p_file,const Map<String,List<St return OK; } + +Error Globals::_save_custom_bnd(const String &p_file) { // add other params as dictionary and array? + + return save_custom(p_file); +}; + Error Globals::save_custom(const String& p_path,const CustomMap& p_custom,const Set<String>& p_ignore_masks) { ERR_FAIL_COND_V(p_path=="",ERR_INVALID_PARAMETER); @@ -1321,7 +1327,7 @@ Vector<String> Globals::get_optimizer_presets() const { if (!E->get().name.begins_with("optimizer_presets/")) continue; - names.push_back(E->get().name.get_slice("/",1)); + names.push_back(E->get().name.get_slicec('/',1)); } names.sort(); @@ -1361,6 +1367,9 @@ void Globals::_bind_methods() { ObjectTypeDB::bind_method(_MD("has_singleton"),&Globals::has_singleton); ObjectTypeDB::bind_method(_MD("get_singleton"),&Globals::get_singleton_object); ObjectTypeDB::bind_method(_MD("load_resource_pack"),&Globals::_load_resource_pack); + + ObjectTypeDB::bind_method(_MD("save_custom"),&Globals::_save_custom_bnd); + } Globals::Globals() { diff --git a/core/globals.h b/core/globals.h index f739bcfb90..2ec56966f6 100644 --- a/core/globals.h +++ b/core/globals.h @@ -86,6 +86,7 @@ protected: List<Singleton> singletons; + Error _save_custom_bnd(const String& p_file); bool _load_resource_pack(const String& p_pack); diff --git a/core/image.cpp b/core/image.cpp index 037018519e..c31fa47847 100644 --- a/core/image.cpp +++ b/core/image.cpp @@ -1016,10 +1016,10 @@ void Image::create( const char ** p_xpm ) { String line_str=line_ptr; line_str.replace("\t"," "); - size_width=line_str.get_slice(" ",0).to_int(); - size_height=line_str.get_slice(" ",1).to_int(); - colormap_size=line_str.get_slice(" ",2).to_int(); - pixelchars=line_str.get_slice(" ",3).to_int(); + size_width=line_str.get_slicec(' ',0).to_int(); + size_height=line_str.get_slicec(' ',1).to_int(); + colormap_size=line_str.get_slicec(' ',2).to_int(); + pixelchars=line_str.get_slicec(' ',3).to_int(); ERR_FAIL_COND(colormap_size > 32766); ERR_FAIL_COND(pixelchars > 5); ERR_FAIL_COND(size_width > 32767); diff --git a/core/io/file_access_encrypted.cpp b/core/io/file_access_encrypted.cpp index 29f27dcbda..65b1ca5207 100644 --- a/core/io/file_access_encrypted.cpp +++ b/core/io/file_access_encrypted.cpp @@ -5,10 +5,12 @@ #include "print_string.h" #define COMP_MAGIC 0x43454447 +#include "core/variant.h" +#include <stdio.h> Error FileAccessEncrypted::open_and_parse(FileAccess *p_base,const Vector<uint8_t>& p_key,Mode p_mode) { - print_line("open and parse!"); + //print_line("open and parse!"); ERR_FAIL_COND_V(file!=NULL,ERR_ALREADY_IN_USE); ERR_FAIL_COND_V(p_key.size()!=32,ERR_INVALID_PARAMETER); diff --git a/core/io/http_client.cpp b/core/io/http_client.cpp index dbd009e319..24012660d2 100644 --- a/core/io/http_client.cpp +++ b/core/io/http_client.cpp @@ -325,7 +325,7 @@ Error HTTPClient::poll(){ if (i==0 && responses[i].begins_with("HTTP")) { - String num = responses[i].get_slice(" ",1); + String num = responses[i].get_slicec(' ',1); response_num=num.to_int(); } else { diff --git a/core/io/ip_address.cpp b/core/io/ip_address.cpp index c5506f1a74..ed5a45c9ef 100644 --- a/core/io/ip_address.cpp +++ b/core/io/ip_address.cpp @@ -47,7 +47,7 @@ IP_Address::IP_Address(const String& p_string) { } for(int i=0;i<4;i++) { - field[i]=p_string.get_slice(".",i).to_int(); + field[i]=p_string.get_slicec('.',i).to_int(); } } diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp index 0f6f8a74b1..c6cf631de6 100644 --- a/core/io/resource_format_binary.cpp +++ b/core/io/resource_format_binary.cpp @@ -1819,7 +1819,7 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path,const RES& p_ Property p; p.name_idx=get_string_index(F->get().name); p.value=E->get()->get(F->get().name); - if (F->get().usage&PROPERTY_USAGE_STORE_IF_NONZERO && p.value.is_zero()) + if ((F->get().usage&PROPERTY_USAGE_STORE_IF_NONZERO && p.value.is_zero())||(F->get().usage&PROPERTY_USAGE_STORE_IF_NONONE && p.value.is_one()) ) continue; p.pi=F->get(); diff --git a/core/io/resource_format_xml.cpp b/core/io/resource_format_xml.cpp index 36746a4111..b744cbf967 100644 --- a/core/io/resource_format_xml.cpp +++ b/core/io/resource_format_xml.cpp @@ -1207,47 +1207,47 @@ Error ResourceInteractiveLoaderXML::parse_property(Variant& r_v, String &r_name) r_v=Vector3( - data.get_slice(",",0).to_double(), - data.get_slice(",",1).to_double(), - data.get_slice(",",2).to_double() + data.get_slicec(',',0).to_double(), + data.get_slicec(',',1).to_double(), + data.get_slicec(',',2).to_double() ); } else if (type=="vector2") { r_v=Vector2( - data.get_slice(",",0).to_double(), - data.get_slice(",",1).to_double() + data.get_slicec(',',0).to_double(), + data.get_slicec(',',1).to_double() ); } else if (type=="plane") { r_v=Plane( - data.get_slice(",",0).to_double(), - data.get_slice(",",1).to_double(), - data.get_slice(",",2).to_double(), - data.get_slice(",",3).to_double() + data.get_slicec(',',0).to_double(), + data.get_slicec(',',1).to_double(), + data.get_slicec(',',2).to_double(), + data.get_slicec(',',3).to_double() ); } else if (type=="quaternion") { r_v=Quat( - data.get_slice(",",0).to_double(), - data.get_slice(",",1).to_double(), - data.get_slice(",",2).to_double(), - data.get_slice(",",3).to_double() + data.get_slicec(',',0).to_double(), + data.get_slicec(',',1).to_double(), + data.get_slicec(',',2).to_double(), + data.get_slicec(',',3).to_double() ); } else if (type=="rect2") { r_v=Rect2( Vector2( - data.get_slice(",",0).to_double(), - data.get_slice(",",1).to_double() + data.get_slicec(',',0).to_double(), + data.get_slicec(',',1).to_double() ), Vector2( - data.get_slice(",",2).to_double(), - data.get_slice(",",3).to_double() + data.get_slicec(',',2).to_double(), + data.get_slicec(',',3).to_double() ) ); @@ -1256,14 +1256,14 @@ Error ResourceInteractiveLoaderXML::parse_property(Variant& r_v, String &r_name) r_v=AABB( Vector3( - data.get_slice(",",0).to_double(), - data.get_slice(",",1).to_double(), - data.get_slice(",",2).to_double() + data.get_slicec(',',0).to_double(), + data.get_slicec(',',1).to_double(), + data.get_slicec(',',2).to_double() ), Vector3( - data.get_slice(",",3).to_double(), - data.get_slice(",",4).to_double(), - data.get_slice(",",5).to_double() + data.get_slicec(',',3).to_double(), + data.get_slicec(',',4).to_double(), + data.get_slicec(',',5).to_double() ) ); @@ -1272,7 +1272,7 @@ Error ResourceInteractiveLoaderXML::parse_property(Variant& r_v, String &r_name) Matrix32 m3; for (int i=0;i<3;i++) { for (int j=0;j<2;j++) { - m3.elements[i][j]=data.get_slice(",",i*2+j).to_double(); + m3.elements[i][j]=data.get_slicec(',',i*2+j).to_double(); } } r_v=m3; @@ -1282,7 +1282,7 @@ Error ResourceInteractiveLoaderXML::parse_property(Variant& r_v, String &r_name) Matrix3 m3; for (int i=0;i<3;i++) { for (int j=0;j<3;j++) { - m3.elements[i][j]=data.get_slice(",",i*3+j).to_double(); + m3.elements[i][j]=data.get_slicec(',',i*3+j).to_double(); } } r_v=m3; @@ -1292,24 +1292,24 @@ Error ResourceInteractiveLoaderXML::parse_property(Variant& r_v, String &r_name) Transform tr; for (int i=0;i<3;i++) { for (int j=0;j<3;j++) { - tr.basis.elements[i][j]=data.get_slice(",",i*3+j).to_double(); + tr.basis.elements[i][j]=data.get_slicec(',',i*3+j).to_double(); } } tr.origin=Vector3( - data.get_slice(",",9).to_double(), - data.get_slice(",",10).to_double(), - data.get_slice(",",11).to_double() + data.get_slicec(',',9).to_double(), + data.get_slicec(',',10).to_double(), + data.get_slicec(',',11).to_double() ); r_v=tr; } else if (type=="color") { r_v=Color( - data.get_slice(",",0).to_double(), - data.get_slice(",",1).to_double(), - data.get_slice(",",2).to_double(), - data.get_slice(",",3).to_double() + data.get_slicec(',',0).to_double(), + data.get_slicec(',',1).to_double(), + data.get_slicec(',',2).to_double(), + data.get_slicec(',',3).to_double() ); } else if (type=="node_path") { @@ -1674,8 +1674,8 @@ void ResourceInteractiveLoaderXML::open(FileAccess *p_f) { ERR_FAIL(); } - int major = version.get_slice(".",0).to_int(); - int minor = version.get_slice(".",1).to_int(); + int major = version.get_slicec('.',0).to_int(); + int minor = version.get_slicec('.',1).to_int(); if (major>VERSION_MAJOR) { @@ -2607,9 +2607,12 @@ Error ResourceFormatSaverXMLInstance::save(const String &p_path,const RES& p_res String name = PE->get().name; Variant value = res->get(name); - if (PE->get().usage&PROPERTY_USAGE_STORE_IF_NONZERO && value.is_zero()) + + + if ((PE->get().usage&PROPERTY_USAGE_STORE_IF_NONZERO && value.is_zero())||(PE->get().usage&PROPERTY_USAGE_STORE_IF_NONONE && value.is_one()) ) continue; + write_property(name,value); } diff --git a/core/method_bind.cpp b/core/method_bind.cpp index 3429e5f0af..ce57380434 100644 --- a/core/method_bind.cpp +++ b/core/method_bind.cpp @@ -40,8 +40,8 @@ PropertyInfo MethodBind::get_argument_info(int p_argument) const { PropertyInfo pi( get_argument_type(p_argument), name ); if ((pi.type==Variant::OBJECT) && name.find(":")!=-1) { pi.hint=PROPERTY_HINT_RESOURCE_TYPE; - pi.hint_string=name.get_slice(":",1); - pi.name=name.get_slice(":",0); + pi.hint_string=name.get_slicec(':',1); + pi.name=name.get_slicec(':',0); } return pi; diff --git a/core/object.cpp b/core/object.cpp index 6bb7973cef..07ac430d7a 100644 --- a/core/object.cpp +++ b/core/object.cpp @@ -258,12 +258,15 @@ bool Object::_predelete() { _predelete_ok=1; notification(NOTIFICATION_PREDELETE,true); + if (_predelete_ok) { + _type_ptr=NULL; //must restore so destructors can access type ptr correctly + } return _predelete_ok; } void Object::_postinitialize() { - + _type_ptr=_get_type_namev(); _initialize_typev(); notification(NOTIFICATION_POSTINITIALIZE); @@ -1707,7 +1710,7 @@ bool Object::is_edited() const { Object::Object() { - + _type_ptr=NULL; _block_signals=false; _predelete_ok=0; _instance_ID=0; diff --git a/core/object.h b/core/object.h index 9680af924a..eb0e78a8c3 100644 --- a/core/object.h +++ b/core/object.h @@ -82,7 +82,8 @@ enum PropertyUsageFlags { PROPERTY_USAGE_BUNDLE=128, //used for optimized bundles PROPERTY_USAGE_CATEGORY=256, PROPERTY_USAGE_STORE_IF_NONZERO=512, //only store if nonzero - PROPERTY_USAGE_NO_INSTANCE_STATE=1024, + PROPERTY_USAGE_STORE_IF_NONONE=1024, //only store if false + PROPERTY_USAGE_NO_INSTANCE_STATE=2048, 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, @@ -97,6 +98,8 @@ enum PropertyUsageFlags { #define ADD_PROPERTYI( m_property, m_setter, m_getter, m_index ) ObjectTypeDB::add_property( get_type_static(), m_property, m_setter, m_getter, m_index ) #define ADD_PROPERTYNZ( m_property, m_setter, m_getter ) ObjectTypeDB::add_property( get_type_static(), (m_property).added_usage(PROPERTY_USAGE_STORE_IF_NONZERO), m_setter, m_getter ) #define ADD_PROPERTYINZ( m_property, m_setter, m_getter, m_index ) ObjectTypeDB::add_property( get_type_static(), (m_property).added_usage(PROPERTY_USAGE_STORE_IF_NONZERO), m_setter, m_getter, m_index ) +#define ADD_PROPERTYNO( m_property, m_setter, m_getter ) ObjectTypeDB::add_property( get_type_static(), (m_property).added_usage(PROPERTY_USAGE_STORE_IF_NONONE), m_setter, m_getter ) +#define ADD_PROPERTYINO( m_property, m_setter, m_getter, m_index ) ObjectTypeDB::add_property( get_type_static(), (m_property).added_usage(PROPERTY_USAGE_STORE_IF_NONONE), m_setter, m_getter, m_index ) struct PropertyInfo { @@ -179,10 +182,10 @@ public:\ virtual String get_type() const { \ return String(#m_type);\ }\ -virtual StringName get_type_name() const { \ +virtual const StringName* _get_type_namev() const { \ if (!_type_name)\ _type_name=get_type_static();\ - return _type_name;\ + return &_type_name;\ }\ static _FORCE_INLINE_ void* get_type_ptr_static() { \ static int ptr;\ @@ -388,6 +391,8 @@ friend void postinitialize_handler(Object*); ScriptInstance *script_instance; RefPtr script; Dictionary metadata; + mutable StringName _type_name; + mutable const StringName* _type_ptr; void _add_user_signal(const String& p_name, const Array& p_pargs=Array()); bool _has_user_signal(const StringName& p_name) const; @@ -445,7 +450,11 @@ protected: Variant _call_deferred_bind(const Variant** p_args, int p_argcount, Variant::CallError& r_error); - + virtual const StringName* _get_type_namev() const { + if (!_type_name) + _type_name=get_type_static(); + return &_type_name; + } DVector<String> _get_meta_list_bind() const; Array _get_property_list_bind() const; @@ -523,11 +532,19 @@ public: virtual String get_type() const { return "Object"; } virtual String get_save_type() const { return get_type(); } //type stored when saving - virtual StringName get_type_name() const { return StringName("Object"); } + + + virtual bool is_type(const String& p_type) const { return (p_type=="Object"); } virtual bool is_type_ptr(void *p_ptr) const { return get_type_ptr_static()==p_ptr; } - + _FORCE_INLINE_ const StringName& get_type_name() const { + if (!_type_ptr) { + return *_get_type_namev(); + } else { + return *_type_ptr; + } + } /* IAPI */ // void set(const String& p_name, const Variant& p_value); diff --git a/core/object_type_db.cpp b/core/object_type_db.cpp index a2cae50940..c291714573 100644 --- a/core/object_type_db.cpp +++ b/core/object_type_db.cpp @@ -205,7 +205,7 @@ ObjectTypeDB::TypeInfo::~TypeInfo() { } -bool ObjectTypeDB::is_type(const String &p_type,const String& p_inherits) { +bool ObjectTypeDB::is_type(const StringName &p_type,const StringName& p_inherits) { OBJTYPE_LOCK; @@ -220,7 +220,7 @@ bool ObjectTypeDB::is_type(const String &p_type,const String& p_inherits) { return false; } -void ObjectTypeDB::get_type_list( List<String> *p_types) { +void ObjectTypeDB::get_type_list( List<StringName> *p_types) { OBJTYPE_LOCK; @@ -235,7 +235,7 @@ void ObjectTypeDB::get_type_list( List<String> *p_types) { } -void ObjectTypeDB::get_inheriters_from( const String& p_type,List<String> *p_types) { +void ObjectTypeDB::get_inheriters_from( const StringName& p_type,List<StringName> *p_types) { OBJTYPE_LOCK; @@ -249,7 +249,7 @@ void ObjectTypeDB::get_inheriters_from( const String& p_type,List<String> *p_typ } -String ObjectTypeDB::type_inherits_from(const String& p_type) { +StringName ObjectTypeDB::type_inherits_from(const StringName& p_type) { OBJTYPE_LOCK; @@ -258,7 +258,7 @@ String ObjectTypeDB::type_inherits_from(const String& p_type) { return ti->inherits; } -bool ObjectTypeDB::type_exists(const String &p_type) { +bool ObjectTypeDB::type_exists(const StringName &p_type) { OBJTYPE_LOCK; return types.has(p_type); @@ -269,7 +269,7 @@ void ObjectTypeDB::add_compatibility_type(const StringName& p_type,const StringN compat_types[p_type]=p_fallback; } -Object *ObjectTypeDB::instance(const String &p_type) { +Object *ObjectTypeDB::instance(const StringName &p_type) { TypeInfo *ti; { @@ -287,7 +287,7 @@ Object *ObjectTypeDB::instance(const String &p_type) { return ti->creation_func(); } -bool ObjectTypeDB::can_instance(const String &p_type) { +bool ObjectTypeDB::can_instance(const StringName &p_type) { OBJTYPE_LOCK; @@ -650,7 +650,13 @@ bool ObjectTypeDB::set_property(Object* p_object,const StringName& p_property, c Variant index=psg->index; const Variant* arg[2]={&index,&p_value}; Variant::CallError ce; - p_object->call(psg->setter,arg,2,ce); +// p_object->call(psg->setter,arg,2,ce); + if (psg->_setptr) { + psg->_setptr->call(p_object,arg,2,ce); + } else { + p_object->call(psg->setter,arg,2,ce); + } + } else { const Variant* arg[1]={&p_value}; diff --git a/core/object_type_db.h b/core/object_type_db.h index 27c1506960..caa5baddd5 100644 --- a/core/object_type_db.h +++ b/core/object_type_db.h @@ -228,13 +228,13 @@ public: T::register_custom_data_to_otdb(); } - static void get_type_list( List<String> *p_types); - static void get_inheriters_from( const String& p_type,List<String> *p_types); - static String type_inherits_from(const String& p_type); - static bool type_exists(const String &p_type); - static bool is_type(const String &p_type,const String& p_inherits); - static bool can_instance(const String &p_type); - static Object *instance(const String &p_type); + static void get_type_list( List<StringName> *p_types); + static void get_inheriters_from( const StringName& p_type,List<StringName> *p_types); + static StringName type_inherits_from(const StringName& p_type); + static bool type_exists(const StringName &p_type); + static bool is_type(const StringName &p_type,const StringName& p_inherits); + static bool can_instance(const StringName &p_type); + static Object *instance(const StringName &p_type); #if 0 template<class N, class M> diff --git a/core/print_string.cpp b/core/print_string.cpp index a06d4de237..42e018f303 100644 --- a/core/print_string.cpp +++ b/core/print_string.cpp @@ -32,6 +32,7 @@ static PrintHandlerList *print_handler_list=NULL; bool _print_line_enabled=true; +bool _print_error_enabled = true; void add_print_handler(PrintHandlerList *p_handler) { diff --git a/core/print_string.h b/core/print_string.h index 854f8ec2e5..4ea389b3a1 100644 --- a/core/print_string.h +++ b/core/print_string.h @@ -52,6 +52,7 @@ void add_print_handler(PrintHandlerList *p_handler); void remove_print_handler(PrintHandlerList *p_handler); extern bool _print_line_enabled; +extern bool _print_error_enabled; extern void print_line(String p_string); #endif diff --git a/core/script_debugger_local.cpp b/core/script_debugger_local.cpp index 2266b05f6d..649bbe89f0 100644 --- a/core/script_debugger_local.cpp +++ b/core/script_debugger_local.cpp @@ -60,7 +60,7 @@ void ScriptDebuggerLocal::debug(ScriptLanguage *p_script,bool p_can_continue) { if (line.get_slice_count(" ")==1) { print_line("*Frame "+itos(current_frame)+" - "+p_script->debug_get_stack_level_source(current_frame)+":"+itos(p_script->debug_get_stack_level_line(current_frame))+" in function '"+p_script->debug_get_stack_level_function(current_frame)+"'"); } else { - int frame = line.get_slice(" ",1).to_int(); + int frame = line.get_slicec(' ',1).to_int(); if (frame<0 || frame >=total_frames) { print_line("Error: Invalid frame."); } else { @@ -108,7 +108,7 @@ void ScriptDebuggerLocal::debug(ScriptLanguage *p_script,bool p_can_continue) { print_line("Usage: print <expre>"); } else { - String expr = line.get_slice(" ",2); + String expr = line.get_slicec(' ',2); String res = p_script->debug_parse_stack_level_expression(current_frame,expr); print_line(res); } @@ -130,9 +130,9 @@ void ScriptDebuggerLocal::debug(ScriptLanguage *p_script,bool p_can_continue) { } else { - String bppos=line.get_slice(" ",1); - String source=bppos.get_slice(":",0).strip_edges(); - int line=bppos.get_slice(":",1).strip_edges().to_int(); + String bppos=line.get_slicec(' ',1); + String source=bppos.get_slicec(':',0).strip_edges(); + int line=bppos.get_slicec(':',1).strip_edges().to_int(); source = breakpoint_find_source(source); @@ -147,9 +147,9 @@ void ScriptDebuggerLocal::debug(ScriptLanguage *p_script,bool p_can_continue) { clear_breakpoints(); } else { - String bppos=line.get_slice(" ",1); - String source=bppos.get_slice(":",0).strip_edges(); - int line=bppos.get_slice(":",1).strip_edges().to_int(); + String bppos=line.get_slicec(' ',1); + String source=bppos.get_slicec(':',0).strip_edges(); + int line=bppos.get_slicec(':',1).strip_edges().to_int(); source = breakpoint_find_source(source); diff --git a/core/string_db.cpp b/core/string_db.cpp index 57fdd6e70f..b48d9f37d4 100644 --- a/core/string_db.cpp +++ b/core/string_db.cpp @@ -158,7 +158,7 @@ void StringName::operator=(const StringName& p_name) { _data = p_name._data; } } - +/* was inlined StringName::operator String() const { if (_data) @@ -166,7 +166,7 @@ StringName::operator String() const { return ""; } - +*/ StringName::StringName(const StringName& p_name) { ERR_FAIL_COND(!configured); diff --git a/core/string_db.h b/core/string_db.h index 912d7513ad..3b3249bf5e 100644 --- a/core/string_db.h +++ b/core/string_db.h @@ -114,7 +114,17 @@ public: } bool operator!=(const StringName& p_name) const; - operator String() const; + _FORCE_INLINE_ operator String() const { + + if (_data) { + if (_data->cname ) + return String(_data->cname); + else + return _data->name; + } + + return String(); + } static StringName search(const char *p_name); static StringName search(const CharType *p_name); diff --git a/core/ustring.cpp b/core/ustring.cpp index 5df95ac4c2..3cfc1e4a3c 100644 --- a/core/ustring.cpp +++ b/core/ustring.cpp @@ -67,11 +67,14 @@ void String::copy_from(const char *p_cstr) { return; } + resize(len+1); // include 0 - for(int i=0;i<len+1;i++) { - - set(i,p_cstr[i]); + CharType *dst = this->ptr(); + + for (int i=0;i<len+1;i++) { + + dst[i]=p_cstr[i]; } } @@ -486,7 +489,7 @@ String String::capitalize() const { String cap; for (int i=0;i<aux.get_slice_count(" ");i++) { - String slice=aux.get_slice(" ",i); + String slice=aux.get_slicec(' ',i); if (slice.length()>0) { slice[0]=_find_upper(slice[0]); @@ -577,6 +580,41 @@ String String::get_slice(String p_splitter, int p_slice) const { } +String String::get_slicec(CharType p_splitter, int p_slice) const { + + if (empty()) + return String(); + + if (p_slice<0) + return String(); + + const CharType *c=this->ptr(); + int i=0; + int prev=0; + int count=0; + while(true) { + + + if (c[i]==0 || c[i]==p_splitter) { + + if (p_slice==count) { + + return substr(prev,i-prev); + } else { + count++; + prev=i+1; + } + + } + + i++; + + } + + return String(); //no find! + +} + Vector<String> String::split_spaces() const { @@ -3333,8 +3371,8 @@ String String::path_to(const String& p_path) const { //nothing } else { //dos style - String src_begin=src.get_slice("/",0); - String dst_begin=dst.get_slice("/",0); + String src_begin=src.get_slicec('/',0); + String dst_begin=dst.get_slicec('/',0); if (src_begin!=dst_begin) return p_path; //impossible to do this diff --git a/core/ustring.h b/core/ustring.h index 53ed319862..1000c1cc8a 100644 --- a/core/ustring.h +++ b/core/ustring.h @@ -153,6 +153,7 @@ public: int get_slice_count(String p_splitter) const; String get_slice(String p_splitter,int p_slice) const; + String get_slicec(CharType splitter,int p_slice) const; Vector<String> split(const String &p_splitter,bool p_allow_empty=true) const; Vector<String> split_spaces() const; diff --git a/core/variant.cpp b/core/variant.cpp index 034dc2b4fc..e0bceb4dd8 100644 --- a/core/variant.cpp +++ b/core/variant.cpp @@ -878,6 +878,63 @@ bool Variant::is_zero() const { return false; } + +bool Variant::is_one() const { + + switch( type ) { + case NIL: { + + return true; + } break; + + // atomic types + case BOOL: { + + return _data._bool==true; + } break; + case INT: { + + return _data._int==1; + + } break; + case REAL: { + + return _data._real==1; + + } break; + case VECTOR2: { + + return *reinterpret_cast<const Vector2*>(_data._mem)==Vector2(1,1); + + } break; + case RECT2: { + + return *reinterpret_cast<const Rect2*>(_data._mem)==Rect2(1,1,1,1); + + } break; + case VECTOR3: { + + return *reinterpret_cast<const Vector3*>(_data._mem)==Vector3(1,1,1); + + } break; + case PLANE: { + + return *reinterpret_cast<const Plane*>(_data._mem)==Plane(1,1,1,1); + + } break; + case COLOR: { + + return *reinterpret_cast<const Color*>(_data._mem)==Color(1,1,1,1); + + } break; + + default: { return !is_zero(); } + } + + return false; +} + + void Variant::reference(const Variant& p_variant) { diff --git a/core/variant.h b/core/variant.h index 5f338ef667..8fd9662c36 100644 --- a/core/variant.h +++ b/core/variant.h @@ -185,6 +185,7 @@ public: _FORCE_INLINE_ bool is_array() const { return type>=ARRAY; }; bool is_shared() const; bool is_zero() const; + bool is_one() const; operator bool() const; operator signed int() const; diff --git a/core/vector.h b/core/vector.h index b93d9a0dea..d103400622 100644 --- a/core/vector.h +++ b/core/vector.h @@ -340,12 +340,14 @@ template<class T> void Vector<T>::remove(int p_index) { ERR_FAIL_INDEX(p_index, size()); - for (int i=p_index; i<size()-1; i++) { + T*p=ptr(); + int len=size(); + for (int i=p_index; i<len-1; i++) { - set(i, get(i+1)); + p[i]=p[i+1]; }; - resize(size()-1); + resize(len-1); }; template<class T> |