Merge pull request #39400 from madmiraal/fix-39374-3.2

[3.2] Test collision mask before creating constraint pair in Godot physics broadphase 2D and 3D.
This commit is contained in:
Rémi Verschelde 2020-06-09 13:38:11 +02:00 committed by GitHub
commit 9901eac9f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 26 additions and 5 deletions

View File

@ -202,9 +202,12 @@ void BroadPhaseBasic::update() {
if (pair_ok && !E) {
void *data = NULL;
if (pair_callback)
if (pair_callback) {
data = pair_callback(elem_A->owner, elem_A->subindex, elem_B->owner, elem_B->subindex, unpair_userdata);
pair_map.insert(key, data);
if (data) {
pair_map.insert(key, data);
}
}
}
}
}

View File

@ -996,6 +996,9 @@ bool SpaceSW::test_body_motion(BodySW *p_body, const Transform &p_from, const Ve
}
void *SpaceSW::_broadphase_pair(CollisionObjectSW *A, int p_subindex_A, CollisionObjectSW *B, int p_subindex_B, void *p_self) {
if (!A->test_collision_mask(B)) {
return nullptr;
}
CollisionObjectSW::Type type_A = A->get_type();
CollisionObjectSW::Type type_B = B->get_type();
@ -1034,6 +1037,9 @@ void *SpaceSW::_broadphase_pair(CollisionObjectSW *A, int p_subindex_A, Collisio
}
void SpaceSW::_broadphase_unpair(CollisionObjectSW *A, int p_subindex_A, CollisionObjectSW *B, int p_subindex_B, void *p_data, void *p_self) {
if (!p_data) {
return;
}
SpaceSW *self = (SpaceSW *)p_self;
self->collision_pairs--;

View File

@ -159,9 +159,12 @@ void BroadPhase2DBasic::update() {
if (pair_ok && !E) {
void *data = NULL;
if (pair_callback)
if (pair_callback) {
data = pair_callback(elem_A->owner, elem_A->subindex, elem_B->owner, elem_B->subindex, unpair_userdata);
pair_map.insert(key, data);
if (data) {
pair_map.insert(key, data);
}
}
}
}
}

View File

@ -83,7 +83,10 @@ void BroadPhase2DHashGrid::_check_motion(Element *p_elem) {
if (pairing) {
if (pair_callback) {
E->get()->ud = pair_callback(p_elem->owner, p_elem->subindex, E->key()->owner, E->key()->subindex, pair_userdata);
void *ud = pair_callback(p_elem->owner, p_elem->subindex, E->key()->owner, E->key()->subindex, pair_userdata);
if (ud) {
E->get()->ud = ud;
}
}
} else {

View File

@ -1122,6 +1122,9 @@ bool Space2DSW::test_body_motion(Body2DSW *p_body, const Transform2D &p_from, co
}
void *Space2DSW::_broadphase_pair(CollisionObject2DSW *A, int p_subindex_A, CollisionObject2DSW *B, int p_subindex_B, void *p_self) {
if (!A->test_collision_mask(B)) {
return nullptr;
}
CollisionObject2DSW::Type type_A = A->get_type();
CollisionObject2DSW::Type type_B = B->get_type();
@ -1160,6 +1163,9 @@ void *Space2DSW::_broadphase_pair(CollisionObject2DSW *A, int p_subindex_A, Coll
}
void Space2DSW::_broadphase_unpair(CollisionObject2DSW *A, int p_subindex_A, CollisionObject2DSW *B, int p_subindex_B, void *p_data, void *p_self) {
if (!p_data) {
return;
}
Space2DSW *self = (Space2DSW *)p_self;
self->collision_pairs--;