Skip to content

Commit

Permalink
Added a Delay element to Tween class
Browse files Browse the repository at this point in the history
It makes it possible to create a delay at the very beginning of a
Sequence
  • Loading branch information
eligt committed Aug 13, 2018
1 parent 485f9e9 commit 079164f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 9 deletions.
10 changes: 5 additions & 5 deletions core/class_db.h
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ class ClassDB {
MethodBind *bind = create_method_bind(p_method);
const Variant *ptr[7] = { &p_def1, &p_def2, &p_def3, &p_def4, &p_def5, &p_def6, &p_def7 };

return bind_methodfi(METHOD_FLAGS_DEFAULT, bind, p_method_name, ptr, 12);
return bind_methodfi(METHOD_FLAGS_DEFAULT, bind, p_method_name, ptr, 7);
}

template <class N, class M>
Expand All @@ -295,7 +295,7 @@ class ClassDB {
MethodBind *bind = create_method_bind(p_method);
const Variant *ptr[8] = { &p_def1, &p_def2, &p_def3, &p_def4, &p_def5, &p_def6, &p_def7, &p_def8 };

return bind_methodfi(METHOD_FLAGS_DEFAULT, bind, p_method_name, ptr, 12);
return bind_methodfi(METHOD_FLAGS_DEFAULT, bind, p_method_name, ptr, 8);
}

template <class N, class M>
Expand All @@ -304,7 +304,7 @@ class ClassDB {
MethodBind *bind = create_method_bind(p_method);
const Variant *ptr[9] = { &p_def1, &p_def2, &p_def3, &p_def4, &p_def5, &p_def6, &p_def7, &p_def8, &p_def9 };

return bind_methodfi(METHOD_FLAGS_DEFAULT, bind, p_method_name, ptr, 12);
return bind_methodfi(METHOD_FLAGS_DEFAULT, bind, p_method_name, ptr, 9);
}

template <class N, class M>
Expand All @@ -313,7 +313,7 @@ class ClassDB {
MethodBind *bind = create_method_bind(p_method);
const Variant *ptr[10] = { &p_def1, &p_def2, &p_def3, &p_def4, &p_def5, &p_def6, &p_def7, &p_def8, &p_def9, &p_def10 };

return bind_methodfi(METHOD_FLAGS_DEFAULT, bind, p_method_name, ptr, 12);
return bind_methodfi(METHOD_FLAGS_DEFAULT, bind, p_method_name, ptr, 10);
}

template <class N, class M>
Expand All @@ -322,7 +322,7 @@ class ClassDB {
MethodBind *bind = create_method_bind(p_method);
const Variant *ptr[11] = { &p_def1, &p_def2, &p_def3, &p_def4, &p_def5, &p_def6, &p_def7, &p_def8, &p_def9, &p_def10, &p_def11 };

return bind_methodfi(METHOD_FLAGS_DEFAULT, bind, p_method_name, ptr, 12);
return bind_methodfi(METHOD_FLAGS_DEFAULT, bind, p_method_name, ptr, 11);
}

template <class N, class M>
Expand Down
31 changes: 28 additions & 3 deletions scene/animation/tween.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ void Tween::_bind_methods() {
ClassDB::bind_method(D_METHOD("targeting_method", "object", "method", "initial", "initial_method", "final_val", "duration", "trans_type", "ease_type", "delay"), &Tween::targeting_method, DEFVAL(0));
ClassDB::bind_method(D_METHOD("create_sequence", "h0", "h1", "h2", "h3", "h4", "h5", "h6", "h7", "h8", "h9", "h10", "h11", "h12"), &Tween::create_sequence, DEFVAL(0), DEFVAL(0), DEFVAL(0), DEFVAL(0), DEFVAL(0), DEFVAL(0), DEFVAL(0), DEFVAL(0), DEFVAL(0), DEFVAL(0), DEFVAL(0), DEFVAL(0));
ClassDB::bind_method(D_METHOD("create_spawner", "h0", "h1", "h2", "h3", "h4", "h5", "h6", "h7", "h8", "h9", "h10", "h11", "h12"), &Tween::create_spawner, DEFVAL(0), DEFVAL(0), DEFVAL(0), DEFVAL(0), DEFVAL(0), DEFVAL(0), DEFVAL(0), DEFVAL(0), DEFVAL(0), DEFVAL(0), DEFVAL(0), DEFVAL(0));
ClassDB::bind_method(D_METHOD("create_delay", "delay"), &Tween::create_delay);

ADD_SIGNAL(MethodInfo("tween_started", PropertyInfo(Variant::OBJECT, "object"), PropertyInfo(Variant::NODE_PATH, "key")));
ADD_SIGNAL(MethodInfo("tween_step", PropertyInfo(Variant::OBJECT, "object"), PropertyInfo(Variant::NODE_PATH, "key"), PropertyInfo(Variant::REAL, "elapsed"), PropertyInfo(Variant::OBJECT, "value")));
Expand Down Expand Up @@ -513,7 +514,7 @@ Variant Tween::_run_equation(InterpolateData &p_data) {
}

bool Tween::_apply_tween_value(InterpolateData &p_data, Variant &value) {
if (p_data.type == SEQUENCE || p_data.type == SPAWNER)
if (p_data.type == SEQUENCE || p_data.type == SPAWNER || p_data.type == DELAY)
return true;

Object *object = ObjectDB::get_instance(p_data.id);
Expand Down Expand Up @@ -604,7 +605,7 @@ void Tween::_tween_process(float p_delta) {
continue;

Object *object = ObjectDB::get_instance(data.id);
if (data.type != SEQUENCE && data.type != SPAWNER && object == NULL)
if (data.type != SEQUENCE && data.type != SPAWNER && data.type != DELAY && object == NULL)
continue;

bool prev_delaying = data.elapsed <= data.delay;
Expand Down Expand Up @@ -669,7 +670,7 @@ void Tween::_tween_process(float p_delta) {
emit_signal("tween_completed", object, NodePath(Vector<StringName>(), data.key, false));
// not repeat mode, remove completed action
if (!repeat) {
if (data.type != SEQUENCE && data.type != SPAWNER)
if (data.type != SEQUENCE && data.type != SPAWNER && data.type != DELAY)
call_deferred("_remove", object, NodePath(Vector<StringName>(), data.key, false), true);
else
call_deferred("remove", data.handle);
Expand Down Expand Up @@ -1363,6 +1364,30 @@ Tween::HANDLE Tween::create_spawner(Tween::HANDLE h0, Tween::HANDLE h1, Tween::H
return data.handle;
}

Tween::HANDLE Tween::create_delay(real_t p_duration) {
InterpolateData data;
data.handle = ++last_index;
data.active = true;
data.type = DELAY;
data.finish = false;
data.elapsed = 0;

data.id = 0;
data.duration = p_duration;
data.trans_type = TRANS_LINEAR;
data.ease_type = EASE_IN;
data.delay = 0;

if (pending_update) {
interpolates_queued.push_back(data);
_add_pending_command("interpolate_queued", data.handle);
} else {
interpolates.push_back(data);
}

return data.handle;
}

Tween::HANDLE Tween::follow_property(Object *p_object, NodePath p_property, Variant p_initial_val, Object *p_target, NodePath p_target_property, real_t p_duration, TransitionType p_trans_type, EaseType p_ease_type, real_t p_delay) {
p_property = p_property.get_as_property_path();
p_target_property = p_target_property.get_as_property_path();
Expand Down
5 changes: 4 additions & 1 deletion scene/animation/tween.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ class Tween : public Node {
TARGETING_METHOD,
INTER_CALLBACK,
SEQUENCE,
SPAWNER
SPAWNER,
DELAY
};

struct InterpolateData {
Expand Down Expand Up @@ -197,6 +198,8 @@ class Tween : public Node {

HANDLE create_spawner(HANDLE h0, HANDLE h1 = 0, HANDLE h2 = 0, HANDLE h3 = 0, HANDLE h4 = 0, HANDLE h5 = 0, HANDLE h6 = 0, HANDLE h7 = 0, HANDLE h8 = 0, HANDLE h9 = 0, HANDLE h10 = 0, HANDLE h11 = 0, HANDLE h12 = 0);

HANDLE create_delay(real_t p_duration);

HANDLE follow_property(Object *p_object, NodePath p_property, Variant p_initial_val, Object *p_target, NodePath p_target_property, real_t p_duration, TransitionType p_trans_type, EaseType p_ease_type, real_t p_delay = 0);

HANDLE follow_method(Object *p_object, StringName p_method, Variant p_initial_val, Object *p_target, StringName p_target_method, real_t p_duration, TransitionType p_trans_type, EaseType p_ease_type, real_t p_delay = 0);
Expand Down

0 comments on commit 079164f

Please sign in to comment.