Merge pull request #17899 from AndreaCatania/area_cleaning

Fixed physics server area cleaning
This commit is contained in:
Rémi Verschelde 2018-04-06 08:15:22 +02:00 committed by GitHub
commit bdfa10fc8f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 8 deletions

View File

@ -68,7 +68,8 @@ AreaBullet::AreaBullet() :
} }
AreaBullet::~AreaBullet() { AreaBullet::~AreaBullet() {
remove_all_overlapping_instantly(); // Call "remove_all_overlapping_instantly();" is not necessary because the exit
// signal are handled by godot, so just clear the array
} }
void AreaBullet::dispatch_callbacks() { void AreaBullet::dispatch_callbacks() {
@ -131,12 +132,13 @@ void AreaBullet::remove_all_overlapping_instantly() {
overlappingObjects.clear(); overlappingObjects.clear();
} }
void AreaBullet::remove_overlapping_instantly(CollisionObjectBullet *p_object) { void AreaBullet::remove_overlapping_instantly(CollisionObjectBullet *p_object, bool p_notify) {
CollisionObjectBullet *supportObject; CollisionObjectBullet *supportObject;
for (int i = overlappingObjects.size() - 1; 0 <= i; --i) { for (int i = overlappingObjects.size() - 1; 0 <= i; --i) {
supportObject = overlappingObjects[i].object; supportObject = overlappingObjects[i].object;
if (supportObject == p_object) { if (supportObject == p_object) {
call_event(supportObject, PhysicsServer::AREA_BODY_REMOVED); if (p_notify)
call_event(supportObject, PhysicsServer::AREA_BODY_REMOVED);
supportObject->on_exit_area(this); supportObject->on_exit_area(this);
overlappingObjects.remove(i); overlappingObjects.remove(i);
break; break;

View File

@ -152,7 +152,7 @@ public:
void remove_all_overlapping_instantly(); void remove_all_overlapping_instantly();
// Dispatch the callbacks and removes from overlapping list // Dispatch the callbacks and removes from overlapping list
void remove_overlapping_instantly(CollisionObjectBullet *p_object); void remove_overlapping_instantly(CollisionObjectBullet *p_object, bool p_notify);
virtual void on_collision_filters_change(); virtual void on_collision_filters_change();
virtual void on_collision_checker_start() {} virtual void on_collision_checker_start() {}

View File

@ -68,12 +68,10 @@ CollisionObjectBullet::CollisionObjectBullet(Type p_type) :
force_shape_reset(false) {} force_shape_reset(false) {}
CollisionObjectBullet::~CollisionObjectBullet() { CollisionObjectBullet::~CollisionObjectBullet() {
// Remove all overlapping // Remove all overlapping, notify is not required since godot take care of it
for (int i = areasOverlapped.size() - 1; 0 <= i; --i) { for (int i = areasOverlapped.size() - 1; 0 <= i; --i) {
areasOverlapped[i]->remove_overlapping_instantly(this); areasOverlapped[i]->remove_overlapping_instantly(this, /*Notify*/ false);
} }
// not required
// areasOverlapped.clear();
destroyBulletCollisionObject(); destroyBulletCollisionObject();
} }