From 4f6b2152e2e12a6c9157ea3190830b627cbae3b7 Mon Sep 17 00:00:00 2001 From: Josh Grams Date: Wed, 6 Apr 2016 15:09:00 -0400 Subject: AnimationTreePlayer (transition_node_set_current): fix by removing copy-paste duplication. --- scene/animation/animation_tree_player.cpp | 34 ++++++++++++++----------------- scene/animation/animation_tree_player.h | 1 + 2 files changed, 16 insertions(+), 19 deletions(-) (limited to 'scene') diff --git a/scene/animation/animation_tree_player.cpp b/scene/animation/animation_tree_player.cpp index 0f8599706e..ce341e2b09 100644 --- a/scene/animation/animation_tree_player.cpp +++ b/scene/animation/animation_tree_player.cpp @@ -676,14 +676,7 @@ float AnimationTreePlayer::_process_node(const StringName& p_node,AnimationNode if (tn->input_data[tn->current].auto_advance && rem <= tn->xfade) { - tn->prev=tn->current; - tn->current++; - if (tn->current>=tn->inputs.size()) - tn->current=0; - tn->prev_xfading=tn->xfade; - tn->prev_time=tn->time; - tn->time=0; - tn->switched=true; + tn->set_current((tn->current+1) % tn->inputs.size()); } @@ -1156,21 +1149,24 @@ void AnimationTreePlayer::transition_node_set_xfade_time(const StringName& p_nod n->xfade=p_time; } +void AnimationTreePlayer::TransitionNode::set_current(int p_current) { + ERR_FAIL_INDEX(p_current,inputs.size()); -void AnimationTreePlayer::transition_node_set_current(const StringName& p_node, int p_current) { - - GET_NODE( NODE_TRANSITION, TransitionNode ); - ERR_FAIL_INDEX(p_current,n->inputs.size()); - - if (n->current==p_current) + if (current==p_current) return; - n->prev=n->current; - n->prev_xfading=n->xfade; - n->prev_time=n->time; - n->time=0; - n->current=p_current; + prev=current; + prev_xfading=xfade; + prev_time=time; + time=0; + current=p_current; + switched=true; +} + +void AnimationTreePlayer::transition_node_set_current(const StringName& p_node, int p_current) { + GET_NODE( NODE_TRANSITION, TransitionNode ); + n->set_current(p_current); } diff --git a/scene/animation/animation_tree_player.h b/scene/animation/animation_tree_player.h index 2e8ddc34d8..7cc96fc1e3 100644 --- a/scene/animation/animation_tree_player.h +++ b/scene/animation/animation_tree_player.h @@ -246,6 +246,7 @@ private: float xfade; TransitionNode() { type=NODE_TRANSITION; xfade=0; inputs.resize(1); input_data.resize(1); current=0; prev=-1; prev_time=0; prev_xfading=0; switched=false; } + void set_current(int p_current); }; -- cgit v1.2.3