Skip to content

Commit dcde70f

Browse files
committed
Merge pull request godotengine#106693 from mihe/jolt/area-cleanup
Remove force enter/exit logic from `JoltArea3D`
2 parents a115af4 + 3d98aaf commit dcde70f

File tree

2 files changed

+6
-101
lines changed

2 files changed

+6
-101
lines changed

modules/jolt_physics/objects/jolt_area_3d.cpp

Lines changed: 5 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -197,82 +197,13 @@ void JoltArea3D::_notify_body_exited(const JPH::BodyID &p_body_id) {
197197
}
198198
}
199199

200-
void JoltArea3D::_force_bodies_entered() {
200+
void JoltArea3D::_remove_all_overlaps() {
201201
for (KeyValue<JPH::BodyID, Overlap> &E : bodies_by_id) {
202-
Overlap &body = E.value;
203-
204-
if (unlikely(body.shape_pairs.is_empty())) {
205-
continue;
206-
}
207-
208-
for (const KeyValue<ShapeIDPair, ShapeIndexPair> &P : body.shape_pairs) {
209-
body.pending_removed.erase(P.value);
210-
body.pending_added.push_back(P.value);
211-
}
212-
213-
_events_changed();
214-
}
215-
}
216-
217-
void JoltArea3D::_force_bodies_exited(bool p_remove) {
218-
for (KeyValue<JPH::BodyID, Overlap> &E : bodies_by_id) {
219-
const JPH::BodyID &id = E.key;
220-
Overlap &body = E.value;
221-
222-
if (unlikely(body.shape_pairs.is_empty())) {
223-
continue;
224-
}
225-
226-
for (const KeyValue<ShapeIDPair, ShapeIndexPair> &P : body.shape_pairs) {
227-
body.pending_added.erase(P.value);
228-
body.pending_removed.push_back(P.value);
229-
}
230-
231-
_events_changed();
232-
233-
if (p_remove) {
234-
body.shape_pairs.clear();
235-
_notify_body_exited(id);
236-
}
237-
}
238-
}
239-
240-
void JoltArea3D::_force_areas_entered() {
241-
for (KeyValue<JPH::BodyID, Overlap> &E : areas_by_id) {
242-
Overlap &area = E.value;
243-
244-
if (unlikely(area.shape_pairs.is_empty())) {
245-
continue;
246-
}
247-
248-
for (const KeyValue<ShapeIDPair, ShapeIndexPair> &P : area.shape_pairs) {
249-
area.pending_removed.erase(P.value);
250-
area.pending_added.push_back(P.value);
251-
}
252-
253-
_events_changed();
202+
_notify_body_exited(E.key);
254203
}
255-
}
256-
257-
void JoltArea3D::_force_areas_exited(bool p_remove) {
258-
for (KeyValue<JPH::BodyID, Overlap> &E : areas_by_id) {
259-
Overlap &area = E.value;
260-
261-
if (unlikely(area.shape_pairs.is_empty())) {
262-
continue;
263-
}
264204

265-
for (const KeyValue<ShapeIDPair, ShapeIndexPair> &P : area.shape_pairs) {
266-
area.pending_added.erase(P.value);
267-
area.pending_removed.push_back(P.value);
268-
}
269-
270-
_events_changed();
271-
272-
if (p_remove) {
273-
area.shape_pairs.clear();
274-
}
275-
}
205+
bodies_by_id.clear();
206+
areas_by_id.clear();
276207
}
277208

278209
void JoltArea3D::_update_sleeping() {
@@ -304,15 +235,7 @@ void JoltArea3D::_update_default_gravity() {
304235
void JoltArea3D::_space_changing() {
305236
JoltShapedObject3D::_space_changing();
306237

307-
if (space != nullptr) {
308-
// Ideally we would rely on our contact listener to report all the exits when we move
309-
// between (or out of) spaces, but because our Jolt body is going to be destroyed when we
310-
// leave this space the contact listener won't be able to retrieve the corresponding area
311-
// and as such cannot report any exits, so we're forced to do it manually instead.
312-
_force_bodies_exited(true);
313-
_force_areas_exited(true);
314-
}
315-
238+
_remove_all_overlaps();
316239
_dequeue_call_queries();
317240
}
318241

@@ -328,22 +251,10 @@ void JoltArea3D::_events_changed() {
328251
}
329252

330253
void JoltArea3D::_body_monitoring_changed() {
331-
if (is_monitoring_bodies()) {
332-
_force_bodies_entered();
333-
} else {
334-
_force_bodies_exited(false);
335-
}
336-
337254
_update_sleeping();
338255
}
339256

340257
void JoltArea3D::_area_monitoring_changed() {
341-
if (is_monitoring_areas()) {
342-
_force_areas_entered();
343-
} else {
344-
_force_areas_exited(false);
345-
}
346-
347258
_update_sleeping();
348259
}
349260

@@ -637,7 +548,6 @@ void JoltArea3D::body_shape_entered(const JPH::BodyID &p_body_id, const JPH::Sub
637548

638549
bool JoltArea3D::body_shape_exited(const JPH::BodyID &p_body_id, const JPH::SubShapeID &p_other_shape_id, const JPH::SubShapeID &p_self_shape_id) {
639550
Overlap *overlap = bodies_by_id.getptr(p_body_id);
640-
641551
if (overlap == nullptr) {
642552
return false;
643553
}
@@ -659,7 +569,6 @@ void JoltArea3D::area_shape_entered(const JPH::BodyID &p_body_id, const JPH::Sub
659569

660570
bool JoltArea3D::area_shape_exited(const JPH::BodyID &p_body_id, const JPH::SubShapeID &p_other_shape_id, const JPH::SubShapeID &p_self_shape_id) {
661571
Overlap *overlap = areas_by_id.getptr(p_body_id);
662-
663572
if (overlap == nullptr) {
664573
return false;
665574
}

modules/jolt_physics/objects/jolt_area_3d.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,7 @@ class JoltArea3D final : public JoltShapedObject3D {
133133
void _notify_body_entered(const JPH::BodyID &p_body_id);
134134
void _notify_body_exited(const JPH::BodyID &p_body_id);
135135

136-
void _force_bodies_entered();
137-
void _force_bodies_exited(bool p_remove);
138-
139-
void _force_areas_entered();
140-
void _force_areas_exited(bool p_remove);
136+
void _remove_all_overlaps();
141137

142138
void _update_sleeping();
143139
void _update_group_filter();

0 commit comments

Comments
 (0)