summaryrefslogtreecommitdiff
path: root/scene/animation
diff options
context:
space:
mode:
authorSilc Renew <tokage.it.lab@gmail.com>2022-09-01 23:00:55 +0900
committerSilc Renew <tokage.it.lab@gmail.com>2022-09-14 21:05:21 +0900
commitcff95e54e05c9b5f14698ecc02f37bda658d0c22 (patch)
tree559fca5090c5425c589280b750d2b0b4bca09ab0 /scene/animation
parent0c221f0284909a1156a1c98de5104e07c1cce0b9 (diff)
Fix redraw timing in AnimationBlendTreeEditor
Diffstat (limited to 'scene/animation')
-rw-r--r--scene/animation/animation_blend_tree.cpp3
-rw-r--r--scene/animation/animation_player.cpp3
-rw-r--r--scene/animation/animation_tree.cpp43
-rw-r--r--scene/animation/animation_tree.h2
4 files changed, 51 insertions, 0 deletions
diff --git a/scene/animation/animation_blend_tree.cpp b/scene/animation/animation_blend_tree.cpp
index 3d81b6b9e8..eb30c7f4d6 100644
--- a/scene/animation/animation_blend_tree.cpp
+++ b/scene/animation/animation_blend_tree.cpp
@@ -1175,6 +1175,7 @@ void AnimationNodeBlendTree::_tree_changed() {
void AnimationNodeBlendTree::_node_changed(const StringName &p_node) {
ERR_FAIL_COND(!nodes.has(p_node));
nodes[p_node].connections.resize(nodes[p_node].node->get_input_count());
+ emit_signal(SNAME("node_changed"), p_node);
}
void AnimationNodeBlendTree::_bind_methods() {
@@ -1200,6 +1201,8 @@ void AnimationNodeBlendTree::_bind_methods() {
BIND_CONSTANT(CONNECTION_ERROR_NO_OUTPUT);
BIND_CONSTANT(CONNECTION_ERROR_SAME_NODE);
BIND_CONSTANT(CONNECTION_ERROR_CONNECTION_EXISTS);
+
+ ADD_SIGNAL(MethodInfo("node_changed", PropertyInfo(Variant::STRING_NAME, "node_name")));
}
void AnimationNodeBlendTree::_initialize_node_tree() {
diff --git a/scene/animation/animation_player.cpp b/scene/animation/animation_player.cpp
index 073f61bfdd..d7afe5070c 100644
--- a/scene/animation/animation_player.cpp
+++ b/scene/animation/animation_player.cpp
@@ -1270,6 +1270,8 @@ void AnimationPlayer::_animation_set_cache_update() {
// If something was modified or removed, caches need to be cleared
clear_caches();
}
+
+ emit_signal(SNAME("animation_list_changed"));
}
void AnimationPlayer::_animation_added(const StringName &p_name, const StringName &p_library) {
@@ -2150,6 +2152,7 @@ void AnimationPlayer::_bind_methods() {
ADD_SIGNAL(MethodInfo("animation_finished", PropertyInfo(Variant::STRING_NAME, "anim_name")));
ADD_SIGNAL(MethodInfo("animation_changed", PropertyInfo(Variant::STRING_NAME, "old_name"), PropertyInfo(Variant::STRING_NAME, "new_name")));
ADD_SIGNAL(MethodInfo("animation_started", PropertyInfo(Variant::STRING_NAME, "anim_name")));
+ ADD_SIGNAL(MethodInfo("animation_list_changed"));
ADD_SIGNAL(MethodInfo("caches_cleared"));
BIND_ENUM_CONSTANT(ANIMATION_PROCESS_PHYSICS);
diff --git a/scene/animation/animation_tree.cpp b/scene/animation/animation_tree.cpp
index d06324f0aa..c1e674dad5 100644
--- a/scene/animation/animation_tree.cpp
+++ b/scene/animation/animation_tree.cpp
@@ -847,6 +847,11 @@ bool AnimationTree::_update_caches(AnimationPlayer *player) {
return true;
}
+void AnimationTree::_animation_player_changed() {
+ emit_signal(SNAME("animation_player_changed"));
+ _clear_caches();
+}
+
void AnimationTree::_clear_caches() {
for (KeyValue<NodePath, TrackCache *> &K : track_cache) {
memdelete(K.value);
@@ -1738,6 +1743,7 @@ void AnimationTree::advance(real_t p_time) {
void AnimationTree::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
+ _setup_animation_player();
if (last_animation_player.is_valid()) {
Object *player = ObjectDB::get_instance(last_animation_player);
if (player) {
@@ -1770,8 +1776,43 @@ void AnimationTree::_notification(int p_what) {
}
}
+void AnimationTree::_setup_animation_player() {
+ if (!is_inside_tree()) {
+ return;
+ }
+
+ AnimationPlayer *new_player = nullptr;
+ if (!animation_player.is_empty()) {
+ new_player = Object::cast_to<AnimationPlayer>(get_node(animation_player));
+ if (new_player && !new_player->is_connected("animation_list_changed", callable_mp(this, &AnimationTree::_animation_player_changed))) {
+ new_player->connect("animation_list_changed", callable_mp(this, &AnimationTree::_animation_player_changed));
+ }
+ }
+
+ if (new_player) {
+ if (!last_animation_player.is_valid()) {
+ // Animation player set newly.
+ emit_signal(SNAME("animation_player_changed"));
+ return;
+ } else if (last_animation_player == new_player->get_instance_id()) {
+ // Animation player isn't changed.
+ return;
+ }
+ } else if (!last_animation_player.is_valid()) {
+ // Animation player is being empty.
+ return;
+ }
+
+ AnimationPlayer *old_player = Object::cast_to<AnimationPlayer>(ObjectDB::get_instance(last_animation_player));
+ if (old_player && old_player->is_connected("animation_list_changed", callable_mp(this, &AnimationTree::_animation_player_changed))) {
+ old_player->disconnect("animation_list_changed", callable_mp(this, &AnimationTree::_animation_player_changed));
+ }
+ emit_signal(SNAME("animation_player_changed"));
+}
+
void AnimationTree::set_animation_player(const NodePath &p_player) {
animation_player = p_player;
+ _setup_animation_player();
update_configuration_warnings();
}
@@ -2008,6 +2049,8 @@ void AnimationTree::_bind_methods() {
BIND_ENUM_CONSTANT(ANIMATION_PROCESS_PHYSICS);
BIND_ENUM_CONSTANT(ANIMATION_PROCESS_IDLE);
BIND_ENUM_CONSTANT(ANIMATION_PROCESS_MANUAL);
+
+ ADD_SIGNAL(MethodInfo("animation_player_changed"));
}
AnimationTree::AnimationTree() {
diff --git a/scene/animation/animation_tree.h b/scene/animation/animation_tree.h
index ee0c0303dc..573448be93 100644
--- a/scene/animation/animation_tree.h
+++ b/scene/animation/animation_tree.h
@@ -282,6 +282,8 @@ private:
bool cache_valid = false;
void _node_removed(Node *p_node);
+ void _setup_animation_player();
+ void _animation_player_changed();
void _clear_caches();
bool _update_caches(AnimationPlayer *player);
void _process_graph(double p_delta);