Path: blob/master/scene/animation/animation_player.h
10277 views
/**************************************************************************/1/* animation_player.h */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#pragma once3132#include "animation_mixer.h"33#include "scene/resources/animation.h"3435class AnimationPlayer : public AnimationMixer {36GDCLASS(AnimationPlayer, AnimationMixer);3738#ifndef DISABLE_DEPRECATED39public:40enum AnimationProcessCallback {41ANIMATION_PROCESS_PHYSICS,42ANIMATION_PROCESS_IDLE,43ANIMATION_PROCESS_MANUAL,44};45enum AnimationMethodCallMode {46ANIMATION_METHOD_CALL_DEFERRED,47ANIMATION_METHOD_CALL_IMMEDIATE,48};49#endif // DISABLE_DEPRECATED5051private:52AHashMap<StringName, StringName> animation_next_set; // For auto advance.5354float speed_scale = 1.0;55double default_blend_time = 0.0;5657bool auto_capture = true;58double auto_capture_duration = -1.0;59Tween::TransitionType auto_capture_transition_type = Tween::TRANS_LINEAR;60Tween::EaseType auto_capture_ease_type = Tween::EASE_IN;6162bool is_stopping = false;6364struct PlaybackData {65AnimationData *from = nullptr;66double pos = 0.0;67float speed_scale = 1.0;68double start_time = 0.0;69double end_time = 0.0;70double get_start_time() const {71if (from && (Animation::is_less_approx(start_time, 0) || Animation::is_greater_approx(start_time, from->animation->get_length()))) {72return 0;73}74return start_time;75}76double get_end_time() const {77if (from && (Animation::is_less_approx(end_time, 0) || Animation::is_greater_approx(end_time, from->animation->get_length()))) {78return from->animation->get_length();79}80return end_time;81}82};8384struct Blend {85PlaybackData data;86double blend_time = 0.0;87double blend_left = 0.0;88};8990struct Playback {91PlaybackData current;92StringName assigned;93bool seeked = false;94bool internal_seeked = false;95bool started = false;96List<Blend> blend;97} playback;9899struct BlendKey {100StringName from;101StringName to;102static uint32_t hash(const BlendKey &p_key) {103return hash_one_uint64((uint64_t(p_key.from.hash()) << 32) | uint32_t(p_key.to.hash()));104}105bool operator==(const BlendKey &bk) const {106return from == bk.from && to == bk.to;107}108bool operator<(const BlendKey &bk) const {109if (from == bk.from) {110return StringName::AlphCompare()(to, bk.to);111} else {112return StringName::AlphCompare()(from, bk.from);113}114}115};116117HashMap<BlendKey, double, BlendKey> blend_times;118119List<StringName> playback_queue;120ObjectID tmp_from;121bool end_reached = false;122bool end_notify = false;123124StringName autoplay;125126bool reset_on_save = true;127bool movie_quit_on_finish = false;128129void _play(const StringName &p_name, double p_custom_blend = -1, float p_custom_scale = 1.0, bool p_from_end = false);130void _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);131void _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);132void _blend_playback_data(double p_delta, bool p_started);133void _stop_internal(bool p_reset, bool p_keep_state);134void _check_immediately_after_start();135136float get_current_blend_amount();137138bool playing = false;139140protected:141bool _set(const StringName &p_name, const Variant &p_value);142bool _get(const StringName &p_name, Variant &r_ret) const;143virtual void _validate_property(PropertyInfo &p_property) const override;144void _get_property_list(List<PropertyInfo> *p_list) const;145void _notification(int p_what);146147static void _bind_methods();148149// Make animation instances.150virtual bool _blend_pre_process(double p_delta, int p_track_count, const AHashMap<NodePath, int> &p_track_map) override;151virtual void _blend_capture(double p_delta) override;152virtual void _blend_post_process() override;153154virtual void _animation_removed(const StringName &p_name, const StringName &p_library) override;155virtual void _rename_animation(const StringName &p_from_name, const StringName &p_to_name) override;156157#ifndef DISABLE_DEPRECATED158void _set_process_callback_bind_compat_80813(AnimationProcessCallback p_mode);159AnimationProcessCallback _get_process_callback_bind_compat_80813() const;160void _set_method_call_mode_bind_compat_80813(AnimationMethodCallMode p_mode);161AnimationMethodCallMode _get_method_call_mode_bind_compat_80813() const;162void _set_root_bind_compat_80813(const NodePath &p_root);163NodePath _get_root_bind_compat_80813() const;164void _seek_bind_compat_80813(double p_time, bool p_update = false);165void _play_compat_84906(const StringName &p_name = StringName(), double p_custom_blend = -1, float p_custom_scale = 1.0, bool p_from_end = false);166void _play_backwards_compat_84906(const StringName &p_name = StringName(), double p_custom_blend = -1);167168static void _bind_compatibility_methods();169#endif // DISABLE_DEPRECATED170171public:172void animation_set_next(const StringName &p_animation, const StringName &p_next);173StringName animation_get_next(const StringName &p_animation) const;174175void set_blend_time(const StringName &p_animation1, const StringName &p_animation2, double p_time);176double get_blend_time(const StringName &p_animation1, const StringName &p_animation2) const;177178void set_default_blend_time(double p_default);179double get_default_blend_time() const;180181void set_auto_capture(bool p_auto_capture);182bool is_auto_capture() const;183void set_auto_capture_duration(double p_auto_capture_duration);184double get_auto_capture_duration() const;185void set_auto_capture_transition_type(Tween::TransitionType p_auto_capture_transition_type);186Tween::TransitionType get_auto_capture_transition_type() const;187void set_auto_capture_ease_type(Tween::EaseType p_auto_capture_ease_type);188Tween::EaseType get_auto_capture_ease_type() const;189190#ifdef TOOLS_ENABLED191void get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const override;192#endif193194void play(const StringName &p_name = StringName(), double p_custom_blend = -1, float p_custom_scale = 1.0, bool p_from_end = false);195void play_section_with_markers(const StringName &p_name = StringName(), const StringName &p_start_marker = StringName(), const StringName &p_end_marker = StringName(), double p_custom_blend = -1, float p_custom_scale = 1.0, bool p_from_end = false);196void play_section(const StringName &p_name = StringName(), double p_start_time = -1, double p_end_time = -1, double p_custom_blend = -1, float p_custom_scale = 1.0, bool p_from_end = false);197void play_backwards(const StringName &p_name = StringName(), double p_custom_blend = -1);198void play_section_with_markers_backwards(const StringName &p_name = StringName(), const StringName &p_start_marker = StringName(), const StringName &p_end_marker = StringName(), double p_custom_blend = -1);199void play_section_backwards(const StringName &p_name = StringName(), double p_start_time = -1, double p_end_time = -1, double p_custom_blend = -1);200void 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);201void queue(const StringName &p_name);202Vector<String> get_queue();203void clear_queue();204void pause();205void stop(bool p_keep_state = false);206bool is_playing() const;207String get_current_animation() const;208void set_current_animation(const String &p_animation);209String get_assigned_animation() const;210void set_assigned_animation(const String &p_animation);211bool is_valid() const;212213void set_speed_scale(float p_speed);214float get_speed_scale() const;215float get_playing_speed() const;216217void set_autoplay(const String &p_name);218String get_autoplay() const;219220void set_movie_quit_on_finish_enabled(bool p_enabled);221bool is_movie_quit_on_finish_enabled() const;222223void seek_internal(double p_time, bool p_update = false, bool p_update_only = false, bool p_is_internal_seek = false);224void seek(double p_time, bool p_update = false, bool p_update_only = false);225226double get_current_animation_position() const;227double get_current_animation_length() const;228229void set_section_with_markers(const StringName &p_start_marker = StringName(), const StringName &p_end_marker = StringName());230void set_section(double p_start_time = -1, double p_end_time = -1);231void reset_section();232233double get_section_start_time() const;234double get_section_end_time() const;235bool has_section() const;236237virtual void advance(double p_time) override;238239AnimationPlayer();240~AnimationPlayer();241};242243#ifndef DISABLE_DEPRECATED244VARIANT_ENUM_CAST(AnimationPlayer::AnimationProcessCallback);245VARIANT_ENUM_CAST(AnimationPlayer::AnimationMethodCallMode);246#endif // DISABLE_DEPRECATED247248249