@@ -59,26 +59,6 @@ JPH::ObjectLayer JoltArea3D::_get_object_layer() const {
5959 return space->map_to_object_layer (_get_broad_phase_layer (), collision_layer, collision_mask);
6060}
6161
62- bool JoltArea3D::_has_pending_events () const {
63- if (body_monitor_callback.is_valid ()) {
64- for (const KeyValue<JPH::BodyID, Overlap> &E : bodies_by_id) {
65- if (!E.value .pending_added .is_empty () || !E.value .pending_removed .is_empty ()) {
66- return true ;
67- }
68- }
69- }
70-
71- if (area_monitor_callback.is_valid ()) {
72- for (const KeyValue<JPH::BodyID, Overlap> &E : areas_by_id) {
73- if (!E.value .pending_added .is_empty () || !E.value .pending_removed .is_empty ()) {
74- return true ;
75- }
76- }
77- }
78-
79- return false ;
80- }
81-
8262void JoltArea3D::_add_to_space () {
8363 jolt_shape = build_shapes (true );
8464
@@ -136,6 +116,8 @@ void JoltArea3D::_add_shape_pair(Overlap &p_overlap, const JPH::BodyID &p_body_i
136116 shape_indices.self = find_shape_index (p_self_shape_id);
137117
138118 p_overlap.pending_added .push_back (shape_indices);
119+
120+ _events_changed ();
139121}
140122
141123bool JoltArea3D::_remove_shape_pair (Overlap &p_overlap, const JPH::SubShapeID &p_other_shape_id, const JPH::SubShapeID &p_self_shape_id) {
@@ -148,6 +130,8 @@ bool JoltArea3D::_remove_shape_pair(Overlap &p_overlap, const JPH::SubShapeID &p
148130 p_overlap.pending_removed .push_back (shape_pair->value );
149131 p_overlap.shape_pairs .remove (shape_pair);
150132
133+ _events_changed ();
134+
151135 return true ;
152136}
153137
@@ -224,10 +208,16 @@ void JoltArea3D::_force_bodies_entered() {
224208 for (KeyValue<JPH::BodyID, Overlap> &E : bodies_by_id) {
225209 Overlap &body = E.value ;
226210
211+ if (unlikely (body.shape_pairs .is_empty ())) {
212+ continue ;
213+ }
214+
227215 for (const KeyValue<ShapeIDPair, ShapeIndexPair> &P : body.shape_pairs ) {
228216 body.pending_removed .erase (P.value );
229217 body.pending_added .push_back (P.value );
230218 }
219+
220+ _events_changed ();
231221 }
232222}
233223
@@ -236,11 +226,17 @@ void JoltArea3D::_force_bodies_exited(bool p_remove) {
236226 const JPH::BodyID &id = E.key ;
237227 Overlap &body = E.value ;
238228
229+ if (unlikely (body.shape_pairs .is_empty ())) {
230+ continue ;
231+ }
232+
239233 for (const KeyValue<ShapeIDPair, ShapeIndexPair> &P : body.shape_pairs ) {
240234 body.pending_added .erase (P.value );
241235 body.pending_removed .push_back (P.value );
242236 }
243237
238+ _events_changed ();
239+
244240 if (p_remove) {
245241 body.shape_pairs .clear ();
246242 _notify_body_exited (id);
@@ -252,22 +248,34 @@ void JoltArea3D::_force_areas_entered() {
252248 for (KeyValue<JPH::BodyID, Overlap> &E : areas_by_id) {
253249 Overlap &area = E.value ;
254250
251+ if (unlikely (area.shape_pairs .is_empty ())) {
252+ continue ;
253+ }
254+
255255 for (const KeyValue<ShapeIDPair, ShapeIndexPair> &P : area.shape_pairs ) {
256256 area.pending_removed .erase (P.value );
257257 area.pending_added .push_back (P.value );
258258 }
259+
260+ _events_changed ();
259261 }
260262}
261263
262264void JoltArea3D::_force_areas_exited (bool p_remove) {
263265 for (KeyValue<JPH::BodyID, Overlap> &E : areas_by_id) {
264266 Overlap &area = E.value ;
265267
268+ if (unlikely (area.shape_pairs .is_empty ())) {
269+ continue ;
270+ }
271+
266272 for (const KeyValue<ShapeIDPair, ShapeIndexPair> &P : area.shape_pairs ) {
267273 area.pending_added .erase (P.value );
268274 area.pending_removed .push_back (P.value );
269275 }
270276
277+ _events_changed ();
278+
271279 if (p_remove) {
272280 area.shape_pairs .clear ();
273281 }
@@ -313,6 +321,10 @@ void JoltArea3D::_space_changed() {
313321 _update_default_gravity ();
314322}
315323
324+ void JoltArea3D::_events_changed () {
325+ _enqueue_call_queries ();
326+ }
327+
316328void JoltArea3D::_body_monitoring_changed () {
317329 if (has_body_monitor_callback ()) {
318330 _force_bodies_entered ();
@@ -664,11 +676,13 @@ void JoltArea3D::body_exited(const JPH::BodyID &p_body_id, bool p_notify) {
664676 return ;
665677 }
666678
667- for (KeyValue<ShapeIDPair, ShapeIndexPair> &E : overlap->shape_pairs ) {
679+ for (const KeyValue<ShapeIDPair, ShapeIndexPair> &E : overlap->shape_pairs ) {
668680 overlap->pending_added .erase (E.value );
669681 overlap->pending_removed .push_back (E.value );
670682 }
671683
684+ _events_changed ();
685+
672686 overlap->shape_pairs .clear ();
673687
674688 if (p_notify) {
@@ -691,16 +705,12 @@ void JoltArea3D::area_exited(const JPH::BodyID &p_body_id) {
691705 overlap->pending_removed .push_back (E.value );
692706 }
693707
708+ _events_changed ();
709+
694710 overlap->shape_pairs .clear ();
695711}
696712
697713void JoltArea3D::call_queries () {
698714 _flush_events (bodies_by_id, body_monitor_callback);
699715 _flush_events (areas_by_id, area_monitor_callback);
700716}
701-
702- void JoltArea3D::post_step (float p_step, JPH::Body &p_jolt_body) {
703- if (_has_pending_events ()) {
704- _enqueue_call_queries ();
705- }
706- }
0 commit comments