summaryrefslogtreecommitdiff
path: root/scene/animation/animation_player.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'scene/animation/animation_player.cpp')
-rw-r--r--scene/animation/animation_player.cpp70
1 files changed, 45 insertions, 25 deletions
diff --git a/scene/animation/animation_player.cpp b/scene/animation/animation_player.cpp
index cfc3b2f4ce..75088c79fe 100644
--- a/scene/animation/animation_player.cpp
+++ b/scene/animation/animation_player.cpp
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */
+/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -34,12 +34,23 @@
#include "core/message_queue.h"
#include "scene/scene_string_names.h"
#include "servers/audio/audio_stream.h"
+
#ifdef TOOLS_ENABLED
+#include "editor/editor_settings.h"
+#include "scene/2d/skeleton_2d.h"
+
void AnimatedValuesBackup::update_skeletons() {
for (int i = 0; i < entries.size(); i++) {
if (entries[i].bone_idx != -1) {
+ // 3D bone
Object::cast_to<Skeleton>(entries[i].object)->notification(Skeleton::NOTIFICATION_UPDATE_SKELETON);
+ } else {
+ Bone2D *bone = Object::cast_to<Bone2D>(entries[i].object);
+ if (bone && bone->skeleton) {
+ // 2D bone
+ bone->skeleton->_update_transform();
+ }
}
}
}
@@ -287,7 +298,6 @@ void AnimationPlayer::_ensure_node_caches(AnimationData *p_anim) {
// broken track (nonexistent bone)
p_anim->node_cache[i]->skeleton = NULL;
p_anim->node_cache[i]->spatial = NULL;
- printf("bone is %ls\n", String(bone_name).c_str());
ERR_CONTINUE(p_anim->node_cache[i]->bone_idx < 0);
}
} else {
@@ -344,10 +354,16 @@ void AnimationPlayer::_animation_process_animation(AnimationData *p_anim, float
for (int i = 0; i < a->get_track_count(); i++) {
+ // If an animation changes this animation (or it animates itself)
+ // we need to recreate our animation cache
+ if (p_anim->node_cache.size() != a->get_track_count()) {
+ _ensure_node_caches(p_anim);
+ }
+
TrackNodeCache *nc = p_anim->node_cache[i];
- if (!nc) // no node cache for this track, skip it
- continue;
+ if (!nc)
+ continue; // no node cache for this track, skip it
if (!a->track_is_enabled(i))
continue; // do nothing if the track is disabled
@@ -985,25 +1001,12 @@ void AnimationPlayer::remove_animation(const StringName &p_name) {
void AnimationPlayer::_ref_anim(const Ref<Animation> &p_anim) {
- if (used_anims.has(p_anim))
- used_anims[p_anim]++;
- else {
- used_anims[p_anim] = 1;
- Ref<Animation>(p_anim)->connect("changed", this, "_animation_changed");
- }
+ Ref<Animation>(p_anim)->connect(SceneStringNames::get_singleton()->tracks_changed, this, "_animation_changed", varray(), CONNECT_REFERENCE_COUNTED);
}
void AnimationPlayer::_unref_anim(const Ref<Animation> &p_anim) {
- ERR_FAIL_COND(!used_anims.has(p_anim));
-
- int &n = used_anims[p_anim];
- n--;
- if (n == 0) {
-
- Ref<Animation>(p_anim)->disconnect("changed", this, "_animation_changed");
- used_anims.erase(p_anim);
- }
+ Ref<Animation>(p_anim)->disconnect(SceneStringNames::get_singleton()->tracks_changed, this, "_animation_changed");
}
void AnimationPlayer::rename_animation(const StringName &p_name, const StringName &p_new_name) {
@@ -1140,8 +1143,6 @@ void AnimationPlayer::play_backwards(const StringName &p_name, float p_custom_bl
void AnimationPlayer::play(const StringName &p_name, float p_custom_blend, float p_custom_scale, bool p_from_end) {
- //printf("animation is %ls\n", String(p_name).c_str());
- //ERR_FAIL_COND(!is_inside_scene());
StringName name = p_name;
if (String(name) == "")
@@ -1199,9 +1200,21 @@ void AnimationPlayer::play(const StringName &p_name, float p_custom_blend, float
_stop_playing_caches();
c.current.from = &animation_set[name];
- c.current.pos = p_from_end ? c.current.from->animation->get_length() : 0;
+
+ if (c.assigned != name) { // reset
+ c.current.pos = p_from_end ? c.current.from->animation->get_length() : 0;
+ } else {
+ if (p_from_end && c.current.pos == 0) {
+ // Animation reset BUT played backwards, set position to the end
+ c.current.pos = c.current.from->animation->get_length();
+ } else if (!p_from_end && c.current.pos == c.current.from->animation->get_length()) {
+ // Animation resumed but already ended, set position to the beginning
+ c.current.pos = 0;
+ }
+ }
+
c.current.speed_scale = p_custom_scale;
- c.assigned = p_name;
+ c.assigned = name;
c.seeked = false;
c.started = true;
@@ -1280,6 +1293,7 @@ void AnimationPlayer::stop(bool p_reset) {
if (p_reset) {
c.current.from = NULL;
c.current.speed_scale = 1;
+ c.current.pos = 0;
}
_set_process(false);
queued.clear();
@@ -1507,13 +1521,19 @@ NodePath AnimationPlayer::get_root() const {
void AnimationPlayer::get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const {
+#ifdef TOOLS_ENABLED
+ const String quote_style = EDITOR_DEF("text_editor/completion/use_single_quotes", 0) ? "'" : "\"";
+#else
+ const String quote_style = "\"";
+#endif
+
String pf = p_function;
if (p_function == "play" || p_function == "play_backwards" || p_function == "remove_animation" || p_function == "has_animation" || p_function == "queue") {
List<StringName> al;
get_animation_list(&al);
for (List<StringName>::Element *E = al.front(); E; E = E->next()) {
- r_options->push_back("\"" + String(E->get()) + "\"");
+ r_options->push_back(quote_style + String(E->get()) + quote_style);
}
}
Node::get_argument_options(p_function, p_idx, r_options);