Merge pull request #18081 from AndreaCatania/arcle

Corrected area overlap cleaning
This commit is contained in:
Rémi Verschelde 2018-04-09 22:04:25 +02:00 committed by GitHub
commit e15f2636ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 16 deletions

View File

@ -68,8 +68,9 @@ AreaBullet::AreaBullet() :
} }
AreaBullet::~AreaBullet() { AreaBullet::~AreaBullet() {
// Call "remove_all_overlapping_instantly();" is not necessary because the exit // signal are handled by godot, so just clear without notify
// signal are handled by godot, so just clear the array for (int i = overlappingObjects.size() - 1; 0 <= i; --i)
overlappingObjects[i].object->on_exit_area(this);
} }
void AreaBullet::dispatch_callbacks() { void AreaBullet::dispatch_callbacks() {
@ -122,24 +123,21 @@ void AreaBullet::scratch() {
isScratched = true; isScratched = true;
} }
void AreaBullet::remove_all_overlapping_instantly() { void AreaBullet::clear_overlaps(bool p_notify) {
CollisionObjectBullet *supportObject;
for (int i = overlappingObjects.size() - 1; 0 <= i; --i) { for (int i = overlappingObjects.size() - 1; 0 <= i; --i) {
supportObject = overlappingObjects[i].object; if (p_notify)
call_event(supportObject, PhysicsServer::AREA_BODY_REMOVED); call_event(overlappingObjects[i].object, PhysicsServer::AREA_BODY_REMOVED);
supportObject->on_exit_area(this); overlappingObjects[i].object->on_exit_area(this);
} }
overlappingObjects.clear(); overlappingObjects.clear();
} }
void AreaBullet::remove_overlapping_instantly(CollisionObjectBullet *p_object, bool p_notify) { void AreaBullet::remove_overlap(CollisionObjectBullet *p_object, bool p_notify) {
CollisionObjectBullet *supportObject;
for (int i = overlappingObjects.size() - 1; 0 <= i; --i) { for (int i = overlappingObjects.size() - 1; 0 <= i; --i) {
supportObject = overlappingObjects[i].object; if (overlappingObjects[i].object == p_object) {
if (supportObject == p_object) {
if (p_notify) if (p_notify)
call_event(supportObject, PhysicsServer::AREA_BODY_REMOVED); call_event(overlappingObjects[i].object, PhysicsServer::AREA_BODY_REMOVED);
supportObject->on_exit_area(this); overlappingObjects[i].object->on_exit_area(this);
overlappingObjects.remove(i); overlappingObjects.remove(i);
break; break;
} }

View File

@ -150,9 +150,9 @@ public:
void set_on_state_change(ObjectID p_id, const StringName &p_method, const Variant &p_udata = Variant()); void set_on_state_change(ObjectID p_id, const StringName &p_method, const Variant &p_udata = Variant());
void scratch(); void scratch();
void remove_all_overlapping_instantly(); void clear_overlaps(bool p_notify);
// Dispatch the callbacks and removes from overlapping list // Dispatch the callbacks and removes from overlapping list
void remove_overlapping_instantly(CollisionObjectBullet *p_object, bool p_notify); void remove_overlap(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

@ -70,7 +70,7 @@ CollisionObjectBullet::CollisionObjectBullet(Type p_type) :
CollisionObjectBullet::~CollisionObjectBullet() { CollisionObjectBullet::~CollisionObjectBullet() {
// Remove all overlapping, notify is not required since godot take care of it // 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, /*Notify*/ false); areasOverlapped[i]->remove_overlap(this, /*Notify*/ false);
} }
destroyBulletCollisionObject(); destroyBulletCollisionObject();