2014-08-20 04:01:41 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* tween.h */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 12:16:55 +00:00
|
|
|
/* https://godotengine.org */
|
2014-08-20 04:01:41 +00:00
|
|
|
/*************************************************************************/
|
2021-01-01 19:13:46 +00:00
|
|
|
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
|
2014-08-20 04:01:41 +00:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
2018-01-04 23:50:27 +00:00
|
|
|
|
2014-08-20 04:01:41 +00:00
|
|
|
#ifndef TWEEN_H
|
|
|
|
#define TWEEN_H
|
|
|
|
|
|
|
|
#include "scene/main/node.h"
|
|
|
|
|
|
|
|
class Tween : public Node {
|
2017-03-05 15:44:50 +00:00
|
|
|
GDCLASS(Tween, Node);
|
2014-08-20 04:01:41 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
enum TweenProcessMode {
|
2017-09-30 14:19:07 +00:00
|
|
|
TWEEN_PROCESS_PHYSICS,
|
2014-08-20 04:01:41 +00:00
|
|
|
TWEEN_PROCESS_IDLE,
|
|
|
|
};
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
enum TransitionType {
|
|
|
|
TRANS_LINEAR,
|
|
|
|
TRANS_SINE,
|
|
|
|
TRANS_QUINT,
|
|
|
|
TRANS_QUART,
|
|
|
|
TRANS_QUAD,
|
|
|
|
TRANS_EXPO,
|
|
|
|
TRANS_ELASTIC,
|
|
|
|
TRANS_CUBIC,
|
|
|
|
TRANS_CIRC,
|
|
|
|
TRANS_BOUNCE,
|
|
|
|
TRANS_BACK,
|
2014-12-19 09:13:20 +00:00
|
|
|
|
|
|
|
TRANS_COUNT,
|
2017-03-05 15:44:50 +00:00
|
|
|
};
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
enum EaseType {
|
|
|
|
EASE_IN,
|
|
|
|
EASE_OUT,
|
|
|
|
EASE_IN_OUT,
|
2014-12-19 09:13:20 +00:00
|
|
|
EASE_OUT_IN,
|
|
|
|
|
|
|
|
EASE_COUNT,
|
2017-03-05 15:44:50 +00:00
|
|
|
};
|
2014-08-20 04:01:41 +00:00
|
|
|
|
|
|
|
private:
|
2014-08-22 03:24:53 +00:00
|
|
|
enum InterpolateType {
|
|
|
|
INTER_PROPERTY,
|
|
|
|
INTER_METHOD,
|
2014-08-25 05:36:56 +00:00
|
|
|
FOLLOW_PROPERTY,
|
|
|
|
FOLLOW_METHOD,
|
|
|
|
TARGETING_PROPERTY,
|
|
|
|
TARGETING_METHOD,
|
2014-08-22 03:24:53 +00:00
|
|
|
INTER_CALLBACK,
|
|
|
|
};
|
2014-08-20 04:01:41 +00:00
|
|
|
|
|
|
|
struct InterpolateData {
|
2021-02-07 21:29:31 +00:00
|
|
|
bool active = false;
|
|
|
|
InterpolateType type = INTER_CALLBACK;
|
|
|
|
bool finish = false;
|
|
|
|
bool call_deferred = false;
|
|
|
|
real_t elapsed = 0.0;
|
2014-12-19 09:13:20 +00:00
|
|
|
ObjectID id;
|
2017-05-30 20:20:15 +00:00
|
|
|
Vector<StringName> key;
|
|
|
|
StringName concatenated_key;
|
2014-08-20 04:01:41 +00:00
|
|
|
Variant initial_val;
|
|
|
|
Variant delta_val;
|
|
|
|
Variant final_val;
|
2014-12-19 09:13:20 +00:00
|
|
|
ObjectID target_id;
|
2017-05-30 20:20:15 +00:00
|
|
|
Vector<StringName> target_key;
|
2021-02-07 21:29:31 +00:00
|
|
|
real_t duration = 0.0;
|
|
|
|
TransitionType trans_type = TransitionType::TRANS_BACK;
|
|
|
|
EaseType ease_type = EaseType::EASE_COUNT;
|
|
|
|
real_t delay = 0.0;
|
|
|
|
int args = 0;
|
2015-01-07 11:46:01 +00:00
|
|
|
Variant arg[5];
|
2021-02-07 21:29:31 +00:00
|
|
|
int uid = 0;
|
2014-08-20 04:01:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
String autoplay;
|
2021-02-07 21:29:31 +00:00
|
|
|
TweenProcessMode tween_process_mode = TWEEN_PROCESS_IDLE;
|
|
|
|
bool repeat = false;
|
|
|
|
float speed_scale = 1.0;
|
|
|
|
mutable int pending_update = 0;
|
|
|
|
int uid = 0;
|
2014-08-20 04:01:41 +00:00
|
|
|
|
|
|
|
List<InterpolateData> interpolates;
|
|
|
|
|
2015-05-05 03:12:17 +00:00
|
|
|
struct PendingCommand {
|
|
|
|
StringName key;
|
2021-02-07 21:29:31 +00:00
|
|
|
int args = 0;
|
2015-05-05 03:12:17 +00:00
|
|
|
Variant arg[10];
|
|
|
|
};
|
|
|
|
List<PendingCommand> pending_commands;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void _add_pending_command(StringName p_key, const Variant &p_arg1 = Variant(), const Variant &p_arg2 = Variant(), const Variant &p_arg3 = Variant(), const Variant &p_arg4 = Variant(), const Variant &p_arg5 = Variant(), const Variant &p_arg6 = Variant(), const Variant &p_arg7 = Variant(), const Variant &p_arg8 = Variant(), const Variant &p_arg9 = Variant(), const Variant &p_arg10 = Variant());
|
2015-05-05 03:12:17 +00:00
|
|
|
void _process_pending_commands();
|
|
|
|
|
2014-08-20 04:01:41 +00:00
|
|
|
typedef real_t (*interpolater)(real_t t, real_t b, real_t c, real_t d);
|
|
|
|
static interpolater interpolaters[TRANS_COUNT][EASE_COUNT];
|
|
|
|
|
|
|
|
real_t _run_equation(TransitionType p_trans_type, EaseType p_ease_type, real_t t, real_t b, real_t c, real_t d);
|
2017-03-05 15:44:50 +00:00
|
|
|
Variant &_get_delta_val(InterpolateData &p_data);
|
2019-10-23 20:38:43 +00:00
|
|
|
Variant _get_initial_val(const InterpolateData &p_data) const;
|
|
|
|
Variant _get_final_val(const InterpolateData &p_data) const;
|
2017-03-05 15:44:50 +00:00
|
|
|
Variant _run_equation(InterpolateData &p_data);
|
|
|
|
bool _calc_delta_val(const Variant &p_initial_val, const Variant &p_final_val, Variant &p_delta_val);
|
|
|
|
bool _apply_tween_value(InterpolateData &p_data, Variant &value);
|
2014-08-20 04:01:41 +00:00
|
|
|
|
|
|
|
void _tween_process(float p_delta);
|
2018-08-15 15:26:10 +00:00
|
|
|
void _remove_by_uid(int uid);
|
|
|
|
void _push_interpolate_data(InterpolateData &p_data);
|
2020-03-06 07:40:40 +00:00
|
|
|
void _build_interpolation(InterpolateType p_interpolation_type, Object *p_object, NodePath *p_property, StringName *p_method, Variant p_initial_val, Variant p_final_val, real_t p_duration, TransitionType p_trans_type, EaseType p_ease_type, real_t p_delay);
|
2014-08-20 04:01:41 +00:00
|
|
|
|
|
|
|
protected:
|
2017-03-05 15:44:50 +00:00
|
|
|
bool _set(const StringName &p_name, const Variant &p_value);
|
|
|
|
bool _get(const StringName &p_name, Variant &r_ret) const;
|
2014-08-20 04:01:41 +00:00
|
|
|
void _get_property_list(List<PropertyInfo> *p_list) const;
|
|
|
|
void _notification(int p_what);
|
|
|
|
|
|
|
|
static void _bind_methods();
|
|
|
|
|
|
|
|
public:
|
|
|
|
bool is_active() const;
|
|
|
|
void set_active(bool p_active);
|
|
|
|
|
2014-08-20 08:39:28 +00:00
|
|
|
bool is_repeat() const;
|
|
|
|
void set_repeat(bool p_repeat);
|
|
|
|
|
2014-08-20 04:01:41 +00:00
|
|
|
void set_tween_process_mode(TweenProcessMode p_mode);
|
|
|
|
TweenProcessMode get_tween_process_mode() const;
|
|
|
|
|
2017-01-13 22:36:04 +00:00
|
|
|
void set_speed_scale(float p_speed);
|
|
|
|
float get_speed_scale() const;
|
2014-08-20 04:01:41 +00:00
|
|
|
|
2020-03-06 07:40:40 +00:00
|
|
|
void start();
|
|
|
|
void reset(Object *p_object, StringName p_key);
|
|
|
|
void reset_all();
|
|
|
|
void stop(Object *p_object, StringName p_key);
|
|
|
|
void stop_all();
|
|
|
|
void resume(Object *p_object, StringName p_key);
|
|
|
|
void resume_all();
|
|
|
|
void remove(Object *p_object, StringName p_key);
|
|
|
|
void remove_all();
|
|
|
|
|
|
|
|
void seek(real_t p_time);
|
2014-08-22 06:25:41 +00:00
|
|
|
real_t tell() const;
|
|
|
|
real_t get_runtime() const;
|
2014-08-20 08:39:28 +00:00
|
|
|
|
2020-03-06 07:40:40 +00:00
|
|
|
void interpolate_property(Object *p_object, NodePath p_property, Variant p_initial_val, Variant p_final_val, real_t p_duration, TransitionType p_trans_type = TRANS_LINEAR, EaseType p_ease_type = EASE_IN_OUT, real_t p_delay = 0);
|
|
|
|
void interpolate_method(Object *p_object, StringName p_method, Variant p_initial_val, Variant p_final_val, real_t p_duration, TransitionType p_trans_type = TRANS_LINEAR, EaseType p_ease_type = EASE_IN_OUT, real_t p_delay = 0);
|
|
|
|
void interpolate_callback(Object *p_object, real_t p_duration, String p_callback, VARIANT_ARG_DECLARE);
|
|
|
|
void interpolate_deferred_callback(Object *p_object, real_t p_duration, String p_callback, VARIANT_ARG_DECLARE);
|
|
|
|
void 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 = TRANS_LINEAR, EaseType p_ease_type = EASE_IN_OUT, real_t p_delay = 0);
|
|
|
|
void 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 = TRANS_LINEAR, EaseType p_ease_type = EASE_IN_OUT, real_t p_delay = 0);
|
|
|
|
void targeting_property(Object *p_object, NodePath p_property, Object *p_initial, NodePath p_initial_property, Variant p_final_val, real_t p_duration, TransitionType p_trans_type = TRANS_LINEAR, EaseType p_ease_type = EASE_IN_OUT, real_t p_delay = 0);
|
|
|
|
void targeting_method(Object *p_object, StringName p_method, Object *p_initial, StringName p_initial_method, Variant p_final_val, real_t p_duration, TransitionType p_trans_type = TRANS_LINEAR, EaseType p_ease_type = EASE_IN_OUT, real_t p_delay = 0);
|
2014-08-22 03:24:53 +00:00
|
|
|
|
2014-08-20 04:01:41 +00:00
|
|
|
Tween();
|
|
|
|
~Tween();
|
|
|
|
};
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
VARIANT_ENUM_CAST(Tween::TweenProcessMode);
|
|
|
|
VARIANT_ENUM_CAST(Tween::TransitionType);
|
|
|
|
VARIANT_ENUM_CAST(Tween::EaseType);
|
2014-08-20 04:01:41 +00:00
|
|
|
|
|
|
|
#endif
|