@@ -59,26 +59,6 @@ JPH::ObjectLayer JoltArea3D::_get_object_layer() const {
59
59
return space->map_to_object_layer (_get_broad_phase_layer (), collision_layer, collision_mask);
60
60
}
61
61
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
-
82
62
void JoltArea3D::_add_to_space () {
83
63
jolt_shape = build_shapes (true );
84
64
@@ -136,6 +116,8 @@ void JoltArea3D::_add_shape_pair(Overlap &p_overlap, const JPH::BodyID &p_body_i
136
116
shape_indices.self = find_shape_index (p_self_shape_id);
137
117
138
118
p_overlap.pending_added .push_back (shape_indices);
119
+
120
+ _events_changed ();
139
121
}
140
122
141
123
bool 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
148
130
p_overlap.pending_removed .push_back (shape_pair->value );
149
131
p_overlap.shape_pairs .remove (shape_pair);
150
132
133
+ _events_changed ();
134
+
151
135
return true ;
152
136
}
153
137
@@ -224,10 +208,16 @@ void JoltArea3D::_force_bodies_entered() {
224
208
for (KeyValue<JPH::BodyID, Overlap> &E : bodies_by_id) {
225
209
Overlap &body = E.value ;
226
210
211
+ if (unlikely (body.shape_pairs .is_empty ())) {
212
+ continue ;
213
+ }
214
+
227
215
for (const KeyValue<ShapeIDPair, ShapeIndexPair> &P : body.shape_pairs ) {
228
216
body.pending_removed .erase (P.value );
229
217
body.pending_added .push_back (P.value );
230
218
}
219
+
220
+ _events_changed ();
231
221
}
232
222
}
233
223
@@ -236,11 +226,17 @@ void JoltArea3D::_force_bodies_exited(bool p_remove) {
236
226
const JPH::BodyID &id = E.key ;
237
227
Overlap &body = E.value ;
238
228
229
+ if (unlikely (body.shape_pairs .is_empty ())) {
230
+ continue ;
231
+ }
232
+
239
233
for (const KeyValue<ShapeIDPair, ShapeIndexPair> &P : body.shape_pairs ) {
240
234
body.pending_added .erase (P.value );
241
235
body.pending_removed .push_back (P.value );
242
236
}
243
237
238
+ _events_changed ();
239
+
244
240
if (p_remove) {
245
241
body.shape_pairs .clear ();
246
242
_notify_body_exited (id);
@@ -252,22 +248,34 @@ void JoltArea3D::_force_areas_entered() {
252
248
for (KeyValue<JPH::BodyID, Overlap> &E : areas_by_id) {
253
249
Overlap &area = E.value ;
254
250
251
+ if (unlikely (area.shape_pairs .is_empty ())) {
252
+ continue ;
253
+ }
254
+
255
255
for (const KeyValue<ShapeIDPair, ShapeIndexPair> &P : area.shape_pairs ) {
256
256
area.pending_removed .erase (P.value );
257
257
area.pending_added .push_back (P.value );
258
258
}
259
+
260
+ _events_changed ();
259
261
}
260
262
}
261
263
262
264
void JoltArea3D::_force_areas_exited (bool p_remove) {
263
265
for (KeyValue<JPH::BodyID, Overlap> &E : areas_by_id) {
264
266
Overlap &area = E.value ;
265
267
268
+ if (unlikely (area.shape_pairs .is_empty ())) {
269
+ continue ;
270
+ }
271
+
266
272
for (const KeyValue<ShapeIDPair, ShapeIndexPair> &P : area.shape_pairs ) {
267
273
area.pending_added .erase (P.value );
268
274
area.pending_removed .push_back (P.value );
269
275
}
270
276
277
+ _events_changed ();
278
+
271
279
if (p_remove) {
272
280
area.shape_pairs .clear ();
273
281
}
@@ -313,6 +321,10 @@ void JoltArea3D::_space_changed() {
313
321
_update_default_gravity ();
314
322
}
315
323
324
+ void JoltArea3D::_events_changed () {
325
+ _enqueue_call_queries ();
326
+ }
327
+
316
328
void JoltArea3D::_body_monitoring_changed () {
317
329
if (has_body_monitor_callback ()) {
318
330
_force_bodies_entered ();
@@ -664,11 +676,13 @@ void JoltArea3D::body_exited(const JPH::BodyID &p_body_id, bool p_notify) {
664
676
return ;
665
677
}
666
678
667
- for (KeyValue<ShapeIDPair, ShapeIndexPair> &E : overlap->shape_pairs ) {
679
+ for (const KeyValue<ShapeIDPair, ShapeIndexPair> &E : overlap->shape_pairs ) {
668
680
overlap->pending_added .erase (E.value );
669
681
overlap->pending_removed .push_back (E.value );
670
682
}
671
683
684
+ _events_changed ();
685
+
672
686
overlap->shape_pairs .clear ();
673
687
674
688
if (p_notify) {
@@ -691,16 +705,12 @@ void JoltArea3D::area_exited(const JPH::BodyID &p_body_id) {
691
705
overlap->pending_removed .push_back (E.value );
692
706
}
693
707
708
+ _events_changed ();
709
+
694
710
overlap->shape_pairs .clear ();
695
711
}
696
712
697
713
void JoltArea3D::call_queries () {
698
714
_flush_events (bodies_by_id, body_monitor_callback);
699
715
_flush_events (areas_by_id, area_monitor_callback);
700
716
}
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