Merge pull request #71218 from KoBeWi/unlimited_bikeshedding_lets_go

Split pause() from AnimationPlayer's stop()
This commit is contained in:
Rémi Verschelde 2023-01-12 14:30:46 +01:00
commit a8a9892ad6
No known key found for this signature in database
GPG Key ID: C3336907360768E1
6 changed files with 53 additions and 29 deletions

View File

@ -137,6 +137,13 @@
Returns [code]true[/code] if playing an animation. Returns [code]true[/code] if playing an animation.
</description> </description>
</method> </method>
<method name="pause">
<return type="void" />
<description>
Pauses the currently playing animation. The [member current_animation_position] will be kept and calling [method play] or [method play_backwards] without arguments or with the same animation name as [member assigned_animation] will resume the animation.
See also [method stop].
</description>
</method>
<method name="play"> <method name="play">
<return type="void" /> <return type="void" />
<param index="0" name="name" type="StringName" default="&quot;&quot;" /> <param index="0" name="name" type="StringName" default="&quot;&quot;" />
@ -201,10 +208,9 @@
</method> </method>
<method name="stop"> <method name="stop">
<return type="void" /> <return type="void" />
<param index="0" name="reset" type="bool" default="true" />
<description> <description>
Stops or pauses the currently playing animation. If [param reset] is [code]true[/code], the animation position is reset to [code]0[/code] and the playback speed is reset to [code]1.0[/code]. Stops the currently playing animation. The animation position is reset to [code]0[/code] and the playback speed is reset to [code]1.0[/code].
If [param reset] is [code]false[/code], the [member current_animation_position] will be kept and calling [method play] or [method play_backwards] without arguments or with the same animation name as [member assigned_animation] will resume the animation. See also [method pause].
</description> </description>
</method> </method>
</methods> </methods>

View File

@ -267,7 +267,7 @@ void AnimationPlayerEditor::_stop_pressed() {
return; return;
} }
player->stop(false); player->pause();
play->set_pressed(false); play->set_pressed(false);
stop->set_pressed(true); stop->set_pressed(true);
} }
@ -1155,7 +1155,7 @@ void AnimationPlayerEditor::_seek_value_changed(float p_value, bool p_set, bool
player->seek_delta(pos, pos - cpos); player->seek_delta(pos, pos - cpos);
} else { } else {
player->stop(true); player->stop();
player->seek(pos, true); player->seek(pos, true);
} }
} }

View File

@ -1731,18 +1731,12 @@ String AnimationPlayer::get_assigned_animation() const {
return playback.assigned; return playback.assigned;
} }
void AnimationPlayer::stop(bool p_reset) { void AnimationPlayer::pause() {
_stop_playing_caches(); _stop_internal(false);
Playback &c = playback; }
c.blend.clear();
if (p_reset) { void AnimationPlayer::stop() {
c.current.from = nullptr; _stop_internal(true);
c.current.speed_scale = 1;
c.current.pos = 0;
}
_set_process(false);
queued.clear();
playing = false;
} }
void AnimationPlayer::set_speed_scale(float p_speed) { void AnimationPlayer::set_speed_scale(float p_speed) {
@ -1957,6 +1951,20 @@ void AnimationPlayer::_set_process(bool p_process, bool p_force) {
processing = p_process; processing = p_process;
} }
void AnimationPlayer::_stop_internal(bool p_reset) {
_stop_playing_caches();
Playback &c = playback;
c.blend.clear();
if (p_reset) {
c.current.from = nullptr;
c.current.speed_scale = 1;
c.current.pos = 0;
}
_set_process(false);
queued.clear();
playing = false;
}
void AnimationPlayer::animation_set_next(const StringName &p_animation, const StringName &p_next) { void AnimationPlayer::animation_set_next(const StringName &p_animation, const StringName &p_next) {
ERR_FAIL_COND_MSG(!animation_set.has(p_animation), vformat("Animation not found: %s.", p_animation)); ERR_FAIL_COND_MSG(!animation_set.has(p_animation), vformat("Animation not found: %s.", p_animation));
animation_set[p_animation].next = p_next; animation_set[p_animation].next = p_next;
@ -2119,7 +2127,8 @@ void AnimationPlayer::_bind_methods() {
ClassDB::bind_method(D_METHOD("play", "name", "custom_blend", "custom_speed", "from_end"), &AnimationPlayer::play, DEFVAL(""), DEFVAL(-1), DEFVAL(1.0), DEFVAL(false)); ClassDB::bind_method(D_METHOD("play", "name", "custom_blend", "custom_speed", "from_end"), &AnimationPlayer::play, DEFVAL(""), DEFVAL(-1), DEFVAL(1.0), DEFVAL(false));
ClassDB::bind_method(D_METHOD("play_backwards", "name", "custom_blend"), &AnimationPlayer::play_backwards, DEFVAL(""), DEFVAL(-1)); ClassDB::bind_method(D_METHOD("play_backwards", "name", "custom_blend"), &AnimationPlayer::play_backwards, DEFVAL(""), DEFVAL(-1));
ClassDB::bind_method(D_METHOD("stop", "reset"), &AnimationPlayer::stop, DEFVAL(true)); ClassDB::bind_method(D_METHOD("pause"), &AnimationPlayer::pause);
ClassDB::bind_method(D_METHOD("stop"), &AnimationPlayer::stop);
ClassDB::bind_method(D_METHOD("is_playing"), &AnimationPlayer::is_playing); ClassDB::bind_method(D_METHOD("is_playing"), &AnimationPlayer::is_playing);
ClassDB::bind_method(D_METHOD("set_current_animation", "anim"), &AnimationPlayer::set_current_animation); ClassDB::bind_method(D_METHOD("set_current_animation", "anim"), &AnimationPlayer::set_current_animation);

View File

@ -294,6 +294,7 @@ private:
void _animation_changed(const StringName &p_name); void _animation_changed(const StringName &p_name);
void _set_process(bool p_process, bool p_force = false); void _set_process(bool p_process, bool p_force = false);
void _stop_internal(bool p_reset);
bool playing = false; bool playing = false;
@ -346,7 +347,8 @@ public:
void queue(const StringName &p_name); void queue(const StringName &p_name);
Vector<String> get_queue(); Vector<String> get_queue();
void clear_queue(); void clear_queue();
void stop(bool p_reset = true); void pause();
void stop();
bool is_playing() const; bool is_playing() const;
String get_current_animation() const; String get_current_animation() const;
void set_current_animation(const String &p_anim); void set_current_animation(const String &p_anim);

View File

@ -60,7 +60,7 @@ void Tweener::_bind_methods() {
ADD_SIGNAL(MethodInfo("finished")); ADD_SIGNAL(MethodInfo("finished"));
} }
void Tween::start_tweeners() { void Tween::_start_tweeners() {
if (tweeners.is_empty()) { if (tweeners.is_empty()) {
dead = true; dead = true;
ERR_FAIL_MSG("Tween without commands, aborting."); ERR_FAIL_MSG("Tween without commands, aborting.");
@ -71,6 +71,15 @@ void Tween::start_tweeners() {
} }
} }
void Tween::_stop_internal(bool p_reset) {
running = false;
if (p_reset) {
started = false;
dead = false;
total_time = 0;
}
}
Ref<PropertyTweener> Tween::tween_property(Object *p_target, NodePath p_property, Variant p_to, double p_duration) { Ref<PropertyTweener> Tween::tween_property(Object *p_target, NodePath p_property, Variant p_to, double p_duration) {
ERR_FAIL_NULL_V(p_target, nullptr); ERR_FAIL_NULL_V(p_target, nullptr);
ERR_FAIL_COND_V_MSG(!valid, nullptr, "Tween invalid. Either finished or created outside scene tree."); ERR_FAIL_COND_V_MSG(!valid, nullptr, "Tween invalid. Either finished or created outside scene tree.");
@ -135,14 +144,11 @@ void Tween::append(Ref<Tweener> p_tweener) {
} }
void Tween::stop() { void Tween::stop() {
started = false; _stop_internal(true);
running = false;
dead = false;
total_time = 0;
} }
void Tween::pause() { void Tween::pause() {
running = false; _stop_internal(false);
} }
void Tween::play() { void Tween::play() {
@ -278,7 +284,7 @@ bool Tween::step(double p_delta) {
current_step = 0; current_step = 0;
loops_done = 0; loops_done = 0;
total_time = 0; total_time = 0;
start_tweeners(); _start_tweeners();
started = true; started = true;
} }
@ -319,7 +325,7 @@ bool Tween::step(double p_delta) {
} else { } else {
emit_signal(SNAME("loop_finished"), loops_done); emit_signal(SNAME("loop_finished"), loops_done);
current_step = 0; current_step = 0;
start_tweeners(); _start_tweeners();
#ifdef DEBUG_ENABLED #ifdef DEBUG_ENABLED
if (loops <= 0 && Math::is_equal_approx(rem_delta, initial_delta)) { if (loops <= 0 && Math::is_equal_approx(rem_delta, initial_delta)) {
if (!potential_infinite) { if (!potential_infinite) {
@ -332,7 +338,7 @@ bool Tween::step(double p_delta) {
#endif #endif
} }
} else { } else {
start_tweeners(); _start_tweeners();
} }
} }
} }

View File

@ -123,7 +123,8 @@ private:
typedef real_t (*interpolater)(real_t t, real_t b, real_t c, real_t d); typedef real_t (*interpolater)(real_t t, real_t b, real_t c, real_t d);
static interpolater interpolaters[TRANS_MAX][EASE_MAX]; static interpolater interpolaters[TRANS_MAX][EASE_MAX];
void start_tweeners(); void _start_tweeners();
void _stop_internal(bool p_reset);
protected: protected:
static void _bind_methods(); static void _bind_methods();