Path: blob/master/scene/animation/animation_player.h
21520 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.5354StringName finished_anim;5556float speed_scale = 1.0;57double default_blend_time = 0.0;5859bool auto_capture = true;60double auto_capture_duration = -1.0;61Tween::TransitionType auto_capture_transition_type = Tween::TRANS_LINEAR;62Tween::EaseType auto_capture_ease_type = Tween::EASE_IN;6364bool is_stopping = false;6566struct PlaybackData {67bool is_enabled = false;68String animation_name;69double animation_length = 0.0;70double pos = 0.0;71float speed_scale = 1.0;72double start_time = 0.0;73double end_time = 0.0;74double get_start_time() const {75if (is_enabled && (Animation::is_less_approx(start_time, 0) || Animation::is_greater_approx(start_time, animation_length))) {76return 0;77}78return start_time;79}80double get_end_time() const {81if (is_enabled && (Animation::is_less_approx(end_time, 0) || Animation::is_greater_approx(end_time, animation_length))) {82return animation_length;83}84return end_time;85}86};8788struct Blend {89PlaybackData data;90double blend_time = 0.0;91double blend_left = 0.0;92};9394struct Playback {95PlaybackData current;96StringName assigned;97bool seeked = false;98bool internal_seeked = false;99bool started = false;100List<Blend> blend;101} playback;102103struct BlendKey {104StringName from;105StringName to;106static uint32_t hash(const BlendKey &p_key) {107return hash_one_uint64((uint64_t(p_key.from.hash()) << 32) | uint32_t(p_key.to.hash()));108}109bool operator==(const BlendKey &bk) const {110return from == bk.from && to == bk.to;111}112bool operator<(const BlendKey &bk) const {113if (from == bk.from) {114return StringName::AlphCompare()(to, bk.to);115} else {116return StringName::AlphCompare()(from, bk.from);117}118}119};120121HashMap<BlendKey, double, BlendKey> blend_times;122123List<StringName> playback_queue;124ObjectID tmp_from;125bool end_reached = false;126bool end_notify = false;127128StringName autoplay;129130bool movie_quit_on_finish = false;131132void _play(const StringName &p_name, double p_custom_blend = -1, float p_custom_scale = 1.0, bool p_from_end = false);133void _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);134void _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);135void _blend_playback_data(double p_delta, bool p_started);136void _stop_internal(bool p_reset, bool p_keep_state);137void _check_immediately_after_start();138139float get_current_blend_amount();140141bool playing = false;142143protected:144bool _set(const StringName &p_name, const Variant &p_value);145bool _get(const StringName &p_name, Variant &r_ret) const;146virtual void _validate_property(PropertyInfo &p_property) const override;147void _get_property_list(List<PropertyInfo> *p_list) const;148void _notification(int p_what);149150static void _bind_methods();151152// Make animation instances.153virtual bool _blend_pre_process(double p_delta, int p_track_count, const AHashMap<NodePath, int> &p_track_map) override;154virtual void _blend_capture(double p_delta) override;155virtual void _blend_post_process() override;156157virtual void _animation_removed(const StringName &p_name, const StringName &p_library) override;158virtual void _rename_animation(const StringName &p_from_name, const StringName &p_to_name) override;159160#ifndef DISABLE_DEPRECATED161void _set_process_callback_bind_compat_80813(AnimationProcessCallback p_mode);162AnimationProcessCallback _get_process_callback_bind_compat_80813() const;163void _set_method_call_mode_bind_compat_80813(AnimationMethodCallMode p_mode);164AnimationMethodCallMode _get_method_call_mode_bind_compat_80813() const;165void _set_root_bind_compat_80813(const NodePath &p_root);166NodePath _get_root_bind_compat_80813() const;167void _seek_bind_compat_80813(double p_time, bool p_update = false);168void _play_compat_84906(const StringName &p_name = StringName(), double p_custom_blend = -1, float p_custom_scale = 1.0, bool p_from_end = false);169void _play_backwards_compat_84906(const StringName &p_name = StringName(), double p_custom_blend = -1);170171Vector<String> _get_queue_compat_110767();172String _get_current_animation_compat_110767() const;173void _set_current_animation_compat_110767(const String &p_animation);174String _get_assigned_animation_compat_110767() const;175void _set_assigned_animation_compat_110767(const String &p_animation);176String _get_autoplay_compat_110767() const;177void _set_autoplay_compat_110767(const String &p_name);178179static void _bind_compatibility_methods();180#endif // DISABLE_DEPRECATED181182public:183void animation_set_next(const StringName &p_animation, const StringName &p_next);184StringName animation_get_next(const StringName &p_animation) const;185186void set_blend_time(const StringName &p_animation1, const StringName &p_animation2, double p_time);187double get_blend_time(const StringName &p_animation1, const StringName &p_animation2) const;188189void set_default_blend_time(double p_default);190double get_default_blend_time() const;191192void set_auto_capture(bool p_auto_capture);193bool is_auto_capture() const;194void set_auto_capture_duration(double p_auto_capture_duration);195double get_auto_capture_duration() const;196void set_auto_capture_transition_type(Tween::TransitionType p_auto_capture_transition_type);197Tween::TransitionType get_auto_capture_transition_type() const;198void set_auto_capture_ease_type(Tween::EaseType p_auto_capture_ease_type);199Tween::EaseType get_auto_capture_ease_type() const;200201#ifdef TOOLS_ENABLED202void get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const override;203#endif204205void play(const StringName &p_name = StringName(), double p_custom_blend = -1, float p_custom_scale = 1.0, bool p_from_end = false);206void 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);207void 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);208void play_backwards(const StringName &p_name = StringName(), double p_custom_blend = -1);209void 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);210void play_section_backwards(const StringName &p_name = StringName(), double p_start_time = -1, double p_end_time = -1, double p_custom_blend = -1);211void 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);212void queue(const StringName &p_name);213TypedArray<StringName> get_queue();214void clear_queue();215void pause();216void stop(bool p_keep_state = false);217bool is_playing() const;218StringName get_current_animation() const;219void set_current_animation(const StringName &p_animation);220StringName get_assigned_animation() const;221void set_assigned_animation(const StringName &p_animation);222bool is_valid() const;223224void set_speed_scale(float p_speed);225float get_speed_scale() const;226float get_playing_speed() const;227228void set_autoplay(const StringName &p_name);229StringName get_autoplay() const;230231void set_movie_quit_on_finish_enabled(bool p_enabled);232bool is_movie_quit_on_finish_enabled() const;233234void seek_internal(double p_time, bool p_update = false, bool p_update_only = false, bool p_is_internal_seek = false);235void seek(double p_time, bool p_update = false, bool p_update_only = false);236237double get_current_animation_position() const;238double get_current_animation_length() const;239240void set_section_with_markers(const StringName &p_start_marker = StringName(), const StringName &p_end_marker = StringName());241void set_section(double p_start_time = -1, double p_end_time = -1);242void reset_section();243244double get_section_start_time() const;245double get_section_end_time() const;246bool has_section() const;247248virtual void advance(double p_time) override;249250AnimationPlayer();251~AnimationPlayer();252};253254#ifndef DISABLE_DEPRECATED255VARIANT_ENUM_CAST(AnimationPlayer::AnimationProcessCallback);256VARIANT_ENUM_CAST(AnimationPlayer::AnimationMethodCallMode);257#endif // DISABLE_DEPRECATED258259260