From eff7f27c48faaee4de915db598705d7946d97a0f Mon Sep 17 00:00:00 2001 From: Jorrit Rouwe Date: Tue, 26 Sep 2023 21:19:58 +0200 Subject: Fixed performance regression in godot 4.2 in RigidBody2D/3D and PhysicalBone3D After change https://github.com/godotengine/godot/commit/c11825686589696f4c03948c11068a30c6c91796 the body state is synched 2x, but this is only needed if _integrate_forces is overridden. Adding this extra if increases the FPS by 2.5% in a heavy physics scene, see: https://github.com/godot-jolt/godot-jolt/discussions/611 --- scene/3d/physics_body_3d.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'scene/3d/physics_body_3d.cpp') diff --git a/scene/3d/physics_body_3d.cpp b/scene/3d/physics_body_3d.cpp index 66895afb27..0bc04755e4 100644 --- a/scene/3d/physics_body_3d.cpp +++ b/scene/3d/physics_body_3d.cpp @@ -502,9 +502,12 @@ void RigidBody3D::_body_state_changed(PhysicsDirectBodyState3D *p_state) { lock_callback(); set_ignore_transform_notification(true); - _sync_body_state(p_state); - GDVIRTUAL_CALL(_integrate_forces, p_state); + if (GDVIRTUAL_IS_OVERRIDDEN(_integrate_forces)) { + _sync_body_state(p_state); + + GDVIRTUAL_CALL(_integrate_forces, p_state); + } _sync_body_state(p_state); set_ignore_transform_notification(false); @@ -2935,9 +2938,12 @@ void PhysicalBone3D::_body_state_changed(PhysicsDirectBodyState3D *p_state) { } set_ignore_transform_notification(true); - _sync_body_state(p_state); - GDVIRTUAL_CALL(_integrate_forces, p_state); + if (GDVIRTUAL_IS_OVERRIDDEN(_integrate_forces)) { + _sync_body_state(p_state); + + GDVIRTUAL_CALL(_integrate_forces, p_state); + } _sync_body_state(p_state); set_ignore_transform_notification(false); -- cgit v1.2.3