From 27cb75112ed3a6b98a1edfefe3c419fbe20d6337 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Sat, 16 May 2015 16:32:46 -0300 Subject: -bit slower execution in debug, but proper error reporting for get index and operators, fixes #1911 --- modules/gdscript/gd_script.cpp | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) (limited to 'modules/gdscript/gd_script.cpp') diff --git a/modules/gdscript/gd_script.cpp b/modules/gdscript/gd_script.cpp index e260f70a9..48269f449 100644 --- a/modules/gdscript/gd_script.cpp +++ b/modules/gdscript/gd_script.cpp @@ -335,17 +335,26 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a GET_VARIANT_PTR(b,3); GET_VARIANT_PTR(dst,4); +#ifdef DEBUG_ENABLED + Variant ret; + Variant::evaluate(op,*a,*b,ret,valid); +#else Variant::evaluate(op,*a,*b,*dst,valid); +#endif + if (!valid) { - if (dst->get_type()==Variant::STRING) { + if (ret.get_type()==Variant::STRING) { //return a string when invalid with the error - err_text=*dst; + err_text=ret; err_text += " in operator '"+Variant::get_operator_name(op)+"'."; } else { err_text="Invalid operands '"+Variant::get_type_name(a->get_type())+"' and '"+Variant::get_type_name(b->get_type())+"' in operator '"+Variant::get_operator_name(op)+"'."; } break; } +#ifdef DEBUG_ENABLED + *dst=ret; +#endif ip+=5; @@ -457,8 +466,13 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a GET_VARIANT_PTR(dst,3); bool valid; +#ifdef DEBUG_ENABLED +//allow better error message in cases where src and dst are the same stack position + Variant ret = src->get(*index,&valid); +#else *dst = src->get(*index,&valid); +#endif if (!valid) { String v = index->operator String(); if (v!="") { @@ -469,6 +483,9 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a err_text="Invalid get index "+v+" (on base: '"+_get_var_type(src)+"')."; break; } +#ifdef DEBUG_ENABLED + *dst=ret; +#endif ip+=4; } continue; case OPCODE_SET_NAMED: { @@ -508,7 +525,13 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a const StringName *index = &_global_names_ptr[indexname]; bool valid; +#ifdef DEBUG_ENABLED +//allow better error message in cases where src and dst are the same stack position + Variant ret = src->get_named(*index,&valid); + +#else *dst = src->get_named(*index,&valid); +#endif if (!valid) { if (src->has_method(*index)) { @@ -518,7 +541,9 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a } break; } - +#ifdef DEBUG_ENABLED + *dst=ret; +#endif ip+=4; } continue; case OPCODE_ASSIGN: { -- cgit v1.2.3-70-g09d2 From e72717e3738ea7fe1a2a6c9447ad0090bdf297ec Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Sun, 17 May 2015 13:11:55 -0300 Subject: properly save external resources, fixes #1924 added API to get scancode names to OS --- core/bind/core_bind.cpp | 19 +++++++++- core/bind/core_bind.h | 5 +++ modules/gdscript/gd_script.cpp | 4 ++ tools/editor/editor_node.cpp | 85 +++++++++++++++++++++++++++--------------- tools/editor/editor_node.h | 5 ++- 5 files changed, 84 insertions(+), 34 deletions(-) (limited to 'modules/gdscript/gd_script.cpp') diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp index cde328bc6..06b71f05c 100644 --- a/core/bind/core_bind.cpp +++ b/core/bind/core_bind.cpp @@ -5,7 +5,7 @@ #include "io/base64.h" #include "core/globals.h" #include "io/file_access_encrypted.h" - +#include "os/keyboard.h" _ResourceLoader *_ResourceLoader::singleton=NULL; Ref _ResourceLoader::load_interactive(const String& p_path,const String& p_type_hint) { @@ -694,6 +694,20 @@ String _OS::get_custom_level() const { return OS::get_singleton()->get_custom_level(); } + +String _OS::get_scancode_string(uint32_t p_code) const { + + return keycode_get_string(p_code); +} +bool _OS::is_scancode_unicode(uint32_t p_unicode) const { + + return keycode_has_unicode(p_unicode); +} +int _OS::find_scancode_from_string(const String& p_code) const { + + return find_keycode(p_code); +} + _OS *_OS::singleton=NULL; void _OS::_bind_methods() { @@ -810,6 +824,9 @@ void _OS::_bind_methods() { ObjectTypeDB::bind_method(_MD("native_video_stop"),&_OS::native_video_stop); ObjectTypeDB::bind_method(_MD("native_video_pause"),&_OS::native_video_pause); + ObjectTypeDB::bind_method(_MD("get_scancode_string","code"),&_OS::get_scancode_string); + ObjectTypeDB::bind_method(_MD("is_scancode_unicode","code"),&_OS::is_scancode_unicode); + ObjectTypeDB::bind_method(_MD("find_scancode_from_string","string"),&_OS::find_scancode_from_string); ObjectTypeDB::bind_method(_MD("set_use_file_access_save_and_swap","enabled"),&_OS::set_use_file_access_save_and_swap); diff --git a/core/bind/core_bind.h b/core/bind/core_bind.h index ea8ca9af9..05f54dd64 100644 --- a/core/bind/core_bind.h +++ b/core/bind/core_bind.h @@ -178,6 +178,11 @@ public: String get_unique_ID() const; + String get_scancode_string(uint32_t p_code) const; + bool is_scancode_unicode(uint32_t p_unicode) const; + int find_scancode_from_string(const String& p_code) const; + + /* struct Date { diff --git a/modules/gdscript/gd_script.cpp b/modules/gdscript/gd_script.cpp index 48269f449..c9b00f49a 100644 --- a/modules/gdscript/gd_script.cpp +++ b/modules/gdscript/gd_script.cpp @@ -343,6 +343,8 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a #endif if (!valid) { +#ifdef DEBUG_ENABLED + if (ret.get_type()==Variant::STRING) { //return a string when invalid with the error err_text=ret; @@ -350,7 +352,9 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a } else { err_text="Invalid operands '"+Variant::get_type_name(a->get_type())+"' and '"+Variant::get_type_name(b->get_type())+"' in operator '"+Variant::get_operator_name(op)+"'."; } +#endif break; + } #ifdef DEBUG_ENABLED *dst=ret; diff --git a/tools/editor/editor_node.cpp b/tools/editor/editor_node.cpp index 5e5d2a540..051f84272 100644 --- a/tools/editor/editor_node.cpp +++ b/tools/editor/editor_node.cpp @@ -610,7 +610,42 @@ static Error _fix_imported_scene_paths(Node* node, Node* root, String save_path) }; -bool EditorNode::_find_and_save_edited_subresources(Object *obj,Set& processed,int32_t flags) { +bool EditorNode::_find_and_save_resource(RES res,Map& processed,int32_t flags) { + + if (res.is_null()) + return false; + + if (processed.has(res)) { + + return processed[res]; + } + + + bool changed = res->is_edited(); + res->set_edited(false); + + bool subchanged = _find_and_save_edited_subresources(res.ptr(),processed,flags); + +// print_line("checking if edited: "+res->get_type()+" :: "+res->get_name()+" :: "+res->get_path()+" :: "+itos(changed)+" :: SR "+itos(subchanged)); + + if (res->get_path().is_resource_file()) { + if (changed || subchanged) { + //save + print_line("Also saving modified external resource: "+res->get_path()); + Error err = ResourceSaver::save(res->get_path(),res,flags); + + } + processed[res]=false; //because it's a file + return false; + } else { + + + processed[res]=changed; + return changed; + } +} + +bool EditorNode::_find_and_save_edited_subresources(Object *obj,Map& processed,int32_t flags) { bool ret_changed=false; List pi; @@ -620,57 +655,45 @@ bool EditorNode::_find_and_save_edited_subresources(Object *obj,Set& proces if (!(E->get().usage&PROPERTY_USAGE_STORAGE)) continue; + + switch(E->get().type) { case Variant::OBJECT: { RES res = obj->get(E->get().name); - if (res.is_null() || processed.has(res)) - break; - - processed.insert(res); - - bool changed = res->is_edited(); - res->set_edited(false); - - bool subchanged = _find_and_save_edited_subresources(res.ptr(),processed,flags); - - if (res->get_path().is_resource_file()) { - if (changed || subchanged) { - //save - print_line("Also saving modified external resource: "+res->get_path()); - Error err = ResourceSaver::save(res->get_path(),res,flags); - - } - } else { - + if (_find_and_save_resource(res,processed,flags)) ret_changed=true; - } - } break; case Variant::ARRAY: { - /*Array varray=p_variant; + Array varray= obj->get(E->get().name); int len=varray.size(); for(int i=0;iget(E->get().name);; List keys; d.get_key_list(&keys); for(List::Element *E=keys.front();E;E=E->next()) { Variant v = d[E->get()]; - _find_resources(v); - } */ + RES res=v; + if (_find_and_save_resource(res,processed,flags)) + ret_changed=true; + } } break; default: {} } @@ -681,7 +704,7 @@ bool EditorNode::_find_and_save_edited_subresources(Object *obj,Set& proces } -void EditorNode::_save_edited_subresources(Node* scene,Set& processed,int32_t flags) { +void EditorNode::_save_edited_subresources(Node* scene,Map& processed,int32_t flags) { _find_and_save_edited_subresources(scene,processed,flags); @@ -741,7 +764,7 @@ void EditorNode::_save_scene(String p_file) { err = ResourceSaver::save(p_file,sdata,flg); - Set processed; + Map processed; _save_edited_subresources(scene,processed,flg); editor_data.save_editor_external_data(); if (err==OK) { diff --git a/tools/editor/editor_node.h b/tools/editor/editor_node.h index ae712004b..76e82b5a6 100644 --- a/tools/editor/editor_node.h +++ b/tools/editor/editor_node.h @@ -390,8 +390,9 @@ class EditorNode : public Node { void _cleanup_scene(); - bool _find_and_save_edited_subresources(Object *obj,Set& processed,int32_t flags); - void _save_edited_subresources(Node* scene,Set& processed,int32_t flags); + bool _find_and_save_resource(RES p_res,Map& processed,int32_t flags); + bool _find_and_save_edited_subresources(Object *obj,Map& processed,int32_t flags); + void _save_edited_subresources(Node* scene,Map& processed,int32_t flags); struct ExportDefer { -- cgit v1.2.3-70-g09d2 From e323cc050564fdb1b5cf81793d173cbd9483f55a Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Mon, 18 May 2015 10:20:54 -0300 Subject: -Rename unexisting by nonexistant, closes #1940 -Added function to retrieve list of actions fron InputMap --- core/input_map.cpp | 18 +++++++++++++++++- core/input_map.h | 2 ++ core/method_bind.h | 2 +- core/object.cpp | 8 ++++---- doc/base/classes.xml | 2 +- modules/gdscript/gd_script.cpp | 2 +- scene/animation/animation_player.cpp | 2 +- servers/visual/shader_language.cpp | 2 +- tools/docdump/class_list.xml | 2 +- tools/editor/project_export.cpp | 2 +- 10 files changed, 30 insertions(+), 12 deletions(-) (limited to 'modules/gdscript/gd_script.cpp') diff --git a/core/input_map.cpp b/core/input_map.cpp index 83b1e757d..1196c0c86 100644 --- a/core/input_map.cpp +++ b/core/input_map.cpp @@ -42,7 +42,7 @@ void InputMap::_bind_methods() { ObjectTypeDB::bind_method(_MD("action_add_event","action","event"),&InputMap::action_add_event); ObjectTypeDB::bind_method(_MD("action_has_event","action","event"),&InputMap::action_has_event); ObjectTypeDB::bind_method(_MD("action_erase_event","action","event"),&InputMap::action_erase_event); - ObjectTypeDB::bind_method(_MD("get_action_list","action"),&InputMap::get_action_list); + ObjectTypeDB::bind_method(_MD("get_action_list","action"),&InputMap::_get_action_list); ObjectTypeDB::bind_method(_MD("event_is_action","event","action"),&InputMap::event_is_action); ObjectTypeDB::bind_method(_MD("load_from_globals"),&InputMap::load_from_globals); @@ -162,6 +162,22 @@ void InputMap::action_erase_event(const StringName& p_action,const InputEvent& p } + +Array InputMap::_get_action_list(const StringName& p_action) { + + Array ret; + const List *al = get_action_list(p_action); + if (al) { + for(List::Element *E=al->front();E;E=E->next()) { + + ret.push_back(E->get());; + } + } + + return ret; + +} + const List *InputMap::get_action_list(const StringName& p_action) { const Map::Element *E=input_map.find(p_action); diff --git a/core/input_map.h b/core/input_map.h index 875a39555..c5b21b145 100644 --- a/core/input_map.h +++ b/core/input_map.h @@ -46,6 +46,8 @@ class InputMap : public Object { List::Element *_find_event(List &p_list,const InputEvent& p_event) const; + Array _get_action_list(const StringName& p_action); + protected: static void _bind_methods(); diff --git a/core/method_bind.h b/core/method_bind.h index 49c64bd11..85c1084f8 100644 --- a/core/method_bind.h +++ b/core/method_bind.h @@ -298,7 +298,7 @@ MethodBind* create_native_method_bind( Variant (T::*p_method)(const Variant**,in // tale of an amazing hack.. // -// if you declare an unexisting class.. +// if you declare an nonexistent class.. class __UnexistingClass; diff --git a/core/object.cpp b/core/object.cpp index c1904d05d..1a51e79a9 100644 --- a/core/object.cpp +++ b/core/object.cpp @@ -1319,7 +1319,7 @@ Error Object::connect(const StringName& p_signal, Object *p_to_object, const Str if (!s) { bool signal_is_valid = ObjectTypeDB::has_signal(get_type_name(),p_signal); if (!signal_is_valid) { - ERR_EXPLAIN("Attempt to connect to unexisting signal: "+p_signal); + ERR_EXPLAIN("Attempt to connect to nonexistent signal: "+p_signal); ERR_FAIL_COND_V(!signal_is_valid,ERR_INVALID_PARAMETER); } signal_map[p_signal]=Signal(); @@ -1356,7 +1356,7 @@ bool Object::is_connected(const StringName& p_signal, Object *p_to_object, const bool signal_is_valid = ObjectTypeDB::has_signal(get_type_name(),p_signal); if (signal_is_valid) return false; - ERR_EXPLAIN("Unexisting signal: "+p_signal); + ERR_EXPLAIN("Nonexistent signal: "+p_signal); ERR_FAIL_COND_V(!s,false); } @@ -1373,7 +1373,7 @@ void Object::disconnect(const StringName& p_signal, Object *p_to_object, const S ERR_FAIL_NULL(p_to_object); Signal *s = signal_map.getptr(p_signal); if (!s) { - ERR_EXPLAIN("Unexisting signal: "+p_signal); + ERR_EXPLAIN("Nonexistent signal: "+p_signal); ERR_FAIL_COND(!s); } if (s->lock>0) { @@ -1384,7 +1384,7 @@ void Object::disconnect(const StringName& p_signal, Object *p_to_object, const S Signal::Target target(p_to_object->get_instance_ID(),p_to_method); if (!s->slot_map.has(target)) { - ERR_EXPLAIN("Disconnecting unexisting signal '"+p_signal+"', slot: "+itos(target._id)+":"+target.method); + ERR_EXPLAIN("Disconnecting nonexistent signal '"+p_signal+"', slot: "+itos(target._id)+":"+target.method); ERR_FAIL(); } int prev = p_to_object->connections.size(); diff --git a/doc/base/classes.xml b/doc/base/classes.xml index 901bfa125..57ca46097 100644 --- a/doc/base/classes.xml +++ b/doc/base/classes.xml @@ -9655,7 +9655,7 @@ - Editor will not allow to select unexisting files. + Editor will not allow to select nonexistent files. diff --git a/modules/gdscript/gd_script.cpp b/modules/gdscript/gd_script.cpp index c9b00f49a..ceca1ff2b 100644 --- a/modules/gdscript/gd_script.cpp +++ b/modules/gdscript/gd_script.cpp @@ -140,7 +140,7 @@ String GDFunction::_get_call_error(const Variant::CallError& p_err, const String } else if (p_err.error==Variant::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS) { err_text="Invalid call to "+p_where+". Expected "+itos(p_err.argument)+" arguments."; } else if (p_err.error==Variant::CallError::CALL_ERROR_INVALID_METHOD) { - err_text="Invalid call. Unexisting "+p_where+"."; + err_text="Invalid call. Nonexistent "+p_where+"."; } else if (p_err.error==Variant::CallError::CALL_ERROR_INSTANCE_IS_NULL) { err_text="Attempt to call "+p_where+" on a null instance."; } else { diff --git a/scene/animation/animation_player.cpp b/scene/animation/animation_player.cpp index 51afe6b3f..4949b33c4 100644 --- a/scene/animation/animation_player.cpp +++ b/scene/animation/animation_player.cpp @@ -295,7 +295,7 @@ void AnimationPlayer::_generate_node_caches(AnimationData* p_anim) { p_anim->node_cache[i]->bone_idx=p_anim->node_cache[i]->skeleton->find_bone(bone_name); if (p_anim->node_cache[i]->bone_idx<0) { - // broken track (unexisting bone) + // broken track (nonexistent bone) p_anim->node_cache[i]->skeleton=NULL; p_anim->node_cache[i]->spatial=NULL; printf("bone is %ls\n", String(bone_name).c_str()); diff --git a/servers/visual/shader_language.cpp b/servers/visual/shader_language.cpp index 77b7ddbc9..ea5630624 100644 --- a/servers/visual/shader_language.cpp +++ b/servers/visual/shader_language.cpp @@ -1714,7 +1714,7 @@ Error ShaderLanguage::parse_expression(Parser& parser,Node *p_parent,Node **r_ex if (!existing) { - parser.set_error("Unexisting identifier in expression: "+identifier); + parser.set_error("Nonexistent identifier in expression: "+identifier); return ERR_PARSE_ERROR; } diff --git a/tools/docdump/class_list.xml b/tools/docdump/class_list.xml index ab33cef7d..3d07f8417 100644 --- a/tools/docdump/class_list.xml +++ b/tools/docdump/class_list.xml @@ -3140,7 +3140,7 @@ - Editor will not allow to select unexisting files. + Editor will not allow to select nonexistent files. Editor will warn when a file exists. diff --git a/tools/editor/project_export.cpp b/tools/editor/project_export.cpp index 374dda852..ab27ac7fa 100644 --- a/tools/editor/project_export.cpp +++ b/tools/editor/project_export.cpp @@ -1653,7 +1653,7 @@ Error ProjectExport::export_project(const String& p_preset) { if (saver.is_null()) { memdelete(d); - ERR_EXPLAIN("Preset '"+preset+"' references unexisting saver: "+type); + ERR_EXPLAIN("Preset '"+preset+"' references nonexistent saver: "+type); ERR_FAIL_COND_V(saver.is_null(),ERR_INVALID_DATA); } -- cgit v1.2.3-70-g09d2