diff options
Diffstat (limited to 'scene/2d')
-rw-r--r-- | scene/2d/area_2d.cpp | 16 | ||||
-rw-r--r-- | scene/2d/audio_stream_player_2d.cpp | 4 | ||||
-rw-r--r-- | scene/2d/camera_2d.cpp | 2 | ||||
-rw-r--r-- | scene/2d/canvas_item.cpp | 26 | ||||
-rw-r--r-- | scene/2d/collision_polygon_2d.cpp | 4 | ||||
-rw-r--r-- | scene/2d/collision_shape_2d.cpp | 4 | ||||
-rw-r--r-- | scene/2d/joints_2d.cpp | 12 | ||||
-rw-r--r-- | scene/2d/navigation_polygon.cpp | 8 | ||||
-rw-r--r-- | scene/2d/node_2d.cpp | 2 | ||||
-rw-r--r-- | scene/2d/parallax_background.cpp | 2 | ||||
-rw-r--r-- | scene/2d/parallax_layer.cpp | 21 | ||||
-rw-r--r-- | scene/2d/path_2d.cpp | 11 | ||||
-rw-r--r-- | scene/2d/physics_body_2d.cpp | 22 | ||||
-rw-r--r-- | scene/2d/ray_cast_2d.cpp | 16 | ||||
-rw-r--r-- | scene/2d/remote_transform_2d.cpp | 8 | ||||
-rw-r--r-- | scene/2d/screen_button.cpp | 4 | ||||
-rw-r--r-- | scene/2d/sprite.cpp | 8 | ||||
-rw-r--r-- | scene/2d/tile_map.cpp | 4 | ||||
-rw-r--r-- | scene/2d/visibility_notifier_2d.cpp | 16 |
19 files changed, 82 insertions, 108 deletions
diff --git a/scene/2d/area_2d.cpp b/scene/2d/area_2d.cpp index 02a0509449..8f405dd314 100644 --- a/scene/2d/area_2d.cpp +++ b/scene/2d/area_2d.cpp @@ -116,7 +116,7 @@ real_t Area2D::get_priority() const { void Area2D::_body_enter_tree(ObjectID p_id) { Object *obj = ObjectDB::get_instance(p_id); - Node *node = obj ? obj->cast_to<Node>() : NULL; + Node *node = Object::cast_to<Node>(obj); ERR_FAIL_COND(!node); Map<ObjectID, BodyState>::Element *E = body_map.find(p_id); @@ -134,7 +134,7 @@ void Area2D::_body_enter_tree(ObjectID p_id) { void Area2D::_body_exit_tree(ObjectID p_id) { Object *obj = ObjectDB::get_instance(p_id); - Node *node = obj ? obj->cast_to<Node>() : NULL; + Node *node = Object::cast_to<Node>(obj); ERR_FAIL_COND(!node); Map<ObjectID, BodyState>::Element *E = body_map.find(p_id); ERR_FAIL_COND(!E); @@ -153,7 +153,7 @@ void Area2D::_body_inout(int p_status, const RID &p_body, int p_instance, int p_ ObjectID objid = p_instance; Object *obj = ObjectDB::get_instance(objid); - Node *node = obj ? obj->cast_to<Node>() : NULL; + Node *node = Object::cast_to<Node>(obj); Map<ObjectID, BodyState>::Element *E = body_map.find(objid); @@ -217,7 +217,7 @@ void Area2D::_body_inout(int p_status, const RID &p_body, int p_instance, int p_ void Area2D::_area_enter_tree(ObjectID p_id) { Object *obj = ObjectDB::get_instance(p_id); - Node *node = obj ? obj->cast_to<Node>() : NULL; + Node *node = Object::cast_to<Node>(obj); ERR_FAIL_COND(!node); Map<ObjectID, AreaState>::Element *E = area_map.find(p_id); @@ -235,7 +235,7 @@ void Area2D::_area_enter_tree(ObjectID p_id) { void Area2D::_area_exit_tree(ObjectID p_id) { Object *obj = ObjectDB::get_instance(p_id); - Node *node = obj ? obj->cast_to<Node>() : NULL; + Node *node = Object::cast_to<Node>(obj); ERR_FAIL_COND(!node); Map<ObjectID, AreaState>::Element *E = area_map.find(p_id); ERR_FAIL_COND(!E); @@ -254,7 +254,7 @@ void Area2D::_area_inout(int p_status, const RID &p_area, int p_instance, int p_ ObjectID objid = p_instance; Object *obj = ObjectDB::get_instance(objid); - Node *node = obj ? obj->cast_to<Node>() : NULL; + Node *node = Object::cast_to<Node>(obj); Map<ObjectID, AreaState>::Element *E = area_map.find(objid); @@ -330,7 +330,7 @@ void Area2D::_clear_monitoring() { for (Map<ObjectID, BodyState>::Element *E = bmcopy.front(); E; E = E->next()) { Object *obj = ObjectDB::get_instance(E->key()); - Node *node = obj ? obj->cast_to<Node>() : NULL; + Node *node = Object::cast_to<Node>(obj); if (!node) //node may have been deleted in previous frame or at other legiminate point continue; @@ -360,7 +360,7 @@ void Area2D::_clear_monitoring() { for (Map<ObjectID, AreaState>::Element *E = bmcopy.front(); E; E = E->next()) { Object *obj = ObjectDB::get_instance(E->key()); - Node *node = obj ? obj->cast_to<Node>() : NULL; + Node *node = Object::cast_to<Node>(obj); if (!node) //node may have been deleted in previous frame or at other legiminate point continue; diff --git a/scene/2d/audio_stream_player_2d.cpp b/scene/2d/audio_stream_player_2d.cpp index 73782e1515..b2848238f4 100644 --- a/scene/2d/audio_stream_player_2d.cpp +++ b/scene/2d/audio_stream_player_2d.cpp @@ -157,10 +157,8 @@ void AudioStreamPlayer2D::_notification(int p_what) { int areas = space_state->intersect_point(global_pos, sr, MAX_INTERSECT_AREAS, Set<RID>(), area_mask, Physics2DDirectSpaceState::TYPE_MASK_AREA); for (int i = 0; i < areas; i++) { - if (!sr[i].collider) - continue; - Area2D *area2d = sr[i].collider->cast_to<Area2D>(); + Area2D *area2d = Object::cast_to<Area2D>(sr[i].collider); if (!area2d) continue; diff --git a/scene/2d/camera_2d.cpp b/scene/2d/camera_2d.cpp index f309631715..6cbac4ed3b 100644 --- a/scene/2d/camera_2d.cpp +++ b/scene/2d/camera_2d.cpp @@ -577,7 +577,7 @@ void Camera2D::set_custom_viewport(Node *p_viewport) { remove_from_group(canvas_group_name); } - custom_viewport = p_viewport->cast_to<Viewport>(); + custom_viewport = Object::cast_to<Viewport>(p_viewport); if (custom_viewport) { custom_viewport_id = custom_viewport->get_instance_id(); diff --git a/scene/2d/canvas_item.cpp b/scene/2d/canvas_item.cpp index 5a519dee69..ea32953d68 100644 --- a/scene/2d/canvas_item.cpp +++ b/scene/2d/canvas_item.cpp @@ -260,7 +260,7 @@ void CanvasItem::_propagate_visibility_changed(bool p_visible) { for (int i = 0; i < get_child_count(); i++) { - CanvasItem *c = get_child(i)->cast_to<CanvasItem>(); + CanvasItem *c = Object::cast_to<CanvasItem>(get_child(i)); if (c && c->visible) //should the toplevels stop propagation? i think so but.. c->_propagate_visibility_changed(p_visible); @@ -398,7 +398,7 @@ void CanvasItem::_toplevel_raise_self() { void CanvasItem::_enter_canvas() { - if ((!get_parent() || !get_parent()->cast_to<CanvasItem>()) || toplevel) { + if ((!Object::cast_to<CanvasItem>(get_parent())) || toplevel) { Node *n = this; @@ -406,7 +406,7 @@ void CanvasItem::_enter_canvas() { while (n) { - canvas_layer = n->cast_to<CanvasLayer>(); + canvas_layer = Object::cast_to<CanvasLayer>(n); if (canvas_layer) { break; } @@ -460,7 +460,7 @@ void CanvasItem::_notification(int p_what) { first_draw = true; if (get_parent()) { - CanvasItem *ci = get_parent()->cast_to<CanvasItem>(); + CanvasItem *ci = Object::cast_to<CanvasItem>(get_parent()); if (ci) C = ci->children_items.push_back(this); } @@ -488,7 +488,7 @@ void CanvasItem::_notification(int p_what) { get_tree()->xform_change_list.remove(&xform_change); _exit_canvas(); if (C) { - get_parent()->cast_to<CanvasItem>()->children_items.erase(C); + Object::cast_to<CanvasItem>(get_parent())->children_items.erase(C); C = NULL; } global_invalid = true; @@ -565,11 +565,7 @@ CanvasItem *CanvasItem::get_parent_item() const { if (toplevel) return NULL; - Node *parent = get_parent(); - if (!parent) - return NULL; - - return parent->cast_to<CanvasItem>(); + return Object::cast_to<CanvasItem>(get_parent()); } void CanvasItem::set_self_modulate(const Color &p_self_modulate) { @@ -830,8 +826,8 @@ RID CanvasItem::get_canvas() const { CanvasItem *CanvasItem::get_toplevel() const { CanvasItem *ci = const_cast<CanvasItem *>(this); - while (!ci->toplevel && ci->get_parent() && ci->get_parent()->cast_to<CanvasItem>()) { - ci = ci->get_parent()->cast_to<CanvasItem>(); + while (!ci->toplevel && Object::cast_to<CanvasItem>(ci->get_parent())) { + ci = Object::cast_to<CanvasItem>(ci->get_parent()); } return ci; @@ -1062,8 +1058,8 @@ Transform2D CanvasItem::get_canvas_transform() const { if (canvas_layer) return canvas_layer->get_transform(); - else if (get_parent()->cast_to<CanvasItem>()) - return get_parent()->cast_to<CanvasItem>()->get_canvas_transform(); + else if (Object::cast_to<CanvasItem>(get_parent())) + return Object::cast_to<CanvasItem>(get_parent())->get_canvas_transform(); else return get_viewport()->get_canvas_transform(); } @@ -1122,7 +1118,7 @@ Rect2 CanvasItem::get_item_and_children_rect() const { Rect2 rect = get_item_rect(); for (int i = 0; i < get_child_count(); i++) { - CanvasItem *c = get_child(i)->cast_to<CanvasItem>(); + CanvasItem *c = Object::cast_to<CanvasItem>(get_child(i)); if (c) { Rect2 sir = c->get_transform().xform(c->get_item_and_children_rect()); rect = rect.merge(sir); diff --git a/scene/2d/collision_polygon_2d.cpp b/scene/2d/collision_polygon_2d.cpp index 433661e393..f136de5166 100644 --- a/scene/2d/collision_polygon_2d.cpp +++ b/scene/2d/collision_polygon_2d.cpp @@ -126,7 +126,7 @@ void CollisionPolygon2D::_notification(int p_what) { switch (p_what) { case NOTIFICATION_PARENTED: { - parent = get_parent()->cast_to<CollisionObject2D>(); + parent = Object::cast_to<CollisionObject2D>(get_parent()); if (parent) { owner_id = parent->create_shape_owner(this); _build_polygon(); @@ -257,7 +257,7 @@ Rect2 CollisionPolygon2D::get_item_rect() const { String CollisionPolygon2D::get_configuration_warning() const { - if (!get_parent()->cast_to<CollisionObject2D>()) { + if (!Object::cast_to<CollisionObject2D>(get_parent())) { return TTR("CollisionPolygon2D only serves to provide a collision shape to a CollisionObject2D derived node. Please only use it as a child of Area2D, StaticBody2D, RigidBody2D, KinematicBody2D, etc. to give them a shape."); } diff --git a/scene/2d/collision_shape_2d.cpp b/scene/2d/collision_shape_2d.cpp index 3fda4ab464..3bb53a5e11 100644 --- a/scene/2d/collision_shape_2d.cpp +++ b/scene/2d/collision_shape_2d.cpp @@ -50,7 +50,7 @@ void CollisionShape2D::_notification(int p_what) { case NOTIFICATION_PARENTED: { - parent = get_parent()->cast_to<CollisionObject2D>(); + parent = Object::cast_to<CollisionObject2D>(get_parent()); if (parent) { owner_id = parent->create_shape_owner(this); if (shape.is_valid()) { @@ -165,7 +165,7 @@ Rect2 CollisionShape2D::get_item_rect() const { String CollisionShape2D::get_configuration_warning() const { - if (!get_parent()->cast_to<CollisionObject2D>()) { + if (!Object::cast_to<CollisionObject2D>(get_parent())) { return TTR("CollisionShape2D only serves to provide a collision shape to a CollisionObject2D derived node. Please only use it as a child of Area2D, StaticBody2D, RigidBody2D, KinematicBody2D, etc. to give them a shape."); } diff --git a/scene/2d/joints_2d.cpp b/scene/2d/joints_2d.cpp index ee41dca3a6..726f57d42e 100644 --- a/scene/2d/joints_2d.cpp +++ b/scene/2d/joints_2d.cpp @@ -172,8 +172,8 @@ RID PinJoint2D::_configure_joint() { if (!node_a && !node_b) return RID(); - PhysicsBody2D *body_a = node_a ? node_a->cast_to<PhysicsBody2D>() : (PhysicsBody2D *)NULL; - PhysicsBody2D *body_b = node_b ? node_b->cast_to<PhysicsBody2D>() : (PhysicsBody2D *)NULL; + PhysicsBody2D *body_a = Object::cast_to<PhysicsBody2D>(node_a); + PhysicsBody2D *body_b = Object::cast_to<PhysicsBody2D>(node_b); if (!body_a && !body_b) return RID(); @@ -249,8 +249,8 @@ RID GrooveJoint2D::_configure_joint() { if (!node_a || !node_b) return RID(); - PhysicsBody2D *body_a = node_a->cast_to<PhysicsBody2D>(); - PhysicsBody2D *body_b = node_b->cast_to<PhysicsBody2D>(); + PhysicsBody2D *body_a = Object::cast_to<PhysicsBody2D>(node_a); + PhysicsBody2D *body_b = Object::cast_to<PhysicsBody2D>(node_b); if (!body_a || !body_b) return RID(); @@ -338,8 +338,8 @@ RID DampedSpringJoint2D::_configure_joint() { if (!node_a || !node_b) return RID(); - PhysicsBody2D *body_a = node_a->cast_to<PhysicsBody2D>(); - PhysicsBody2D *body_b = node_b->cast_to<PhysicsBody2D>(); + PhysicsBody2D *body_a = Object::cast_to<PhysicsBody2D>(node_a); + PhysicsBody2D *body_b = Object::cast_to<PhysicsBody2D>(node_b); if (!body_a || !body_b) return RID(); diff --git a/scene/2d/navigation_polygon.cpp b/scene/2d/navigation_polygon.cpp index 7515d486c2..0d5d06bef7 100644 --- a/scene/2d/navigation_polygon.cpp +++ b/scene/2d/navigation_polygon.cpp @@ -319,7 +319,7 @@ void NavigationPolygonInstance::_notification(int p_what) { Node2D *c = this; while (c) { - navigation = c->cast_to<Navigation2D>(); + navigation = Object::cast_to<Navigation2D>(c); if (navigation) { if (enabled && navpoly.is_valid()) { @@ -329,7 +329,7 @@ void NavigationPolygonInstance::_notification(int p_what) { break; } - c = c->get_parent()->cast_to<Node2D>(); + c = Object::cast_to<Node2D>(get_parent()); } } break; @@ -448,11 +448,11 @@ String NavigationPolygonInstance::get_configuration_warning() const { const Node2D *c = this; while (c) { - if (c->cast_to<Navigation2D>()) { + if (Object::cast_to<Navigation2D>(c)) { return String(); } - c = c->get_parent()->cast_to<Node2D>(); + c = Object::cast_to<Node2D>(get_parent()); } return TTR("NavigationPolygonInstance must be a child or grandchild to a Navigation2D node. It only provides navigation data."); diff --git a/scene/2d/node_2d.cpp b/scene/2d/node_2d.cpp index 98d6a467b1..af5834c5b6 100644 --- a/scene/2d/node_2d.cpp +++ b/scene/2d/node_2d.cpp @@ -379,7 +379,7 @@ Transform2D Node2D::get_relative_transform_to_parent(const Node *p_parent) const if (p_parent == this) return Transform2D(); - Node2D *parent_2d = get_parent()->cast_to<Node2D>(); + Node2D *parent_2d = Object::cast_to<Node2D>(get_parent()); ERR_FAIL_COND_V(!parent_2d, Transform2D()); if (p_parent == parent_2d) diff --git a/scene/2d/parallax_background.cpp b/scene/2d/parallax_background.cpp index 433ab5ff8d..bdb4bd2b16 100644 --- a/scene/2d/parallax_background.cpp +++ b/scene/2d/parallax_background.cpp @@ -101,7 +101,7 @@ void ParallaxBackground::_update_scroll() { for (int i = 0; i < get_child_count(); i++) { - ParallaxLayer *l = get_child(i)->cast_to<ParallaxLayer>(); + ParallaxLayer *l = Object::cast_to<ParallaxLayer>(get_child(i)); if (!l) continue; diff --git a/scene/2d/parallax_layer.cpp b/scene/2d/parallax_layer.cpp index debdc22b65..40d688b708 100644 --- a/scene/2d/parallax_layer.cpp +++ b/scene/2d/parallax_layer.cpp @@ -36,11 +36,8 @@ void ParallaxLayer::set_motion_scale(const Size2 &p_scale) { motion_scale = p_scale; - if (!get_parent()) - return; - - ParallaxBackground *pb = get_parent()->cast_to<ParallaxBackground>(); - if (is_inside_tree() && pb) { + ParallaxBackground *pb = Object::cast_to<ParallaxBackground>(get_parent()); + if (pb && is_inside_tree()) { Vector2 ofs = pb->get_final_offset(); float scale = pb->get_scroll_scale(); set_base_offset_and_scale(ofs, scale); @@ -56,11 +53,8 @@ void ParallaxLayer::set_motion_offset(const Size2 &p_offset) { motion_offset = p_offset; - if (!get_parent()) - return; - - ParallaxBackground *pb = get_parent()->cast_to<ParallaxBackground>(); - if (is_inside_tree() && pb) { + ParallaxBackground *pb = Object::cast_to<ParallaxBackground>(get_parent()); + if (pb && is_inside_tree()) { Vector2 ofs = pb->get_final_offset(); float scale = pb->get_scroll_scale(); set_base_offset_and_scale(ofs, scale); @@ -74,10 +68,7 @@ Size2 ParallaxLayer::get_motion_offset() const { void ParallaxLayer::_update_mirroring() { - if (!get_parent()) - return; - - ParallaxBackground *pb = get_parent()->cast_to<ParallaxBackground>(); + ParallaxBackground *pb = Object::cast_to<ParallaxBackground>(get_parent()); if (pb) { RID c = pb->get_world_2d()->get_canvas(); @@ -139,7 +130,7 @@ void ParallaxLayer::set_base_offset_and_scale(const Point2 &p_offset, float p_sc String ParallaxLayer::get_configuration_warning() const { - if (!get_parent() || !get_parent()->cast_to<ParallaxBackground>()) { + if (!Object::cast_to<ParallaxBackground>(get_parent())) { return TTR("ParallaxLayer node only works when set as child of a ParallaxBackground node."); } diff --git a/scene/2d/path_2d.cpp b/scene/2d/path_2d.cpp index a79f60c96f..d2474d9557 100644 --- a/scene/2d/path_2d.cpp +++ b/scene/2d/path_2d.cpp @@ -137,13 +137,8 @@ void PathFollow2D::_notification(int p_what) { case NOTIFICATION_ENTER_TREE: { - Node *parent = get_parent(); - if (parent) { - - path = parent->cast_to<Path2D>(); - if (path) { - _update_transform(); - } + if ((path = Object::cast_to<Path2D>(get_parent()))) { + _update_transform(); } } break; @@ -231,7 +226,7 @@ String PathFollow2D::get_configuration_warning() const { if (!is_visible_in_tree() || !is_inside_tree()) return String(); - if (!get_parent() || !get_parent()->cast_to<Path2D>()) { + if (!Object::cast_to<Path2D>(get_parent())) { return TTR("PathFollow2D only works when set as a child of a Path2D node."); } diff --git a/scene/2d/physics_body_2d.cpp b/scene/2d/physics_body_2d.cpp index aaba9da299..30ede699fa 100644 --- a/scene/2d/physics_body_2d.cpp +++ b/scene/2d/physics_body_2d.cpp @@ -143,7 +143,7 @@ PhysicsBody2D::PhysicsBody2D(Physics2DServer::BodyMode p_mode) void PhysicsBody2D::add_collision_exception_with(Node *p_node) { ERR_FAIL_NULL(p_node); - PhysicsBody2D *physics_body = p_node->cast_to<PhysicsBody2D>(); + PhysicsBody2D *physics_body = Object::cast_to<PhysicsBody2D>(p_node); if (!physics_body) { ERR_EXPLAIN("Collision exception only works between two objects of PhysicsBody type"); } @@ -154,7 +154,7 @@ void PhysicsBody2D::add_collision_exception_with(Node *p_node) { void PhysicsBody2D::remove_collision_exception_with(Node *p_node) { ERR_FAIL_NULL(p_node); - PhysicsBody2D *physics_body = p_node->cast_to<PhysicsBody2D>(); + PhysicsBody2D *physics_body = Object::cast_to<PhysicsBody2D>(p_node); if (!physics_body) { ERR_EXPLAIN("Collision exception only works between two objects of PhysicsBody type"); } @@ -262,7 +262,7 @@ StaticBody2D::~StaticBody2D() { void RigidBody2D::_body_enter_tree(ObjectID p_id) { Object *obj = ObjectDB::get_instance(p_id); - Node *node = obj ? obj->cast_to<Node>() : NULL; + Node *node = Object::cast_to<Node>(obj); ERR_FAIL_COND(!node); Map<ObjectID, BodyState>::Element *E = contact_monitor->body_map.find(p_id); @@ -285,7 +285,7 @@ void RigidBody2D::_body_enter_tree(ObjectID p_id) { void RigidBody2D::_body_exit_tree(ObjectID p_id) { Object *obj = ObjectDB::get_instance(p_id); - Node *node = obj ? obj->cast_to<Node>() : NULL; + Node *node = Object::cast_to<Node>(obj); ERR_FAIL_COND(!node); Map<ObjectID, BodyState>::Element *E = contact_monitor->body_map.find(p_id); ERR_FAIL_COND(!E); @@ -310,7 +310,7 @@ void RigidBody2D::_body_inout(int p_status, ObjectID p_instance, int p_body_shap ObjectID objid = p_instance; Object *obj = ObjectDB::get_instance(objid); - Node *node = obj ? obj->cast_to<Node>() : NULL; + Node *node = Object::cast_to<Node>(obj); Map<ObjectID, BodyState>::Element *E = contact_monitor->body_map.find(objid); @@ -393,7 +393,7 @@ void RigidBody2D::_direct_state_changed(Object *p_state) { //eh.. fuck #ifdef DEBUG_ENABLED - state = p_state->cast_to<Physics2DDirectBodyState>(); + state = Object::cast_to<Physics2DDirectBodyState>(p_state); #else state = (Physics2DDirectBodyState *)p_state; //trust it #endif @@ -1171,12 +1171,10 @@ ObjectID KinematicBody2D::get_collision_collider_id(int p_collision) const { Object *KinematicBody2D::get_collision_collider_shape(int p_collision) const { ERR_FAIL_INDEX_V(p_collision, colliders.size(), NULL); Object *collider = get_collision_collider(p_collision); - if (collider) { - CollisionObject2D *obj2d = collider->cast_to<CollisionObject2D>(); - if (obj2d) { - uint32_t owner = shape_find_owner(colliders[p_collision].collider_shape); - return obj2d->shape_owner_get_owner(owner); - } + CollisionObject2D *obj2d = Object::cast_to<CollisionObject2D>(collider); + if (obj2d) { + uint32_t owner = shape_find_owner(colliders[p_collision].collider_shape); + return obj2d->shape_owner_get_owner(owner); } return NULL; diff --git a/scene/2d/ray_cast_2d.cpp b/scene/2d/ray_cast_2d.cpp index fbec922a2d..2d2a00847d 100644 --- a/scene/2d/ray_cast_2d.cpp +++ b/scene/2d/ray_cast_2d.cpp @@ -115,11 +115,11 @@ void RayCast2D::set_exclude_parent_body(bool p_exclude_parent_body) { if (!is_inside_tree()) return; - if (get_parent()->cast_to<PhysicsBody2D>()) { + if (Object::cast_to<PhysicsBody2D>(get_parent())) { if (exclude_parent_body) - exclude.insert(get_parent()->cast_to<PhysicsBody2D>()->get_rid()); + exclude.insert(Object::cast_to<PhysicsBody2D>(get_parent())->get_rid()); else - exclude.erase(get_parent()->cast_to<PhysicsBody2D>()->get_rid()); + exclude.erase(Object::cast_to<PhysicsBody2D>(get_parent())->get_rid()); } } @@ -139,11 +139,11 @@ void RayCast2D::_notification(int p_what) { else set_fixed_process(false); - if (get_parent()->cast_to<PhysicsBody2D>()) { + if (Object::cast_to<PhysicsBody2D>(get_parent())) { if (exclude_parent_body) - exclude.insert(get_parent()->cast_to<PhysicsBody2D>()->get_rid()); + exclude.insert(Object::cast_to<PhysicsBody2D>(get_parent())->get_rid()); else - exclude.erase(get_parent()->cast_to<PhysicsBody2D>()->get_rid()); + exclude.erase(Object::cast_to<PhysicsBody2D>(get_parent())->get_rid()); } } break; case NOTIFICATION_EXIT_TREE: { @@ -227,7 +227,7 @@ void RayCast2D::add_exception_rid(const RID &p_rid) { void RayCast2D::add_exception(const Object *p_object) { ERR_FAIL_NULL(p_object); - CollisionObject2D *co = ((Object *)p_object)->cast_to<CollisionObject2D>(); + const CollisionObject2D *co = Object::cast_to<CollisionObject2D>(p_object); if (!co) return; add_exception_rid(co->get_rid()); @@ -241,7 +241,7 @@ void RayCast2D::remove_exception_rid(const RID &p_rid) { void RayCast2D::remove_exception(const Object *p_object) { ERR_FAIL_NULL(p_object); - CollisionObject2D *co = ((Object *)p_object)->cast_to<CollisionObject2D>(); + const CollisionObject2D *co = Object::cast_to<CollisionObject2D>(p_object); if (!co) return; remove_exception_rid(co->get_rid()); diff --git a/scene/2d/remote_transform_2d.cpp b/scene/2d/remote_transform_2d.cpp index cbd7ac06f5..a2d53f0c7b 100644 --- a/scene/2d/remote_transform_2d.cpp +++ b/scene/2d/remote_transform_2d.cpp @@ -51,11 +51,7 @@ void RemoteTransform2D::_update_remote() { if (!cache) return; - Object *obj = ObjectDB::get_instance(cache); - if (!obj) - return; - - Node2D *n = obj->cast_to<Node2D>(); + Node2D *n = Object::cast_to<Node2D>(ObjectDB::get_instance(cache)); if (!n) return; @@ -182,7 +178,7 @@ bool RemoteTransform2D::get_update_scale() const { String RemoteTransform2D::get_configuration_warning() const { - if (!has_node(remote_node) || !get_node(remote_node) || !get_node(remote_node)->cast_to<Node2D>()) { + if (!has_node(remote_node) || !Object::cast_to<Node2D>(get_node(remote_node))) { return TTR("Path property must point to a valid Node2D node to work."); } diff --git a/scene/2d/screen_button.cpp b/scene/2d/screen_button.cpp index e8e5e9411f..c39b12fc9a 100644 --- a/scene/2d/screen_button.cpp +++ b/scene/2d/screen_button.cpp @@ -196,11 +196,11 @@ void TouchScreenButton::_input(const Ref<InputEvent> &p_event) { ERR_FAIL_COND(!is_visible_in_tree()); - const InputEventScreenTouch *st = p_event->cast_to<InputEventScreenTouch>(); + const InputEventScreenTouch *st = Object::cast_to<InputEventScreenTouch>(*p_event); if (passby_press) { - const InputEventScreenDrag *sd = p_event->cast_to<InputEventScreenDrag>(); + const InputEventScreenDrag *sd = Object::cast_to<InputEventScreenDrag>(*p_event); if (st && !st->is_pressed() && finger_pressed == st->get_index()) { diff --git a/scene/2d/sprite.cpp b/scene/2d/sprite.cpp index 2ec529a166..b7b68d8060 100644 --- a/scene/2d/sprite.cpp +++ b/scene/2d/sprite.cpp @@ -399,7 +399,7 @@ void ViewportSprite::_notification(int p_what) { Node *n = get_node(viewport_path); ERR_FAIL_COND(!n); - Viewport *vp=n->cast_to<Viewport>(); + Viewport *vp=Object::cast_to<Viewport>(n); ERR_FAIL_COND(!vp); Ref<RenderTargetTexture> rtt = vp->get_render_target_texture(); @@ -467,7 +467,7 @@ void ViewportSprite::set_viewport_path(const NodePath& p_viewport) { Node *n = get_node(viewport_path); ERR_FAIL_COND(!n); - Viewport *vp=n->cast_to<Viewport>(); + Viewport *vp=Object::cast_to<Viewport>(n); ERR_FAIL_COND(!vp); Ref<RenderTargetTexture> rtt = vp->get_render_target_texture(); @@ -544,13 +544,13 @@ Rect2 ViewportSprite::get_item_rect() const { String ViewportSprite::get_configuration_warning() const { - if (!has_node(viewport_path) || !get_node(viewport_path) || !get_node(viewport_path)->cast_to<Viewport>()) { + if (!has_node(viewport_path) || !Object::cast_to<Viewport>(get_node(viewport_path))) { return TTR("Path property must point to a valid Viewport node to work. Such Viewport must be set to 'render target' mode."); } else { Node *n = get_node(viewport_path); if (n) { - Viewport *vp = n->cast_to<Viewport>(); + Viewport *vp = Object::cast_to<Viewport>(n); if (!vp->is_set_as_render_target()) { return TTR("The Viewport set in the path property must be set as 'render target' in order for this sprite to work."); diff --git a/scene/2d/tile_map.cpp b/scene/2d/tile_map.cpp index 5d246e331f..a4a7d5eae8 100644 --- a/scene/2d/tile_map.cpp +++ b/scene/2d/tile_map.cpp @@ -50,12 +50,12 @@ void TileMap::_notification(int p_what) { Node2D *c = this; while (c) { - navigation = c->cast_to<Navigation2D>(); + navigation = Object::cast_to<Navigation2D>(c); if (navigation) { break; } - c = c->get_parent()->cast_to<Node2D>(); + c = Object::cast_to<Node2D>(c->get_parent()); } pending_update = true; diff --git a/scene/2d/visibility_notifier_2d.cpp b/scene/2d/visibility_notifier_2d.cpp index 2f2ad08f01..a641828df8 100644 --- a/scene/2d/visibility_notifier_2d.cpp +++ b/scene/2d/visibility_notifier_2d.cpp @@ -184,7 +184,7 @@ void VisibilityEnabler2D::_find_nodes(Node *p_node) { if (enabler[ENABLER_FREEZE_BODIES]) { - RigidBody2D *rb2d = p_node->cast_to<RigidBody2D>(); + RigidBody2D *rb2d = Object::cast_to<RigidBody2D>(p_node); if (rb2d && ((rb2d->get_mode() == RigidBody2D::MODE_CHARACTER || (rb2d->get_mode() == RigidBody2D::MODE_RIGID && !rb2d->is_able_to_sleep())))) { add = true; @@ -194,7 +194,7 @@ void VisibilityEnabler2D::_find_nodes(Node *p_node) { if (enabler[ENABLER_PAUSE_ANIMATIONS]) { - AnimationPlayer *ap = p_node->cast_to<AnimationPlayer>(); + AnimationPlayer *ap = Object::cast_to<AnimationPlayer>(p_node); if (ap) { add = true; } @@ -202,7 +202,7 @@ void VisibilityEnabler2D::_find_nodes(Node *p_node) { if (enabler[ENABLER_PAUSE_ANIMATED_SPRITES]) { - AnimatedSprite *as = p_node->cast_to<AnimatedSprite>(); + AnimatedSprite *as = Object::cast_to<AnimatedSprite>(p_node); if (as) { add = true; } @@ -210,7 +210,7 @@ void VisibilityEnabler2D::_find_nodes(Node *p_node) { if (enabler[ENABLER_PAUSE_PARTICLES]) { - Particles2D *ps = p_node->cast_to<Particles2D>(); + Particles2D *ps = Object::cast_to<Particles2D>(p_node); if (ps) { add = true; } @@ -273,7 +273,7 @@ void VisibilityEnabler2D::_change_node_state(Node *p_node, bool p_enabled) { ERR_FAIL_COND(!nodes.has(p_node)); { - RigidBody2D *rb = p_node->cast_to<RigidBody2D>(); + RigidBody2D *rb = Object::cast_to<RigidBody2D>(p_node); if (rb) { rb->set_sleeping(!p_enabled); @@ -281,7 +281,7 @@ void VisibilityEnabler2D::_change_node_state(Node *p_node, bool p_enabled) { } { - AnimationPlayer *ap = p_node->cast_to<AnimationPlayer>(); + AnimationPlayer *ap = Object::cast_to<AnimationPlayer>(p_node); if (ap) { @@ -289,7 +289,7 @@ void VisibilityEnabler2D::_change_node_state(Node *p_node, bool p_enabled) { } } { - AnimatedSprite *as = p_node->cast_to<AnimatedSprite>(); + AnimatedSprite *as = Object::cast_to<AnimatedSprite>(p_node); if (as) { @@ -301,7 +301,7 @@ void VisibilityEnabler2D::_change_node_state(Node *p_node, bool p_enabled) { } { - Particles2D *ps = p_node->cast_to<Particles2D>(); + Particles2D *ps = Object::cast_to<Particles2D>(p_node); if (ps) { |