diff options
author | Silc Lizard (Tokage) Renew <61938263+TokageItLab@users.noreply.github.com> | 2023-12-31 16:05:34 +0900 |
---|---|---|
committer | Silc Lizard (Tokage) Renew <61938263+TokageItLab@users.noreply.github.com> | 2024-02-18 00:15:33 +0900 |
commit | 465909054338b6e0ce9c1f62952694f114bce8d2 (patch) | |
tree | 1bc309a160dd8501e637f7597f658b6683e78207 /scene/resources/animation.cpp | |
parent | 0a89888cba71c5adb175df99011fd5dc3bdebff9 (diff) | |
download | redot-engine-465909054338b6e0ce9c1f62952694f114bce8d2.tar.gz |
Make consistent the retrieval of audio tracks
Diffstat (limited to 'scene/resources/animation.cpp')
-rw-r--r-- | scene/resources/animation.cpp | 34 |
1 files changed, 21 insertions, 13 deletions
diff --git a/scene/resources/animation.cpp b/scene/resources/animation.cpp index 796a03bd8b..079101f679 100644 --- a/scene/resources/animation.cpp +++ b/scene/resources/animation.cpp @@ -1474,7 +1474,7 @@ void Animation::track_remove_key(int p_track, int p_idx) { emit_changed(); } -int Animation::track_find_key(int p_track, double p_time, FindMode p_find_mode) const { +int Animation::track_find_key(int p_track, double p_time, FindMode p_find_mode, bool p_limit) const { ERR_FAIL_INDEX_V(p_track, tracks.size(), -1); Track *t = tracks[p_track]; @@ -1496,7 +1496,7 @@ int Animation::track_find_key(int p_track, double p_time, FindMode p_find_mode) return key_index; } - int k = _find(tt->positions, p_time); + int k = _find(tt->positions, p_time, false, p_limit); if (k < 0 || k >= tt->positions.size()) { return -1; } @@ -1523,7 +1523,7 @@ int Animation::track_find_key(int p_track, double p_time, FindMode p_find_mode) return key_index; } - int k = _find(rt->rotations, p_time); + int k = _find(rt->rotations, p_time, false, p_limit); if (k < 0 || k >= rt->rotations.size()) { return -1; } @@ -1550,7 +1550,7 @@ int Animation::track_find_key(int p_track, double p_time, FindMode p_find_mode) return key_index; } - int k = _find(st->scales, p_time); + int k = _find(st->scales, p_time, false, p_limit); if (k < 0 || k >= st->scales.size()) { return -1; } @@ -1577,7 +1577,7 @@ int Animation::track_find_key(int p_track, double p_time, FindMode p_find_mode) return key_index; } - int k = _find(bst->blend_shapes, p_time); + int k = _find(bst->blend_shapes, p_time, false, p_limit); if (k < 0 || k >= bst->blend_shapes.size()) { return -1; } @@ -1589,7 +1589,7 @@ int Animation::track_find_key(int p_track, double p_time, FindMode p_find_mode) } break; case TYPE_VALUE: { ValueTrack *vt = static_cast<ValueTrack *>(t); - int k = _find(vt->values, p_time); + int k = _find(vt->values, p_time, false, p_limit); if (k < 0 || k >= vt->values.size()) { return -1; } @@ -1601,7 +1601,7 @@ int Animation::track_find_key(int p_track, double p_time, FindMode p_find_mode) } break; case TYPE_METHOD: { MethodTrack *mt = static_cast<MethodTrack *>(t); - int k = _find(mt->methods, p_time); + int k = _find(mt->methods, p_time, false, p_limit); if (k < 0 || k >= mt->methods.size()) { return -1; } @@ -1613,7 +1613,7 @@ int Animation::track_find_key(int p_track, double p_time, FindMode p_find_mode) } break; case TYPE_BEZIER: { BezierTrack *bt = static_cast<BezierTrack *>(t); - int k = _find(bt->values, p_time); + int k = _find(bt->values, p_time, false, p_limit); if (k < 0 || k >= bt->values.size()) { return -1; } @@ -1625,7 +1625,7 @@ int Animation::track_find_key(int p_track, double p_time, FindMode p_find_mode) } break; case TYPE_AUDIO: { AudioTrack *at = static_cast<AudioTrack *>(t); - int k = _find(at->values, p_time); + int k = _find(at->values, p_time, false, p_limit); if (k < 0 || k >= at->values.size()) { return -1; } @@ -1637,7 +1637,7 @@ int Animation::track_find_key(int p_track, double p_time, FindMode p_find_mode) } break; case TYPE_ANIMATION: { AnimationTrack *at = static_cast<AnimationTrack *>(t); - int k = _find(at->values, p_time); + int k = _find(at->values, p_time, false, p_limit); if (k < 0 || k >= at->values.size()) { return -1; } @@ -2332,7 +2332,7 @@ void Animation::track_set_key_transition(int p_track, int p_key_idx, real_t p_tr } template <class K> -int Animation::_find(const Vector<K> &p_keys, double p_time, bool p_backward) const { +int Animation::_find(const Vector<K> &p_keys, double p_time, bool p_backward, bool p_limit) const { int len = p_keys.size(); if (len == 0) { return -2; @@ -2344,7 +2344,7 @@ int Animation::_find(const Vector<K> &p_keys, double p_time, bool p_backward) co #ifdef DEBUG_ENABLED if (low > high) { - ERR_PRINT("low > high, this may be a bug"); + ERR_PRINT("low > high, this may be a bug."); } #endif @@ -2372,6 +2372,14 @@ int Animation::_find(const Vector<K> &p_keys, double p_time, bool p_backward) co } } + if (p_limit) { + double diff = length - keys[middle].time; + if ((signbit(keys[middle].time) && !Math::is_zero_approx(keys[middle].time)) || (signbit(diff) && !Math::is_zero_approx(diff))) { + ERR_PRINT_ONCE_ED("Found the key outside the animation range. Consider using the clean-up option in AnimationTrackEditor to fix it."); + return -1; + } + } + return middle; } @@ -3804,7 +3812,7 @@ void Animation::_bind_methods() { ClassDB::bind_method(D_METHOD("track_get_key_count", "track_idx"), &Animation::track_get_key_count); ClassDB::bind_method(D_METHOD("track_get_key_value", "track_idx", "key_idx"), &Animation::track_get_key_value); ClassDB::bind_method(D_METHOD("track_get_key_time", "track_idx", "key_idx"), &Animation::track_get_key_time); - ClassDB::bind_method(D_METHOD("track_find_key", "track_idx", "time", "find_mode"), &Animation::track_find_key, DEFVAL(FIND_MODE_NEAREST)); + ClassDB::bind_method(D_METHOD("track_find_key", "track_idx", "time", "find_mode", "limit"), &Animation::track_find_key, DEFVAL(FIND_MODE_NEAREST), DEFVAL(false)); ClassDB::bind_method(D_METHOD("track_set_interpolation_type", "track_idx", "interpolation"), &Animation::track_set_interpolation_type); ClassDB::bind_method(D_METHOD("track_get_interpolation_type", "track_idx"), &Animation::track_get_interpolation_type); |