diff options
Diffstat (limited to 'scene/animation/animation_tree.cpp')
-rw-r--r-- | scene/animation/animation_tree.cpp | 105 |
1 files changed, 47 insertions, 58 deletions
diff --git a/scene/animation/animation_tree.cpp b/scene/animation/animation_tree.cpp index 68b0602c67..1513010a8a 100644 --- a/scene/animation/animation_tree.cpp +++ b/scene/animation/animation_tree.cpp @@ -5,36 +5,32 @@ #include "scene/scene_string_names.h" #include "servers/audio/audio_stream.h" - - void AnimationNode::get_parameter_list(List<PropertyInfo> *r_list) const { - } Variant AnimationNode::get_parameter_default_value(const StringName &p_parameter) const { return Variant(); } -void AnimationNode::set_parameter(const StringName& p_name, const Variant& p_value) { +void AnimationNode::set_parameter(const StringName &p_name, const Variant &p_value) { ERR_FAIL_COND(!state); ERR_FAIL_COND(!state->tree->property_parent_map.has(base_path)); ERR_FAIL_COND(!state->tree->property_parent_map[base_path].has(p_name)); StringName path = state->tree->property_parent_map[base_path][p_name]; - state->tree->property_map[path]=p_value; + state->tree->property_map[path] = p_value; } -Variant AnimationNode::get_parameter(const StringName& p_name) const { - ERR_FAIL_COND_V(!state,Variant()); - ERR_FAIL_COND_V(!state->tree->property_parent_map.has(base_path),Variant()); - ERR_FAIL_COND_V(!state->tree->property_parent_map[base_path].has(p_name),Variant()); +Variant AnimationNode::get_parameter(const StringName &p_name) const { + ERR_FAIL_COND_V(!state, Variant()); + ERR_FAIL_COND_V(!state->tree->property_parent_map.has(base_path), Variant()); + ERR_FAIL_COND_V(!state->tree->property_parent_map[base_path].has(p_name), Variant()); StringName path = state->tree->property_parent_map[base_path][p_name]; return state->tree->property_map[path]; } void AnimationNode::get_child_nodes(List<ChildNode> *r_child_nodes) { - } void AnimationNode::blend_animation(const StringName &p_animation, float p_time, float p_delta, bool p_seeked, float p_blend) { @@ -46,7 +42,7 @@ void AnimationNode::blend_animation(const StringName &p_animation, float p_time, if (animation.is_null()) { - AnimationNodeBlendTree* btree = Object::cast_to<AnimationNodeBlendTree>(parent); + AnimationNodeBlendTree *btree = Object::cast_to<AnimationNodeBlendTree>(parent); if (btree) { String name = btree->get_node_name(Ref<AnimationNodeAnimation>(this)); make_invalid(vformat(RTR("In node '%s', invalid animation: '%s'."), name, p_animation)); @@ -69,11 +65,11 @@ void AnimationNode::blend_animation(const StringName &p_animation, float p_time, state->animation_states.push_back(anim_state); } -float AnimationNode::_pre_process(const StringName& p_base_path, AnimationNode *p_parent, State *p_state, float p_time, bool p_seek, const Vector<StringName>& p_connections) { +float AnimationNode::_pre_process(const StringName &p_base_path, AnimationNode *p_parent, State *p_state, float p_time, bool p_seek, const Vector<StringName> &p_connections) { base_path = p_base_path; parent = p_parent; - connections=p_connections; + connections = p_connections; state = p_state; float t = process(p_time, p_seek); @@ -99,8 +95,8 @@ float AnimationNode::blend_input(int p_input, float p_time, bool p_seek, float p ERR_FAIL_INDEX_V(p_input, inputs.size(), 0); ERR_FAIL_COND_V(!state, 0); - AnimationNodeBlendTree* blend_tree = Object::cast_to<AnimationNodeBlendTree>(parent); - ERR_FAIL_COND_V(!blend_tree,0); + AnimationNodeBlendTree *blend_tree = Object::cast_to<AnimationNodeBlendTree>(parent); + ERR_FAIL_COND_V(!blend_tree, 0); StringName node_name = connections[p_input]; @@ -114,15 +110,15 @@ float AnimationNode::blend_input(int p_input, float p_time, bool p_seek, float p //inputs.write[p_input].last_pass = state->last_pass; float activity; - return _blend_node(node_name,blend_tree->get_node_connection_array(node_name),NULL,node, p_time, p_seek, p_blend, p_filter, p_optimize, &activity); + return _blend_node(node_name, blend_tree->get_node_connection_array(node_name), NULL, node, p_time, p_seek, p_blend, p_filter, p_optimize, &activity); } -float AnimationNode::blend_node(const StringName& p_sub_path,Ref<AnimationNode> p_node, float p_time, bool p_seek, float p_blend, FilterAction p_filter, bool p_optimize) { +float AnimationNode::blend_node(const StringName &p_sub_path, Ref<AnimationNode> p_node, float p_time, bool p_seek, float p_blend, FilterAction p_filter, bool p_optimize) { - return _blend_node(p_sub_path,Vector<StringName>(),this,p_node, p_time, p_seek, p_blend, p_filter, p_optimize); + return _blend_node(p_sub_path, Vector<StringName>(), this, p_node, p_time, p_seek, p_blend, p_filter, p_optimize); } -float AnimationNode::_blend_node(const StringName &p_subpath, const Vector<StringName>& p_connections, AnimationNode *p_new_parent, Ref<AnimationNode> p_node, float p_time, bool p_seek, float p_blend, FilterAction p_filter, bool p_optimize, float *r_max) { +float AnimationNode::_blend_node(const StringName &p_subpath, const Vector<StringName> &p_connections, AnimationNode *p_new_parent, Ref<AnimationNode> p_node, float p_time, bool p_seek, float p_blend, FilterAction p_filter, bool p_optimize, float *r_max) { ERR_FAIL_COND_V(!p_node.is_valid(), 0); ERR_FAIL_COND_V(!state, 0); @@ -229,13 +225,13 @@ float AnimationNode::_blend_node(const StringName &p_subpath, const Vector<Strin //this is the slowest part of processing, but as strings process in powers of 2, and the paths always exist, it will not result in that many allocations if (p_new_parent) { new_parent = p_new_parent; - new_path = String(base_path)+String(p_subpath)+"/"; + new_path = String(base_path) + String(p_subpath) + "/"; } else { - ERR_FAIL_COND_V(!parent,0); + ERR_FAIL_COND_V(!parent, 0); new_parent = parent; - new_path = String(parent->base_path) + String(p_subpath)+"/"; + new_path = String(parent->base_path) + String(p_subpath) + "/"; } - return p_node->_pre_process(new_path,new_parent,state, p_time, p_seek, p_connections); + return p_node->_pre_process(new_path, new_parent, state, p_time, p_seek, p_connections); } int AnimationNode::get_input_count() const { @@ -247,7 +243,6 @@ String AnimationNode::get_input_name(int p_input) { return inputs[p_input].name; } - String AnimationNode::get_caption() const { if (get_script_instance()) { @@ -313,8 +308,6 @@ bool AnimationNode::has_filter() const { return false; } - - Array AnimationNode::_get_filters() const { Array paths; @@ -358,16 +351,15 @@ void AnimationNode::_bind_methods() { ClassDB::bind_method(D_METHOD("set_filter_enabled", "enable"), &AnimationNode::set_filter_enabled); ClassDB::bind_method(D_METHOD("is_filter_enabled"), &AnimationNode::is_filter_enabled); - ClassDB::bind_method(D_METHOD("_set_filters", "filters"), &AnimationNode::_set_filters); ClassDB::bind_method(D_METHOD("_get_filters"), &AnimationNode::_get_filters); ClassDB::bind_method(D_METHOD("blend_animation", "animation", "time", "delta", "seeked", "blend"), &AnimationNode::blend_animation); - ClassDB::bind_method(D_METHOD("blend_node", "name","node", "time", "seek", "blend", "filter", "optimize"), &AnimationNode::blend_node, DEFVAL(FILTER_IGNORE), DEFVAL(true)); + ClassDB::bind_method(D_METHOD("blend_node", "name", "node", "time", "seek", "blend", "filter", "optimize"), &AnimationNode::blend_node, DEFVAL(FILTER_IGNORE), DEFVAL(true)); ClassDB::bind_method(D_METHOD("blend_input", "input_index", "time", "seek", "blend", "filter", "optimize"), &AnimationNode::blend_input, DEFVAL(FILTER_IGNORE), DEFVAL(true)); - ClassDB::bind_method(D_METHOD("set_parameter","name","value"), &AnimationNode::set_parameter); - ClassDB::bind_method(D_METHOD("get_parameter","name"), &AnimationNode::get_parameter); + ClassDB::bind_method(D_METHOD("set_parameter", "name", "value"), &AnimationNode::set_parameter); + ClassDB::bind_method(D_METHOD("get_parameter", "name"), &AnimationNode::get_parameter); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "filter_enabled", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_filter_enabled", "is_filter_enabled"); ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "filters", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL), "_set_filters", "_get_filters"); @@ -398,16 +390,16 @@ AnimationNode::AnimationNode() { void AnimationTree::set_tree_root(const Ref<AnimationNode> &p_root) { if (root.is_valid()) { - root->disconnect("tree_changed",this,"_tree_changed"); + root->disconnect("tree_changed", this, "_tree_changed"); } root = p_root; if (root.is_valid()) { - root->connect("tree_changed",this,"_tree_changed"); + root->connect("tree_changed", this, "_tree_changed"); } - properties_dirty=true; + properties_dirty = true; update_configuration_warning(); } @@ -738,11 +730,11 @@ void AnimationTree::_process_graph(float p_delta) { if (started) { //if started, seek - root->_pre_process(SceneStringNames::get_singleton()->parameters_base_path,NULL,&state, 0, true,Vector<StringName>()); + root->_pre_process(SceneStringNames::get_singleton()->parameters_base_path, NULL, &state, 0, true, Vector<StringName>()); started = false; } - root->_pre_process(SceneStringNames::get_singleton()->parameters_base_path,NULL,&state, p_delta, false,Vector<StringName>()); + root->_pre_process(SceneStringNames::get_singleton()->parameters_base_path, NULL, &state, p_delta, false, Vector<StringName>()); } if (!state.valid) { @@ -1284,27 +1276,27 @@ void AnimationTree::_tree_changed() { } call_deferred("_update_properties"); - properties_dirty=true; + properties_dirty = true; } -void AnimationTree::_update_properties_for_node(const String& p_base_path,Ref<AnimationNode> node) { +void AnimationTree::_update_properties_for_node(const String &p_base_path, Ref<AnimationNode> node) { if (!property_parent_map.has(p_base_path)) { - property_parent_map[p_base_path]=HashMap<StringName, StringName>(); + property_parent_map[p_base_path] = HashMap<StringName, StringName>(); } List<PropertyInfo> plist; node->get_parameter_list(&plist); - for(List<PropertyInfo>::Element *E=plist.front();E;E=E->next()) { + for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) { PropertyInfo pinfo = E->get(); StringName key = pinfo.name; - if (!property_map.has(p_base_path +key)) { + if (!property_map.has(p_base_path + key)) { property_map[p_base_path + key] = node->get_parameter_default_value(key); } - property_parent_map[p_base_path][key]=p_base_path+key; + property_parent_map[p_base_path][key] = p_base_path + key; pinfo.name = p_base_path + key; properties.push_back(pinfo); @@ -1313,8 +1305,8 @@ void AnimationTree::_update_properties_for_node(const String& p_base_path,Ref<An List<AnimationNode::ChildNode> children; node->get_child_nodes(&children); - for (List<AnimationNode::ChildNode>::Element *E=children.front();E;E=E->next()) { - _update_properties_for_node(p_base_path+E->get().name+"/",E->get().node); + for (List<AnimationNode::ChildNode>::Element *E = children.front(); E; E = E->next()) { + _update_properties_for_node(p_base_path + E->get().name + "/", E->get().node); } } @@ -1327,7 +1319,7 @@ void AnimationTree::_update_properties() { property_parent_map.clear(); if (root.is_valid()) { - _update_properties_for_node(SceneStringNames::get_singleton()->parameters_base_path,root); + _update_properties_for_node(SceneStringNames::get_singleton()->parameters_base_path, root); } properties_dirty = false; @@ -1341,7 +1333,7 @@ bool AnimationTree::_set(const StringName &p_name, const Variant &p_value) { } if (property_map.has(p_name)) { - property_map[p_name]=p_value; + property_map[p_name] = p_value; #ifdef TOOLS_ENABLED _change_notify(p_name.operator String().utf8().get_data()); #endif @@ -1353,39 +1345,38 @@ bool AnimationTree::_set(const StringName &p_name, const Variant &p_value) { bool AnimationTree::_get(const StringName &p_name, Variant &r_ret) const { if (properties_dirty) { - const_cast<AnimationTree*>(this)->_update_properties(); + const_cast<AnimationTree *>(this)->_update_properties(); } if (property_map.has(p_name)) { - r_ret=property_map[p_name]; + r_ret = property_map[p_name]; return true; } return false; - } void AnimationTree::_get_property_list(List<PropertyInfo> *p_list) const { if (properties_dirty) { - const_cast<AnimationTree*>(this)->_update_properties(); + const_cast<AnimationTree *>(this)->_update_properties(); } - for (const List<PropertyInfo>::Element *E=properties.front();E;E=E->next()) { + for (const List<PropertyInfo>::Element *E = properties.front(); E; E = E->next()) { p_list->push_back(E->get()); } } -void AnimationTree::rename_parameter(const String& p_base,const String& p_new_base) { +void AnimationTree::rename_parameter(const String &p_base, const String &p_new_base) { //rename values first - for (const List<PropertyInfo>::Element *E=properties.front();E;E=E->next()) { + for (const List<PropertyInfo>::Element *E = properties.front(); E; E = E->next()) { if (E->get().name.begins_with(p_base)) { - String new_name = E->get().name.replace_first(p_base,p_new_base); - property_map[new_name]=property_map[E->get().name]; + String new_name = E->get().name.replace_first(p_base, p_new_base); + property_map[new_name] = property_map[E->get().name]; } } //update tree second - properties_dirty=true; + properties_dirty = true; _update_properties(); } @@ -1410,8 +1401,7 @@ void AnimationTree::_bind_methods() { ClassDB::bind_method(D_METHOD("_tree_changed"), &AnimationTree::_tree_changed); ClassDB::bind_method(D_METHOD("_update_properties"), &AnimationTree::_update_properties); - ClassDB::bind_method(D_METHOD("rename_parameter","old_name","new_name"), &AnimationTree::rename_parameter); - + ClassDB::bind_method(D_METHOD("rename_parameter", "old_name", "new_name"), &AnimationTree::rename_parameter); ClassDB::bind_method(D_METHOD("advance", "delta"), &AnimationTree::advance); @@ -1440,5 +1430,4 @@ AnimationTree::AnimationTree() { } AnimationTree::~AnimationTree() { - } |