diff --git a/modules/jolt_physics/objects/jolt_object_3d.h b/modules/jolt_physics/objects/jolt_object_3d.h index fb338f4e14b9..fcbef1db9e6a 100644 --- a/modules/jolt_physics/objects/jolt_object_3d.h +++ b/modules/jolt_physics/objects/jolt_object_3d.h @@ -61,8 +61,6 @@ class JoltObject3D { }; 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 2f96bc1032b1..83ac84ce90b7 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 6cf4b7e67547..bf70fab73811 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 @@ class JoltShapedObject3D : public JoltObject3D { 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 630f5c2a7829..ccbee290ac9c 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 cc9966d12a6d..f1b1a345e144 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 2ea9fb90bc51..a2e6c42f6cfc 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;