From 72494ba3bcdb7a49ecf75d01615395f29a6b16da Mon Sep 17 00:00:00 2001 From: Mikael Hermansson Date: Wed, 25 Feb 2026 17:27:13 +0100 Subject: [PATCH] Tidy some things up in `modules/jolt_physics` --- modules/jolt_physics/objects/jolt_object_3d.h | 2 -- modules/jolt_physics/objects/jolt_shaped_object_3d.cpp | 2 +- modules/jolt_physics/objects/jolt_shaped_object_3d.h | 2 ++ .../jolt_physics/spaces/jolt_contact_listener_3d.cpp | 2 +- modules/jolt_physics/spaces/jolt_contact_listener_3d.h | 2 +- modules/jolt_physics/spaces/jolt_space_3d.cpp | 10 +++++----- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/modules/jolt_physics/objects/jolt_object_3d.h b/modules/jolt_physics/objects/jolt_object_3d.h index fb338f4e14..fcbef1db9e 100644 --- a/modules/jolt_physics/objects/jolt_object_3d.h +++ b/modules/jolt_physics/objects/jolt_object_3d.h @@ -61,8 +61,6 @@ public: }; protected: - LocalVector shapes; - RID rid; ObjectID instance_id; JoltSpace3D *space = nullptr; diff --git a/modules/jolt_physics/objects/jolt_shaped_object_3d.cpp b/modules/jolt_physics/objects/jolt_shaped_object_3d.cpp index 2f96bc1032..83ac84ce90 100644 --- a/modules/jolt_physics/objects/jolt_shaped_object_3d.cpp +++ b/modules/jolt_physics/objects/jolt_shaped_object_3d.cpp @@ -286,7 +286,7 @@ JPH::ShapeRefC JoltShapedObject3D::build_shapes(bool p_optimize_compound) { if (new_shape == nullptr) { if (has_custom_center_of_mass()) { - new_shape = JPH::EmptyShapeSettings(to_jolt(get_center_of_mass_custom())).Create().Get(); + new_shape = new JPH::EmptyShape(to_jolt(get_center_of_mass_custom())); } else { new_shape = new JPH::EmptyShape(); } diff --git a/modules/jolt_physics/objects/jolt_shaped_object_3d.h b/modules/jolt_physics/objects/jolt_shaped_object_3d.h index 6cf4b7e675..bf70fab738 100644 --- a/modules/jolt_physics/objects/jolt_shaped_object_3d.h +++ b/modules/jolt_physics/objects/jolt_shaped_object_3d.h @@ -46,6 +46,8 @@ protected: SelfList shapes_changed_element; SelfList needs_optimization_element; + LocalVector shapes; + Vector3 scale = Vector3(1, 1, 1); JPH::ShapeRefC jolt_shape; diff --git a/modules/jolt_physics/spaces/jolt_contact_listener_3d.cpp b/modules/jolt_physics/spaces/jolt_contact_listener_3d.cpp index 630f5c2a78..ccbee290ac 100644 --- a/modules/jolt_physics/spaces/jolt_contact_listener_3d.cpp +++ b/modules/jolt_physics/spaces/jolt_contact_listener_3d.cpp @@ -447,7 +447,7 @@ void JoltContactListener3D::_evaluate_area_overlap(const JoltArea3D &p_area, con const MutexLock write_lock(write_mutex); if (p_area.can_monitor(p_body)) { - area_soft_body_overlaps.insert(p_shape_pair); + area_soft_body_overlaps.push_back(p_shape_pair); if (!area_exits.erase(p_shape_pair)) { area_enters.insert(p_shape_pair); } diff --git a/modules/jolt_physics/spaces/jolt_contact_listener_3d.h b/modules/jolt_physics/spaces/jolt_contact_listener_3d.h index cc9966d12a..f1b1a345e1 100644 --- a/modules/jolt_physics/spaces/jolt_contact_listener_3d.h +++ b/modules/jolt_physics/spaces/jolt_contact_listener_3d.h @@ -88,9 +88,9 @@ class JoltContactListener3D final HashMap manifolds_by_shape_pair; HashSet area_overlaps; - HashSet area_soft_body_overlaps; HashSet area_enters; HashSet area_exits; + LocalVector area_soft_body_overlaps; Mutex write_mutex; JoltSpace3D *space = nullptr; diff --git a/modules/jolt_physics/spaces/jolt_space_3d.cpp b/modules/jolt_physics/spaces/jolt_space_3d.cpp index 2ea9fb90bc..a2e6c42f6c 100644 --- a/modules/jolt_physics/spaces/jolt_space_3d.cpp +++ b/modules/jolt_physics/spaces/jolt_space_3d.cpp @@ -94,9 +94,14 @@ void JoltSpace3D::_pre_step(float p_step) { JoltObject3D *object = reinterpret_cast(jolt_body->GetUserData()); object->pre_step(p_step, *jolt_body); } + + physics_system->SetBodyActivationListener(body_activation_listener); } void JoltSpace3D::_post_step(float p_step) { + // We only want a listener during the step, as it will otherwise be called when pending bodies are flushed, which causes issues (e.g. GH-115322). + physics_system->SetBodyActivationListener(nullptr); + contact_listener->post_step(); while (shapes_changed_list.first()) { @@ -195,8 +200,6 @@ void JoltSpace3D::step(float p_step) { _pre_step(p_step); - physics_system->SetBodyActivationListener(body_activation_listener); - const JPH::EPhysicsUpdateError update_error = physics_system->Update(p_step, 1, temp_allocator, job_system); if ((update_error & JPH::EPhysicsUpdateError::ManifoldCacheFull) != JPH::EPhysicsUpdateError::None) { @@ -220,9 +223,6 @@ void JoltSpace3D::step(float p_step) { JoltProjectSettings::max_contact_constraints)); } - // We only want a listener during the step, as it will otherwise be called when pending bodies are flushed, which causes issues (e.g. GH-115322). - physics_system->SetBodyActivationListener(nullptr); - _post_step(p_step); stepping = false;