diff options
author | Juan Linietsky <reduzio@gmail.com> | 2016-01-23 23:07:23 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2016-01-23 23:07:23 -0300 |
commit | d01f55a78eb08e5645310f17caac0ae49647a013 (patch) | |
tree | 3b1ac9f745908b3f9ab3aacc856882b07c3146fd /servers/physics | |
parent | a74138a0dc5862d2c26eb78a141ba3c3f9d01c6d (diff) | |
parent | 1231c795dedbaaefae8c99f23f7547d320a4ffc9 (diff) |
Merge pull request #2698 from Faless/add_area_fix
Fix bug in Body(2D)SW::add_area
Diffstat (limited to 'servers/physics')
-rw-r--r-- | servers/physics/body_sw.h | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/servers/physics/body_sw.h b/servers/physics/body_sw.h index c958177a19..870e8357f1 100644 --- a/servers/physics/body_sw.h +++ b/servers/physics/body_sw.h @@ -93,10 +93,11 @@ class BodySW : public CollisionObjectSW { struct AreaCMP { AreaSW *area; + int refCount; _FORCE_INLINE_ bool operator==(const AreaCMP& p_cmp) const { return area->get_self() == p_cmp.area->get_self();} _FORCE_INLINE_ bool operator<(const AreaCMP& p_cmp) const { return area->get_priority() < p_cmp.area->get_priority();} _FORCE_INLINE_ AreaCMP() {} - _FORCE_INLINE_ AreaCMP(AreaSW *p_area) { area=p_area;} + _FORCE_INLINE_ AreaCMP(AreaSW *p_area) { area=p_area; refCount=1;} }; Vector<AreaCMP> areas; @@ -143,8 +144,23 @@ public: void set_force_integration_callback(ObjectID p_id,const StringName& p_method,const Variant& p_udata=Variant()); - _FORCE_INLINE_ void add_area(AreaSW *p_area) { areas.ordered_insert(AreaCMP(p_area)); } - _FORCE_INLINE_ void remove_area(AreaSW *p_area) { areas.erase(AreaCMP(p_area)); } + _FORCE_INLINE_ void add_area(AreaSW *p_area) { + int index = areas.find(AreaCMP(p_area)); + if( index > -1 ) { + areas[index].refCount += 1; + } else { + areas.ordered_insert(AreaCMP(p_area)); + } + } + + _FORCE_INLINE_ void remove_area(AreaSW *p_area) { + int index = areas.find(AreaCMP(p_area)); + if( index > -1 ) { + areas[index].refCount -= 1; + if( areas[index].refCount < 1 ) + areas.remove(index); + } + } _FORCE_INLINE_ void set_max_contacts_reported(int p_size) { contacts.resize(p_size); contact_count=0; if (mode==PhysicsServer::BODY_MODE_KINEMATIC && p_size) set_active(true);} _FORCE_INLINE_ int get_max_contacts_reported() const { return contacts.size(); } |