diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2017-08-25 08:37:38 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-25 08:37:38 +0200 |
commit | 490aef93699abc00da58f73b1596fb3473fd53c6 (patch) | |
tree | 7912c7a540eca6b09392bbd2aa2f30fefe37f51a /modules | |
parent | b1c0e45b03aa14453846c9a888763077eef2476b (diff) | |
parent | cacced7e507f7603bacc03ae2616e58f0ede122a (diff) |
Merge pull request #10581 from hpvb/fix-gcc6+
Make cast_to a static member of Object.
Diffstat (limited to 'modules')
-rw-r--r-- | modules/gdnative/godot/rid.cpp | 2 | ||||
-rw-r--r-- | modules/gdscript/gd_compiler.cpp | 2 | ||||
-rw-r--r-- | modules/gdscript/gd_editor.cpp | 115 | ||||
-rw-r--r-- | modules/gdscript/gd_function.cpp | 8 | ||||
-rw-r--r-- | modules/gdscript/gd_parser.cpp | 2 | ||||
-rw-r--r-- | modules/gdscript/gd_script.cpp | 14 | ||||
-rw-r--r-- | modules/gridmap/grid_map.cpp | 4 | ||||
-rw-r--r-- | modules/gridmap/grid_map_editor_plugin.cpp | 8 | ||||
-rw-r--r-- | modules/nativescript/nativescript.cpp | 6 | ||||
-rw-r--r-- | modules/visual_script/visual_script.cpp | 22 | ||||
-rw-r--r-- | modules/visual_script/visual_script_editor.cpp | 61 | ||||
-rw-r--r-- | modules/visual_script/visual_script_func_nodes.cpp | 25 | ||||
-rw-r--r-- | modules/visual_script/visual_script_nodes.cpp | 14 | ||||
-rw-r--r-- | modules/visual_script/visual_script_yield_nodes.cpp | 9 |
14 files changed, 130 insertions, 162 deletions
diff --git a/modules/gdnative/godot/rid.cpp b/modules/gdnative/godot/rid.cpp index eb9538e692..09ce3a5979 100644 --- a/modules/gdnative/godot/rid.cpp +++ b/modules/gdnative/godot/rid.cpp @@ -50,7 +50,7 @@ godot_int GDAPI godot_rid_get_id(const godot_rid *p_self) { } void GDAPI godot_rid_new_with_resource(godot_rid *r_dest, const godot_object *p_from) { - const Resource *res_from = ((const Object *)p_from)->cast_to<Resource>(); + const Resource *res_from = Object::cast_to<Resource>((Object *)p_from); godot_rid_new(r_dest); if (res_from) { RID *dest = (RID *)r_dest; diff --git a/modules/gdscript/gd_compiler.cpp b/modules/gdscript/gd_compiler.cpp index c243f88b7a..2aa24e88a9 100644 --- a/modules/gdscript/gd_compiler.cpp +++ b/modules/gdscript/gd_compiler.cpp @@ -1971,7 +1971,7 @@ Error GDCompiler::_parse_class(GDScript *p_script, GDScript *p_owner, const GDPa p_script->placeholders.erase(psi); //remove placeholder GDInstance *instance = memnew(GDInstance); - instance->base_ref = E->get()->cast_to<Reference>(); + instance->base_ref = Object::cast_to<Reference>(E->get()); instance->members.resize(p_script->member_indices.size()); instance->script = Ref<GDScript>(p_script); instance->owner = E->get(); diff --git a/modules/gdscript/gd_editor.cpp b/modules/gdscript/gd_editor.cpp index 95091831a9..d06da08551 100644 --- a/modules/gdscript/gd_editor.cpp +++ b/modules/gdscript/gd_editor.cpp @@ -372,8 +372,8 @@ static GDCompletionIdentifier _get_type_from_variant(const Variant &p_variant) { Object *obj = p_variant; if (obj) { /* - if (obj->cast_to<GDNativeClass>()) { - t.obj_type=obj->cast_to<GDNativeClass>()->get_name(); + if (Object::cast_to<GDNativeClass>(obj)) { + t.obj_type=Object::cast_to<GDNativeClass>(obj)->get_name(); t.value=Variant(); } else { */ @@ -597,8 +597,7 @@ static bool _guess_expression_type(GDCompletionContext &context, const GDParser: if (id.operator String() == "new" && base.value.get_type() == Variant::OBJECT) { Object *obj = base.value; - if (obj && obj->cast_to<GDNativeClass>()) { - GDNativeClass *gdnc = obj->cast_to<GDNativeClass>(); + if (GDNativeClass *gdnc = Object::cast_to<GDNativeClass>(obj)) { r_type.type = Variant::OBJECT; r_type.value = Variant(); r_type.obj_type = gdnc->get_name(); @@ -1509,48 +1508,45 @@ static void _find_type_arguments(GDCompletionContext &context, const GDParser::N if (id.value.get_type()) { Object *obj = id.value; - if (obj) { - - GDScript *scr = obj->cast_to<GDScript>(); - if (scr) { - while (scr) { + GDScript *scr = Object::cast_to<GDScript>(obj); + if (scr) { + while (scr) { - for (const Map<StringName, GDFunction *>::Element *E = scr->get_member_functions().front(); E; E = E->next()) { - if (E->get()->is_static() && p_method == E->get()->get_name()) { - arghint = "static func " + String(p_method) + "("; - for (int i = 0; i < E->get()->get_argument_count(); i++) { - if (i > 0) - arghint += ", "; - else - arghint += " "; - if (i == p_argidx) { - arghint += String::chr(0xFFFF); - } - arghint += "var " + E->get()->get_argument_name(i); - int deffrom = E->get()->get_argument_count() - E->get()->get_default_argument_count(); - if (i >= deffrom) { - int defidx = deffrom - i; - if (defidx >= 0 && defidx < E->get()->get_default_argument_count()) { - arghint += "=" + E->get()->get_default_argument(defidx).get_construct_string(); - } - } - if (i == p_argidx) { - arghint += String::chr(0xFFFF); + for (const Map<StringName, GDFunction *>::Element *E = scr->get_member_functions().front(); E; E = E->next()) { + if (E->get()->is_static() && p_method == E->get()->get_name()) { + arghint = "static func " + String(p_method) + "("; + for (int i = 0; i < E->get()->get_argument_count(); i++) { + if (i > 0) + arghint += ", "; + else + arghint += " "; + if (i == p_argidx) { + arghint += String::chr(0xFFFF); + } + arghint += "var " + E->get()->get_argument_name(i); + int deffrom = E->get()->get_argument_count() - E->get()->get_default_argument_count(); + if (i >= deffrom) { + int defidx = deffrom - i; + if (defidx >= 0 && defidx < E->get()->get_default_argument_count()) { + arghint += "=" + E->get()->get_default_argument(defidx).get_construct_string(); } } - arghint += ")"; - return; //found + if (i == p_argidx) { + arghint += String::chr(0xFFFF); + } } + arghint += ")"; + return; //found } - - if (scr->get_base().is_valid()) - scr = scr->get_base().ptr(); - else - scr = NULL; } - } else { - on_script = obj->get_script(); + + if (scr->get_base().is_valid()) + scr = scr->get_base().ptr(); + else + scr = NULL; } + } else { + on_script = obj->get_script(); } } @@ -2221,30 +2217,27 @@ Error GDScriptLanguage::complete_code(const String &p_code, const String &p_base if (t.value.get_type()) { Object *obj = t.value; - if (obj) { - - GDScript *scr = obj->cast_to<GDScript>(); - if (scr) { - while (scr) { + GDScript *scr = Object::cast_to<GDScript>(obj); + if (scr) { + while (scr) { - if (!isfunction) { - for (const Map<StringName, Variant>::Element *E = scr->get_constants().front(); E; E = E->next()) { - options.insert(E->key()); - } + if (!isfunction) { + for (const Map<StringName, Variant>::Element *E = scr->get_constants().front(); E; E = E->next()) { + options.insert(E->key()); } - for (const Map<StringName, GDFunction *>::Element *E = scr->get_member_functions().front(); E; E = E->next()) { - if (E->get()->is_static()) - options.insert(E->key()); - } - - if (scr->get_base().is_valid()) - scr = scr->get_base().ptr(); - else - scr = NULL; } - } else { - on_script = obj->get_script(); + for (const Map<StringName, GDFunction *>::Element *E = scr->get_member_functions().front(); E; E = E->next()) { + if (E->get()->is_static()) + options.insert(E->key()); + } + + if (scr->get_base().is_valid()) + scr = scr->get_base().ptr(); + else + scr = NULL; } + } else { + on_script = obj->get_script(); } } @@ -2836,9 +2829,9 @@ Error GDScriptLanguage::lookup_code(const String &p_code, const String &p_symbol Object *obj = value; if (obj) { - if (obj->cast_to<GDNativeClass>()) { + if (Object::cast_to<GDNativeClass>(obj)) { r_result.type = ScriptLanguage::LookupResult::RESULT_CLASS; - r_result.class_name = obj->cast_to<GDNativeClass>()->get_name(); + r_result.class_name = Object::cast_to<GDNativeClass>(obj)->get_name(); } else { r_result.type = ScriptLanguage::LookupResult::RESULT_CLASS; diff --git a/modules/gdscript/gd_function.cpp b/modules/gdscript/gd_function.cpp index 13a7480a36..3b78573f58 100644 --- a/modules/gdscript/gd_function.cpp +++ b/modules/gdscript/gd_function.cpp @@ -371,7 +371,7 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a Object *obj_A = *a; Object *obj_B = *b; - GDScript *scr_B = obj_B->cast_to<GDScript>(); + GDScript *scr_B = Object::cast_to<GDScript>(obj_B); bool extends_ok = false; @@ -397,7 +397,7 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a } else { - GDNativeClass *nc = obj_B->cast_to<GDNativeClass>(); + GDNativeClass *nc = Object::cast_to<GDNativeClass>(obj_B); if (!nc) { @@ -1434,7 +1434,7 @@ Variant GDFunctionState::_signal_callback(const Variant **p_args, int p_argcount // If the return value is a GDFunctionState reference, // then the function did yield again after resuming. if (ret.is_ref()) { - GDFunctionState *gdfs = ret.operator Object *()->cast_to<GDFunctionState>(); + GDFunctionState *gdfs = Object::cast_to<GDFunctionState>((Object *)&ret); if (gdfs && gdfs->function == function) completed = false; } @@ -1490,7 +1490,7 @@ Variant GDFunctionState::resume(const Variant &p_arg) { // If the return value is a GDFunctionState reference, // then the function did yield again after resuming. if (ret.is_ref()) { - GDFunctionState *gdfs = ret.operator Object *()->cast_to<GDFunctionState>(); + GDFunctionState *gdfs = Object::cast_to<GDFunctionState>((Object *)&ret); if (gdfs && gdfs->function == function) completed = false; } diff --git a/modules/gdscript/gd_parser.cpp b/modules/gdscript/gd_parser.cpp index 0cda1701cd..48da2135fa 100644 --- a/modules/gdscript/gd_parser.cpp +++ b/modules/gdscript/gd_parser.cpp @@ -3959,7 +3959,7 @@ void GDParser::_parse_class(ClassNode *p_class) { member._export.usage |= PROPERTY_USAGE_SCRIPT_VARIABLE; if (cn->value.get_type() == Variant::OBJECT) { Object *obj = cn->value; - Resource *res = obj->cast_to<Resource>(); + Resource *res = Object::cast_to<Resource>(obj); if (res == NULL) { _set_error("Exported constant not a type or resource."); return; diff --git a/modules/gdscript/gd_script.cpp b/modules/gdscript/gd_script.cpp index fbc7816f91..68c1fb3635 100644 --- a/modules/gdscript/gd_script.cpp +++ b/modules/gdscript/gd_script.cpp @@ -73,7 +73,7 @@ Variant GDNativeClass::_new() { ERR_FAIL_COND_V(!o, Variant()); } - Reference *ref = o->cast_to<Reference>(); + Reference *ref = Object::cast_to<Reference>(o); if (ref) { return REF(ref); } else { @@ -161,7 +161,7 @@ Variant GDScript::_new(const Variant **p_args, int p_argcount, Variant::CallErro owner = memnew(Reference); //by default, no base means use reference } - Reference *r = owner->cast_to<Reference>(); + Reference *r = Object::cast_to<Reference>(owner); if (r) { ref = REF(r); } @@ -397,7 +397,7 @@ ScriptInstance *GDScript::instance_create(Object *p_this) { } Variant::CallError unchecked_error; - return _create_instance(NULL, 0, p_this, p_this->cast_to<Reference>(), unchecked_error); + return _create_instance(NULL, 0, p_this, Object::cast_to<Reference>(p_this), unchecked_error); } bool GDScript::instance_has(const Object *p_this) const { @@ -575,9 +575,7 @@ void GDScript::update_exports() { //print_line("update exports for "+get_path()+" ic: "+itos(copy.size())); for (Set<ObjectID>::Element *E = copy.front(); E; E = E->next()) { Object *id = ObjectDB::get_instance(E->get()); - if (!id) - continue; - GDScript *s = id->cast_to<GDScript>(); + GDScript *s = Object::cast_to<GDScript>(id); if (!s) continue; s->update_exports(); @@ -2006,11 +2004,11 @@ Error ResourceFormatSaverGDScript::save(const String &p_path, const RES &p_resou void ResourceFormatSaverGDScript::get_recognized_extensions(const RES &p_resource, List<String> *p_extensions) const { - if (p_resource->cast_to<GDScript>()) { + if (Object::cast_to<GDScript>(*p_resource)) { p_extensions->push_back("gd"); } } bool ResourceFormatSaverGDScript::recognize(const RES &p_resource) const { - return p_resource->cast_to<GDScript>() != NULL; + return Object::cast_to<GDScript>(*p_resource) != NULL; } diff --git a/modules/gridmap/grid_map.cpp b/modules/gridmap/grid_map.cpp index 1205776882..fe5936b715 100644 --- a/modules/gridmap/grid_map.cpp +++ b/modules/gridmap/grid_map.cpp @@ -715,12 +715,12 @@ void GridMap::_notification(int p_what) { Spatial *c = this; while (c) { - navigation = c->cast_to<Navigation>(); + navigation = Object::cast_to<Navigation>(c); if (navigation) { break; } - c = c->get_parent()->cast_to<Spatial>(); + c = Object::cast_to<Spatial>(c->get_parent()); } if (navigation) { diff --git a/modules/gridmap/grid_map_editor_plugin.cpp b/modules/gridmap/grid_map_editor_plugin.cpp index 7bb80c2510..8c56da4492 100644 --- a/modules/gridmap/grid_map_editor_plugin.cpp +++ b/modules/gridmap/grid_map_editor_plugin.cpp @@ -806,7 +806,7 @@ void GridMapEditor::edit(GridMap *p_gridmap) { _update_selection_transform(); _update_duplicate_indicator(); - spatial_editor = editor->get_editor_plugin_screen()->cast_to<SpatialEditorPlugin>(); + spatial_editor = Object::cast_to<SpatialEditorPlugin>(editor->get_editor_plugin_screen()); if (!node) { set_process(false); @@ -978,14 +978,14 @@ void GridMapEditor::_notification(int p_what) { if (lock_view) { - EditorNode *editor = get_tree()->get_root()->get_child(0)->cast_to<EditorNode>(); + EditorNode *editor = Object::cast_to<EditorNode>(get_tree()->get_root()->get_child(0)); Plane p; p.normal[edit_axis] = 1.0; p.d = edit_floor[edit_axis] * node->get_cell_size(); p = node->get_transform().xform(p); // plane to snap - SpatialEditorPlugin *sep = editor->get_editor_plugin_screen()->cast_to<SpatialEditorPlugin>(); + SpatialEditorPlugin *sep = Object::cast_to<SpatialEditorPlugin>(editor->get_editor_plugin_screen()); if (sep) sep->snap_cursor_to_plane(p); //editor->get_editor_plugin_screen()->call("snap_cursor_to_plane",p); @@ -1371,7 +1371,7 @@ GridMapEditor::~GridMapEditor() { void GridMapEditorPlugin::edit(Object *p_object) { - gridmap_editor->edit(p_object ? p_object->cast_to<GridMap>() : NULL); + gridmap_editor->edit(Object::cast_to<GridMap>(p_object)); } bool GridMapEditorPlugin::handles(Object *p_object) const { diff --git a/modules/nativescript/nativescript.cpp b/modules/nativescript/nativescript.cpp index d428834d59..b495c7bf4d 100644 --- a/modules/nativescript/nativescript.cpp +++ b/modules/nativescript/nativescript.cpp @@ -399,7 +399,7 @@ Variant NativeScript::_new(const Variant **p_args, int p_argcount, Variant::Call owner = memnew(Reference); } - Reference *r = owner->cast_to<Reference>(); + Reference *r = Object::cast_to<Reference>(owner); if (r) { ref = REF(r); } @@ -1203,11 +1203,11 @@ Error ResourceFormatSaverNativeScript::save(const String &p_path, const RES &p_r } bool ResourceFormatSaverNativeScript::recognize(const RES &p_resource) const { - return p_resource->cast_to<NativeScript>() != NULL; + return Object::cast_to<NativeScript>(*p_resource) != NULL; } void ResourceFormatSaverNativeScript::get_recognized_extensions(const RES &p_resource, List<String> *p_extensions) const { - if (p_resource->cast_to<NativeScript>()) { + if (Object::cast_to<NativeScript>(*p_resource)) { p_extensions->push_back("gdns"); } } diff --git a/modules/visual_script/visual_script.cpp b/modules/visual_script/visual_script.cpp index b4bdbe16b4..6b69ffdf8d 100644 --- a/modules/visual_script/visual_script.cpp +++ b/modules/visual_script/visual_script.cpp @@ -273,7 +273,9 @@ void VisualScript::_node_ports_changed(int p_id) { Function &func = functions[function]; Ref<VisualScriptNode> vsn = func.nodes[p_id].node; - if (OS::get_singleton()->get_main_loop() && OS::get_singleton()->get_main_loop()->cast_to<SceneTree>() && Engine::get_singleton()->is_editor_hint()) { + if (OS::get_singleton()->get_main_loop() && + Object::cast_to<SceneTree>(OS::get_singleton()->get_main_loop()) && + Engine::get_singleton()->is_editor_hint()) { vsn->validate_input_default_values(); //force validate default values when editing on editor } @@ -336,7 +338,7 @@ void VisualScript::add_node(const StringName &p_func, int p_id, const Ref<Visual Function &func = functions[p_func]; - if (p_node->cast_to<VisualScriptFunction>()) { + if (Object::cast_to<VisualScriptFunction>(*p_node)) { //the function indeed ERR_EXPLAIN("A function node already has been set here."); ERR_FAIL_COND(func.function_id >= 0); @@ -393,7 +395,7 @@ void VisualScript::remove_node(const StringName &p_func, int p_id) { } } - if (func.nodes[p_id].node->cast_to<VisualScriptFunction>()) { + if (Object::cast_to<VisualScriptFunction>(func.nodes[p_id].node.ptr())) { func.function_id = -1; //revert to invalid } @@ -1086,7 +1088,7 @@ int VisualScript::get_member_line(const StringName &p_member) const { #ifdef TOOLS_ENABLED if (has_function(p_member)) { for (Map<int, Function::NodeData>::Element *E = functions[p_member].nodes.front(); E; E = E->next()) { - if (E->get().node->cast_to<VisualScriptFunction>()) + if (Object::cast_to<VisualScriptFunction>(E->get().node.ptr())) return E->key(); } } @@ -2001,9 +2003,9 @@ void VisualScriptInstance::create(const Ref<VisualScript> &p_script, Object *p_o max_input_args = 0; max_output_args = 0; - if (p_owner->cast_to<Node>()) { + if (Object::cast_to<Node>(p_owner)) { //turn on these if they exist and base is a node - Node *node = p_owner->cast_to<Node>(); + Node *node = Object::cast_to<Node>(p_owner); if (p_script->functions.has("_process")) node->set_process(true); if (p_script->functions.has("_fixed_process")) @@ -2094,16 +2096,16 @@ void VisualScriptInstance::create(const Ref<VisualScript> &p_script, Object *p_o } } - if (node->cast_to<VisualScriptLocalVar>() || node->cast_to<VisualScriptLocalVarSet>()) { + if (Object::cast_to<VisualScriptLocalVar>(node.ptr()) || Object::cast_to<VisualScriptLocalVarSet>(*node)) { //working memory is shared only for this node, for the same variables Ref<VisualScriptLocalVar> vslv = node; StringName var_name; - if (node->cast_to<VisualScriptLocalVar>()) - var_name = String(node->cast_to<VisualScriptLocalVar>()->get_var_name()).strip_edges(); + if (Object::cast_to<VisualScriptLocalVar>(*node)) + var_name = String(Object::cast_to<VisualScriptLocalVar>(*node)->get_var_name()).strip_edges(); else - var_name = String(node->cast_to<VisualScriptLocalVarSet>()->get_var_name()).strip_edges(); + var_name = String(Object::cast_to<VisualScriptLocalVarSet>(*node)->get_var_name()).strip_edges(); if (!local_var_indices.has(var_name)) { local_var_indices[var_name] = function.max_stack; diff --git a/modules/visual_script/visual_script_editor.cpp b/modules/visual_script/visual_script_editor.cpp index e7aaf0aa4a..61c21227fa 100644 --- a/modules/visual_script/visual_script_editor.cpp +++ b/modules/visual_script/visual_script_editor.cpp @@ -422,7 +422,7 @@ void VisualScriptEditor::_update_graph(int p_only_id) { for (int i = 0; i < graph->get_child_count(); i++) { - if (graph->get_child(i)->cast_to<GraphNode>()) { + if (Object::cast_to<GraphNode>(graph->get_child(i))) { memdelete(graph->get_child(i)); i--; } @@ -506,7 +506,7 @@ void VisualScriptEditor::_update_graph(int p_only_id) { gnode->set_show_close_button(true); } - if (node->cast_to<VisualScriptExpression>()) { + if (Object::cast_to<VisualScriptExpression>(*node)) { LineEdit *line_edit = memnew(LineEdit); line_edit->set_text(node->get_text()); @@ -520,7 +520,7 @@ void VisualScriptEditor::_update_graph(int p_only_id) { gnode->add_child(text); } - if (node->cast_to<VisualScriptComment>()) { + if (Object::cast_to<VisualScriptExpression>(*node)) { Ref<VisualScriptComment> vsc = node; gnode->set_comment(true); gnode->set_resizeable(true); @@ -970,7 +970,7 @@ void VisualScriptEditor::_override_pressed(int p_id) { void VisualScriptEditor::_member_button(Object *p_item, int p_column, int p_button) { - TreeItem *ti = p_item->cast_to<TreeItem>(); + TreeItem *ti = Object::cast_to<TreeItem>(p_item); TreeItem *root = members->get_root(); @@ -1117,8 +1117,8 @@ void VisualScriptEditor::_expression_text_changed(const String &p_text, int p_id undo_redo->commit_action(); Node *node = graph->get_node(itos(p_id)); - if (node->cast_to<Control>()) - node->cast_to<Control>()->set_size(Vector2(1, 1)); //shrink if text is smaller + if (Object::cast_to<Control>(node)) + Object::cast_to<Control>(node)->set_size(Vector2(1, 1)); //shrink if text is smaller updating_graph = false; } @@ -1253,7 +1253,7 @@ void VisualScriptEditor::_on_nodes_delete() { List<int> to_erase; for (int i = 0; i < graph->get_child_count(); i++) { - GraphNode *gn = graph->get_child(i)->cast_to<GraphNode>(); + GraphNode *gn = Object::cast_to<GraphNode>(graph->get_child(i)); if (gn) { if (gn->is_selected() && gn->is_close_button_visible()) { to_erase.push_back(gn->get_name().operator String().to_int()); @@ -1302,7 +1302,7 @@ void VisualScriptEditor::_on_nodes_duplicate() { List<int> to_duplicate; for (int i = 0; i < graph->get_child_count(); i++) { - GraphNode *gn = graph->get_child(i)->cast_to<GraphNode>(); + GraphNode *gn = Object::cast_to<GraphNode>(graph->get_child(i)); if (gn) { if (gn->is_selected() && gn->is_close_button_visible()) { to_duplicate.push_back(gn->get_name().operator String().to_int()); @@ -1335,7 +1335,7 @@ void VisualScriptEditor::_on_nodes_duplicate() { undo_redo->commit_action(); for (int i = 0; i < graph->get_child_count(); i++) { - GraphNode *gn = graph->get_child(i)->cast_to<GraphNode>(); + GraphNode *gn = Object::cast_to<GraphNode>(graph->get_child(i)); if (gn) { int id = gn->get_name().operator String().to_int(); gn->set_selected(to_select.has(id)); @@ -1799,7 +1799,7 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da if (!obj) return; - Node *node = obj->cast_to<Node>(); + Node *node = Object::cast_to<Node>(obj); Vector2 ofs = graph->get_scroll_ofs() + p_point; if (graph->is_using_snap()) { @@ -1918,7 +1918,7 @@ void VisualScriptEditor::_selected_method(const String &p_method) { void VisualScriptEditor::_draw_color_over_button(Object *obj, Color p_color) { - Button *button = obj->cast_to<Button>(); + Button *button = Object::cast_to<Button>(obj); if (!button) return; @@ -1937,7 +1937,7 @@ void VisualScriptEditor::_button_resource_previewed(const String &p_path, const if (!obj) return; - Button *b = obj->cast_to<Button>(); + Button *b = Object::cast_to<Button>(obj); ERR_FAIL_COND(!b); if (p_preview.is_null()) { @@ -2050,9 +2050,7 @@ void VisualScriptEditor::set_edit_state(const Variant &p_state) { void VisualScriptEditor::_center_on_node(int p_id) { Node *n = graph->get_node(itos(p_id)); - if (!n) - return; - GraphNode *gn = n->cast_to<GraphNode>(); + GraphNode *gn = Object::cast_to<GraphNode>(n); if (gn) { gn->set_selected(true); Vector2 new_scroll = gn->get_offset() - graph->get_size() * 0.5 + gn->get_size() * 0.5; @@ -2270,8 +2268,8 @@ void VisualScriptEditor::_move_node(String func, int p_id, const Vector2 &p_to) if (func == String(edited_func)) { Node *node = graph->get_node(itos(p_id)); - if (node && node->cast_to<GraphNode>()) - node->cast_to<GraphNode>()->set_offset(p_to); + if (Object::cast_to<GraphNode>(node)) + Object::cast_to<GraphNode>(node)->set_offset(p_to); } script->set_node_pos(edited_func, p_id, p_to / EDSCALE); } @@ -2421,10 +2419,7 @@ void VisualScriptEditor::_graph_disconnected(const String &p_from, int p_from_sl void VisualScriptEditor::_graph_connect_to_empty(const String &p_from, int p_from_slot, const Vector2 &p_release_pos) { Node *node = graph->get_node(p_from); - if (!node) - return; - - GraphNode *gn = node->cast_to<GraphNode>(); + GraphNode *gn = Object::cast_to<GraphNode>(node); if (!gn) return; @@ -2691,21 +2686,21 @@ void VisualScriptEditor::_selected_connect_node_method_or_setget(const String &p Ref<VisualScriptNode> vsn = script->get_node(edited_func, port_action_new_node); - if (vsn->cast_to<VisualScriptFunctionCall>()) { + if (Object::cast_to<VisualScriptFunctionCall>(*vsn)) { Ref<VisualScriptFunctionCall> vsfc = vsn; vsfc->set_function(p_text); script->data_connect(edited_func, port_action_node, port_action_output, port_action_new_node, 0); } - if (vsn->cast_to<VisualScriptPropertySet>()) { + if (Object::cast_to<VisualScriptPropertySet>(*vsn)) { Ref<VisualScriptPropertySet> vsp = vsn; vsp->set_property(p_text); script->data_connect(edited_func, port_action_node, port_action_output, port_action_new_node, 0); } - if (vsn->cast_to<VisualScriptPropertyGet>()) { + if (Object::cast_to<VisualScriptPropertyGet>(*vsn)) { Ref<VisualScriptPropertyGet> vsp = vsn; vsp->set_property(p_text); @@ -2752,7 +2747,7 @@ void VisualScriptEditor::_default_value_edited(Node *p_button, int p_id, int p_i existing = Variant::construct(pinfo.type, &existingp, 1, ce, false); } - default_value_edit->set_position(p_button->cast_to<Control>()->get_global_position() + Vector2(0, p_button->cast_to<Control>()->get_size().y)); + default_value_edit->set_position(Object::cast_to<Control>(p_button)->get_global_position() + Vector2(0, Object::cast_to<Control>(p_button)->get_size().y)); default_value_edit->set_size(Size2(1, 1)); if (default_value_edit->edit(NULL, pinfo.name, pinfo.type, existing, pinfo.hint, pinfo.hint_string)) { if (pinfo.hint == PROPERTY_HINT_MULTILINE_TEXT) @@ -2818,9 +2813,7 @@ void VisualScriptEditor::_comment_node_resized(const Vector2 &p_new_size, int p_ return; Node *node = graph->get_node(itos(p_node)); - if (!node) - return; - GraphNode *gn = node->cast_to<GraphNode>(); + GraphNode *gn = Object::cast_to<GraphNode>(node); if (!gn) return; @@ -2849,7 +2842,7 @@ void VisualScriptEditor::_menu_option(int p_what) { List<String> reselect; for (int i = 0; i < graph->get_child_count(); i++) { - GraphNode *gn = graph->get_child(i)->cast_to<GraphNode>(); + GraphNode *gn = Object::cast_to<GraphNode>(graph->get_child(i)); if (gn) { if (gn->is_selected()) { int id = String(gn->get_name()).to_int(); @@ -2865,7 +2858,7 @@ void VisualScriptEditor::_menu_option(int p_what) { _update_graph(); for (List<String>::Element *E = reselect.front(); E; E = E->next()) { - GraphNode *gn = graph->get_node(E->get())->cast_to<GraphNode>(); + GraphNode *gn = Object::cast_to<GraphNode>(graph->get_node(E->get())); gn->set_selected(true); } @@ -2886,13 +2879,13 @@ void VisualScriptEditor::_menu_option(int p_what) { clipboard->sequence_connections.clear(); for (int i = 0; i < graph->get_child_count(); i++) { - GraphNode *gn = graph->get_child(i)->cast_to<GraphNode>(); + GraphNode *gn = Object::cast_to<GraphNode>(graph->get_child(i)); if (gn) { if (gn->is_selected()) { int id = String(gn->get_name()).to_int(); Ref<VisualScriptNode> node = script->get_node(edited_func, id); - if (node->cast_to<VisualScriptFunction>()) { + if (Object::cast_to<VisualScriptFunction>(*node)) { EditorNode::get_singleton()->show_warning("Can't copy the function node."); return; } @@ -3000,7 +2993,7 @@ void VisualScriptEditor::_menu_option(int p_what) { undo_redo->commit_action(); for (int i = 0; i < graph->get_child_count(); i++) { - GraphNode *gn = graph->get_child(i)->cast_to<GraphNode>(); + GraphNode *gn = Object::cast_to<GraphNode>(graph->get_child(i)); if (gn) { int id = gn->get_name().operator String().to_int(); gn->set_selected(to_select.has(id)); @@ -3393,7 +3386,7 @@ VisualScriptEditor::~VisualScriptEditor() { static ScriptEditorBase *create_editor(const Ref<Script> &p_script) { - if (p_script->cast_to<VisualScript>()) { + if (Object::cast_to<VisualScript>(*p_script)) { return memnew(VisualScriptEditor); } diff --git a/modules/visual_script/visual_script_func_nodes.cpp b/modules/visual_script/visual_script_func_nodes.cpp index 47cdfff494..32f5945a10 100644 --- a/modules/visual_script/visual_script_func_nodes.cpp +++ b/modules/visual_script/visual_script_func_nodes.cpp @@ -85,10 +85,7 @@ Node *VisualScriptFunctionCall::_get_base_node() const { return NULL; MainLoop *main_loop = OS::get_singleton()->get_main_loop(); - if (!main_loop) - return NULL; - - SceneTree *scene_tree = main_loop->cast_to<SceneTree>(); + SceneTree *scene_tree = Object::cast_to<SceneTree>(main_loop); if (!scene_tree) return NULL; @@ -776,7 +773,7 @@ public: if (!p_base) return false; - Node *node = p_base->cast_to<Node>(); + Node *node = Object::cast_to<Node>(p_base); if (!node) return false; @@ -817,7 +814,7 @@ public: } break; case VisualScriptFunctionCall::CALL_MODE_NODE_PATH: { - Node *node = instance->get_owner_ptr()->cast_to<Node>(); + Node *node = Object::cast_to<Node>(instance->get_owner_ptr()); if (!node) { r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD; r_error_str = "Base object is not a Node!"; @@ -961,10 +958,8 @@ Node *VisualScriptPropertySet::_get_base_node() const { return NULL; MainLoop *main_loop = OS::get_singleton()->get_main_loop(); - if (!main_loop) - return NULL; - SceneTree *scene_tree = main_loop->cast_to<SceneTree>(); + SceneTree *scene_tree = Object::cast_to<SceneTree>(main_loop); if (!scene_tree) return NULL; @@ -1159,9 +1154,7 @@ String VisualScriptPropertySet::get_base_script() const { void VisualScriptPropertySet::_update_cache() { - if (!OS::get_singleton()->get_main_loop()) - return; - if (!OS::get_singleton()->get_main_loop()->cast_to<SceneTree>()) + if (!Object::cast_to<SceneTree>(OS::get_singleton()->get_main_loop())) return; if (!Engine::get_singleton()->is_editor_hint()) //only update cache if editor exists, it's pointless otherwise @@ -1595,7 +1588,7 @@ public: } break; case VisualScriptPropertySet::CALL_MODE_NODE_PATH: { - Node *node = instance->get_owner_ptr()->cast_to<Node>(); + Node *node = Object::cast_to<Node>(instance->get_owner_ptr()); if (!node) { r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD; r_error_str = "Base object is not a Node!"; @@ -1730,10 +1723,8 @@ Node *VisualScriptPropertyGet::_get_base_node() const { return NULL; MainLoop *main_loop = OS::get_singleton()->get_main_loop(); - if (!main_loop) - return NULL; - SceneTree *scene_tree = main_loop->cast_to<SceneTree>(); + SceneTree *scene_tree = Object::cast_to<SceneTree>(main_loop); if (!scene_tree) return NULL; @@ -2242,7 +2233,7 @@ public: } break; case VisualScriptPropertyGet::CALL_MODE_NODE_PATH: { - Node *node = instance->get_owner_ptr()->cast_to<Node>(); + Node *node = Object::cast_to<Node>(instance->get_owner_ptr()); if (!node) { r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD; r_error_str = RTR("Base object is not a Node!"); diff --git a/modules/visual_script/visual_script_nodes.cpp b/modules/visual_script/visual_script_nodes.cpp index 15e25c99ee..0d65638bb9 100644 --- a/modules/visual_script/visual_script_nodes.cpp +++ b/modules/visual_script/visual_script_nodes.cpp @@ -2079,7 +2079,7 @@ public: virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Variant::CallError &r_error, String &r_error_str) { - Node *node = instance->get_owner_ptr()->cast_to<Node>(); + Node *node = Object::cast_to<Node>(instance->get_owner_ptr()); if (!node) { r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD; r_error_str = "Base object is not a Node!"; @@ -2143,10 +2143,7 @@ VisualScriptSceneNode::TypeGuess VisualScriptSceneNode::guess_output_type(TypeGu return tg; MainLoop *main_loop = OS::get_singleton()->get_main_loop(); - if (!main_loop) - return tg; - - SceneTree *scene_tree = main_loop->cast_to<SceneTree>(); + SceneTree *scene_tree = Object::cast_to<SceneTree>(main_loop); if (!scene_tree) return tg; @@ -2181,10 +2178,7 @@ void VisualScriptSceneNode::_validate_property(PropertyInfo &property) const { return; MainLoop *main_loop = OS::get_singleton()->get_main_loop(); - if (!main_loop) - return; - - SceneTree *scene_tree = main_loop->cast_to<SceneTree>(); + SceneTree *scene_tree = Object::cast_to<SceneTree>(main_loop); if (!scene_tree) return; @@ -2274,7 +2268,7 @@ public: virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Variant::CallError &r_error, String &r_error_str) { - Node *node = instance->get_owner_ptr()->cast_to<Node>(); + Node *node = Object::cast_to<Node>(instance->get_owner_ptr()); if (!node) { r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD; r_error_str = "Base object is not a Node!"; diff --git a/modules/visual_script/visual_script_yield_nodes.cpp b/modules/visual_script/visual_script_yield_nodes.cpp index df88d2e7f7..958eacf2f2 100644 --- a/modules/visual_script/visual_script_yield_nodes.cpp +++ b/modules/visual_script/visual_script_yield_nodes.cpp @@ -105,7 +105,7 @@ public: } else { //yield - SceneTree *tree = OS::get_singleton()->get_main_loop()->cast_to<SceneTree>(); + SceneTree *tree = Object::cast_to<SceneTree>(OS::get_singleton()->get_main_loop()); if (!tree) { r_error_str = "Main Loop is not SceneTree"; r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD; @@ -252,10 +252,7 @@ Node *VisualScriptYieldSignal::_get_base_node() const { return NULL; MainLoop *main_loop = OS::get_singleton()->get_main_loop(); - if (!main_loop) - return NULL; - - SceneTree *scene_tree = main_loop->cast_to<SceneTree>(); + SceneTree *scene_tree = Object::cast_to<SceneTree>(main_loop); if (!scene_tree) return NULL; @@ -530,7 +527,7 @@ public: } break; case VisualScriptYieldSignal::CALL_MODE_NODE_PATH: { - Node *node = instance->get_owner_ptr()->cast_to<Node>(); + Node *node = Object::cast_to<Node>(instance->get_owner_ptr()); if (!node) { r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD; r_error_str = "Base object is not a Node!"; |