Improve some Tween internals

This commit is contained in:
kobewi 2023-01-11 14:08:14 +01:00
parent da9396881e
commit f64dd732b8
2 changed files with 17 additions and 10 deletions

View File

@ -60,7 +60,7 @@ void Tweener::_bind_methods() {
ADD_SIGNAL(MethodInfo("finished"));
}
void Tween::start_tweeners() {
void Tween::_start_tweeners() {
if (tweeners.is_empty()) {
dead = true;
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) {
ERR_FAIL_NULL_V(p_target, nullptr);
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() {
started = false;
running = false;
dead = false;
total_time = 0;
_stop_internal(true);
}
void Tween::pause() {
running = false;
_stop_internal(false);
}
void Tween::play() {
@ -278,7 +284,7 @@ bool Tween::step(double p_delta) {
current_step = 0;
loops_done = 0;
total_time = 0;
start_tweeners();
_start_tweeners();
started = true;
}
@ -319,7 +325,7 @@ bool Tween::step(double p_delta) {
} else {
emit_signal(SNAME("loop_finished"), loops_done);
current_step = 0;
start_tweeners();
_start_tweeners();
#ifdef DEBUG_ENABLED
if (loops <= 0 && Math::is_equal_approx(rem_delta, initial_delta)) {
if (!potential_infinite) {
@ -332,7 +338,7 @@ bool Tween::step(double p_delta) {
#endif
}
} 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);
static interpolater interpolaters[TRANS_MAX][EASE_MAX];
void start_tweeners();
void _start_tweeners();
void _stop_internal(bool p_reset);
protected:
static void _bind_methods();