summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJorrit Rouwe <jrouwe@gmail.com>2023-09-26 21:19:58 +0200
committerJorrit Rouwe <jrouwe@gmail.com>2023-09-26 21:19:58 +0200
commiteff7f27c48faaee4de915db598705d7946d97a0f (patch)
treea5d3f0254e7e3d5b4cab3f6d83b0999b3fb157b5
parentb905959f4382020b424fa093c380e163a7a7f404 (diff)
downloadredot-engine-eff7f27c48faaee4de915db598705d7946d97a0f.tar.gz
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
-rw-r--r--scene/2d/physics_body_2d.cpp7
-rw-r--r--scene/3d/physics_body_3d.cpp14
2 files changed, 15 insertions, 6 deletions
diff --git a/scene/2d/physics_body_2d.cpp b/scene/2d/physics_body_2d.cpp
index b6a36b2391..32b46987fc 100644
--- a/scene/2d/physics_body_2d.cpp
+++ b/scene/2d/physics_body_2d.cpp
@@ -447,9 +447,12 @@ void RigidBody2D::_body_state_changed(PhysicsDirectBodyState2D *p_state) {
lock_callback();
set_block_transform_notify(true); // don't want notify (would feedback loop)
- _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_block_transform_notify(false); // want it back
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);