From ec09cff7f3509eabdeeff7fa418ed49f8a56136d Mon Sep 17 00:00:00 2001 From: Aaron Franke Date: Wed, 7 Jun 2023 11:43:47 -0500 Subject: [PATCH] Internally rename parent to collision_object in CollisionShape(2D/3D) --- scene/2d/collision_shape_2d.cpp | 51 +++++++++++++++++---------------- scene/2d/collision_shape_2d.h | 2 +- scene/3d/collision_shape_3d.cpp | 39 +++++++++++++------------ scene/3d/collision_shape_3d.h | 2 +- 4 files changed, 48 insertions(+), 46 deletions(-) diff --git a/scene/2d/collision_shape_2d.cpp b/scene/2d/collision_shape_2d.cpp index 5951405bbef..10fc7ef5b2d 100644 --- a/scene/2d/collision_shape_2d.cpp +++ b/scene/2d/collision_shape_2d.cpp @@ -40,13 +40,13 @@ void CollisionShape2D::_shape_changed() { } void CollisionShape2D::_update_in_shape_owner(bool p_xform_only) { - parent->shape_owner_set_transform(owner_id, get_transform()); + collision_object->shape_owner_set_transform(owner_id, get_transform()); if (p_xform_only) { return; } - parent->shape_owner_set_disabled(owner_id, disabled); - parent->shape_owner_set_one_way_collision(owner_id, one_way_collision); - parent->shape_owner_set_one_way_collision_margin(owner_id, one_way_collision_margin); + collision_object->shape_owner_set_disabled(owner_id, disabled); + collision_object->shape_owner_set_one_way_collision(owner_id, one_way_collision); + collision_object->shape_owner_set_one_way_collision_margin(owner_id, one_way_collision_margin); } Color CollisionShape2D::_get_default_debug_color() const { @@ -57,34 +57,34 @@ Color CollisionShape2D::_get_default_debug_color() const { void CollisionShape2D::_notification(int p_what) { switch (p_what) { case NOTIFICATION_PARENTED: { - parent = Object::cast_to(get_parent()); - if (parent) { - owner_id = parent->create_shape_owner(this); + collision_object = Object::cast_to(get_parent()); + if (collision_object) { + owner_id = collision_object->create_shape_owner(this); if (shape.is_valid()) { - parent->shape_owner_add_shape(owner_id, shape); + collision_object->shape_owner_add_shape(owner_id, shape); } _update_in_shape_owner(); } } break; case NOTIFICATION_ENTER_TREE: { - if (parent) { + if (collision_object) { _update_in_shape_owner(); } } break; case NOTIFICATION_LOCAL_TRANSFORM_CHANGED: { - if (parent) { + if (collision_object) { _update_in_shape_owner(true); } } break; case NOTIFICATION_UNPARENTED: { - if (parent) { - parent->remove_shape_owner(owner_id); + if (collision_object) { + collision_object->remove_shape_owner(owner_id); } owner_id = 0; - parent = nullptr; + collision_object = nullptr; } break; case NOTIFICATION_DRAW: { @@ -146,10 +146,10 @@ void CollisionShape2D::set_shape(const Ref &p_shape) { } shape = p_shape; queue_redraw(); - if (parent) { - parent->shape_owner_clear_shapes(owner_id); + if (collision_object) { + collision_object->shape_owner_clear_shapes(owner_id); if (shape.is_valid()) { - parent->shape_owner_add_shape(owner_id, shape); + collision_object->shape_owner_add_shape(owner_id, shape); } _update_in_shape_owner(); } @@ -176,14 +176,15 @@ bool CollisionShape2D::_edit_is_selected_on_click(const Point2 &p_point, double PackedStringArray CollisionShape2D::get_configuration_warnings() const { PackedStringArray warnings = Node::get_configuration_warnings(); - if (!Object::cast_to(get_parent())) { + CollisionObject2D *col_object = Object::cast_to(get_parent()); + if (col_object == nullptr) { warnings.push_back(RTR("CollisionShape2D only serves to provide a collision shape to a CollisionObject2D derived node. Please only use it as a child of Area2D, StaticBody2D, RigidBody2D, CharacterBody2D, etc. to give them a shape.")); } if (!shape.is_valid()) { warnings.push_back(RTR("A shape must be provided for CollisionShape2D to function. Please create a shape resource for it!")); } - if (one_way_collision && Object::cast_to(get_parent())) { - warnings.push_back(RTR("The One Way Collision property will be ignored when the parent is an Area2D.")); + if (one_way_collision && Object::cast_to(col_object)) { + warnings.push_back(RTR("The One Way Collision property will be ignored when the collision object is an Area2D.")); } Ref convex = shape; @@ -198,8 +199,8 @@ PackedStringArray CollisionShape2D::get_configuration_warnings() const { void CollisionShape2D::set_disabled(bool p_disabled) { disabled = p_disabled; queue_redraw(); - if (parent) { - parent->shape_owner_set_disabled(owner_id, p_disabled); + if (collision_object) { + collision_object->shape_owner_set_disabled(owner_id, p_disabled); } } @@ -210,8 +211,8 @@ bool CollisionShape2D::is_disabled() const { void CollisionShape2D::set_one_way_collision(bool p_enable) { one_way_collision = p_enable; queue_redraw(); - if (parent) { - parent->shape_owner_set_one_way_collision(owner_id, p_enable); + if (collision_object) { + collision_object->shape_owner_set_one_way_collision(owner_id, p_enable); } update_configuration_warnings(); } @@ -222,8 +223,8 @@ bool CollisionShape2D::is_one_way_collision_enabled() const { void CollisionShape2D::set_one_way_collision_margin(real_t p_margin) { one_way_collision_margin = p_margin; - if (parent) { - parent->shape_owner_set_one_way_collision_margin(owner_id, one_way_collision_margin); + if (collision_object) { + collision_object->shape_owner_set_one_way_collision_margin(owner_id, one_way_collision_margin); } } diff --git a/scene/2d/collision_shape_2d.h b/scene/2d/collision_shape_2d.h index 0cfe1047742..3e13dd698c1 100644 --- a/scene/2d/collision_shape_2d.h +++ b/scene/2d/collision_shape_2d.h @@ -41,7 +41,7 @@ class CollisionShape2D : public Node2D { Ref shape; Rect2 rect = Rect2(-Point2(10, 10), Point2(20, 20)); uint32_t owner_id = 0; - CollisionObject2D *parent = nullptr; + CollisionObject2D *collision_object = nullptr; bool disabled = false; bool one_way_collision = false; real_t one_way_collision_margin = 1.0; diff --git a/scene/3d/collision_shape_3d.cpp b/scene/3d/collision_shape_3d.cpp index b7f3b12c25a..10eefc784d7 100644 --- a/scene/3d/collision_shape_3d.cpp +++ b/scene/3d/collision_shape_3d.cpp @@ -69,45 +69,45 @@ void CollisionShape3D::make_convex_from_siblings() { } void CollisionShape3D::_update_in_shape_owner(bool p_xform_only) { - parent->shape_owner_set_transform(owner_id, get_transform()); + collision_object->shape_owner_set_transform(owner_id, get_transform()); if (p_xform_only) { return; } - parent->shape_owner_set_disabled(owner_id, disabled); + collision_object->shape_owner_set_disabled(owner_id, disabled); } void CollisionShape3D::_notification(int p_what) { switch (p_what) { case NOTIFICATION_PARENTED: { - parent = Object::cast_to(get_parent()); - if (parent) { - owner_id = parent->create_shape_owner(this); + collision_object = Object::cast_to(get_parent()); + if (collision_object) { + owner_id = collision_object->create_shape_owner(this); if (shape.is_valid()) { - parent->shape_owner_add_shape(owner_id, shape); + collision_object->shape_owner_add_shape(owner_id, shape); } _update_in_shape_owner(); } } break; case NOTIFICATION_ENTER_TREE: { - if (parent) { + if (collision_object) { _update_in_shape_owner(); } } break; case NOTIFICATION_LOCAL_TRANSFORM_CHANGED: { - if (parent) { + if (collision_object) { _update_in_shape_owner(true); } update_configuration_warnings(); } break; case NOTIFICATION_UNPARENTED: { - if (parent) { - parent->remove_shape_owner(owner_id); + if (collision_object) { + collision_object->remove_shape_owner(owner_id); } owner_id = 0; - parent = nullptr; + collision_object = nullptr; } break; } } @@ -119,7 +119,8 @@ void CollisionShape3D::resource_changed(Ref res) { PackedStringArray CollisionShape3D::get_configuration_warnings() const { PackedStringArray warnings = Node::get_configuration_warnings(); - if (!Object::cast_to(get_parent())) { + CollisionObject3D *col_object = Object::cast_to(get_parent()); + if (col_object == nullptr) { warnings.push_back(RTR("CollisionShape3D only serves to provide a collision shape to a CollisionObject3D derived node.\nPlease only use it as a child of Area3D, StaticBody3D, RigidBody3D, CharacterBody3D, etc. to give them a shape.")); } @@ -127,7 +128,7 @@ PackedStringArray CollisionShape3D::get_configuration_warnings() const { warnings.push_back(RTR("A shape must be provided for CollisionShape3D to function. Please create a shape resource for it.")); } - if (shape.is_valid() && Object::cast_to(get_parent())) { + if (shape.is_valid() && Object::cast_to(col_object)) { if (Object::cast_to(*shape)) { warnings.push_back(RTR("ConcavePolygonShape3D doesn't support RigidBody3D in another mode than static.")); } else if (Object::cast_to(*shape)) { @@ -169,14 +170,14 @@ void CollisionShape3D::set_shape(const Ref &p_shape) { shape->register_owner(this); } update_gizmos(); - if (parent) { - parent->shape_owner_clear_shapes(owner_id); + if (collision_object) { + collision_object->shape_owner_clear_shapes(owner_id); if (shape.is_valid()) { - parent->shape_owner_add_shape(owner_id, shape); + collision_object->shape_owner_add_shape(owner_id, shape); } } - if (is_inside_tree() && parent) { + if (is_inside_tree() && collision_object) { // If this is a heightfield shape our center may have changed _update_in_shape_owner(true); } @@ -190,8 +191,8 @@ Ref CollisionShape3D::get_shape() const { void CollisionShape3D::set_disabled(bool p_disabled) { disabled = p_disabled; update_gizmos(); - if (parent) { - parent->shape_owner_set_disabled(owner_id, p_disabled); + if (collision_object) { + collision_object->shape_owner_set_disabled(owner_id, p_disabled); } } diff --git a/scene/3d/collision_shape_3d.h b/scene/3d/collision_shape_3d.h index c43f1da39cc..74928bad6d3 100644 --- a/scene/3d/collision_shape_3d.h +++ b/scene/3d/collision_shape_3d.h @@ -41,7 +41,7 @@ class CollisionShape3D : public Node3D { Ref shape; uint32_t owner_id = 0; - CollisionObject3D *parent = nullptr; + CollisionObject3D *collision_object = nullptr; void resource_changed(Ref res); bool disabled = false;