Quellcode durchsuchen

Fix spamming audio preview and cleanup process in AnimationPlayer/Tree

Silc Renew vor 2 Jahren
Ursprung
Commit
4e56c2b0b0
2 geänderte Dateien mit 22 neuen und 17 gelöschten Zeilen
  1. 13 9
      scene/animation/animation_player.cpp
  2. 9 8
      scene/animation/animation_tree.cpp

+ 13 - 9
scene/animation/animation_player.cpp

@@ -473,7 +473,9 @@ void AnimationPlayer::_animation_process_animation(AnimationData *p_anim, double
 	ERR_FAIL_COND(p_anim->node_cache.size() != p_anim->animation->get_track_count());
 
 	Animation *a = p_anim->animation.operator->();
+#ifdef TOOLS_ENABLED
 	bool can_call = is_inside_tree() && !Engine::get_singleton()->is_editor_hint();
+#endif // TOOLS_ENABLED
 	bool backward = signbit(p_delta);
 
 	for (int i = 0; i < a->get_track_count(); i++) {
@@ -745,11 +747,13 @@ void AnimationPlayer::_animation_process_animation(AnimationData *p_anim, double
 
 			} break;
 			case Animation::TYPE_METHOD: {
-				if (!nc->node || is_stopping) {
+#ifdef TOOLS_ENABLED
+				if (!can_call) {
 					continue;
 				}
-				if (!p_is_current) {
-					break;
+#endif // TOOLS_ENABLED
+				if (!p_is_current || !nc->node || is_stopping) {
+					continue;
 				}
 
 				List<int> indices;
@@ -772,16 +776,12 @@ void AnimationPlayer::_animation_process_animation(AnimationData *p_anim, double
 				for (int &E : indices) {
 					StringName method = a->method_track_get_name(i, E);
 					Vector<Variant> params = a->method_track_get_params(i, E);
-
 #ifdef DEBUG_ENABLED
 					if (!nc->node->has_method(method)) {
 						ERR_PRINT("Invalid method call '" + method + "'. '" + a->get_name() + "' at node '" + get_path() + "'.");
 					}
 #endif
-
-					if (can_call) {
-						_call_object(nc->node, method, params, method_call_mode == ANIMATION_METHOD_CALL_DEFERRED);
-					}
+					_call_object(nc->node, method, params, method_call_mode == ANIMATION_METHOD_CALL_DEFERRED);
 				}
 
 			} break;
@@ -813,7 +813,11 @@ void AnimationPlayer::_animation_process_animation(AnimationData *p_anim, double
 				}
 
 				if (p_seeked) {
-					//find whatever should be playing
+#ifdef TOOLS_ENABLED
+					if (!can_call) {
+						continue; // To avoid spamming the preview in editor.
+					}
+#endif // TOOLS_ENABLED
 					int idx = a->track_find_key(i, p_time);
 					if (idx < 0) {
 						continue;

+ 9 - 8
scene/animation/animation_tree.cpp

@@ -1015,8 +1015,9 @@ void AnimationTree::_process_graph(double p_delta) {
 
 	// Apply value/transform/blend/bezier blends to track caches and execute method/audio/animation tracks.
 	{
+#ifdef TOOLS_ENABLED
 		bool can_call = is_inside_tree() && !Engine::get_singleton()->is_editor_hint();
-
+#endif // TOOLS_ENABLED
 		for (const AnimationNode::AnimationState &as : state.animation_states) {
 			Ref<Animation> a = as.animation;
 			double time = as.time;
@@ -1408,6 +1409,11 @@ void AnimationTree::_process_graph(double p_delta) {
 
 					} break;
 					case Animation::TYPE_METHOD: {
+#ifdef TOOLS_ENABLED
+						if (!can_call) {
+							return;
+						}
+#endif // TOOLS_ENABLED
 						TrackCacheMethod *t = static_cast<TrackCacheMethod *>(track);
 
 						if (seeked) {
@@ -1417,18 +1423,14 @@ void AnimationTree::_process_graph(double p_delta) {
 							}
 							StringName method = a->method_track_get_name(i, idx);
 							Vector<Variant> params = a->method_track_get_params(i, idx);
-							if (can_call) {
-								_call_object(t->object, method, params, false);
-							}
+							_call_object(t->object, method, params, false);
 						} else {
 							List<int> indices;
 							a->track_get_key_indices_in_range(i, time, delta, &indices, looped_flag);
 							for (int &F : indices) {
 								StringName method = a->method_track_get_name(i, F);
 								Vector<Variant> params = a->method_track_get_params(i, F);
-								if (can_call) {
-									_call_object(t->object, method, params, true);
-								}
+								_call_object(t->object, method, params, true);
 							}
 						}
 					} break;
@@ -1444,7 +1446,6 @@ void AnimationTree::_process_graph(double p_delta) {
 						TrackCacheAudio *t = static_cast<TrackCacheAudio *>(track);
 
 						if (seeked) {
-							//find whatever should be playing
 							int idx = a->track_find_key(i, time, is_external_seeking ? Animation::FIND_MODE_NEAREST : Animation::FIND_MODE_EXACT);
 							if (idx < 0) {
 								continue;