Merge pull request #72096 from TokageItLab/spamspamspam

Fix spamming audio preview and cleanup process in `AnimationPlayer/Tree`
This commit is contained in:
Rémi Verschelde 2023-01-26 09:51:54 +01:00
commit b29cd0699a
No known key found for this signature in database
GPG Key ID: C3336907360768E1
2 changed files with 22 additions and 17 deletions

View File

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

View File

@ -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. // 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(); bool can_call = is_inside_tree() && !Engine::get_singleton()->is_editor_hint();
#endif // TOOLS_ENABLED
for (const AnimationNode::AnimationState &as : state.animation_states) { for (const AnimationNode::AnimationState &as : state.animation_states) {
Ref<Animation> a = as.animation; Ref<Animation> a = as.animation;
double time = as.time; double time = as.time;
@ -1408,6 +1409,11 @@ void AnimationTree::_process_graph(double p_delta) {
} break; } break;
case Animation::TYPE_METHOD: { case Animation::TYPE_METHOD: {
#ifdef TOOLS_ENABLED
if (!can_call) {
return;
}
#endif // TOOLS_ENABLED
TrackCacheMethod *t = static_cast<TrackCacheMethod *>(track); TrackCacheMethod *t = static_cast<TrackCacheMethod *>(track);
if (seeked) { if (seeked) {
@ -1417,18 +1423,14 @@ void AnimationTree::_process_graph(double p_delta) {
} }
StringName method = a->method_track_get_name(i, idx); StringName method = a->method_track_get_name(i, idx);
Vector<Variant> params = a->method_track_get_params(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 { } else {
List<int> indices; List<int> indices;
a->track_get_key_indices_in_range(i, time, delta, &indices, looped_flag); a->track_get_key_indices_in_range(i, time, delta, &indices, looped_flag);
for (int &F : indices) { for (int &F : indices) {
StringName method = a->method_track_get_name(i, F); StringName method = a->method_track_get_name(i, F);
Vector<Variant> params = a->method_track_get_params(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; } break;
@ -1444,7 +1446,6 @@ void AnimationTree::_process_graph(double p_delta) {
TrackCacheAudio *t = static_cast<TrackCacheAudio *>(track); TrackCacheAudio *t = static_cast<TrackCacheAudio *>(track);
if (seeked) { 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); int idx = a->track_find_key(i, time, is_external_seeking ? Animation::FIND_MODE_NEAREST : Animation::FIND_MODE_EXACT);
if (idx < 0) { if (idx < 0) {
continue; continue;