Merge pull request #15606 from RandomShaper/fix-inherited-coll-shapes

Update collision shapes data on tree entered
This commit is contained in:
Rémi Verschelde 2018-01-12 13:48:17 +01:00 committed by GitHub
commit bab9759645
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 74 additions and 15 deletions

View file

@ -115,6 +115,15 @@ Vector<Vector<Vector2> > CollisionPolygon2D::_decompose_in_convex() {
return decomp; return decomp;
} }
void CollisionPolygon2D::_update_in_shape_owner(bool p_xform_only) {
parent->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);
}
void CollisionPolygon2D::_notification(int p_what) { void CollisionPolygon2D::_notification(int p_what) {
switch (p_what) { switch (p_what) {
@ -124,9 +133,7 @@ void CollisionPolygon2D::_notification(int p_what) {
if (parent) { if (parent) {
owner_id = parent->create_shape_owner(this); owner_id = parent->create_shape_owner(this);
_build_polygon(); _build_polygon();
parent->shape_owner_set_transform(owner_id, get_transform()); _update_in_shape_owner();
parent->shape_owner_set_disabled(owner_id, disabled);
parent->shape_owner_set_one_way_collision(owner_id, one_way_collision);
} }
/*if (Engine::get_singleton()->is_editor_hint()) { /*if (Engine::get_singleton()->is_editor_hint()) {
@ -135,11 +142,18 @@ void CollisionPolygon2D::_notification(int p_what) {
set_z_index(VS::CANVAS_ITEM_Z_MAX - 1); set_z_index(VS::CANVAS_ITEM_Z_MAX - 1);
}*/ }*/
} break;
case NOTIFICATION_ENTER_TREE: {
if (parent) {
_update_in_shape_owner();
}
} break; } break;
case NOTIFICATION_LOCAL_TRANSFORM_CHANGED: { case NOTIFICATION_LOCAL_TRANSFORM_CHANGED: {
if (parent) { if (parent) {
parent->shape_owner_set_transform(owner_id, get_transform()); _update_in_shape_owner(true);
} }
} break; } break;

View file

@ -59,6 +59,8 @@ protected:
void _build_polygon(); void _build_polygon();
void _update_in_shape_owner(bool p_xform_only = false);
protected: protected:
void _notification(int p_what); void _notification(int p_what);
static void _bind_methods(); static void _bind_methods();

View file

@ -45,6 +45,15 @@ void CollisionShape2D::_shape_changed() {
update(); update();
} }
void CollisionShape2D::_update_in_shape_owner(bool p_xform_only) {
parent->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);
}
void CollisionShape2D::_notification(int p_what) { void CollisionShape2D::_notification(int p_what) {
switch (p_what) { switch (p_what) {
@ -57,9 +66,7 @@ void CollisionShape2D::_notification(int p_what) {
if (shape.is_valid()) { if (shape.is_valid()) {
parent->shape_owner_add_shape(owner_id, shape); parent->shape_owner_add_shape(owner_id, shape);
} }
parent->shape_owner_set_transform(owner_id, get_transform()); _update_in_shape_owner();
parent->shape_owner_set_disabled(owner_id, disabled);
parent->shape_owner_set_one_way_collision(owner_id, one_way_collision);
} }
/*if (Engine::get_singleton()->is_editor_hint()) { /*if (Engine::get_singleton()->is_editor_hint()) {
@ -68,11 +75,18 @@ void CollisionShape2D::_notification(int p_what) {
set_z_index(VS::CANVAS_ITEM_Z_MAX - 1); set_z_index(VS::CANVAS_ITEM_Z_MAX - 1);
}*/ }*/
} break;
case NOTIFICATION_ENTER_TREE: {
if (parent) {
_update_in_shape_owner();
}
} break; } break;
case NOTIFICATION_LOCAL_TRANSFORM_CHANGED: { case NOTIFICATION_LOCAL_TRANSFORM_CHANGED: {
if (parent) { if (parent) {
parent->shape_owner_set_transform(owner_id, get_transform()); _update_in_shape_owner(true);
} }
} break; } break;

View file

@ -47,6 +47,8 @@ class CollisionShape2D : public Node2D {
bool disabled; bool disabled;
bool one_way_collision; bool one_way_collision;
void _update_in_shape_owner(bool p_xform_only = false);
protected: protected:
void _notification(int p_what); void _notification(int p_what);
static void _bind_methods(); static void _bind_methods();

View file

@ -73,6 +73,14 @@ void CollisionPolygon::_build_polygon() {
} }
} }
void CollisionPolygon::_update_in_shape_owner(bool p_xform_only) {
parent->shape_owner_set_transform(owner_id, get_transform());
if (p_xform_only)
return;
parent->shape_owner_set_disabled(owner_id, disabled);
}
void CollisionPolygon::_notification(int p_what) { void CollisionPolygon::_notification(int p_what) {
switch (p_what) { switch (p_what) {
@ -82,14 +90,20 @@ void CollisionPolygon::_notification(int p_what) {
if (parent) { if (parent) {
owner_id = parent->create_shape_owner(this); owner_id = parent->create_shape_owner(this);
_build_polygon(); _build_polygon();
parent->shape_owner_set_transform(owner_id, get_transform()); _update_in_shape_owner();
parent->shape_owner_set_disabled(owner_id, disabled);
} }
} break; } break;
case NOTIFICATION_ENTER_TREE: {
if (parent) {
_update_in_shape_owner();
}
} break;
case NOTIFICATION_LOCAL_TRANSFORM_CHANGED: { case NOTIFICATION_LOCAL_TRANSFORM_CHANGED: {
if (parent) { if (parent) {
parent->shape_owner_set_transform(owner_id, get_transform()); _update_in_shape_owner(true);
} }
} break; } break;

View file

@ -51,6 +51,8 @@ protected:
void _build_polygon(); void _build_polygon();
void _update_in_shape_owner(bool p_xform_only = false);
protected: protected:
void _notification(int p_what); void _notification(int p_what);
static void _bind_methods(); static void _bind_methods();

View file

@ -64,6 +64,14 @@ void CollisionShape::make_convex_from_brothers() {
} }
} }
void CollisionShape::_update_in_shape_owner(bool p_xform_only) {
parent->shape_owner_set_transform(owner_id, get_transform());
if (p_xform_only)
return;
parent->shape_owner_set_disabled(owner_id, disabled);
}
void CollisionShape::_notification(int p_what) { void CollisionShape::_notification(int p_what) {
switch (p_what) { switch (p_what) {
@ -75,19 +83,20 @@ void CollisionShape::_notification(int p_what) {
if (shape.is_valid()) { if (shape.is_valid()) {
parent->shape_owner_add_shape(owner_id, shape); parent->shape_owner_add_shape(owner_id, shape);
} }
parent->shape_owner_set_transform(owner_id, get_transform()); _update_in_shape_owner();
parent->shape_owner_set_disabled(owner_id, disabled);
} }
} break; } break;
case NOTIFICATION_ENTER_TREE: { case NOTIFICATION_ENTER_TREE: {
if (parent) {
_update_in_shape_owner();
}
if (get_tree()->is_debugging_collisions_hint()) { if (get_tree()->is_debugging_collisions_hint()) {
_create_debug_shape(); _create_debug_shape();
} }
} break; } break;
case NOTIFICATION_LOCAL_TRANSFORM_CHANGED: { case NOTIFICATION_LOCAL_TRANSFORM_CHANGED: {
if (parent) { if (parent) {
parent->shape_owner_set_transform(owner_id, get_transform()); _update_in_shape_owner(true);
} }
} break; } break;
case NOTIFICATION_UNPARENTED: { case NOTIFICATION_UNPARENTED: {

View file

@ -51,6 +51,8 @@ class CollisionShape : public Spatial {
void _create_debug_shape(); void _create_debug_shape();
void _update_in_shape_owner(bool p_xform_only = false);
protected: protected:
void _notification(int p_what); void _notification(int p_what);
static void _bind_methods(); static void _bind_methods();