2014-02-10 01:10:30 +00:00
|
|
|
/**************************************************************************/
|
|
|
|
/* animation_player.h */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
|
|
|
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* */
|
|
|
|
/* 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-02-10 01:10:30 +00:00
|
|
|
#ifndef ANIMATION_PLAYER_H
|
|
|
|
#define ANIMATION_PLAYER_H
|
|
|
|
|
2023-07-20 15:34:06 +00:00
|
|
|
#include "animation_mixer.h"
|
2014-02-10 01:10:30 +00:00
|
|
|
#include "scene/2d/node_2d.h"
|
|
|
|
#include "scene/resources/animation.h"
|
2017-10-30 18:43:19 +00:00
|
|
|
|
2023-07-20 15:34:06 +00:00
|
|
|
class AnimationPlayer : public AnimationMixer {
|
|
|
|
GDCLASS(AnimationPlayer, AnimationMixer);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2023-07-20 15:34:06 +00:00
|
|
|
#ifndef DISABLE_DEPRECATED
|
2014-02-10 01:10:30 +00:00
|
|
|
public:
|
2021-02-18 18:52:29 +00:00
|
|
|
enum AnimationProcessCallback {
|
2017-09-30 14:19:07 +00:00
|
|
|
ANIMATION_PROCESS_PHYSICS,
|
2014-02-10 01:10:30 +00:00
|
|
|
ANIMATION_PROCESS_IDLE,
|
2018-08-02 07:22:24 +00:00
|
|
|
ANIMATION_PROCESS_MANUAL,
|
2014-02-10 01:10:30 +00:00
|
|
|
};
|
2018-12-08 18:56:20 +00:00
|
|
|
enum AnimationMethodCallMode {
|
|
|
|
ANIMATION_METHOD_CALL_DEFERRED,
|
|
|
|
ANIMATION_METHOD_CALL_IMMEDIATE,
|
|
|
|
};
|
2023-07-20 15:34:06 +00:00
|
|
|
#endif // DISABLE_DEPRECATED
|
2018-12-08 18:56:20 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
private:
|
2023-07-20 15:34:06 +00:00
|
|
|
HashMap<StringName, StringName> animation_next_set; // For auto advance.
|
2022-05-13 13:04:37 +00:00
|
|
|
|
2021-02-07 21:29:31 +00:00
|
|
|
float speed_scale = 1.0;
|
2022-09-22 13:54:15 +00:00
|
|
|
double default_blend_time = 0.0;
|
2024-05-02 20:36:36 +00:00
|
|
|
|
2024-05-02 02:23:11 +00:00
|
|
|
bool auto_capture = true;
|
2024-05-02 20:36:36 +00:00
|
|
|
double auto_capture_duration = -1.0;
|
|
|
|
Tween::TransitionType auto_capture_transition_type = Tween::TRANS_LINEAR;
|
|
|
|
Tween::EaseType auto_capture_ease_type = Tween::EASE_IN;
|
|
|
|
|
2019-11-19 13:39:10 +00:00
|
|
|
bool is_stopping = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2023-07-20 15:34:06 +00:00
|
|
|
struct PlaybackData {
|
|
|
|
AnimationData *from = nullptr;
|
|
|
|
double pos = 0.0;
|
|
|
|
float speed_scale = 1.0;
|
2014-02-10 01:10:30 +00:00
|
|
|
};
|
|
|
|
|
2023-07-20 15:34:06 +00:00
|
|
|
struct Blend {
|
|
|
|
PlaybackData data;
|
|
|
|
double blend_time = 0.0;
|
|
|
|
double blend_left = 0.0;
|
2022-04-07 11:49:28 +00:00
|
|
|
};
|
|
|
|
|
2023-07-20 15:34:06 +00:00
|
|
|
struct Playback {
|
|
|
|
PlaybackData current;
|
|
|
|
StringName assigned;
|
|
|
|
bool seeked = false;
|
2024-07-16 05:38:56 +00:00
|
|
|
bool internal_seeked = false;
|
2023-07-20 15:34:06 +00:00
|
|
|
bool started = false;
|
|
|
|
List<Blend> blend;
|
|
|
|
} playback;
|
2022-04-07 11:49:28 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
struct BlendKey {
|
|
|
|
StringName from;
|
|
|
|
StringName to;
|
2022-05-13 13:04:37 +00:00
|
|
|
static uint32_t hash(const BlendKey &p_key) {
|
|
|
|
return hash_one_uint64((uint64_t(p_key.from.hash()) << 32) | uint32_t(p_key.to.hash()));
|
|
|
|
}
|
|
|
|
bool operator==(const BlendKey &bk) const {
|
|
|
|
return from == bk.from && to == bk.to;
|
|
|
|
}
|
|
|
|
bool operator<(const BlendKey &bk) const {
|
|
|
|
if (from == bk.from) {
|
2024-07-03 13:56:39 +00:00
|
|
|
return StringName::AlphCompare()(to, bk.to);
|
2022-05-13 13:04:37 +00:00
|
|
|
} else {
|
2024-07-03 13:56:39 +00:00
|
|
|
return StringName::AlphCompare()(from, bk.from);
|
2022-05-13 13:04:37 +00:00
|
|
|
}
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
};
|
|
|
|
|
2022-09-22 13:54:15 +00:00
|
|
|
HashMap<BlendKey, double, BlendKey> blend_times;
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2023-07-20 15:34:06 +00:00
|
|
|
List<StringName> playback_queue;
|
|
|
|
ObjectID tmp_from;
|
2021-02-07 21:29:31 +00:00
|
|
|
bool end_reached = false;
|
|
|
|
bool end_notify = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2023-07-20 15:34:06 +00:00
|
|
|
StringName autoplay;
|
|
|
|
|
2021-02-07 21:29:31 +00:00
|
|
|
bool reset_on_save = true;
|
2022-06-25 23:38:20 +00:00
|
|
|
bool movie_quit_on_finish = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2024-05-02 02:23:11 +00:00
|
|
|
void _play(const StringName &p_name, double p_custom_blend = -1, float p_custom_scale = 1.0, bool p_from_end = false);
|
|
|
|
void _capture(const StringName &p_name, bool p_from_end = false, double p_duration = -1.0, Tween::TransitionType p_trans_type = Tween::TRANS_LINEAR, Tween::EaseType p_ease_type = Tween::EASE_IN);
|
2024-07-16 05:38:56 +00:00
|
|
|
void _process_playback_data(PlaybackData &cd, double p_delta, float p_blend, bool p_seeked, bool p_internal_seeked, bool p_started, bool p_is_current = false);
|
2023-07-20 15:34:06 +00:00
|
|
|
void _blend_playback_data(double p_delta, bool p_started);
|
2023-01-18 13:02:04 +00:00
|
|
|
void _stop_internal(bool p_reset, bool p_keep_state);
|
2023-11-25 21:28:22 +00:00
|
|
|
void _check_immediately_after_start();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2023-12-16 00:42:48 +00:00
|
|
|
float get_current_blend_amount();
|
|
|
|
|
2021-02-07 21:29:31 +00:00
|
|
|
bool playing = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
bool _set(const StringName &p_name, const Variant &p_value);
|
|
|
|
bool _get(const StringName &p_name, Variant &r_ret) const;
|
2023-07-20 15:34:06 +00:00
|
|
|
virtual void _validate_property(PropertyInfo &p_property) const override;
|
2014-02-10 01:10:30 +00:00
|
|
|
void _get_property_list(List<PropertyInfo> *p_list) const;
|
|
|
|
void _notification(int p_what);
|
2016-03-08 23:00:52 +00:00
|
|
|
|
|
|
|
static void _bind_methods();
|
|
|
|
|
2023-07-20 15:34:06 +00:00
|
|
|
// Make animation instances.
|
|
|
|
virtual bool _blend_pre_process(double p_delta, int p_track_count, const HashMap<NodePath, int> &p_track_map) override;
|
2024-01-05 17:40:58 +00:00
|
|
|
virtual void _blend_capture(double p_delta) override;
|
2023-07-20 15:34:06 +00:00
|
|
|
virtual void _blend_post_process() override;
|
2022-07-26 09:48:08 +00:00
|
|
|
|
2023-07-20 15:34:06 +00:00
|
|
|
virtual void _animation_removed(const StringName &p_name, const StringName &p_library) override;
|
|
|
|
virtual void _rename_animation(const StringName &p_from_name, const StringName &p_to_name) override;
|
2022-04-07 11:49:28 +00:00
|
|
|
|
2023-07-20 15:34:06 +00:00
|
|
|
#ifndef DISABLE_DEPRECATED
|
|
|
|
void _set_process_callback_bind_compat_80813(AnimationProcessCallback p_mode);
|
|
|
|
AnimationProcessCallback _get_process_callback_bind_compat_80813() const;
|
|
|
|
void _set_method_call_mode_bind_compat_80813(AnimationMethodCallMode p_mode);
|
|
|
|
AnimationMethodCallMode _get_method_call_mode_bind_compat_80813() const;
|
|
|
|
void _set_root_bind_compat_80813(const NodePath &p_root);
|
|
|
|
NodePath _get_root_bind_compat_80813() const;
|
|
|
|
void _seek_bind_compat_80813(double p_time, bool p_update = false);
|
2024-01-30 20:03:28 +00:00
|
|
|
void _play_compat_84906(const StringName &p_name = StringName(), double p_custom_blend = -1, float p_custom_scale = 1.0, bool p_from_end = false);
|
|
|
|
void _play_backwards_compat_84906(const StringName &p_name = StringName(), double p_custom_blend = -1);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2023-07-20 15:34:06 +00:00
|
|
|
static void _bind_compatibility_methods();
|
|
|
|
#endif // DISABLE_DEPRECATED
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2023-07-20 15:34:06 +00:00
|
|
|
public:
|
2014-02-10 01:10:30 +00:00
|
|
|
void animation_set_next(const StringName &p_animation, const StringName &p_next);
|
|
|
|
StringName animation_get_next(const StringName &p_animation) const;
|
|
|
|
|
2023-07-20 15:34:06 +00:00
|
|
|
void set_blend_time(const StringName &p_animation1, const StringName &p_animation2, double p_time);
|
|
|
|
double get_blend_time(const StringName &p_animation1, const StringName &p_animation2) const;
|
|
|
|
|
2022-09-22 13:54:15 +00:00
|
|
|
void set_default_blend_time(double p_default);
|
|
|
|
double get_default_blend_time() const;
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2024-05-02 02:23:11 +00:00
|
|
|
void set_auto_capture(bool p_auto_capture);
|
|
|
|
bool is_auto_capture() const;
|
2024-05-02 20:36:36 +00:00
|
|
|
void set_auto_capture_duration(double p_auto_capture_duration);
|
|
|
|
double get_auto_capture_duration() const;
|
|
|
|
void set_auto_capture_transition_type(Tween::TransitionType p_auto_capture_transition_type);
|
|
|
|
Tween::TransitionType get_auto_capture_transition_type() const;
|
|
|
|
void set_auto_capture_ease_type(Tween::EaseType p_auto_capture_ease_type);
|
|
|
|
Tween::EaseType get_auto_capture_ease_type() const;
|
2024-05-02 02:23:11 +00:00
|
|
|
|
2022-09-22 13:54:15 +00:00
|
|
|
void play(const StringName &p_name = StringName(), double p_custom_blend = -1, float p_custom_scale = 1.0, bool p_from_end = false);
|
|
|
|
void play_backwards(const StringName &p_name = StringName(), double p_custom_blend = -1);
|
2024-05-02 02:23:11 +00:00
|
|
|
void play_with_capture(const StringName &p_name = StringName(), double p_duration = -1.0, double p_custom_blend = -1, float p_custom_scale = 1.0, bool p_from_end = false, Tween::TransitionType p_trans_type = Tween::TRANS_LINEAR, Tween::EaseType p_ease_type = Tween::EASE_IN);
|
2014-02-10 01:10:30 +00:00
|
|
|
void queue(const StringName &p_name);
|
2020-02-17 21:06:54 +00:00
|
|
|
Vector<String> get_queue();
|
2014-02-10 01:10:30 +00:00
|
|
|
void clear_queue();
|
2023-01-11 12:39:39 +00:00
|
|
|
void pause();
|
2023-01-18 13:02:04 +00:00
|
|
|
void stop(bool p_keep_state = false);
|
2014-02-10 01:10:30 +00:00
|
|
|
bool is_playing() const;
|
|
|
|
String get_current_animation() const;
|
2023-07-20 15:34:06 +00:00
|
|
|
void set_current_animation(const String &p_animation);
|
2018-01-14 10:28:57 +00:00
|
|
|
String get_assigned_animation() const;
|
2023-07-20 15:34:06 +00:00
|
|
|
void set_assigned_animation(const String &p_animation);
|
2014-02-10 01:10:30 +00:00
|
|
|
bool is_valid() const;
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-01-13 22:36:04 +00:00
|
|
|
void set_speed_scale(float p_speed);
|
|
|
|
float get_speed_scale() const;
|
2018-03-01 18:52:00 +00:00
|
|
|
float get_playing_speed() const;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-08-11 19:10:05 +00:00
|
|
|
void set_autoplay(const String &p_name);
|
2014-02-10 01:10:30 +00:00
|
|
|
String get_autoplay() const;
|
|
|
|
|
2022-06-25 23:38:20 +00:00
|
|
|
void set_movie_quit_on_finish_enabled(bool p_enabled);
|
|
|
|
bool is_movie_quit_on_finish_enabled() const;
|
|
|
|
|
2024-07-16 05:38:56 +00:00
|
|
|
void seek_internal(double p_time, bool p_update = false, bool p_update_only = false, bool p_is_internal_seek = false);
|
2023-07-20 15:34:06 +00:00
|
|
|
void seek(double p_time, bool p_update = false, bool p_update_only = false);
|
|
|
|
|
2022-09-22 13:54:15 +00:00
|
|
|
double get_current_animation_position() const;
|
|
|
|
double get_current_animation_length() const;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2024-01-03 11:10:11 +00:00
|
|
|
#ifdef TOOLS_ENABLED
|
2020-07-10 10:34:39 +00:00
|
|
|
void get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const override;
|
2024-01-03 11:10:11 +00:00
|
|
|
#endif
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2023-11-22 14:08:21 +00:00
|
|
|
virtual void advance(double p_time) override;
|
|
|
|
|
2016-03-08 23:00:52 +00:00
|
|
|
AnimationPlayer();
|
2014-02-10 01:10:30 +00:00
|
|
|
~AnimationPlayer();
|
|
|
|
};
|
|
|
|
|
2023-07-20 15:34:06 +00:00
|
|
|
#ifndef DISABLE_DEPRECATED
|
2021-02-18 18:52:29 +00:00
|
|
|
VARIANT_ENUM_CAST(AnimationPlayer::AnimationProcessCallback);
|
2018-12-08 18:56:20 +00:00
|
|
|
VARIANT_ENUM_CAST(AnimationPlayer::AnimationMethodCallMode);
|
2023-07-20 15:34:06 +00:00
|
|
|
#endif // DISABLE_DEPRECATED
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2022-07-23 21:41:51 +00:00
|
|
|
#endif // ANIMATION_PLAYER_H
|