|
@@ -39,7 +39,7 @@
|
|
#include "thirdparty/misc/polypartition.h"
|
|
#include "thirdparty/misc/polypartition.h"
|
|
|
|
|
|
void CollisionPolygon2D::_build_polygon() {
|
|
void CollisionPolygon2D::_build_polygon() {
|
|
- parent->shape_owner_clear_shapes(owner_id);
|
|
|
|
|
|
+ collision_object->shape_owner_clear_shapes(owner_id);
|
|
|
|
|
|
bool solids = build_mode == BUILD_SOLIDS;
|
|
bool solids = build_mode == BUILD_SOLIDS;
|
|
|
|
|
|
@@ -54,7 +54,7 @@ void CollisionPolygon2D::_build_polygon() {
|
|
for (int i = 0; i < decomp.size(); i++) {
|
|
for (int i = 0; i < decomp.size(); i++) {
|
|
Ref<ConvexPolygonShape2D> convex = memnew(ConvexPolygonShape2D);
|
|
Ref<ConvexPolygonShape2D> convex = memnew(ConvexPolygonShape2D);
|
|
convex->set_points(decomp[i]);
|
|
convex->set_points(decomp[i]);
|
|
- parent->shape_owner_add_shape(owner_id, convex);
|
|
|
|
|
|
+ collision_object->shape_owner_add_shape(owner_id, convex);
|
|
}
|
|
}
|
|
|
|
|
|
} else {
|
|
} else {
|
|
@@ -75,7 +75,7 @@ void CollisionPolygon2D::_build_polygon() {
|
|
|
|
|
|
concave->set_segments(segments);
|
|
concave->set_segments(segments);
|
|
|
|
|
|
- parent->shape_owner_add_shape(owner_id, concave);
|
|
|
|
|
|
+ collision_object->shape_owner_add_shape(owner_id, concave);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -85,44 +85,44 @@ Vector<Vector<Vector2>> CollisionPolygon2D::_decompose_in_convex() {
|
|
}
|
|
}
|
|
|
|
|
|
void CollisionPolygon2D::_update_in_shape_owner(bool p_xform_only) {
|
|
void CollisionPolygon2D::_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) {
|
|
if (p_xform_only) {
|
|
return;
|
|
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);
|
|
}
|
|
}
|
|
|
|
|
|
void CollisionPolygon2D::_notification(int p_what) {
|
|
void CollisionPolygon2D::_notification(int p_what) {
|
|
switch (p_what) {
|
|
switch (p_what) {
|
|
case NOTIFICATION_PARENTED: {
|
|
case NOTIFICATION_PARENTED: {
|
|
- parent = Object::cast_to<CollisionObject2D>(get_parent());
|
|
|
|
- if (parent) {
|
|
|
|
- owner_id = parent->create_shape_owner(this);
|
|
|
|
|
|
+ collision_object = Object::cast_to<CollisionObject2D>(get_parent());
|
|
|
|
+ if (collision_object) {
|
|
|
|
+ owner_id = collision_object->create_shape_owner(this);
|
|
_build_polygon();
|
|
_build_polygon();
|
|
_update_in_shape_owner();
|
|
_update_in_shape_owner();
|
|
}
|
|
}
|
|
} break;
|
|
} break;
|
|
|
|
|
|
case NOTIFICATION_ENTER_TREE: {
|
|
case NOTIFICATION_ENTER_TREE: {
|
|
- if (parent) {
|
|
|
|
|
|
+ if (collision_object) {
|
|
_update_in_shape_owner();
|
|
_update_in_shape_owner();
|
|
}
|
|
}
|
|
} break;
|
|
} break;
|
|
|
|
|
|
case NOTIFICATION_LOCAL_TRANSFORM_CHANGED: {
|
|
case NOTIFICATION_LOCAL_TRANSFORM_CHANGED: {
|
|
- if (parent) {
|
|
|
|
|
|
+ if (collision_object) {
|
|
_update_in_shape_owner(true);
|
|
_update_in_shape_owner(true);
|
|
}
|
|
}
|
|
} break;
|
|
} break;
|
|
|
|
|
|
case NOTIFICATION_UNPARENTED: {
|
|
case NOTIFICATION_UNPARENTED: {
|
|
- if (parent) {
|
|
|
|
- parent->remove_shape_owner(owner_id);
|
|
|
|
|
|
+ if (collision_object) {
|
|
|
|
+ collision_object->remove_shape_owner(owner_id);
|
|
}
|
|
}
|
|
owner_id = 0;
|
|
owner_id = 0;
|
|
- parent = nullptr;
|
|
|
|
|
|
+ collision_object = nullptr;
|
|
} break;
|
|
} break;
|
|
|
|
|
|
case NOTIFICATION_DRAW: {
|
|
case NOTIFICATION_DRAW: {
|
|
@@ -191,7 +191,7 @@ void CollisionPolygon2D::set_polygon(const Vector<Point2> &p_polygon) {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- if (parent) {
|
|
|
|
|
|
+ if (collision_object) {
|
|
_build_polygon();
|
|
_build_polygon();
|
|
_update_in_shape_owner();
|
|
_update_in_shape_owner();
|
|
}
|
|
}
|
|
@@ -206,7 +206,7 @@ Vector<Point2> CollisionPolygon2D::get_polygon() const {
|
|
void CollisionPolygon2D::set_build_mode(BuildMode p_mode) {
|
|
void CollisionPolygon2D::set_build_mode(BuildMode p_mode) {
|
|
ERR_FAIL_INDEX((int)p_mode, 2);
|
|
ERR_FAIL_INDEX((int)p_mode, 2);
|
|
build_mode = p_mode;
|
|
build_mode = p_mode;
|
|
- if (parent) {
|
|
|
|
|
|
+ if (collision_object) {
|
|
_build_polygon();
|
|
_build_polygon();
|
|
_update_in_shape_owner();
|
|
_update_in_shape_owner();
|
|
}
|
|
}
|
|
@@ -253,7 +253,7 @@ PackedStringArray CollisionPolygon2D::get_configuration_warnings() const {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (one_way_collision && Object::cast_to<Area2D>(get_parent())) {
|
|
if (one_way_collision && Object::cast_to<Area2D>(get_parent())) {
|
|
- warnings.push_back(RTR("The One Way Collision property will be ignored when the parent is an Area2D."));
|
|
|
|
|
|
+ warnings.push_back(RTR("The One Way Collision property will be ignored when the collision object is an Area2D."));
|
|
}
|
|
}
|
|
|
|
|
|
return warnings;
|
|
return warnings;
|
|
@@ -262,8 +262,8 @@ PackedStringArray CollisionPolygon2D::get_configuration_warnings() const {
|
|
void CollisionPolygon2D::set_disabled(bool p_disabled) {
|
|
void CollisionPolygon2D::set_disabled(bool p_disabled) {
|
|
disabled = p_disabled;
|
|
disabled = p_disabled;
|
|
queue_redraw();
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -274,8 +274,8 @@ bool CollisionPolygon2D::is_disabled() const {
|
|
void CollisionPolygon2D::set_one_way_collision(bool p_enable) {
|
|
void CollisionPolygon2D::set_one_way_collision(bool p_enable) {
|
|
one_way_collision = p_enable;
|
|
one_way_collision = p_enable;
|
|
queue_redraw();
|
|
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();
|
|
update_configuration_warnings();
|
|
}
|
|
}
|
|
@@ -286,8 +286,8 @@ bool CollisionPolygon2D::is_one_way_collision_enabled() const {
|
|
|
|
|
|
void CollisionPolygon2D::set_one_way_collision_margin(real_t p_margin) {
|
|
void CollisionPolygon2D::set_one_way_collision_margin(real_t p_margin) {
|
|
one_way_collision_margin = 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);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|