Improve RefCounted support in Tween
This commit is contained in:
parent
8a98110e3e
commit
a6e02f149f
|
@ -563,6 +563,10 @@ PropertyTweener::PropertyTweener(Object *p_target, NodePath p_property, Variant
|
|||
base_final_val = p_to;
|
||||
final_val = base_final_val;
|
||||
duration = p_duration;
|
||||
|
||||
if (p_target->is_ref_counted()) {
|
||||
ref_copy = p_target;
|
||||
}
|
||||
}
|
||||
|
||||
PropertyTweener::PropertyTweener() {
|
||||
|
@ -640,6 +644,11 @@ void CallbackTweener::_bind_methods() {
|
|||
|
||||
CallbackTweener::CallbackTweener(Callable p_callback) {
|
||||
callback = p_callback;
|
||||
|
||||
Object *callback_instance = p_callback.get_object();
|
||||
if (callback_instance && callback_instance->is_ref_counted()) {
|
||||
ref_copy = callback_instance;
|
||||
}
|
||||
}
|
||||
|
||||
CallbackTweener::CallbackTweener() {
|
||||
|
@ -728,6 +737,11 @@ MethodTweener::MethodTweener(Callable p_callback, Variant p_from, Variant p_to,
|
|||
delta_val = Animation::subtract_variant(p_to, p_from);
|
||||
final_val = p_to;
|
||||
duration = p_duration;
|
||||
|
||||
Object *callback_instance = p_callback.get_object();
|
||||
if (callback_instance && callback_instance->is_ref_counted()) {
|
||||
ref_copy = callback_instance;
|
||||
}
|
||||
}
|
||||
|
||||
MethodTweener::MethodTweener() {
|
||||
|
|
|
@ -208,6 +208,8 @@ private:
|
|||
Variant final_val;
|
||||
Variant delta_val;
|
||||
|
||||
Ref<RefCounted> ref_copy; // Makes sure that RefCounted objects are not freed too early.
|
||||
|
||||
double duration = 0;
|
||||
Tween::TransitionType trans_type = Tween::TRANS_MAX; // This is set inside set_tween();
|
||||
Tween::EaseType ease_type = Tween::EASE_MAX;
|
||||
|
@ -249,6 +251,8 @@ protected:
|
|||
private:
|
||||
Callable callback;
|
||||
double delay = 0;
|
||||
|
||||
Ref<RefCounted> ref_copy;
|
||||
};
|
||||
|
||||
class MethodTweener : public Tweener {
|
||||
|
@ -280,6 +284,8 @@ private:
|
|||
Variant delta_val;
|
||||
Variant final_val;
|
||||
Callable callback;
|
||||
|
||||
Ref<RefCounted> ref_copy;
|
||||
};
|
||||
|
||||
#endif // TWEEN_H
|
||||
|
|
Loading…
Reference in New Issue