Browse Source

Physics Interpolation - Reduce unnecessary `VisualServer` updates

With the new `SceneTreeFTI`, most xforms are updated to the server externally by the FTI system, so it is no longer necessary to update the server on each `NOTIFICATION_TRANSFORM_CHANGED`.
lawnjelly 5 months ago
parent
commit
65185415b2
1 changed files with 12 additions and 12 deletions
  1. 12 12
      scene/3d/visual_instance.cpp

+ 12 - 12
scene/3d/visual_instance.cpp

@@ -105,20 +105,20 @@ void VisualInstance::_notification(int p_what) {
 		case NOTIFICATION_TRANSFORM_CHANGED: {
 			if (_is_vi_visible()) {
 				if (!_is_using_identity_transform()) {
-					// Physics interpolated VIs don't need to send their transform immediately after setting,
-					// indeed it is counterproductive, because the interpolated transform will be sent
-					// to the VisualServer immediately prior to rendering.
-					if (!is_physics_interpolated_and_enabled()) {
-						VisualServer::get_singleton()->instance_set_transform(instance, get_global_transform());
-					} else {
-						// For instance when first adding to the tree, when the previous transform is
-						// unset, to prevent streaking from the origin.
-						if (_is_physics_interpolation_reset_requested() && is_inside_tree()) {
-							if (_is_vi_visible()) {
-								_notification(NOTIFICATION_RESET_PHYSICS_INTERPOLATION);
-							}
+					// Physics interpolation cases.
+					if (is_inside_tree() && get_tree()->is_physics_interpolation_enabled()) {
+						// Physics interpolated VIs don't need to send their transform immediately after setting,
+						// indeed it is counterproductive, because the interpolated transform will be sent
+						// to the VisualServer immediately prior to rendering.
+						if (is_physics_interpolated() && _is_physics_interpolation_reset_requested()) {
+							// For instance when first adding to the tree, when the previous transform is
+							// unset, to prevent streaking from the origin.
+							_notification(NOTIFICATION_RESET_PHYSICS_INTERPOLATION);
 							_set_physics_interpolation_reset_requested(false);
 						}
+					} else {
+						// Physics interpolation global off, always send.
+						VisualServer::get_singleton()->instance_set_transform(instance, get_global_transform());
 					}
 				}
 			}