From cacced7e507f7603bacc03ae2616e58f0ede122a Mon Sep 17 00:00:00 2001 From: Hein-Pieter van Braam Date: Thu, 24 Aug 2017 22:58:51 +0200 Subject: [PATCH] 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/ --- core/bind/core_bind.cpp | 2 +- core/io/marshalls.cpp | 4 +- core/io/resource_format_binary.cpp | 2 +- core/make_binders.py | 4 +- core/object.cpp | 4 +- core/object.h | 40 --- core/os/os.cpp | 2 +- core/ref_ptr.cpp | 2 +- core/reference.cpp | 2 +- core/reference.h | 12 +- core/undo_redo.cpp | 28 +- core/variant.cpp | 4 +- core/variant_parser.cpp | 2 +- drivers/png/resource_saver_png.cpp | 2 +- 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 ++++--- .../io_plugins/editor_font_import_plugin.cpp | 2 +- .../editor_sample_import_plugin.cpp | 2 +- .../io_plugins/editor_scene_import_plugin.cpp | 122 ++++----- .../editor_scene_importer_fbxconv.cpp | 2 +- .../editor_texture_import_plugin.cpp | 10 +- .../animation_player_editor_plugin.cpp | 10 +- .../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 +++++++++--------- .../collision_polygon_2d_editor_plugin.cpp | 4 +- .../collision_polygon_editor_plugin.cpp | 4 +- .../collision_shape_2d_editor_plugin.cpp | 20 +- .../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 +- .../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 +- .../plugins/mesh_instance_editor_plugin.cpp | 4 +- editor/plugins/multimesh_editor_plugin.cpp | 8 +- .../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 +- .../resource_preloader_editor_plugin.cpp | 2 +- editor/plugins/rich_text_editor_plugin.cpp | 4 +- editor/plugins/sample_editor_plugin.cpp | 2 +- .../plugins/sample_library_editor_plugin.cpp | 8 +- .../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 ++++---- .../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 +- .../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 +- main/main.cpp | 10 +- main/performance.cpp | 4 +- modules/gdnative/godot/rid.cpp | 2 +- modules/gdscript/gd_compiler.cpp | 2 +- modules/gdscript/gd_editor.cpp | 115 ++++---- modules/gdscript/gd_function.cpp | 8 +- modules/gdscript/gd_parser.cpp | 2 +- modules/gdscript/gd_script.cpp | 14 +- modules/gridmap/grid_map.cpp | 4 +- modules/gridmap/grid_map_editor_plugin.cpp | 8 +- modules/nativescript/nativescript.cpp | 6 +- modules/visual_script/visual_script.cpp | 22 +- .../visual_script/visual_script_editor.cpp | 61 ++--- .../visual_script_func_nodes.cpp | 25 +- modules/visual_script/visual_script_nodes.cpp | 14 +- .../visual_script_yield_nodes.cpp | 9 +- platform/android/java_class_wrapper.cpp | 2 +- platform/uwp/export/export.cpp | 28 +- scene/2d/area_2d.cpp | 16 +- scene/2d/audio_stream_player_2d.cpp | 4 +- scene/2d/camera_2d.cpp | 2 +- scene/2d/canvas_item.cpp | 26 +- scene/2d/collision_polygon_2d.cpp | 4 +- scene/2d/collision_shape_2d.cpp | 4 +- scene/2d/joints_2d.cpp | 12 +- scene/2d/navigation_polygon.cpp | 8 +- scene/2d/node_2d.cpp | 2 +- scene/2d/parallax_background.cpp | 2 +- scene/2d/parallax_layer.cpp | 21 +- scene/2d/path_2d.cpp | 11 +- scene/2d/physics_body_2d.cpp | 22 +- scene/2d/ray_cast_2d.cpp | 16 +- scene/2d/remote_transform_2d.cpp | 8 +- scene/2d/screen_button.cpp | 4 +- scene/2d/sprite.cpp | 8 +- scene/2d/tile_map.cpp | 4 +- scene/2d/visibility_notifier_2d.cpp | 16 +- scene/3d/area.cpp | 16 +- scene/3d/arvr_nodes.cpp | 10 +- scene/3d/audio_stream_player_3d.cpp | 2 +- scene/3d/bone_attachment.cpp | 12 +- scene/3d/character_camera.cpp | 2 +- scene/3d/collision_polygon.cpp | 4 +- scene/3d/collision_shape.cpp | 7 +- scene/3d/gi_probe.cpp | 5 +- scene/3d/interpolated_camera.cpp | 8 +- scene/3d/mesh_instance.cpp | 10 +- scene/3d/navigation.cpp | 2 +- scene/3d/navigation_mesh.cpp | 10 +- scene/3d/path.cpp | 3 +- scene/3d/physics_body.cpp | 14 +- scene/3d/physics_joint.cpp | 12 +- scene/3d/ray_cast.cpp | 4 +- scene/3d/remote_transform.cpp | 8 +- scene/3d/room_instance.cpp | 4 +- scene/3d/skeleton.cpp | 6 +- scene/3d/spatial.cpp | 8 +- scene/3d/sprite_3d.cpp | 10 +- scene/3d/vehicle_body.cpp | 12 +- scene/3d/visibility_notifier.cpp | 8 +- scene/3d/visual_instance.cpp | 10 +- scene/animation/animation_cache.cpp | 4 +- scene/animation/animation_player.cpp | 10 +- scene/animation/animation_tree_player.cpp | 10 +- scene/gui/box_container.cpp | 8 +- scene/gui/button_group.cpp | 2 +- scene/gui/center_container.cpp | 4 +- scene/gui/color_picker.cpp | 9 +- scene/gui/container.cpp | 6 +- scene/gui/control.cpp | 78 +++--- scene/gui/dialogs.cpp | 8 +- scene/gui/graph_edit.cpp | 66 ++--- scene/gui/graph_node.cpp | 10 +- scene/gui/grid_container.cpp | 6 +- scene/gui/margin_container.cpp | 4 +- scene/gui/menu_button.cpp | 2 +- scene/gui/panel_container.cpp | 4 +- scene/gui/popup.cpp | 4 +- scene/gui/popup_menu.cpp | 10 +- scene/gui/range.cpp | 2 +- scene/gui/scroll_bar.cpp | 4 +- scene/gui/scroll_container.cpp | 6 +- scene/gui/split_container.cpp | 2 +- scene/gui/tab_container.cpp | 10 +- scene/gui/tree.h | 18 +- scene/gui/viewport_container.cpp | 8 +- scene/main/canvas_layer.cpp | 2 +- scene/main/node.cpp | 16 +- scene/main/scene_tree.cpp | 7 +- scene/main/viewport.cpp | 114 ++++---- scene/resources/packed_scene.cpp | 12 +- scene/resources/scene_format_text.cpp | 4 +- scene/resources/shape.cpp | 2 +- scene/resources/theme.cpp | 9 +- servers/audio_server.cpp | 4 +- 185 files changed, 1314 insertions(+), 1508 deletions(-) diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp index 5f534f63a85f..7f4a83ed49c0 100644 --- a/core/bind/core_bind.cpp +++ b/core/bind/core_bind.cpp @@ -2354,7 +2354,7 @@ Variant _ClassDB::instance(const StringName &p_class) const { if (!obj) return Variant(); - Reference *r = obj->cast_to(); + Reference *r = Object::cast_to(obj); if (r) { return REF(r); } else { diff --git a/core/io/marshalls.cpp b/core/io/marshalls.cpp index e701a89c7882..93002e5446ae 100644 --- a/core/io/marshalls.cpp +++ b/core/io/marshalls.cpp @@ -463,8 +463,8 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int obj->set(str, value); } - if (obj->cast_to()) { - REF ref = REF(obj->cast_to()); + if (Object::cast_to(obj)) { + REF ref = REF(Object::cast_to(obj)); r_variant = ref; } else { r_variant = obj; diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp index fd8928b8a07e..b8e0bbf557f7 100644 --- a/core/io/resource_format_binary.cpp +++ b/core/io/resource_format_binary.cpp @@ -713,7 +713,7 @@ Error ResourceInteractiveLoaderBinary::poll() { } ERR_FAIL_COND_V(!obj, ERR_FILE_CORRUPT); - Resource *r = obj->cast_to(); + Resource *r = Object::cast_to(obj); if (!r) { error = ERR_FILE_CORRUPT; memdelete(obj); //bye diff --git a/core/make_binders.py b/core/make_binders.py index 0252bb638bb3..6468c029f040 100644 --- a/core/make_binders.py +++ b/core/make_binders.py @@ -29,7 +29,7 @@ class MethodBind$argc$$ifret R$$ifconst C$ : public MethodBind { virtual Variant call(Object* p_object,const Variant** p_args,int p_arg_count, Variant::CallError& r_error) { - T *instance=p_object->cast_to(); + T *instance=Object::cast_to(p_object); r_error.error=Variant::CallError::CALL_OK; #ifdef DEBUG_METHODS_ENABLED @@ -57,7 +57,7 @@ class MethodBind$argc$$ifret R$$ifconst C$ : public MethodBind { #ifdef PTRCALL_ENABLED virtual void ptrcall(Object*p_object,const void** p_args,void *r_ret) { - T *instance=p_object->cast_to(); + T *instance=Object::cast_to(p_object); $ifret PtrToArg::encode( $ (instance->*method)($arg, PtrToArg::convert(p_args[@-1])$) $ifret ,r_ret)$ ; } #endif diff --git a/core/object.cpp b/core/object.cpp index 928e9bb97873..5e6c809f7ae0 100644 --- a/core/object.cpp +++ b/core/object.cpp @@ -654,7 +654,7 @@ void Object::call_multilevel(const StringName &p_method, const Variant **p_args, if (p_method == CoreStringNames::get_singleton()->_free) { #ifdef DEBUG_ENABLED - if (cast_to()) { + if (Object::cast_to(this)) { ERR_EXPLAIN("Can't 'free' a reference."); ERR_FAIL(); return; @@ -900,7 +900,7 @@ Variant Object::call(const StringName &p_method, const Variant **p_args, int p_a r_error.error = Variant::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS; return Variant(); } - if (cast_to()) { + if (Object::cast_to(this)) { r_error.argument = 0; r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD; ERR_EXPLAIN("Can't 'free' a reference."); diff --git a/core/object.h b/core/object.h index ab1421e35705..88229d27b609 100644 --- a/core/object.h +++ b/core/object.h @@ -598,46 +598,6 @@ class Object { #endif } -// TODO: ensure 'this' is never NULL since it's UB, but by now, avoid warning flood -#ifdef __clang__ -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wundefined-bool-conversion" -#endif - - template - T *cast_to() { - -#ifndef NO_SAFE_CAST - return SAFE_CAST(this); -#else - if (!this) - return NULL; - if (is_class_ptr(T::get_class_ptr_static())) - return static_cast(this); - else - return NULL; -#endif - } - - template - const T *cast_to() const { - -#ifndef NO_SAFE_CAST - return SAFE_CAST(this); -#else - if (!this) - return NULL; - if (is_class_ptr(T::get_class_ptr_static())) - return static_cast(this); - else - return NULL; -#endif - } - -#ifdef __clang__ -#pragma clang diagnostic pop -#endif - enum { NOTIFICATION_POSTINITIALIZE = 0, diff --git a/core/os/os.cpp b/core/os/os.cpp index 3a06a3fa8fad..c49ab6f70673 100644 --- a/core/os/os.cpp +++ b/core/os/os.cpp @@ -171,7 +171,7 @@ static FileAccess *_OSPRF = NULL; static void _OS_printres(Object *p_obj) { - Resource *res = p_obj->cast_to(); + Resource *res = Object::cast_to(p_obj); if (!res) return; diff --git a/core/ref_ptr.cpp b/core/ref_ptr.cpp index c2128fd45d3e..7bd852329226 100644 --- a/core/ref_ptr.cpp +++ b/core/ref_ptr.cpp @@ -69,7 +69,7 @@ RID RefPtr::get_rid() const { Ref *ref = reinterpret_cast *>(&data[0]); if (ref->is_null()) return RID(); - Resource *res = (*ref)->cast_to(); + Resource *res = Object::cast_to(ref->ptr()); if (res) return res->get_rid(); return RID(); diff --git a/core/reference.cpp b/core/reference.cpp index e9629ee7c08e..1380dbd56e48 100644 --- a/core/reference.cpp +++ b/core/reference.cpp @@ -98,7 +98,7 @@ Variant WeakRef::get_ref() const { Object *obj = ObjectDB::get_instance(ref); if (!obj) return Variant(); - Reference *r = obj->cast_to(); + Reference *r = cast_to(obj); if (r) { return REF(r); diff --git a/core/reference.h b/core/reference.h index 764c924cdb95..a8034a73c6c2 100644 --- a/core/reference.h +++ b/core/reference.h @@ -180,7 +180,7 @@ class Ref { return; } Ref r; - r.reference = refb->cast_to(); + r.reference = Object::cast_to(refb); ref(r); r.reference = NULL; } @@ -194,7 +194,7 @@ class Ref { return; } Ref r; - r.reference = refb->cast_to(); + r.reference = Object::cast_to(refb); ref(r); r.reference = NULL; } @@ -209,7 +209,7 @@ class Ref { return; } Ref r; - r.reference = refb->cast_to(); + r.reference = Object::cast_to(refb); ref(r); r.reference = NULL; } @@ -230,7 +230,7 @@ class Ref { return; } Ref r; - r.reference = refb->cast_to(); + r.reference = Object::cast_to(refb); ref(r); r.reference = NULL; } @@ -254,7 +254,7 @@ class Ref { return; } Ref r; - r.reference = refb->cast_to(); + r.reference = Object::cast_to(refb); ref(r); r.reference = NULL; } @@ -269,7 +269,7 @@ class Ref { return; } Ref r; - r.reference = refb->cast_to(); + r.reference = Object::cast_to(refb); ref(r); r.reference = NULL; } diff --git a/core/undo_redo.cpp b/core/undo_redo.cpp index bb70146396ba..00a468816a3c 100644 --- a/core/undo_redo.cpp +++ b/core/undo_redo.cpp @@ -111,8 +111,8 @@ void UndoRedo::add_do_method(Object *p_object, const String &p_method, VARIANT_A ERR_FAIL_COND((current_action + 1) >= actions.size()); Operation do_op; do_op.object = p_object->get_instance_id(); - if (p_object->cast_to()) - do_op.resref = Ref(p_object->cast_to()); + if (Object::cast_to(p_object)) + do_op.resref = Ref(Object::cast_to(p_object)); do_op.type = Operation::TYPE_METHOD; do_op.name = p_method; @@ -135,8 +135,8 @@ void UndoRedo::add_undo_method(Object *p_object, const String &p_method, VARIANT Operation undo_op; undo_op.object = p_object->get_instance_id(); - if (p_object->cast_to()) - undo_op.resref = Ref(p_object->cast_to()); + if (Object::cast_to(p_object)) + undo_op.resref = Ref(Object::cast_to(p_object)); undo_op.type = Operation::TYPE_METHOD; undo_op.name = p_method; @@ -152,8 +152,8 @@ void UndoRedo::add_do_property(Object *p_object, const String &p_property, const ERR_FAIL_COND((current_action + 1) >= actions.size()); Operation do_op; do_op.object = p_object->get_instance_id(); - if (p_object->cast_to()) - do_op.resref = Ref(p_object->cast_to()); + if (Object::cast_to(p_object)) + do_op.resref = Ref(Object::cast_to(p_object)); do_op.type = Operation::TYPE_PROPERTY; do_op.name = p_property; @@ -171,8 +171,8 @@ void UndoRedo::add_undo_property(Object *p_object, const String &p_property, con Operation undo_op; undo_op.object = p_object->get_instance_id(); - if (p_object->cast_to()) - undo_op.resref = Ref(p_object->cast_to()); + if (Object::cast_to(p_object)) + undo_op.resref = Ref(Object::cast_to(p_object)); undo_op.type = Operation::TYPE_PROPERTY; undo_op.name = p_property; @@ -185,8 +185,8 @@ void UndoRedo::add_do_reference(Object *p_object) { ERR_FAIL_COND((current_action + 1) >= actions.size()); Operation do_op; do_op.object = p_object->get_instance_id(); - if (p_object->cast_to()) - do_op.resref = Ref(p_object->cast_to()); + if (Object::cast_to(p_object)) + do_op.resref = Ref(Object::cast_to(p_object)); do_op.type = Operation::TYPE_REFERENCE; actions[current_action + 1].do_ops.push_back(do_op); @@ -202,8 +202,8 @@ void UndoRedo::add_undo_reference(Object *p_object) { Operation undo_op; undo_op.object = p_object->get_instance_id(); - if (p_object->cast_to()) - undo_op.resref = Ref(p_object->cast_to()); + if (Object::cast_to(p_object)) + undo_op.resref = Ref(Object::cast_to(p_object)); undo_op.type = Operation::TYPE_REFERENCE; actions[current_action + 1].undo_ops.push_back(undo_op); @@ -270,7 +270,7 @@ void UndoRedo::_process_operation_list(List::Element *E) { obj->call(op.name, VARIANT_ARGS_FROM_ARRAY(op.args)); #ifdef TOOLS_ENABLED - Resource *res = obj->cast_to(); + Resource *res = Object::cast_to(obj); if (res) res->set_edited(true); @@ -284,7 +284,7 @@ void UndoRedo::_process_operation_list(List::Element *E) { obj->set(op.name, op.args[0]); #ifdef TOOLS_ENABLED - Resource *res = obj->cast_to(); + Resource *res = Object::cast_to(obj); if (res) res->set_edited(true); #endif diff --git a/core/variant.cpp b/core/variant.cpp index 51c4b70bdc76..e6a69edd08e4 100644 --- a/core/variant.cpp +++ b/core/variant.cpp @@ -1764,14 +1764,14 @@ Variant::operator Object *() const { Variant::operator Node *() const { if (type == OBJECT) - return _get_obj().obj ? _get_obj().obj->cast_to() : NULL; + return Object::cast_to(_get_obj().obj); else return NULL; } Variant::operator Control *() const { if (type == OBJECT) - return _get_obj().obj ? _get_obj().obj->cast_to() : NULL; + return Object::cast_to(_get_obj().obj); else return NULL; } diff --git a/core/variant_parser.cpp b/core/variant_parser.cpp index 5aa71f670483..a1b168621c35 100644 --- a/core/variant_parser.cpp +++ b/core/variant_parser.cpp @@ -742,7 +742,7 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, return err; if (token.type == TK_PARENTHESIS_CLOSE) { - Reference *reference = obj->cast_to(); + Reference *reference = Object::cast_to(obj); if (reference) { value = REF(reference); } else { diff --git a/drivers/png/resource_saver_png.cpp b/drivers/png/resource_saver_png.cpp index 4f1f318aeefa..876fb820b2e8 100644 --- a/drivers/png/resource_saver_png.cpp +++ b/drivers/png/resource_saver_png.cpp @@ -187,7 +187,7 @@ bool ResourceSaverPNG::recognize(const RES &p_resource) const { } void ResourceSaverPNG::get_recognized_extensions(const RES &p_resource, List *p_extensions) const { - if (p_resource->cast_to()) { + if (Object::cast_to(*p_resource)) { p_extensions->push_back("png"); } } diff --git a/editor/animation_editor.cpp b/editor/animation_editor.cpp index ed80be9e17a8..55542a59a295 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 06d7d5fdc809..7ef24cf62718 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 5ff9c7bb8a53..c01c2de6b72d 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 47c2cb5536ee..56759a808603 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 3533c0993f2d..78773ce3a6f1 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 282055be4a68..3494aa577d37 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 0d7874818c62..f0f6aac0892c 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 51fb1554c121..0a5220497a2c 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 a601b5019dba..2b336c4716d7 100644 --- a/editor/editor_data.h +++ b/editor/editor_data.h @@ -236,10 +236,7 @@ class EditorSelection : public Object { 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 b64f5f1c695e..12c55d967168 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 86964b3ca061..fb3c52e77328 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 fdac68ea1fda..24206b0f0d86 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 f8ed18bba453..220b5fb2d6f5 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 358d57576448..88c8c368d415 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 ea1827f16fb9..fbbbf913953f 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 b3ccb5097e86..1680b3250983 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 b6f17b712109..5bba2894929f 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 25d8a5b7eb61..f7975e53ea1c 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 0909b96cdcf7..69cfb560d513 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 1890ca906a14..06d12917fd4f 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 784ad8536e17..4e246d1ef995 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 1dc264147438..9432377648b8 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