From cacced7e507f7603bacc03ae2616e58f0ede122a Mon Sep 17 00:00:00 2001 From: Hein-Pieter van Braam Date: Thu, 24 Aug 2017 22:58:51 +0200 Subject: Convert Object::cast_to() to the static version Currently we rely on some undefined behavior when Object->cast_to() gets called with a Null pointer. This used to work fine with GCC < 6 but newer versions of GCC remove all codepaths in which the this pointer is Null. However, the non-static cast_to() was supposed to be null safe. This patch makes cast_to() Null safe and removes the now redundant Null checks where they existed. It is explained in this article: https://www.viva64.com/en/b/0226/ --- editor/animation_editor.cpp | 4 +- editor/array_property_edit.cpp | 6 +- editor/asset_library_editor_plugin.cpp | 2 +- editor/connections_dialog.cpp | 2 +- editor/dependency_editor.cpp | 4 +- editor/editor_audio_buses.cpp | 12 +- editor/editor_autoload_settings.cpp | 2 +- editor/editor_data.cpp | 2 +- editor/editor_data.h | 5 +- editor/editor_dir_dialog.cpp | 2 +- editor/editor_node.cpp | 60 ++--- editor/editor_path.cpp | 12 +- editor/editor_plugin.cpp | 2 +- editor/editor_settings.cpp | 5 +- editor/groups_editor.cpp | 2 +- editor/import/editor_import_collada.cpp | 14 +- editor/import/resource_importer_scene.cpp | 102 ++++----- editor/io_plugins/editor_font_import_plugin.cpp | 2 +- editor/io_plugins/editor_sample_import_plugin.cpp | 2 +- editor/io_plugins/editor_scene_import_plugin.cpp | 122 +++++----- .../io_plugins/editor_scene_importer_fbxconv.cpp | 2 +- editor/io_plugins/editor_texture_import_plugin.cpp | 10 +- editor/plugins/animation_player_editor_plugin.cpp | 10 +- editor/plugins/animation_tree_editor_plugin.cpp | 8 +- editor/plugins/baked_light_baker.cpp | 13 +- editor/plugins/baked_light_editor_plugin.cpp | 2 +- editor/plugins/camera_editor_plugin.cpp | 6 +- editor/plugins/canvas_item_editor_plugin.cpp | 252 ++++++++++----------- .../plugins/collision_polygon_2d_editor_plugin.cpp | 4 +- editor/plugins/collision_polygon_editor_plugin.cpp | 4 +- .../plugins/collision_shape_2d_editor_plugin.cpp | 20 +- editor/plugins/cube_grid_theme_editor_plugin.cpp | 18 +- editor/plugins/curve_editor_plugin.cpp | 14 +- editor/plugins/gi_probe_editor_plugin.cpp | 2 +- editor/plugins/gradient_editor_plugin.cpp | 2 +- editor/plugins/item_list_editor_plugin.cpp | 10 +- editor/plugins/light_occluder_2d_editor_plugin.cpp | 4 +- editor/plugins/line_2d_editor_plugin.cpp | 4 +- editor/plugins/material_editor_plugin.cpp | 2 +- editor/plugins/mesh_editor_plugin.cpp | 2 +- editor/plugins/mesh_instance_editor_plugin.cpp | 4 +- editor/plugins/multimesh_editor_plugin.cpp | 8 +- .../plugins/navigation_polygon_editor_plugin.cpp | 4 +- editor/plugins/particles_2d_editor_plugin.cpp | 7 +- editor/plugins/particles_editor_plugin.cpp | 6 +- editor/plugins/path_2d_editor_plugin.cpp | 4 +- editor/plugins/path_editor_plugin.cpp | 8 +- editor/plugins/polygon_2d_editor_plugin.cpp | 4 +- .../plugins/resource_preloader_editor_plugin.cpp | 2 +- editor/plugins/rich_text_editor_plugin.cpp | 4 +- editor/plugins/sample_editor_plugin.cpp | 2 +- editor/plugins/sample_library_editor_plugin.cpp | 8 +- editor/plugins/sample_player_editor_plugin.cpp | 2 +- editor/plugins/script_editor_plugin.cpp | 162 +++++++------ editor/plugins/shader_editor_plugin.cpp | 10 +- editor/plugins/shader_graph_editor_plugin.cpp | 34 +-- editor/plugins/spatial_editor_plugin.cpp | 110 ++++----- editor/plugins/sprite_frames_editor_plugin.cpp | 6 +- editor/plugins/stream_editor_plugin.cpp | 2 +- editor/plugins/style_box_editor_plugin.cpp | 4 +- editor/plugins/texture_editor_plugin.cpp | 12 +- editor/plugins/texture_region_editor_plugin.cpp | 12 +- editor/plugins/theme_editor_plugin.cpp | 6 +- editor/plugins/tile_map_editor_plugin.cpp | 6 +- editor/plugins/tile_set_editor_plugin.cpp | 20 +- editor/project_manager.cpp | 24 +- editor/project_settings_editor.cpp | 8 +- editor/property_editor.cpp | 70 +++--- editor/property_selector.cpp | 8 +- editor/resources_dock.cpp | 4 +- editor/scene_tree_dock.cpp | 50 ++-- editor/scene_tree_editor.cpp | 8 +- editor/script_editor_debugger.cpp | 10 +- editor/settings_config_dialog.cpp | 2 +- editor/spatial_editor_gizmos.cpp | 148 ++++++------ editor/spatial_editor_gizmos.h | 2 +- 76 files changed, 732 insertions(+), 802 deletions(-) (limited to 'editor') diff --git a/editor/animation_editor.cpp b/editor/animation_editor.cpp index ed80be9e1..55542a59a 100644 --- a/editor/animation_editor.cpp +++ b/editor/animation_editor.cpp @@ -3249,9 +3249,9 @@ void AnimationKeyEditor::insert_value_key(const String &p_property, const Varian //let's build a node path ERR_FAIL_COND(history->get_path_size() == 0); Object *obj = ObjectDB::get_instance(history->get_path_object(0)); - ERR_FAIL_COND(!obj || !obj->cast_to()); + ERR_FAIL_COND(!Object::cast_to(obj)); - Node *node = obj->cast_to(); + Node *node = Object::cast_to(obj); String path = root->get_path_to(node); diff --git a/editor/array_property_edit.cpp b/editor/array_property_edit.cpp index 06d7d5fdc..7ef24cf62 100644 --- a/editor/array_property_edit.cpp +++ b/editor/array_property_edit.cpp @@ -273,11 +273,7 @@ void ArrayPropertyEdit::edit(Object *p_obj, const StringName &p_prop, const Stri Node *ArrayPropertyEdit::get_node() { - Object *o = ObjectDB::get_instance(obj); - if (!o) - return NULL; - - return o->cast_to(); + return Object::cast_to(ObjectDB::get_instance(obj)); } void ArrayPropertyEdit::_bind_methods() { diff --git a/editor/asset_library_editor_plugin.cpp b/editor/asset_library_editor_plugin.cpp index 5ff9c7bb8..c01c2de6b 100644 --- a/editor/asset_library_editor_plugin.cpp +++ b/editor/asset_library_editor_plugin.cpp @@ -595,7 +595,7 @@ void EditorAssetLibrary::_install_asset() { for (int i = 0; i < downloads_hb->get_child_count(); i++) { - EditorAssetLibraryItemDownload *d = downloads_hb->get_child(i)->cast_to(); + EditorAssetLibraryItemDownload *d = Object::cast_to(downloads_hb->get_child(i)); if (d && d->get_asset_id() == description->get_asset_id()) { if (EditorNode::get_singleton() != NULL) diff --git a/editor/connections_dialog.cpp b/editor/connections_dialog.cpp index 47c2cb553..56759a808 100644 --- a/editor/connections_dialog.cpp +++ b/editor/connections_dialog.cpp @@ -664,7 +664,7 @@ void ConnectionsDock::update_tree() { if (!(c.flags & CONNECT_PERSIST)) continue; - Node *target = c.target->cast_to(); + Node *target = Object::cast_to(c.target); if (!target) continue; diff --git a/editor/dependency_editor.cpp b/editor/dependency_editor.cpp index 3533c0993..78773ce3a 100644 --- a/editor/dependency_editor.cpp +++ b/editor/dependency_editor.cpp @@ -50,7 +50,7 @@ void DependencyEditor::_searched(const String &p_path) { void DependencyEditor::_load_pressed(Object *p_item, int p_cell, int p_button) { - TreeItem *ti = p_item->cast_to(); + TreeItem *ti = Object::cast_to(p_item); String fname = ti->get_text(0); replacing = ti->get_text(1); @@ -626,7 +626,7 @@ void OrphanResourcesDialog::_delete_confirm() { void OrphanResourcesDialog::_button_pressed(Object *p_item, int p_column, int p_id) { - TreeItem *ti = p_item->cast_to(); + TreeItem *ti = Object::cast_to(p_item); String path = ti->get_metadata(0); dep_edit->edit(path); diff --git a/editor/editor_audio_buses.cpp b/editor/editor_audio_buses.cpp index 282055be4..3494aa577 100644 --- a/editor/editor_audio_buses.cpp +++ b/editor/editor_audio_buses.cpp @@ -376,7 +376,7 @@ void EditorAudioBus::_effect_add(int p_which) { Object *fx = ClassDB::instance(name); ERR_FAIL_COND(!fx); - AudioEffect *afx = fx->cast_to(); + AudioEffect *afx = Object::cast_to(fx); ERR_FAIL_COND(!afx); Ref afxr = Ref(afx); @@ -865,7 +865,7 @@ void EditorAudioBuses::_update_sends() { void EditorAudioBuses::_delete_bus(Object *p_which) { - EditorAudioBus *bus = p_which->cast_to(); + EditorAudioBus *bus = Object::cast_to(p_which); int index = bus->get_index(); if (index == 0) { EditorNode::get_singleton()->show_warning("Master bus can't be deleted!"); @@ -922,7 +922,7 @@ void EditorAudioBuses::_request_drop_end() { drop_end = memnew(EditorAudioBusDrop); bus_hb->add_child(drop_end); - drop_end->set_custom_minimum_size(bus_hb->get_child(0)->cast_to()->get_size()); + drop_end->set_custom_minimum_size(Object::cast_to(bus_hb->get_child(0))->get_size()); drop_end->connect("dropped", this, "_drop_at_index", varray(), CONNECT_DEFERRED); } } @@ -1158,9 +1158,9 @@ void EditorAudioBuses::open_layout(const String &p_path) { void AudioBusesEditorPlugin::edit(Object *p_node) { - if (p_node->cast_to()) { + if (Object::cast_to(p_node)) { - String path = p_node->cast_to()->get_path(); + String path = Object::cast_to(p_node)->get_path(); if (path.is_resource_file()) { audio_bus_editor->open_layout(path); } @@ -1169,7 +1169,7 @@ void AudioBusesEditorPlugin::edit(Object *p_node) { bool AudioBusesEditorPlugin::handles(Object *p_node) const { - return (p_node->cast_to() != NULL); + return (Object::cast_to(p_node) != NULL); } void AudioBusesEditorPlugin::make_visible(bool p_visible) { diff --git a/editor/editor_autoload_settings.cpp b/editor/editor_autoload_settings.cpp index 0d7874818..f0f6aac08 100644 --- a/editor/editor_autoload_settings.cpp +++ b/editor/editor_autoload_settings.cpp @@ -238,7 +238,7 @@ void EditorAutoloadSettings::_autoload_edited() { void EditorAutoloadSettings::_autoload_button_pressed(Object *p_item, int p_column, int p_button) { - TreeItem *ti = p_item->cast_to(); + TreeItem *ti = Object::cast_to(p_item); String name = "autoload/" + ti->get_text(0); diff --git a/editor/editor_data.cpp b/editor/editor_data.cpp index 51fb1554c..0a5220497 100644 --- a/editor/editor_data.cpp +++ b/editor/editor_data.cpp @@ -75,7 +75,7 @@ void EditorHistory::_add_object(ObjectID p_object, const String &p_property, int Object *obj = ObjectDB::get_instance(p_object); ERR_FAIL_COND(!obj); - Reference *r = obj->cast_to(); + Reference *r = Object::cast_to(obj); Obj o; if (r) o.ref = REF(r); diff --git a/editor/editor_data.h b/editor/editor_data.h index a601b5019..2b336c471 100644 --- a/editor/editor_data.h +++ b/editor/editor_data.h @@ -236,10 +236,7 @@ public: T *get_node_editor_data(Node *p_node) { if (!selection.has(p_node)) return NULL; - Object *obj = selection[p_node]; - if (!obj) - return NULL; - return obj->cast_to(); + return Object::cast_to(selection[p_node]); } void add_editor_plugin(Object *p_object); diff --git a/editor/editor_dir_dialog.cpp b/editor/editor_dir_dialog.cpp index b64f5f1c6..12c55d967 100644 --- a/editor/editor_dir_dialog.cpp +++ b/editor/editor_dir_dialog.cpp @@ -114,7 +114,7 @@ void EditorDirDialog::_notification(int p_what) { void EditorDirDialog::_item_collapsed(Object *p_item) { - TreeItem *item = p_item->cast_to(); + TreeItem *item = Object::cast_to(p_item); if (updating || item->is_collapsed()) return; diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 86964b3ca..fb3c52e77 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -930,7 +930,7 @@ void EditorNode::_save_scene(String p_file, int idx) { // we must update it, but also let the previous scene state go, as // old version still work for referencing changes in instanced or inherited scenes - sdata = Ref(ResourceCache::get(p_file)->cast_to()); + sdata = Ref(Object::cast_to(ResourceCache::get(p_file))); if (sdata.is_valid()) sdata->recreate_state(); else @@ -1291,9 +1291,9 @@ void EditorNode::_dialog_action(String p_file) { uint32_t current = editor_history.get_current(); Object *current_obj = current > 0 ? ObjectDB::get_instance(current) : NULL; - ERR_FAIL_COND(!current_obj->cast_to()) + ERR_FAIL_COND(!Object::cast_to(current_obj)) - RES current_res = RES(current_obj->cast_to()); + RES current_res = RES(Object::cast_to(current_obj)); save_resource_in_path(current_res, p_file); @@ -1428,8 +1428,8 @@ void EditorNode::_prepare_history() { icon = base_icon; String text; - if (obj->cast_to()) { - Resource *r = obj->cast_to(); + if (Object::cast_to(obj)) { + Resource *r = Object::cast_to(obj); if (r->get_path().is_resource_file()) text = r->get_path().get_file(); else if (r->get_name() != String()) { @@ -1437,8 +1437,8 @@ void EditorNode::_prepare_history() { } else { text = r->get_class(); } - } else if (obj->cast_to()) { - text = obj->cast_to()->get_name(); + } else if (Object::cast_to(obj)) { + text = Object::cast_to(obj)->get_name(); } else { text = obj->get_class(); } @@ -1536,7 +1536,7 @@ void EditorNode::_edit_current() { if (is_resource) { - Resource *current_res = current_obj->cast_to(); + Resource *current_res = Object::cast_to(current_obj); ERR_FAIL_COND(!current_res); scene_tree_dock->set_selected(NULL); property_editor->edit(current_res); @@ -1548,7 +1548,7 @@ void EditorNode::_edit_current() { //top_pallete->set_current_tab(1); } else if (is_node) { - Node *current_node = current_obj->cast_to(); + Node *current_node = Object::cast_to(current_obj); ERR_FAIL_COND(!current_node); // ERR_FAIL_COND(!current_node->is_inside_tree()); @@ -1688,7 +1688,7 @@ void EditorNode::_resource_created() { Object *c = create_dialog->instance_selected(); ERR_FAIL_COND(!c); - Resource *r = c->cast_to(); + Resource *r = Object::cast_to(c); ERR_FAIL_COND(!r); REF res(r); @@ -2273,9 +2273,9 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { uint32_t current = editor_history.get_current(); Object *current_obj = current > 0 ? ObjectDB::get_instance(current) : NULL; - ERR_FAIL_COND(!current_obj->cast_to()) + ERR_FAIL_COND(!Object::cast_to(current_obj)) - RES current_res = RES(current_obj->cast_to()); + RES current_res = RES(Object::cast_to(current_obj)); save_resource(current_res); @@ -2285,9 +2285,9 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { uint32_t current = editor_history.get_current(); Object *current_obj = current > 0 ? ObjectDB::get_instance(current) : NULL; - ERR_FAIL_COND(!current_obj->cast_to()) + ERR_FAIL_COND(!Object::cast_to(current_obj)) - RES current_res = RES(current_obj->cast_to()); + RES current_res = RES(Object::cast_to(current_obj)); save_resource_as(current_res); @@ -2297,9 +2297,9 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { uint32_t current = editor_history.get_current(); Object *current_obj = current > 0 ? ObjectDB::get_instance(current) : NULL; - ERR_FAIL_COND(!current_obj->cast_to()) + ERR_FAIL_COND(!Object::cast_to(current_obj)) - RES current_res = RES(current_obj->cast_to()); + RES current_res = RES(Object::cast_to(current_obj)); current_res->set_path(""); _edit_current(); } break; @@ -2308,9 +2308,9 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { uint32_t current = editor_history.get_current(); Object *current_obj = current > 0 ? ObjectDB::get_instance(current) : NULL; - ERR_FAIL_COND(!current_obj->cast_to()) + ERR_FAIL_COND(!Object::cast_to(current_obj)) - RES current_res = RES(current_obj->cast_to()); + RES current_res = RES(Object::cast_to(current_obj)); EditorSettings::get_singleton()->set_resource_clipboard(current_res); @@ -3038,8 +3038,8 @@ void EditorNode::set_edited_scene(Node *p_scene) { } get_editor_data().set_edited_scene_root(p_scene); - if (p_scene && p_scene->cast_to()) - p_scene->cast_to()->show(); //show popups + if (Object::cast_to(p_scene)) + Object::cast_to(p_scene)->show(); //show popups scene_tree_dock->set_edited_scene(p_scene); if (get_tree()) get_tree()->set_edited_scene_root(p_scene); @@ -3182,8 +3182,8 @@ void EditorNode::set_current_scene(int p_idx) { Node *new_scene = editor_data.get_edited_scene_root(); - if (new_scene && new_scene->cast_to()) - new_scene->cast_to()->show(); //show popups + if (Object::cast_to(new_scene)) + Object::cast_to(new_scene)->show(); //show popups //print_line("set current 3 "); @@ -3333,7 +3333,7 @@ Error EditorNode::load_scene(const String &p_scene, bool p_ignore_broken_deps, b if (ResourceCache::has(lpath)) { //used from somewhere else? no problem! update state and replace sdata - Ref ps = Ref(ResourceCache::get(lpath)->cast_to()); + Ref ps = Ref(Object::cast_to(ResourceCache::get(lpath))); if (ps.is_valid()) { ps->replace_state(sdata->get_state()); ps->set_last_modified_time(sdata->get_last_modified_time()); @@ -3461,7 +3461,7 @@ void EditorNode::_property_keyed(const String &p_keyed, const Variant &p_value, void EditorNode::_transform_keyed(Object *sp, const String &p_sub, const Transform &p_key) { - Spatial *s = sp->cast_to(); + Spatial *s = Object::cast_to(sp); if (!s) return; AnimationPlayerEditor::singleton->get_key_editor()->insert_transform_key(s, p_sub, p_key); @@ -3478,7 +3478,7 @@ void EditorNode::update_keying() { if (editor_history.get_path_size() >= 1) { Object *obj = ObjectDB::get_instance(editor_history.get_path_object(0)); - if (obj && obj->cast_to()) { + if (Object::cast_to(obj)) { valid = true; } @@ -4200,7 +4200,7 @@ void EditorNode::_load_docks_from_config(Ref p_layout, const String for (int k = 0; k < DOCK_SLOT_MAX; k++) { if (!dock_slot[k]->has_node(name)) continue; - node = dock_slot[k]->get_node(name)->cast_to(); + node = Object::cast_to(dock_slot[k]->get_node(name)); if (!node) continue; atidx = k; @@ -4785,7 +4785,7 @@ void EditorNode::reload_scene(const String &p_path) { if (E->get()->get_path().begins_with(p_path + "::")) //subresources of existing scene to_clear.push_back(E->get()); - if (!E->get()->cast_to()) + if (!cast_to(E->get().ptr())) continue; if (!E->get()->get_path().is_resource_file() && !E->get()->get_path().is_abs_path()) continue; @@ -4926,13 +4926,13 @@ void EditorNode::_dim_timeout() { void EditorNode::_check_gui_base_size() { if (gui_base->get_size().width > 1200 * EDSCALE) { for (int i = 0; i < singleton->main_editor_button_vb->get_child_count(); i++) { - ToolButton *btn = singleton->main_editor_button_vb->get_child(i)->cast_to(); + ToolButton *btn = Object::cast_to(singleton->main_editor_button_vb->get_child(i)); if (btn == singleton->distraction_free) continue; btn->set_text(btn->get_name()); } } else { for (int i = 0; i < singleton->main_editor_button_vb->get_child_count(); i++) { - ToolButton *btn = singleton->main_editor_button_vb->get_child(i)->cast_to(); + ToolButton *btn = Object::cast_to(singleton->main_editor_button_vb->get_child(i)); if (btn == singleton->distraction_free) continue; btn->set_text(""); } @@ -5056,7 +5056,7 @@ EditorNode::EditorNode() { ResourceLoader::clear_translation_remaps(); //no remaps using during editor editor_initialize_certificates(); //for asset sharing - InputDefault *id = Input::get_singleton()->cast_to(); + InputDefault *id = Object::cast_to(Input::get_singleton()); if (id) { diff --git a/editor/editor_path.cpp b/editor/editor_path.cpp index fdac68ea1..24206b0f0 100644 --- a/editor/editor_path.cpp +++ b/editor/editor_path.cpp @@ -139,9 +139,9 @@ void EditorPath::_notification(int p_what) { if (left < 0) continue; String name; - if (obj->cast_to()) { + if (Object::cast_to(obj)) { - Resource *r = obj->cast_to(); + Resource *r = Object::cast_to(obj); if (r->get_path().is_resource_file()) name = r->get_path().get_file(); else @@ -149,11 +149,11 @@ void EditorPath::_notification(int p_what) { if (name == "") name = r->get_class(); - } else if (obj->cast_to()) { + } else if (Object::cast_to(obj)) { - name = obj->cast_to()->get_name(); - } else if (obj->cast_to() && obj->cast_to()->get_name() != "") { - name = obj->cast_to()->get_name(); + name = Object::cast_to(obj)->get_name(); + } else if (Object::cast_to(obj) && Object::cast_to(obj)->get_name() != "") { + name = Object::cast_to(obj)->get_name(); } else { name = obj->get_class(); } diff --git a/editor/editor_plugin.cpp b/editor/editor_plugin.cpp index f8ed18bba..220b5fb2d 100644 --- a/editor/editor_plugin.cpp +++ b/editor/editor_plugin.cpp @@ -155,7 +155,7 @@ void EditorPlugin::add_tool_menu_item(const String &p_name, Object *p_handler, c void EditorPlugin::add_tool_submenu_item(const String &p_name, Object *p_submenu) { ERR_FAIL_NULL(p_submenu); - PopupMenu *submenu = p_submenu->cast_to(); + PopupMenu *submenu = Object::cast_to(p_submenu); ERR_FAIL_NULL(submenu); //EditorNode::get_singleton()->add_tool_submenu_item(p_name, submenu); } diff --git a/editor/editor_settings.cpp b/editor/editor_settings.cpp index 358d57576..88c8c368d 100644 --- a/editor/editor_settings.cpp +++ b/editor/editor_settings.cpp @@ -804,10 +804,7 @@ void EditorSettings::notify_changes() { _THREAD_SAFE_METHOD_ - SceneTree *sml = NULL; - - if (OS::get_singleton()->get_main_loop()) - sml = OS::get_singleton()->get_main_loop()->cast_to(); + SceneTree *sml = Object::cast_to(OS::get_singleton()->get_main_loop()); if (!sml) { return; diff --git a/editor/groups_editor.cpp b/editor/groups_editor.cpp index ea1827f16..fbbbf9139 100644 --- a/editor/groups_editor.cpp +++ b/editor/groups_editor.cpp @@ -65,7 +65,7 @@ void GroupsEditor::_remove_group(Object *p_item, int p_column, int p_id) { if (!node) return; - TreeItem *ti = p_item->cast_to(); + TreeItem *ti = Object::cast_to(p_item); if (!ti) return; diff --git a/editor/import/editor_import_collada.cpp b/editor/import/editor_import_collada.cpp index b3ccb5097..1680b3250 100644 --- a/editor/import/editor_import_collada.cpp +++ b/editor/import/editor_import_collada.cpp @@ -320,7 +320,7 @@ Error ColladaImport::_create_scene(Collada::Node *p_node, Spatial *p_parent) { } else { //mesh since nothing else node = memnew(MeshInstance); - node->cast_to()->set_flag(GeometryInstance::FLAG_USE_BAKED_LIGHT, true); + Object::cast_to(node)->set_flag(GeometryInstance::FLAG_USE_BAKED_LIGHT, true); } } break; case Collada::Node::TYPE_SKELETON: { @@ -1448,9 +1448,9 @@ Error ColladaImport::_create_resources(Collada::Node *p_node) { Spatial *node = node_map[p_node->id].node; Collada::NodeGeometry *ng = static_cast(p_node); - if (node->cast_to()) { + if (Object::cast_to(node)) { - Path *path = node->cast_to(); + Path *path = Object::cast_to(node); String curve = ng->source; @@ -1523,11 +1523,11 @@ Error ColladaImport::_create_resources(Collada::Node *p_node) { } } - if (node->cast_to()) { + if (Object::cast_to(node)) { Collada::NodeGeometry *ng = static_cast(p_node); - MeshInstance *mi = node->cast_to(); + MeshInstance *mi = Object::cast_to(node); ERR_FAIL_COND_V(!mi, ERR_BUG); @@ -1561,7 +1561,7 @@ Error ColladaImport::_create_resources(Collada::Node *p_node) { } ERR_FAIL_COND_V(!node_map.has(skname), ERR_INVALID_DATA); NodeMap nmsk = node_map[skname]; - Skeleton *sk = nmsk.node->cast_to(); + Skeleton *sk = Object::cast_to(nmsk.node); ERR_FAIL_COND_V(!sk, ERR_INVALID_DATA); ERR_FAIL_COND_V(!skeleton_bone_map.has(sk), ERR_INVALID_DATA); Map &bone_remap_map = skeleton_bone_map[sk]; @@ -2092,7 +2092,7 @@ void ColladaImport::create_animation(int p_clip, bool p_make_tracks_in_all_bones if (nm.bone >= 0) { //make bone transform relative to rest (in case of skeleton) - Skeleton *sk = nm.node->cast_to(); + Skeleton *sk = Object::cast_to(nm.node); if (sk) { xform = sk->get_bone_rest(nm.bone).affine_inverse() * xform; diff --git a/editor/import/resource_importer_scene.cpp b/editor/import/resource_importer_scene.cpp index b6f17b712..5bba28949 100644 --- a/editor/import/resource_importer_scene.cpp +++ b/editor/import/resource_importer_scene.cpp @@ -172,9 +172,9 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Mapcast_to()) { + if (Object::cast_to(p_node)) { - MeshInstance *mi = p_node->cast_to(); + MeshInstance *mi = Object::cast_to(p_node); bool bb = false; @@ -203,9 +203,9 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Mapcast_to()) { + if (Object::cast_to(p_node)) { - MeshInstance *mi = p_node->cast_to(); + MeshInstance *mi = Object::cast_to(p_node); Ref m = mi->get_mesh(); @@ -232,9 +232,9 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Mapcast_to()) { + if (Object::cast_to(p_node)) { //remove animations referencing non-importable nodes - AnimationPlayer *ap = p_node->cast_to(); + AnimationPlayer *ap = Object::cast_to(p_node); List anims; ap->get_animation_list(&anims); @@ -257,9 +257,9 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Mapcast_to()) { + if (Object::cast_to(p_node)) { - MeshInstance *mi = p_node->cast_to(); + MeshInstance *mi = Object::cast_to(p_node); String str; @@ -269,9 +269,9 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Mapget_mesh()->get_name(); } - if (p_node->get_parent() && p_node->get_parent()->cast_to()) { - MeshInstance *mi = p_node->cast_to(); - MeshInstance *mip = p_node->get_parent()->cast_to(); + if (Object::cast_to(p_node->get_parent())) { + MeshInstance *mi = Object::cast_to(p_node); + MeshInstance *mip = Object::cast_to(p_node->get_parent()); String d = str.substr(str.find("imp") + 3, str.length()); if (d != "") { if ((d[0] < '0' || d[0] > '9')) @@ -307,9 +307,9 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Mapcast_to()) { + if (p_flags&SCENE_FLAG_CREATE_LODS && Object::cast_to(p_node)) { - MeshInstance *mi = p_node->cast_to(); + MeshInstance *mi = Object::cast_to(p_node); String str; @@ -321,9 +321,9 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Mapget_parent() && p_node->get_parent()->cast_to()) { - MeshInstance *mi = p_node->cast_to(); - MeshInstance *mip = p_node->get_parent()->cast_to(); + if (Object::cast_to(p_node->get_parent())) { + MeshInstance *mi = Object::cast_to(p_node); + MeshInstance *mip = Object::cast_to(p_node->get_parent()); String d=str.substr(str.find("lod")+3,str.length()); if (d!="") { if ((d[0]<'0' || d[0]>'9')) @@ -356,9 +356,9 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Mapcast_to()) { + if (p_flags&SCENE_FLAG_DETECT_LIGHTMAP_LAYER && _teststr(name,"lm") && Object::cast_to(p_node)) { - MeshInstance *mi = p_node->cast_to(); + MeshInstance *mi = Object::cast_to(p_node); String str=name; int layer = str.substr(str.find("lm")+3,str.length()).to_int(); @@ -370,19 +370,18 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Mapcast_to()) { - MeshInstance *mi = p_node->cast_to(); + if (MeshInstance *mi = Object::cast_to(p_node)) { Node *col = mi->create_trimesh_collision_node(); ERR_FAIL_COND_V(!col, NULL); col->set_name(_fixstr(name, "colonly")); - col->cast_to()->set_transform(mi->get_transform()); + Object::cast_to(col)->set_transform(mi->get_transform()); p_node->replace_by(col); memdelete(p_node); p_node = col; - StaticBody *sb = col->cast_to(); - CollisionShape *colshape = sb->get_child(0)->cast_to(); + StaticBody *sb = Object::cast_to(col); + CollisionShape *colshape = Object::cast_to(sb->get_child(0)); colshape->set_name("shape"); colshape->set_owner(p_node->get_owner()); } else if (p_node->has_meta("empty_draw_type")) { @@ -390,7 +389,7 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Mapset_name(_fixstr(name, "colonly")); - sb->cast_to()->set_transform(p_node->cast_to()->get_transform()); + Object::cast_to(sb)->set_transform(Object::cast_to(p_node)->get_transform()); p_node->replace_by(sb); memdelete(p_node); CollisionShape *colshape = memnew(CollisionShape); @@ -404,7 +403,7 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Mapset_length(1); colshape->set_shape(rayShape); colshape->set_name("RayShape"); - sb->cast_to()->rotate_x(Math_PI / 2); + Object::cast_to(sb)->rotate_x(Math_PI / 2); } else if (empty_draw_type == "IMAGE") { PlaneShape *planeShape = memnew(PlaneShape); colshape->set_shape(planeShape); @@ -419,13 +418,13 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Mapset_owner(sb->get_owner()); } - } else if (_teststr(name, "rigid") && p_node->cast_to()) { + } else if (_teststr(name, "rigid") && Object::cast_to(p_node)) { if (isroot) return p_node; // get mesh instance and bounding box - MeshInstance *mi = p_node->cast_to(); + MeshInstance *mi = Object::cast_to(p_node); Rect3 aabb = mi->get_aabb(); // create a new rigid body collision node @@ -436,12 +435,12 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Mapset_name(_fixstr(name, "rigid")); // get mesh instance xform matrix to the rigid body collision node - col->cast_to()->set_transform(mi->get_transform()); + Object::cast_to(col)->set_transform(mi->get_transform()); // save original node by duplicating it into a new instance and correcting the name Node *mesh = p_node->duplicate(); mesh->set_name(_fixstr(name, "rigid")); // reset the xform matrix of the duplicated node so it can inherit parent node xform - mesh->cast_to()->set_transform(Transform(Basis())); + Object::cast_to(mesh)->set_transform(Transform(Basis())); // reparent the new mesh node to the rigid body collision node p_node->add_child(mesh); mesh->set_owner(p_node->get_owner()); @@ -451,7 +450,7 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Mapcast_to(); + RigidBody *rb = Object::cast_to(col); // create a new Box collision shape and set the right extents Ref shape = memnew(BoxShape); shape->set_extents(aabb.get_size() * 0.5); @@ -462,9 +461,9 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Mapadd_child(colshape); colshape->set_owner(p_node->get_owner()); - } else if (_teststr(name, "col") && p_node->cast_to()) { + } else if (_teststr(name, "col") && Object::cast_to(p_node)) { - MeshInstance *mi = p_node->cast_to(); + MeshInstance *mi = Object::cast_to(p_node); mi->set_name(_fixstr(name, "col")); Node *col = mi->create_trimesh_collision_node(); @@ -473,19 +472,19 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Mapset_name("col"); p_node->add_child(col); - StaticBody *sb = col->cast_to(); - CollisionShape *colshape = sb->get_child(0)->cast_to(); + StaticBody *sb = Object::cast_to(col); + CollisionShape *colshape = Object::cast_to(sb->get_child(0)); colshape->set_name("shape"); col->add_child(colshape); colshape->set_owner(p_node->get_owner()); sb->set_owner(p_node->get_owner()); - } else if (_teststr(name, "navmesh") && p_node->cast_to()) { + } else if (_teststr(name, "navmesh") && Object::cast_to(p_node)) { if (isroot) return p_node; - MeshInstance *mi = p_node->cast_to(); + MeshInstance *mi = Object::cast_to(p_node); Ref mesh = mi->get_mesh(); ERR_FAIL_COND_V(mesh.is_null(), NULL); @@ -495,7 +494,7 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map nmesh = memnew(NavigationMesh); nmesh->create_from_mesh(mesh); nmi->set_navigation_mesh(nmesh); - nmi->cast_to()->set_transform(mi->get_transform()); + Object::cast_to(nmi)->set_transform(mi->get_transform()); p_node->replace_by(nmi); memdelete(p_node); p_node = nmi; @@ -505,7 +504,7 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Mapget_owner(); - Spatial *s = p_node->cast_to(); + Spatial *s = Object::cast_to(p_node); VehicleBody *bv = memnew(VehicleBody); String n = _fixstr(p_node->get_name(), "vehicle"); bv->set_name(n); @@ -525,7 +524,7 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Mapget_owner(); - Spatial *s = p_node->cast_to(); + Spatial *s = Object::cast_to(p_node); VehicleWheel *bv = memnew(VehicleWheel); String n = _fixstr(p_node->get_name(), "wheel"); bv->set_name(n); @@ -539,12 +538,12 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Mapcast_to()) { + } else if (_teststr(name, "room") && Object::cast_to(p_node)) { if (isroot) return p_node; - MeshInstance *mi = p_node->cast_to(); + MeshInstance *mi = Object::cast_to(p_node); PoolVector faces = mi->get_faces(VisualInstance::FACES_SOLID); BSP_Tree bsptree(faces); @@ -567,7 +566,7 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Mapcast_to(); + Spatial *dummy = Object::cast_to(p_node); ERR_FAIL_COND_V(!dummy, NULL); Room *room = memnew(Room); @@ -580,12 +579,12 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Mapcompute_room_from_subtree(); - } else if (_teststr(name, "portal") && p_node->cast_to()) { + } else if (_teststr(name, "portal") && Object::cast_to(p_node)) { if (isroot) return p_node; - MeshInstance *mi = p_node->cast_to(); + MeshInstance *mi = Object::cast_to(p_node); PoolVector faces = mi->get_faces(VisualInstance::FACES_SOLID); ERR_FAIL_COND_V(faces.size() == 0, NULL); @@ -659,11 +658,11 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Mapcast_to()) { + } else if (Object::cast_to(p_node)) { //last attempt, maybe collision insde the mesh data - MeshInstance *mi = p_node->cast_to(); + MeshInstance *mi = Object::cast_to(p_node); Ref mesh = mi->get_mesh(); if (!mesh.is_null()) { @@ -728,7 +727,7 @@ void ResourceImporterScene::_create_clips(Node *scene, const Array &p_clips, boo Node *n = scene->get_node(String("AnimationPlayer")); ERR_FAIL_COND(!n); - AnimationPlayer *anim = n->cast_to(); + AnimationPlayer *anim = Object::cast_to(n); ERR_FAIL_COND(!anim); if (!anim->has_animation("default")) @@ -847,7 +846,7 @@ void ResourceImporterScene::_filter_tracks(Node *scene, const String &p_text) { return; Node *n = scene->get_node(String("AnimationPlayer")); ERR_FAIL_COND(!n); - AnimationPlayer *anim = n->cast_to(); + AnimationPlayer *anim = Object::cast_to(n); ERR_FAIL_COND(!anim); Vector strings = p_text.split("\n"); @@ -954,7 +953,7 @@ void ResourceImporterScene::_optimize_animations(Node *scene, float p_max_lin_er return; Node *n = scene->get_node(String("AnimationPlayer")); ERR_FAIL_COND(!n); - AnimationPlayer *anim = n->cast_to(); + AnimationPlayer *anim = Object::cast_to(n); ERR_FAIL_COND(!anim); List anim_names; @@ -1196,10 +1195,7 @@ Error ResourceImporterScene::import(const String &p_source_file, const String &p String root_type = p_options["nodes/root_type"]; if (scene->get_class() != root_type) { - Object *base = ClassDB::instance(root_type); - Node *base_node = NULL; - if (base) - base_node = base->cast_to(); + Node *base_node = base_node = Object::cast_to(ClassDB::instance(root_type)); if (base_node) { diff --git a/editor/io_plugins/editor_font_import_plugin.cpp b/editor/io_plugins/editor_font_import_plugin.cpp index 25d8a5b7e..f7975e53e 100644 --- a/editor/io_plugins/editor_font_import_plugin.cpp +++ b/editor/io_plugins/editor_font_import_plugin.cpp @@ -1603,7 +1603,7 @@ Ref EditorFontImportPlugin::generate_font(const Ref( ResourceCache::get(p_existing)->cast_to()); + font = Ref( Object::cast_to(ResourceCache::get(p_existing))); } if (font.is_null()) { diff --git a/editor/io_plugins/editor_sample_import_plugin.cpp b/editor/io_plugins/editor_sample_import_plugin.cpp index 0909b96cd..69cfb560d 100644 --- a/editor/io_plugins/editor_sample_import_plugin.cpp +++ b/editor/io_plugins/editor_sample_import_plugin.cpp @@ -679,7 +679,7 @@ Error EditorSampleImportPlugin::import(const String& p_path, const Ref( ResourceCache::get(p_path)->cast_to() ); + target = Ref( Object::cast_to(ResourceCache::get(p_path)) ); } else { target = smp; diff --git a/editor/io_plugins/editor_scene_import_plugin.cpp b/editor/io_plugins/editor_scene_import_plugin.cpp index 1890ca906..06d12917f 100644 --- a/editor/io_plugins/editor_scene_import_plugin.cpp +++ b/editor/io_plugins/editor_scene_import_plugin.cpp @@ -1409,7 +1409,7 @@ void EditorSceneImportPlugin::_find_resources(const Variant& p_var, Map::Element *E=pl.front();E;E=E->next()) { if (E->get().type==Variant::OBJECT || E->get().type==Variant::ARRAY || E->get().type==Variant::DICTIONARY) { - if (E->get().type==Variant::OBJECT && res->cast_to() && (E->get().name=="textures/diffuse" || E->get().name=="textures/detail" || E->get().name=="textures/emission")) { + if (E->get().type==Variant::OBJECT && Object::cast_to(*res) && (E->get().name=="textures/diffuse" || E->get().name=="textures/detail" || E->get().name=="textures/emission")) { Ref tex =res->get(E->get().name); if (tex.is_valid()) { @@ -1417,7 +1417,7 @@ void EditorSceneImportPlugin::_find_resources(const Variant& p_var, Mapget().type==Variant::OBJECT && res->cast_to() && (E->get().name=="textures/normal")) { + } else if (E->get().type==Variant::OBJECT && Object::cast_to(*res) && (E->get().name=="textures/normal")) { Ref tex =res->get(E->get().name); if (tex.is_valid()) { @@ -1425,7 +1425,7 @@ void EditorSceneImportPlugin::_find_resources(const Variant& p_var, Mapcast_to()->set_fixed_flag(SpatialMaterial::FLAG_USE_XY_NORMALMAP,true); + Object::cast_to(*res)->set_fixed_flag(SpatialMaterial::FLAG_USE_XY_NORMALMAP,true); */ } @@ -1513,9 +1513,9 @@ Node* EditorSceneImportPlugin::_fix_node(Node *p_node,Node *p_root,Map - if (p_flags&SCENE_FLAG_CREATE_BILLBOARDS && p_node->cast_to()) { + if (p_flags&SCENE_FLAG_CREATE_BILLBOARDS && Object::cast_to(p_node)) { - MeshInstance *mi = p_node->cast_to(); + MeshInstance *mi = Object::cast_to(p_node); bool bb=false; @@ -1546,9 +1546,9 @@ Node* EditorSceneImportPlugin::_fix_node(Node *p_node,Node *p_root,Map } - if (p_flags&(SCENE_FLAG_DETECT_ALPHA|SCENE_FLAG_DETECT_VCOLOR|SCENE_FLAG_SET_LIGHTMAP_TO_UV2_IF_EXISTS) && p_node->cast_to()) { + if (p_flags&(SCENE_FLAG_DETECT_ALPHA|SCENE_FLAG_DETECT_VCOLOR|SCENE_FLAG_SET_LIGHTMAP_TO_UV2_IF_EXISTS) && Object::cast_to(p_node)) { - MeshInstance *mi = p_node->cast_to(); + MeshInstance *mi = Object::cast_to(p_node); Ref m = mi->get_mesh(); @@ -1579,9 +1579,9 @@ Node* EditorSceneImportPlugin::_fix_node(Node *p_node,Node *p_root,Map } } - if (p_flags&SCENE_FLAG_REMOVE_NOIMP && p_node->cast_to()) { + if (p_flags&SCENE_FLAG_REMOVE_NOIMP && Object::cast_to(p_node)) { //remove animations referencing non-importable nodes - AnimationPlayer *ap = p_node->cast_to(); + AnimationPlayer *ap = Object::cast_to(p_node); List anims; ap->get_animation_list(&anims); @@ -1606,9 +1606,9 @@ Node* EditorSceneImportPlugin::_fix_node(Node *p_node,Node *p_root,Map } - if (p_flags&SCENE_FLAG_CREATE_IMPOSTORS && p_node->cast_to()) { + if (p_flags&SCENE_FLAG_CREATE_IMPOSTORS && Object::cast_to(p_node)) { - MeshInstance *mi = p_node->cast_to(); + MeshInstance *mi = Object::cast_to(p_node); String str; @@ -1620,9 +1620,9 @@ Node* EditorSceneImportPlugin::_fix_node(Node *p_node,Node *p_root,Map } - if (p_node->get_parent() && p_node->get_parent()->cast_to()) { - MeshInstance *mi = p_node->cast_to(); - MeshInstance *mip = p_node->get_parent()->cast_to(); + if (Object::cast_to(p_node->get_parent())) { + MeshInstance *mi = Object::cast_to(p_node); + MeshInstance *mip = Object::cast_to(p_node->get_parent()); String d=str.substr(str.find("imp")+3,str.length()); if (d!="") { if ((d[0]<'0' || d[0]>'9')) @@ -1656,9 +1656,9 @@ Node* EditorSceneImportPlugin::_fix_node(Node *p_node,Node *p_root,Map } } - if (p_flags&SCENE_FLAG_CREATE_LODS && p_node->cast_to()) { + if (p_flags&SCENE_FLAG_CREATE_LODS && Object::cast_to(p_node)) { - MeshInstance *mi = p_node->cast_to(); + MeshInstance *mi = Object::cast_to(p_node); String str; @@ -1670,9 +1670,9 @@ Node* EditorSceneImportPlugin::_fix_node(Node *p_node,Node *p_root,Map } - if (p_node->get_parent() && p_node->get_parent()->cast_to()) { - MeshInstance *mi = p_node->cast_to(); - MeshInstance *mip = p_node->get_parent()->cast_to(); + if (Object::cast_to(p_node->get_parent())) { + MeshInstance *mi = Object::cast_to(p_node); + MeshInstance *mip = Object::cast_to(p_node->get_parent()); String d=str.substr(str.find("lod")+3,str.length()); if (d!="") { if ((d[0]<'0' || d[0]>'9')) @@ -1705,9 +1705,9 @@ Node* EditorSceneImportPlugin::_fix_node(Node *p_node,Node *p_root,Map } - if (p_flags&SCENE_FLAG_DETECT_LIGHTMAP_LAYER && _teststr(name,"lm") && p_node->cast_to()) { + if (p_flags&SCENE_FLAG_DETECT_LIGHTMAP_LAYER && _teststr(name,"lm") && Object::cast_to(p_node)) { - MeshInstance *mi = p_node->cast_to(); + MeshInstance *mi = Object::cast_to(p_node); String str=name; int layer = str.substr(str.find("lm")+3,str.length()).to_int(); @@ -1721,18 +1721,18 @@ Node* EditorSceneImportPlugin::_fix_node(Node *p_node,Node *p_root,Map if (isroot) return p_node; - if (p_node->cast_to() && !is_rigid) { - MeshInstance *mi = p_node->cast_to(); + if (Object::cast_to(p_node) && !is_rigid) { + MeshInstance *mi = Object::cast_to(p_node); Node * col = mi->create_trimesh_collision_node(); ERR_FAIL_COND_V(!col,NULL); col->set_name(_fixstr(name,"colonly")); - col->cast_to()->set_transform(mi->get_transform()); + Object::cast_to(col)->set_transform(mi->get_transform()); p_node->replace_by(col); memdelete(p_node); p_node=col; - StaticBody *sb = col->cast_to(); + StaticBody *sb = Object::cast_to(col); CollisionShape *colshape = memnew( CollisionShape); colshape->set_shape(sb->get_shape(0)); colshape->set_name("shape"); @@ -1749,7 +1749,7 @@ Node* EditorSceneImportPlugin::_fix_node(Node *p_node,Node *p_root,Map pb = memnew(StaticBody); pb->set_name(_fixstr(name, "colonly")); } - pb->cast_to()->set_transform(p_node->cast_to()->get_transform()); + Object::cast_to(pb)->set_transform(Object::cast_to(p_node)->get_transform()); p_node->replace_by(pb); memdelete(p_node); CollisionShape *colshape = memnew( CollisionShape); @@ -1763,7 +1763,7 @@ Node* EditorSceneImportPlugin::_fix_node(Node *p_node,Node *p_root,Map rayShape->set_length(1); colshape->set_shape(rayShape); colshape->set_name("RayShape"); - pb->cast_to()->rotate_x(Math_PI / 2); + Object::cast_to(pb)->rotate_x(Math_PI / 2); } else if (empty_draw_type == "IMAGE") { PlaneShape *planeShape = memnew( PlaneShape); colshape->set_shape(planeShape); @@ -1778,13 +1778,13 @@ Node* EditorSceneImportPlugin::_fix_node(Node *p_node,Node *p_root,Map colshape->set_owner(pb->get_owner()); } - } else if (p_flags&SCENE_FLAG_CREATE_COLLISIONS && _teststr(name,"rigid") && p_node->cast_to()) { + } else if (p_flags&SCENE_FLAG_CREATE_COLLISIONS && _teststr(name,"rigid") && Object::cast_to(p_node)) { if (isroot) return p_node; // get mesh instance and bounding box - MeshInstance *mi = p_node->cast_to(); + MeshInstance *mi = Object::cast_to(p_node); Rect3 aabb = mi->get_aabb(); // create a new rigid body collision node @@ -1795,12 +1795,12 @@ Node* EditorSceneImportPlugin::_fix_node(Node *p_node,Node *p_root,Map // remove node name postfix col->set_name(_fixstr(name,"rigid")); // get mesh instance xform matrix to the rigid body collision node - col->cast_to()->set_transform(mi->get_transform()); + Object::cast_to(col)->set_transform(mi->get_transform()); // save original node by duplicating it into a new instance and correcting the name Node * mesh = p_node->duplicate(); mesh->set_name(_fixstr(name,"rigid")); // reset the xform matrix of the duplicated node so it can inherit parent node xform - mesh->cast_to()->set_transform(Transform(Basis())); + Object::cast_to(mesh)->set_transform(Transform(Basis())); // reparent the new mesh node to the rigid body collision node p_node->add_child(mesh); mesh->set_owner(p_node->get_owner()); @@ -1810,7 +1810,7 @@ Node* EditorSceneImportPlugin::_fix_node(Node *p_node,Node *p_root,Map p_node=col; // create an alias for the rigid body collision node - RigidBody *rb = col->cast_to(); + RigidBody *rb = Object::cast_to(col); // create a new Box collision shape and set the right extents Ref shape = memnew( BoxShape ); shape->set_extents(aabb.get_size() * 0.5); @@ -1821,10 +1821,10 @@ Node* EditorSceneImportPlugin::_fix_node(Node *p_node,Node *p_root,Map rb->add_child(colshape); colshape->set_owner(p_node->get_owner()); - } else if (p_flags&SCENE_FLAG_CREATE_COLLISIONS &&_teststr(name,"col") && p_node->cast_to()) { + } else if (p_flags&SCENE_FLAG_CREATE_COLLISIONS &&_teststr(name,"col") && Object::cast_to(p_node)) { - MeshInstance *mi = p_node->cast_to(); + MeshInstance *mi = Object::cast_to(p_node); mi->set_name(_fixstr(name,"col")); Node *col= mi->create_trimesh_collision_node(); @@ -1833,7 +1833,7 @@ Node* EditorSceneImportPlugin::_fix_node(Node *p_node,Node *p_root,Map col->set_name("col"); p_node->add_child(col); - StaticBody *sb=col->cast_to(); + StaticBody *sb=Object::cast_to(col); CollisionShape *colshape = memnew( CollisionShape); colshape->set_shape(sb->get_shape(0)); colshape->set_name("shape"); @@ -1841,12 +1841,12 @@ Node* EditorSceneImportPlugin::_fix_node(Node *p_node,Node *p_root,Map colshape->set_owner(p_node->get_owner()); sb->set_owner(p_node->get_owner()); - } else if (p_flags&SCENE_FLAG_CREATE_NAVMESH &&_teststr(name,"navmesh") && p_node->cast_to()) { + } else if (p_flags&SCENE_FLAG_CREATE_NAVMESH &&_teststr(name,"navmesh") && Object::cast_to(p_node)) { if (isroot) return p_node; - MeshInstance *mi = p_node->cast_to(); + MeshInstance *mi = Object::cast_to(p_node); Ref mesh=mi->get_mesh(); ERR_FAIL_COND_V(mesh.is_null(),NULL); @@ -1857,7 +1857,7 @@ Node* EditorSceneImportPlugin::_fix_node(Node *p_node,Node *p_root,Map Ref nmesh = memnew( NavigationMesh); nmesh->create_from_mesh(mesh); nmi->set_navigation_mesh(nmesh); - nmi->cast_to()->set_transform(mi->get_transform()); + Object::cast_to(nmi)->set_transform(mi->get_transform()); p_node->replace_by(nmi); memdelete(p_node); p_node=nmi; @@ -1867,7 +1867,7 @@ Node* EditorSceneImportPlugin::_fix_node(Node *p_node,Node *p_root,Map return p_node; Node *owner = p_node->get_owner(); - Spatial *s = p_node->cast_to(); + Spatial *s = Object::cast_to(p_node); VehicleBody *bv = memnew( VehicleBody ); String n = _fixstr(p_node->get_name(),"vehicle"); bv->set_name(n); @@ -1888,7 +1888,7 @@ Node* EditorSceneImportPlugin::_fix_node(Node *p_node,Node *p_root,Map return p_node; Node *owner = p_node->get_owner(); - Spatial *s = p_node->cast_to(); + Spatial *s = Object::cast_to(p_node); VehicleWheel *bv = memnew( VehicleWheel ); String n = _fixstr(p_node->get_name(),"wheel"); bv->set_name(n); @@ -1902,13 +1902,13 @@ Node* EditorSceneImportPlugin::_fix_node(Node *p_node,Node *p_root,Map p_node=bv; - } else if (p_flags&SCENE_FLAG_CREATE_ROOMS && _teststr(name,"room") && p_node->cast_to()) { + } else if (p_flags&SCENE_FLAG_CREATE_ROOMS && _teststr(name,"room") && Object::cast_to(p_node)) { if (isroot) return p_node; - MeshInstance *mi = p_node->cast_to(); + MeshInstance *mi = Object::cast_to(p_node); PoolVector faces = mi->get_faces(VisualInstance::FACES_SOLID); @@ -1933,7 +1933,7 @@ Node* EditorSceneImportPlugin::_fix_node(Node *p_node,Node *p_root,Map if (isroot) return p_node; - Spatial *dummy = p_node->cast_to(); + Spatial *dummy = Object::cast_to(p_node); ERR_FAIL_COND_V(!dummy,NULL); Room * room = memnew( Room ); @@ -1946,12 +1946,12 @@ Node* EditorSceneImportPlugin::_fix_node(Node *p_node,Node *p_root,Map //room->compute_room_from_subtree(); - } else if (p_flags&SCENE_FLAG_CREATE_PORTALS &&_teststr(name,"portal") && p_node->cast_to()) { + } else if (p_flags&SCENE_FLAG_CREATE_PORTALS &&_teststr(name,"portal") && Object::cast_to(p_node)) { if (isroot) return p_node; - MeshInstance *mi = p_node->cast_to(); + MeshInstance *mi = Object::cast_to(p_node); PoolVector faces = mi->get_faces(VisualInstance::FACES_SOLID); ERR_FAIL_COND_V(faces.size()==0,NULL); @@ -2027,11 +2027,11 @@ Node* EditorSceneImportPlugin::_fix_node(Node *p_node,Node *p_root,Map memdelete(p_node); p_node=portal; - } else if (p_node->cast_to()) { + } else if (Object::cast_to(p_node)) { //last attempt, maybe collision insde the mesh data - MeshInstance *mi = p_node->cast_to(); + MeshInstance *mi = Object::cast_to(p_node); Ref mesh = mi->get_mesh(); if (!mesh.is_null()) { @@ -2111,7 +2111,7 @@ void EditorSceneImportPlugin::_tag_import_paths(Node *p_scene,Node *p_node) { NodePath path = p_scene->get_path_to(p_node); p_node->set_import_path( path ); - Spatial *snode=p_node->cast_to(); + Spatial *snode=Object::cast_to(p_node); if (snode) { @@ -2200,10 +2200,7 @@ Error EditorSceneImportPlugin::import1(const Ref& p_from if (from->has_option("root_type")) { String type = from->get_option("root_type"); - Object *base = ClassDB::instance(type); - Node *base_node = NULL; - if (base) - base_node=base->cast_to(); + Node *base_node = Object::cast_to(ClassDB::instance(type)); if (base_node) { @@ -2228,7 +2225,7 @@ void EditorSceneImportPlugin::_create_clips(Node *scene, const Array& p_clips,bo Node* n = scene->get_node(String("AnimationPlayer")); ERR_FAIL_COND(!n); - AnimationPlayer *anim = n->cast_to(); + AnimationPlayer *anim = Object::cast_to(n); ERR_FAIL_COND(!anim); if (!anim->has_animation("default")) @@ -2357,7 +2354,7 @@ void EditorSceneImportPlugin::_filter_tracks(Node *scene, const String& p_text) return; Node* n = scene->get_node(String("AnimationPlayer")); ERR_FAIL_COND(!n); - AnimationPlayer *anim = n->cast_to(); + AnimationPlayer *anim = Object::cast_to(n); ERR_FAIL_COND(!anim); Vector strings = p_text.split("\n"); @@ -2475,7 +2472,7 @@ void EditorSceneImportPlugin::_optimize_animations(Node *scene, float p_max_lin_ return; Node* n = scene->get_node(String("AnimationPlayer")); ERR_FAIL_COND(!n); - AnimationPlayer *anim = n->cast_to(); + AnimationPlayer *anim = Object::cast_to(n); ERR_FAIL_COND(!anim); @@ -2496,9 +2493,9 @@ void EditorSceneImportPlugin::_find_resources_to_merge(Node *scene, Node *node, String path = scene->get_path_to(node); - if (p_merge_anims && node->cast_to()) { + if (p_merge_anims && Object::cast_to(node)) { - AnimationPlayer *ap = node->cast_to(); + AnimationPlayer *ap = Object::cast_to(node); List anims; ap->get_animation_list(&anims); for (List::Element *E=anims.front();E;E=E->next()) { @@ -2532,8 +2529,8 @@ void EditorSceneImportPlugin::_find_resources_to_merge(Node *scene, Node *node, - if (p_merge_material && node->cast_to()) { - MeshInstance *mi=node->cast_to(); + if (p_merge_material && Object::cast_to(node)) { + MeshInstance *mi=Object::cast_to(node); Ref mesh = mi->get_mesh(); if (mesh.is_valid() && mesh->get_name()!=String() && !tested_meshes.has(mesh)) { @@ -2596,9 +2593,8 @@ void EditorSceneImportPlugin::_merge_found_resources(Node *scene, Node *node, bo print_line("at path: "+path); - if (node->cast_to()) { + if (AnimationPlayer *ap = Object::cast_to(node)) { - AnimationPlayer *ap = node->cast_to(); List anims; ap->get_animation_list(&anims); for (List::Element *E=anims.front();E;E=E->next()) { @@ -2630,8 +2626,8 @@ void EditorSceneImportPlugin::_merge_found_resources(Node *scene, Node *node, bo - if (node->cast_to()) { - MeshInstance *mi=node->cast_to(); + if (MeshInstance *mi=Object::cast_to(node)) { + Ref mesh = mi->get_mesh(); if (mesh.is_valid() && mesh->get_name()!=String() && !tested_meshes.has(mesh)) { diff --git a/editor/io_plugins/editor_scene_importer_fbxconv.cpp b/editor/io_plugins/editor_scene_importer_fbxconv.cpp index 784ad8536..4e246d1ef 100644 --- a/editor/io_plugins/editor_scene_importer_fbxconv.cpp +++ b/editor/io_plugins/editor_scene_importer_fbxconv.cpp @@ -407,7 +407,7 @@ Error EditorSceneImporterFBXConv::_parse_nodes(State& state,const Array &p_nodes print_line("IS SKELETON! "); } else if (state.bones.has(id)) { if (p_base) - node=p_base->cast_to(); + node=Object::cast_to(p_base); if (!state.bones[id].has_anim_chan) { print_line("no has anim "+id); } diff --git a/editor/io_plugins/editor_texture_import_plugin.cpp b/editor/io_plugins/editor_texture_import_plugin.cpp index 1dc264147..943237764 100644 --- a/editor/io_plugins/editor_texture_import_plugin.cpp +++ b/editor/io_plugins/editor_texture_import_plugin.cpp @@ -703,7 +703,7 @@ EditorTextureImportDialog::EditorTextureImportDialog(EditorTextureImportPlugin* VBoxContainer *source_vb=memnew(VBoxContainer); MarginContainer *source_mc = vbc->add_margin_child(TTR("Source Texture(s):"),source_vb); - source_label = vbc->get_child(source_mc->get_index()-1)->cast_to