Merge pull request #19781 from razcore-art/fix-tween

Fix and make Tween node less confusing
This commit is contained in:
Rémi Verschelde 2018-07-24 21:24:38 +02:00 committed by GitHub
commit 15c6adcd5b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 49 deletions

View File

@ -150,7 +150,7 @@ void Tween::_notification(int p_what) {
case NOTIFICATION_ENTER_TREE: {
if (!processing) {
if (!is_active()) {
//make sure that a previous process state was not saved
//only process if "processing" is set
set_physics_process_internal(false);
@ -164,7 +164,7 @@ void Tween::_notification(int p_what) {
if (tween_process_mode == TWEEN_PROCESS_PHYSICS)
break;
if (processing)
if (is_active())
_tween_process(get_process_delta_time());
} break;
case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
@ -172,7 +172,7 @@ void Tween::_notification(int p_what) {
if (tween_process_mode == TWEEN_PROCESS_IDLE)
break;
if (processing)
if (is_active())
_tween_process(get_physics_process_delta_time());
} break;
case NOTIFICATION_EXIT_TREE: {
@ -201,7 +201,6 @@ void Tween::_bind_methods() {
ClassDB::bind_method(D_METHOD("reset_all"), &Tween::reset_all);
ClassDB::bind_method(D_METHOD("stop", "object", "key"), &Tween::stop, DEFVAL(""));
ClassDB::bind_method(D_METHOD("stop_all"), &Tween::stop_all);
ClassDB::bind_method(D_METHOD("is_stopped"), &Tween::is_stopped);
ClassDB::bind_method(D_METHOD("resume", "object", "key"), &Tween::resume, DEFVAL(""));
ClassDB::bind_method(D_METHOD("resume_all"), &Tween::resume_all);
ClassDB::bind_method(D_METHOD("remove", "object", "key"), &Tween::remove, DEFVAL(""));
@ -522,8 +521,8 @@ void Tween::_tween_process(float p_delta) {
pending_update++;
// if repeat and all interpolates was finished then reset all interpolates
bool all_finished = true;
if (repeat) {
bool all_finished = true;
for (List<InterpolateData>::Element *E = interpolates.front(); E; E = E->next()) {
@ -539,9 +538,12 @@ void Tween::_tween_process(float p_delta) {
reset_all();
}
all_finished = true;
for (List<InterpolateData>::Element *E = interpolates.front(); E; E = E->next()) {
InterpolateData &data = E->get();
all_finished = all_finished && data.finish;
if (!data.active || data.finish)
continue;
@ -555,8 +557,8 @@ void Tween::_tween_process(float p_delta) {
continue;
else if (prev_delaying) {
emit_signal("tween_started", object, NodePath(Vector<StringName>(), data.key, false));
_apply_tween_value(data, data.initial_val);
emit_signal("tween_started", object, NodePath(Vector<StringName>(), data.key, false));
}
if (data.elapsed > (data.delay + data.duration)) {
@ -603,32 +605,29 @@ void Tween::_tween_process(float p_delta) {
}
} else {
Variant result = _run_equation(data);
emit_signal("tween_step", object, NodePath(Vector<StringName>(), data.key, false), data.elapsed, result);
_apply_tween_value(data, result);
emit_signal("tween_step", object, NodePath(Vector<StringName>(), data.key, false), data.elapsed, result);
}
if (data.finish) {
_apply_tween_value(data, data.final_val);
data.elapsed = 0;
emit_signal("tween_completed", object, NodePath(Vector<StringName>(), data.key, false));
// not repeat mode, remove completed action
if (!repeat)
call_deferred("_remove", object, NodePath(Vector<StringName>(), data.key, false), true);
}
} else if (!repeat)
all_finished = all_finished && data.finish;
}
pending_update--;
if (all_finished)
set_active(false);
}
void Tween::set_tween_process_mode(TweenProcessMode p_mode) {
if (tween_process_mode == p_mode)
return;
bool pr = processing;
if (pr)
_set_process(false);
tween_process_mode = p_mode;
if (pr)
_set_process(true);
}
Tween::TweenProcessMode Tween::get_tween_process_mode() const {
@ -636,32 +635,21 @@ Tween::TweenProcessMode Tween::get_tween_process_mode() const {
return tween_process_mode;
}
void Tween::_set_process(bool p_process, bool p_force) {
if (processing == p_process && !p_force)
return;
switch (tween_process_mode) {
case TWEEN_PROCESS_PHYSICS: set_physics_process_internal(p_process && active); break;
case TWEEN_PROCESS_IDLE: set_process_internal(p_process && active); break;
}
processing = p_process;
}
bool Tween::is_active() const {
return active;
return is_processing_internal() || is_physics_processing_internal();
}
void Tween::set_active(bool p_active) {
if (active == p_active)
if (is_active() == p_active)
return;
active = p_active;
_set_process(processing, true);
switch (tween_process_mode) {
case TWEEN_PROCESS_IDLE: set_process_internal(p_active); break;
case TWEEN_PROCESS_PHYSICS: set_physics_process_internal(p_active); break;
}
}
bool Tween::is_repeat() const {
@ -687,7 +675,6 @@ float Tween::get_speed_scale() const {
bool Tween::start() {
set_active(true);
_set_process(true);
return true;
}
@ -744,14 +731,9 @@ bool Tween::stop(Object *p_object, StringName p_key) {
return true;
}
bool Tween::is_stopped() const {
return tell() >= get_runtime();
}
bool Tween::stop_all() {
set_active(false);
_set_process(false);
pending_update++;
for (List<InterpolateData>::Element *E = interpolates.front(); E; E = E->next()) {
@ -766,7 +748,6 @@ bool Tween::stop_all() {
bool Tween::resume(Object *p_object, StringName p_key) {
set_active(true);
_set_process(true);
pending_update++;
for (List<InterpolateData>::Element *E = interpolates.front(); E; E = E->next()) {
@ -785,7 +766,6 @@ bool Tween::resume(Object *p_object, StringName p_key) {
bool Tween::resume_all() {
set_active(true);
_set_process(true);
pending_update++;
for (List<InterpolateData>::Element *E = interpolates.front(); E; E = E->next()) {
@ -834,7 +814,6 @@ bool Tween::remove_all() {
return true;
}
set_active(false);
_set_process(false);
interpolates.clear();
return true;
}
@ -1425,8 +1404,6 @@ Tween::Tween() {
//String autoplay;
tween_process_mode = TWEEN_PROCESS_IDLE;
processing = false;
active = false;
repeat = false;
speed_scale = 1;
pending_update = 0;

View File

@ -104,8 +104,6 @@ private:
String autoplay;
TweenProcessMode tween_process_mode;
bool processing;
bool active;
bool repeat;
float speed_scale;
mutable int pending_update;
@ -133,7 +131,6 @@ private:
bool _apply_tween_value(InterpolateData &p_data, Variant &value);
void _tween_process(float p_delta);
void _set_process(bool p_process, bool p_force = false);
void _remove(Object *p_object, StringName p_key, bool first_only);
protected:
@ -162,7 +159,6 @@ public:
bool reset_all();
bool stop(Object *p_object, StringName p_key);
bool stop_all();
bool is_stopped() const;
bool resume(Object *p_object, StringName p_key);
bool resume_all();
bool remove(Object *p_object, StringName p_key);