diff options
Diffstat (limited to 'scene/animation')
-rw-r--r-- | scene/animation/animation_blend_space_2d.cpp | 18 | ||||
-rw-r--r-- | scene/animation/animation_blend_tree.cpp | 21 | ||||
-rw-r--r-- | scene/animation/animation_cache.cpp | 30 | ||||
-rw-r--r-- | scene/animation/animation_node_state_machine.cpp | 9 | ||||
-rw-r--r-- | scene/animation/animation_player.cpp | 174 | ||||
-rw-r--r-- | scene/animation/animation_player.h | 5 | ||||
-rw-r--r-- | scene/animation/animation_tree.cpp | 39 | ||||
-rw-r--r-- | scene/animation/tween.cpp | 197 |
8 files changed, 318 insertions, 175 deletions
diff --git a/scene/animation/animation_blend_space_2d.cpp b/scene/animation/animation_blend_space_2d.cpp index 436ff553ec..003a4fad90 100644 --- a/scene/animation/animation_blend_space_2d.cpp +++ b/scene/animation/animation_blend_space_2d.cpp @@ -171,8 +171,9 @@ bool AnimationNodeBlendSpace2D::has_triangle(int p_x, int p_y, int p_z) const { break; } } - if (all_equal) + if (all_equal) { return true; + } } return false; @@ -290,8 +291,9 @@ void AnimationNodeBlendSpace2D::_add_blend_point(int p_index, const Ref<Animatio } void AnimationNodeBlendSpace2D::_set_triangles(const Vector<int> &p_triangles) { - if (auto_triangles) + if (auto_triangles) { return; + } ERR_FAIL_COND(p_triangles.size() % 3 != 0); for (int i = 0; i < p_triangles.size(); i += 3) { add_triangle(p_triangles[i + 0], p_triangles[i + 1], p_triangles[i + 2]); @@ -300,8 +302,9 @@ void AnimationNodeBlendSpace2D::_set_triangles(const Vector<int> &p_triangles) { Vector<int> AnimationNodeBlendSpace2D::_get_triangles() const { Vector<int> t; - if (auto_triangles && trianges_dirty) + if (auto_triangles && trianges_dirty) { return t; + } t.resize(triangles.size() * 3); for (int i = 0; i < triangles.size(); i++) { @@ -322,8 +325,9 @@ void AnimationNodeBlendSpace2D::_queue_auto_triangles() { } void AnimationNodeBlendSpace2D::_update_triangles() { - if (!auto_triangles || !trianges_dirty) + if (!auto_triangles || !trianges_dirty) { return; + } trianges_dirty = false; triangles.clear(); @@ -349,8 +353,9 @@ void AnimationNodeBlendSpace2D::_update_triangles() { Vector2 AnimationNodeBlendSpace2D::get_closest_point(const Vector2 &p_point) { _update_triangles(); - if (triangles.size() == 0) + if (triangles.size() == 0) { return Vector2(); + } Vector2 best_point; bool first = true; @@ -435,8 +440,9 @@ float AnimationNodeBlendSpace2D::process(float p_time, bool p_seek) { float mind = 0; //time of min distance point if (blend_mode == BLEND_MODE_INTERPOLATED) { - if (triangles.size() == 0) + if (triangles.size() == 0) { return 0; + } Vector2 best_point; bool first = true; diff --git a/scene/animation/animation_blend_tree.cpp b/scene/animation/animation_blend_tree.cpp index 2fa9aaa4da..56995c0c13 100644 --- a/scene/animation/animation_blend_tree.cpp +++ b/scene/animation/animation_blend_tree.cpp @@ -235,8 +235,9 @@ float AnimationNodeOneShot::process(float p_time, bool p_seek) { bool os_seek = p_seek; - if (p_seek) + if (p_seek) { time = p_time; + } bool do_start = !prev_active; if (do_start) { @@ -248,18 +249,21 @@ float AnimationNodeOneShot::process(float p_time, bool p_seek) { float blend; if (time < fade_in) { - if (fade_in > 0) + if (fade_in > 0) { blend = time / fade_in; - else + } else { blend = 0; //wtf + } } else if (!do_start && remaining < fade_out) { - if (fade_out) + if (fade_out) { blend = (remaining / fade_out); - else + } else { blend = 1.0; - } else + } + } else { blend = 1.0; + } float main_rem; if (mix == MIX_MODE_ADD) { @@ -730,10 +734,11 @@ float AnimationNodeTransition::process(float p_time, bool p_seek) { rem = blend_input(current, p_time, p_seek, 1.0, FILTER_IGNORE, false); - if (p_seek) + if (p_seek) { time = p_time; - else + } else { time += p_time; + } if (inputs[current].auto_advance && rem <= xfade) { set_parameter(this->current, (current + 1) % enabled_inputs); diff --git a/scene/animation/animation_cache.cpp b/scene/animation/animation_cache.cpp index 1eea73fab8..abb2cf1b65 100644 --- a/scene/animation/animation_cache.cpp +++ b/scene/animation/animation_cache.cpp @@ -38,8 +38,9 @@ void AnimationCache::_node_exit_tree(Node *p_node) { connected_nodes.erase(p_node); for (int i = 0; i < path_cache.size(); i++) { - if (path_cache[i].node != p_node) + if (path_cache[i].node != p_node) { continue; + } path_cache.write[i].valid = false; //invalidate path cache } @@ -167,14 +168,16 @@ void AnimationCache::_update_cache() { } void AnimationCache::set_track_transform(int p_idx, const Transform &p_transform) { - if (cache_dirty) + if (cache_dirty) { _update_cache(); + } ERR_FAIL_COND(!cache_valid); ERR_FAIL_INDEX(p_idx, path_cache.size()); Path &p = path_cache.write[p_idx]; - if (!p.valid) + if (!p.valid) { return; + } ERR_FAIL_COND(!p.node); ERR_FAIL_COND(!p.spatial); @@ -187,36 +190,41 @@ void AnimationCache::set_track_transform(int p_idx, const Transform &p_transform } void AnimationCache::set_track_value(int p_idx, const Variant &p_value) { - if (cache_dirty) + if (cache_dirty) { _update_cache(); + } ERR_FAIL_COND(!cache_valid); ERR_FAIL_INDEX(p_idx, path_cache.size()); Path &p = path_cache.write[p_idx]; - if (!p.valid) + if (!p.valid) { return; + } ERR_FAIL_COND(!p.object); p.object->set_indexed(p.subpath, p_value); } void AnimationCache::call_track(int p_idx, const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error) { - if (cache_dirty) + if (cache_dirty) { _update_cache(); + } ERR_FAIL_COND(!cache_valid); ERR_FAIL_INDEX(p_idx, path_cache.size()); Path &p = path_cache.write[p_idx]; - if (!p.valid) + if (!p.valid) { return; + } ERR_FAIL_COND(!p.object); p.object->call(p_method, p_args, p_argcount, r_error); } void AnimationCache::set_all(float p_time, float p_delta) { - if (cache_dirty) + if (cache_dirty) { _update_cache(); + } ERR_FAIL_COND(!cache_valid); @@ -280,13 +288,15 @@ void AnimationCache::set_all(float p_time, float p_delta) { void AnimationCache::set_animation(const Ref<Animation> &p_animation) { _clear_cache(); - if (animation.is_valid()) + if (animation.is_valid()) { animation->disconnect("changed", callable_mp(this, &AnimationCache::_animation_changed)); + } animation = p_animation; - if (animation.is_valid()) + if (animation.is_valid()) { animation->connect("changed", callable_mp(this, &AnimationCache::_animation_changed)); + } } void AnimationCache::_bind_methods() { diff --git a/scene/animation/animation_node_state_machine.cpp b/scene/animation/animation_node_state_machine.cpp index 7c4f84b373..17ce05f130 100644 --- a/scene/animation/animation_node_state_machine.cpp +++ b/scene/animation/animation_node_state_machine.cpp @@ -186,8 +186,9 @@ bool AnimationNodeStateMachinePlayback::_travel(AnimationNodeStateMachine *p_sta path.clear(); //a new one will be needed - if (current == p_travel) + if (current == p_travel) { return true; //nothing to do + } loops_current = 0; // reset loops, so fade does not happen immediately @@ -698,16 +699,18 @@ void AnimationNodeStateMachine::get_node_list(List<StringName> *r_nodes) const { bool AnimationNodeStateMachine::has_transition(const StringName &p_from, const StringName &p_to) const { for (int i = 0; i < transitions.size(); i++) { - if (transitions[i].from == p_from && transitions[i].to == p_to) + if (transitions[i].from == p_from && transitions[i].to == p_to) { return true; + } } return false; } int AnimationNodeStateMachine::find_transition(const StringName &p_from, const StringName &p_to) const { for (int i = 0; i < transitions.size(); i++) { - if (transitions[i].from == p_from && transitions[i].to == p_to) + if (transitions[i].from == p_from && transitions[i].to == p_to) { return i; + } } return -1; } diff --git a/scene/animation/animation_player.cpp b/scene/animation/animation_player.cpp index b8d7cbc823..4e56f1acf0 100644 --- a/scene/animation/animation_player.cpp +++ b/scene/animation/animation_player.cpp @@ -83,8 +83,9 @@ bool AnimationPlayer::_set(const StringName &p_name, const Variant &p_value) { set_blend_time(from, to, time); } - } else + } else { return false; + } return true; } @@ -119,8 +120,9 @@ bool AnimationPlayer::_get(const StringName &p_name, Variant &r_ret) const { } r_ret = array; - } else + } else { return false; + } return true; } @@ -136,8 +138,9 @@ void AnimationPlayer::_validate_property(PropertyInfo &property) const { names.push_front("[stop]"); String hint; for (List<String>::Element *E = names.front(); E; E = E->next()) { - if (E != names.front()) + if (E != names.front()) { hint += ","; + } hint += E->get(); } @@ -150,8 +153,9 @@ void AnimationPlayer::_get_property_list(List<PropertyInfo> *p_list) const { for (Map<StringName, AnimationData>::Element *E = animation_set.front(); E; E = E->next()) { anim_names.push_back(PropertyInfo(Variant::OBJECT, "anims/" + String(E->key()), PROPERTY_HINT_RESOURCE_TYPE, "Animation", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_DO_NOT_SHARE_ON_DUPLICATE)); - if (E->get().next != StringName()) + if (E->get().next != StringName()) { anim_names.push_back(PropertyInfo(Variant::STRING, "next/" + String(E->key()), PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL)); + } } anim_names.sort(); @@ -186,18 +190,22 @@ void AnimationPlayer::_notification(int p_what) { } } break; case NOTIFICATION_INTERNAL_PROCESS: { - if (animation_process_mode == ANIMATION_PROCESS_PHYSICS) + if (animation_process_mode == ANIMATION_PROCESS_PHYSICS) { break; + } - if (processing) + if (processing) { _animation_process(get_process_delta_time()); + } } break; case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: { - if (animation_process_mode == ANIMATION_PROCESS_IDLE) + if (animation_process_mode == ANIMATION_PROCESS_IDLE) { break; + } - if (processing) + if (processing) { _animation_process(get_physics_process_delta_time()); + } } break; case NOTIFICATION_EXIT_TREE: { clear_caches(); @@ -207,8 +215,9 @@ void AnimationPlayer::_notification(int p_what) { void AnimationPlayer::_ensure_node_caches(AnimationData *p_anim) { // Already cached? - if (p_anim->node_cache.size() == p_anim->animation->get_track_count()) + if (p_anim->node_cache.size() == p_anim->animation->get_track_count()) { return; + } Node *parent = get_node(root); @@ -236,16 +245,18 @@ void AnimationPlayer::_ensure_node_caches(AnimationData *p_anim) { } { - if (!child->is_connected("tree_exiting", callable_mp(this, &AnimationPlayer::_node_removed))) + if (!child->is_connected("tree_exiting", callable_mp(this, &AnimationPlayer::_node_removed))) { child->connect("tree_exiting", callable_mp(this, &AnimationPlayer::_node_removed), make_binds(child), CONNECT_ONESHOT); + } } TrackNodeCacheKey key; key.id = id; key.bone_idx = bone_idx; - if (!node_cache_map.has(key)) + if (!node_cache_map.has(key)) { node_cache_map[key] = TrackNodeCache(); + } p_anim->node_cache.write[i] = &node_cache_map[key]; p_anim->node_cache[i]->path = a->track_get_path(i); @@ -285,12 +296,13 @@ void AnimationPlayer::_ensure_node_caches(AnimationData *p_anim) { pa.special = SP_NONE; pa.owner = p_anim->node_cache[i]; if (false && p_anim->node_cache[i]->node_2d) { - if (leftover_path.size() == 1 && leftover_path[0] == SceneStringNames::get_singleton()->transform_pos) + if (leftover_path.size() == 1 && leftover_path[0] == SceneStringNames::get_singleton()->transform_pos) { pa.special = SP_NODE2D_POS; - else if (leftover_path.size() == 1 && leftover_path[0] == SceneStringNames::get_singleton()->transform_rot) + } else if (leftover_path.size() == 1 && leftover_path[0] == SceneStringNames::get_singleton()->transform_rot) { pa.special = SP_NODE2D_ROT; - else if (leftover_path.size() == 1 && leftover_path[0] == SceneStringNames::get_singleton()->transform_scale) + } else if (leftover_path.size() == 1 && leftover_path[0] == SceneStringNames::get_singleton()->transform_scale) { pa.special = SP_NODE2D_SCALE; + } } p_anim->node_cache[i]->property_anim[a->track_get_path(i).get_concatenated_subnames()] = pa; } @@ -325,19 +337,23 @@ void AnimationPlayer::_animation_process_animation(AnimationData *p_anim, float TrackNodeCache *nc = p_anim->node_cache[i]; - if (!nc) + if (!nc) { continue; // no node cache for this track, skip it + } - if (!a->track_is_enabled(i)) + if (!a->track_is_enabled(i)) { continue; // do nothing if the track is disabled + } - if (a->track_get_key_count(i) == 0) + if (a->track_get_key_count(i) == 0) { continue; // do nothing if track is empty + } switch (a->track_get_type(i)) { case Animation::TYPE_TRANSFORM: { - if (!nc->spatial) + if (!nc->spatial) { continue; + } Vector3 loc; Quat rot; @@ -346,8 +362,9 @@ void AnimationPlayer::_animation_process_animation(AnimationData *p_anim, float Error err = a->transform_track_interpolate(i, p_time, &loc, &rot, &scale); //ERR_CONTINUE(err!=OK); //used for testing, should be removed - if (err != OK) + if (err != OK) { continue; + } if (nc->accum_pass != accum_pass) { ERR_CONTINUE(cache_update_size >= NODE_CACHE_UPDATE_MAX); @@ -365,8 +382,9 @@ void AnimationPlayer::_animation_process_animation(AnimationData *p_anim, float } break; case Animation::TYPE_VALUE: { - if (!nc->node) + if (!nc->node) { continue; + } //StringName property=a->track_get_path(i).get_property(); @@ -383,8 +401,9 @@ void AnimationPlayer::_animation_process_animation(AnimationData *p_anim, float } int key_count = a->track_get_key_count(i); - if (key_count == 0) + if (key_count == 0) { continue; //eeh not worth it + } float first_key_time = a->track_get_key_time(i, 0); float transition = 1.0; @@ -392,8 +411,9 @@ void AnimationPlayer::_animation_process_animation(AnimationData *p_anim, float if (first_key_time == 0.0) { //ignore, use for transition - if (key_count == 1) + if (key_count == 1) { continue; //with one key we can't do anything + } transition = a->track_get_key_transition(i, 0); first_key_time = a->track_get_key_time(i, 1); first_key = 1; @@ -422,8 +442,9 @@ void AnimationPlayer::_animation_process_animation(AnimationData *p_anim, float Variant value = a->value_track_interpolate(i, p_time); - if (value == Variant()) + if (value == Variant()) { continue; + } //thanks to trigger mode, this should be solved now.. /* @@ -488,13 +509,15 @@ void AnimationPlayer::_animation_process_animation(AnimationData *p_anim, float } break; case Animation::TYPE_METHOD: { - if (!nc->node) + if (!nc->node) { continue; + } if (p_delta == 0) { continue; } - if (!p_is_current) + if (!p_is_current) { break; + } List<int> indices; @@ -537,8 +560,9 @@ void AnimationPlayer::_animation_process_animation(AnimationData *p_anim, float } break; case Animation::TYPE_BEZIER: { - if (!nc->node) + if (!nc->node) { continue; + } Map<StringName, TrackNodeCache::BezierAnim>::Element *E = nc->bezier_anim.find(a->track_get_path(i).get_concatenated_subnames()); ERR_CONTINUE(!E); //should it continue, or create a new one? @@ -557,8 +581,9 @@ void AnimationPlayer::_animation_process_animation(AnimationData *p_anim, float } break; case Animation::TYPE_AUDIO: { - if (!nc->node) + if (!nc->node) { continue; + } if (p_delta == 0) { continue; } @@ -566,8 +591,9 @@ void AnimationPlayer::_animation_process_animation(AnimationData *p_anim, float if (p_seeked) { //find whathever should be playing int idx = a->track_find_key(i, p_time); - if (idx < 0) + if (idx < 0) { continue; + } Ref<AudioStream> stream = a->audio_track_get_key_stream(i, idx); if (!stream.is_valid()) { @@ -658,20 +684,23 @@ void AnimationPlayer::_animation_process_animation(AnimationData *p_anim, float } break; case Animation::TYPE_ANIMATION: { AnimationPlayer *player = Object::cast_to<AnimationPlayer>(nc->node); - if (!player) + if (!player) { continue; + } if (p_delta == 0 || p_seeked) { //seek int idx = a->track_find_key(i, p_time); - if (idx < 0) + if (idx < 0) { continue; + } float pos = a->track_get_key_time(i, idx); StringName anim_name = a->animation_track_get_key_animation(i, idx); - if (String(anim_name) == "[stop]" || !player->has_animation(anim_name)) + if (String(anim_name) == "[stop]" || !player->has_animation(anim_name)) { continue; + } Ref<Animation> anim = player->get_animation(anim_name); @@ -727,10 +756,11 @@ void AnimationPlayer::_animation_process_data(PlaybackData &cd, float p_delta, f bool loop = cd.from->animation->has_loop(); if (!loop) { - if (next_pos < 0) + if (next_pos < 0) { next_pos = 0; - else if (next_pos > len) + } else if (next_pos > len) { next_pos = len; + } // fix delta delta = next_pos - cd.pos; @@ -887,14 +917,16 @@ void AnimationPlayer::_animation_process(float p_delta) { play(queued.front()->get()); String new_name = playback.assigned; queued.pop_front(); - if (end_notify) + if (end_notify) { emit_signal(SceneStringNames::get_singleton()->animation_changed, old, new_name); + } } else { //stop(); playing = false; _set_process(false); - if (end_notify) + if (end_notify) { emit_signal(SceneStringNames::get_singleton()->animation_finished, playback.assigned); + } } end_reached = false; } @@ -988,8 +1020,9 @@ void AnimationPlayer::rename_animation(const StringName &p_name, const StringNam to_insert.erase(to_insert.front()); } - if (autoplay == p_name) + if (autoplay == p_name) { autoplay = p_new_name; + } clear_caches(); _change_notify(); @@ -1027,10 +1060,11 @@ void AnimationPlayer::set_blend_time(const StringName &p_animation1, const Strin BlendKey bk; bk.from = p_animation1; bk.to = p_animation2; - if (p_time == 0) + if (p_time == 0) { blend_times.erase(bk); - else + } else { blend_times[bk] = p_time; + } } float AnimationPlayer::get_blend_time(const StringName &p_animation1, const StringName &p_animation2) const { @@ -1038,17 +1072,19 @@ float AnimationPlayer::get_blend_time(const StringName &p_animation1, const Stri bk.from = p_animation1; bk.to = p_animation2; - if (blend_times.has(bk)) + if (blend_times.has(bk)) { return blend_times[bk]; - else + } else { return 0; + } } void AnimationPlayer::queue(const StringName &p_name) { - if (!is_playing()) + if (!is_playing()) { play(p_name); - else + } else { queued.push_back(p_name); + } } Vector<String> AnimationPlayer::get_queue() { @@ -1071,8 +1107,9 @@ 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) { StringName name = p_name; - if (String(name) == "") + if (String(name) == "") { name = playback.assigned; + } ERR_FAIL_COND_MSG(!animation_set.has(name), "Animation not found: " + name + "."); @@ -1103,8 +1140,9 @@ void AnimationPlayer::play(const StringName &p_name, float p_custom_blend, float } } - if (p_custom_blend < 0 && blend_time == 0 && default_blend_time) + if (p_custom_blend < 0 && blend_time == 0 && default_blend_time) { blend_time = default_blend_time; + } if (blend_time > 0) { Blend b; b.data = c.current; @@ -1136,15 +1174,17 @@ void AnimationPlayer::play(const StringName &p_name, float p_custom_blend, float c.seeked = false; c.started = true; - if (!end_reached) + if (!end_reached) { queued.clear(); + } _set_process(true); // always process when starting an animation playing = true; emit_signal(SceneStringNames::get_singleton()->animation_started, c.assigned); - if (is_inside_tree() && Engine::get_singleton()->is_editor_hint()) + if (is_inside_tree() && Engine::get_singleton()->is_editor_hint()) { return; // no next in this case + } StringName next = animation_get_next(p_name); if (next != StringName() && animation_set.has(next)) { @@ -1240,8 +1280,9 @@ void AnimationPlayer::seek_delta(float p_time, float p_delta) { } playback.current.pos = p_time - p_delta; - if (speed_scale != 0.0) + if (speed_scale != 0.0) { p_delta /= speed_scale; + } _animation_process(p_delta); //playback.current.pos=p_time; } @@ -1275,8 +1316,9 @@ void AnimationPlayer::_stop_playing_caches() { } if (E->get()->node && E->get()->animation_playing) { AnimationPlayer *player = Object::cast_to<AnimationPlayer>(E->get()->node); - if (!player) + if (!player) { continue; + } player->stop(); } } @@ -1303,8 +1345,9 @@ void AnimationPlayer::clear_caches() { } void AnimationPlayer::set_active(bool p_active) { - if (active == p_active) + if (active == p_active) { return; + } active = p_active; _set_process(processing, true); @@ -1316,16 +1359,18 @@ bool AnimationPlayer::is_active() const { StringName AnimationPlayer::find_animation(const Ref<Animation> &p_animation) const { for (Map<StringName, AnimationData>::Element *E = animation_set.front(); E; E = E->next()) { - if (E->get().animation == p_animation) + if (E->get().animation == p_animation) { return E->key(); + } } return ""; } void AnimationPlayer::set_autoplay(const String &p_name) { - if (is_inside_tree() && !Engine::get_singleton()->is_editor_hint()) + if (is_inside_tree() && !Engine::get_singleton()->is_editor_hint()) { WARN_PRINT("Setting autoplay after the node has been added to the scene has no effect."); + } autoplay = p_name; } @@ -1335,15 +1380,18 @@ String AnimationPlayer::get_autoplay() const { } void AnimationPlayer::set_animation_process_mode(AnimationProcessMode p_mode) { - if (animation_process_mode == p_mode) + if (animation_process_mode == p_mode) { return; + } bool pr = processing; - if (pr) + if (pr) { _set_process(false); + } animation_process_mode = p_mode; - if (pr) + if (pr) { _set_process(true); + } } AnimationPlayer::AnimationProcessMode AnimationPlayer::get_animation_process_mode() const { @@ -1359,8 +1407,9 @@ AnimationPlayer::AnimationMethodCallMode AnimationPlayer::get_method_call_mode() } void AnimationPlayer::_set_process(bool p_process, bool p_force) { - if (processing == p_process && !p_force) + if (processing == p_process && !p_force) { return; + } switch (animation_process_mode) { case ANIMATION_PROCESS_PHYSICS: @@ -1382,8 +1431,9 @@ void AnimationPlayer::animation_set_next(const StringName &p_animation, const St } StringName AnimationPlayer::animation_get_next(const StringName &p_animation) const { - if (!animation_set.has(p_animation)) + if (!animation_set.has(p_animation)) { return StringName(); + } return animation_set[p_animation].next; } @@ -1424,8 +1474,9 @@ void AnimationPlayer::get_argument_options(const StringName &p_function, int p_i #ifdef TOOLS_ENABLED AnimatedValuesBackup AnimationPlayer::backup_animated_values() { - if (!playback.current.from) + if (!playback.current.from) { return AnimatedValuesBackup(); + } _ensure_node_caches(playback.current.from); @@ -1433,12 +1484,14 @@ AnimatedValuesBackup AnimationPlayer::backup_animated_values() { for (int i = 0; i < playback.current.from->node_cache.size(); i++) { TrackNodeCache *nc = playback.current.from->node_cache[i]; - if (!nc) + if (!nc) { continue; + } if (nc->skeleton) { - if (nc->bone_idx == -1) + if (nc->bone_idx == -1) { continue; + } AnimatedValuesBackup::Entry entry; entry.object = nc->skeleton; @@ -1461,8 +1514,9 @@ AnimatedValuesBackup AnimationPlayer::backup_animated_values() { bool valid; entry.value = E->value().object->get_indexed(E->value().subpath, &valid); entry.bone_idx = -1; - if (valid) + if (valid) { backup.entries.push_back(entry); + } } } } diff --git a/scene/animation/animation_player.h b/scene/animation/animation_player.h index c7b3d7fc7b..1a66665803 100644 --- a/scene/animation/animation_player.h +++ b/scene/animation/animation_player.h @@ -140,10 +140,11 @@ private: int bone_idx; inline bool operator<(const TrackNodeCacheKey &p_right) const { - if (id == p_right.id) + if (id == p_right.id) { return bone_idx < p_right.bone_idx; - else + } else { return id < p_right.id; + } } }; diff --git a/scene/animation/animation_tree.cpp b/scene/animation/animation_tree.cpp index 671c87eb58..466536db10 100644 --- a/scene/animation/animation_tree.cpp +++ b/scene/animation/animation_tree.cpp @@ -210,8 +210,9 @@ float AnimationNode::_blend_node(const StringName &p_subpath, const Vector<Strin case FILTER_PASS: { //values filtered pass, the rest don't for (int i = 0; i < blend_count; i++) { - if (blendw[i] == 0) //not filtered, does not pass + if (blendw[i] == 0) { //not filtered, does not pass continue; + } blendw[i] = blendr[i] * p_blend; if (blendw[i] > CMP_EPSILON) { @@ -224,8 +225,9 @@ float AnimationNode::_blend_node(const StringName &p_subpath, const Vector<Strin //values filtered don't pass, the rest are blended for (int i = 0; i < blend_count; i++) { - if (blendw[i] > 0) //filtered, does not pass + if (blendw[i] > 0) { //filtered, does not pass continue; + } blendw[i] = blendr[i] * p_blend; if (blendw[i] > CMP_EPSILON) { @@ -268,8 +270,9 @@ float AnimationNode::_blend_node(const StringName &p_subpath, const Vector<Strin } } - if (!p_seek && p_optimize && !any_valid) //pointless to go on, all are zero + if (!p_seek && p_optimize && !any_valid) { //pointless to go on, all are zero return 0; + } String new_path; AnimationNode *new_parent; @@ -467,8 +470,9 @@ Ref<AnimationNode> AnimationTree::get_tree_root() const { } void AnimationTree::set_active(bool p_active) { - if (active == p_active) + if (active == p_active) { return; + } active = p_active; started = active; @@ -495,8 +499,9 @@ bool AnimationTree::is_active() const { } void AnimationTree::set_process_mode(AnimationProcessMode p_mode) { - if (process_mode == p_mode) + if (process_mode == p_mode) { return; + } bool was_active = is_active(); if (was_active) { @@ -837,8 +842,9 @@ void AnimationTree::_process_graph(float p_delta) { float blend = (*as.track_blends)[blend_idx]; - if (blend < CMP_EPSILON) + if (blend < CMP_EPSILON) { continue; //nothing to blend + } switch (track->type) { case Animation::TYPE_TRANSFORM: { @@ -912,8 +918,9 @@ void AnimationTree::_process_graph(float p_delta) { t->scale = scale; } - if (err != OK) + if (err != OK) { continue; + } t->loc = t->loc.lerp(loc, blend); if (t->rot_blend_accum == 0) { @@ -937,8 +944,9 @@ void AnimationTree::_process_graph(float p_delta) { Variant value = a->value_track_interpolate(i, time); - if (value == Variant()) + if (value == Variant()) { continue; + } if (t->process_pass != process_pass) { t->value = value; @@ -1006,8 +1014,9 @@ void AnimationTree::_process_graph(float p_delta) { if (seeked) { //find whathever should be playing int idx = a->track_find_key(i, time); - if (idx < 0) + if (idx < 0) { continue; + } Ref<AudioStream> stream = a->audio_track_get_key_stream(i, idx); if (!stream.is_valid()) { @@ -1107,20 +1116,23 @@ void AnimationTree::_process_graph(float p_delta) { AnimationPlayer *player2 = Object::cast_to<AnimationPlayer>(t->object); - if (!player2) + if (!player2) { continue; + } if (delta == 0 || seeked) { //seek int idx = a->track_find_key(i, time); - if (idx < 0) + if (idx < 0) { continue; + } float pos = a->track_get_key_time(i, idx); StringName anim_name = a->animation_track_get_key_animation(i, idx); - if (String(anim_name) == "[stop]" || !player2->has_animation(anim_name)) + if (String(anim_name) == "[stop]" || !player2->has_animation(anim_name)) { continue; + } Ref<Animation> anim = player2->get_animation(anim_name); @@ -1174,8 +1186,9 @@ void AnimationTree::_process_graph(float p_delta) { const NodePath *K = nullptr; while ((K = track_cache.next(K))) { TrackCache *track = track_cache[*K]; - if (track->process_pass != process_pass) + if (track->process_pass != process_pass) { continue; //not processed, ignore + } switch (track->type) { case Animation::TYPE_TRANSFORM: { diff --git a/scene/animation/tween.cpp b/scene/animation/tween.cpp index d94cbfa08c..854db5fee2 100644 --- a/scene/animation/tween.cpp +++ b/scene/animation/tween.cpp @@ -42,50 +42,61 @@ void Tween::_add_pending_command(StringName p_key, const Variant &p_arg1, const // Determine command argument count int &count = cmd.args; - if (p_arg10.get_type() != Variant::NIL) + if (p_arg10.get_type() != Variant::NIL) { count = 10; - else if (p_arg9.get_type() != Variant::NIL) + } else if (p_arg9.get_type() != Variant::NIL) { count = 9; - else if (p_arg8.get_type() != Variant::NIL) + } else if (p_arg8.get_type() != Variant::NIL) { count = 8; - else if (p_arg7.get_type() != Variant::NIL) + } else if (p_arg7.get_type() != Variant::NIL) { count = 7; - else if (p_arg6.get_type() != Variant::NIL) + } else if (p_arg6.get_type() != Variant::NIL) { count = 6; - else if (p_arg5.get_type() != Variant::NIL) + } else if (p_arg5.get_type() != Variant::NIL) { count = 5; - else if (p_arg4.get_type() != Variant::NIL) + } else if (p_arg4.get_type() != Variant::NIL) { count = 4; - else if (p_arg3.get_type() != Variant::NIL) + } else if (p_arg3.get_type() != Variant::NIL) { count = 3; - else if (p_arg2.get_type() != Variant::NIL) + } else if (p_arg2.get_type() != Variant::NIL) { count = 2; - else if (p_arg1.get_type() != Variant::NIL) + } else if (p_arg1.get_type() != Variant::NIL) { count = 1; - else + } else { count = 0; + } // Add the specified arguments to the command - if (count > 0) + if (count > 0) { cmd.arg[0] = p_arg1; - if (count > 1) + } + if (count > 1) { cmd.arg[1] = p_arg2; - if (count > 2) + } + if (count > 2) { cmd.arg[2] = p_arg3; - if (count > 3) + } + if (count > 3) { cmd.arg[3] = p_arg4; - if (count > 4) + } + if (count > 4) { cmd.arg[4] = p_arg5; - if (count > 5) + } + if (count > 5) { cmd.arg[5] = p_arg6; - if (count > 6) + } + if (count > 6) { cmd.arg[6] = p_arg7; - if (count > 7) + } + if (count > 7) { cmd.arg[7] = p_arg8; - if (count > 8) + } + if (count > 8) { cmd.arg[8] = p_arg9; - if (count > 9) + } + if (count > 9) { cmd.arg[9] = p_arg10; + } } void Tween::_process_pending_commands() { @@ -179,26 +190,30 @@ void Tween::_notification(int p_what) { case NOTIFICATION_INTERNAL_PROCESS: { // Are we processing during physics time? - if (tween_process_mode == TWEEN_PROCESS_PHYSICS) + if (tween_process_mode == TWEEN_PROCESS_PHYSICS) { // Do nothing since we aren't aligned with physics when we should be break; + } // Should we update? - if (is_active()) + if (is_active()) { // Update the tweens _tween_process(get_process_delta_time()); + } } break; case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: { // Are we processing during 'regular' time? - if (tween_process_mode == TWEEN_PROCESS_IDLE) + if (tween_process_mode == TWEEN_PROCESS_IDLE) { // Do nothing since we would only process during idle time break; + } // Should we update? - if (is_active()) + if (is_active()) { // Update the tweens _tween_process(get_physics_process_delta_time()); + } } break; case NOTIFICATION_EXIT_TREE: { @@ -346,8 +361,9 @@ Variant Tween::_get_final_val(const InterpolateData &p_data) const { // If we're looking at an INT value, instead convert it to a FLOAT // This is better for interpolation - if (final_val.get_type() == Variant::INT) + if (final_val.get_type() == Variant::INT) { final_val = final_val.operator real_t(); + } return final_val; } @@ -388,8 +404,9 @@ Variant &Tween::_get_delta_val(InterpolateData &p_data) { // If we're looking at an INT value, instead convert it to a FLOAT // This is better for interpolation - if (final_val.get_type() == Variant::INT) + if (final_val.get_type() == Variant::INT) { final_val = final_val.operator real_t(); + } // Calculate the delta based on the initial value and the final value _calc_delta_val(p_data.initial_val, final_val, p_data.delta_val); @@ -403,8 +420,9 @@ Variant &Tween::_get_delta_val(InterpolateData &p_data) { // If we're looking at an INT value, instead convert it to a FLOAT // This is better for interpolation - if (initial_val.get_type() == Variant::INT) + if (initial_val.get_type() == Variant::INT) { initial_val = initial_val.operator real_t(); + } // Calculate the delta based on the initial value and the final value _calc_delta_val(initial_val, p_data.final_val, p_data.delta_val); @@ -652,8 +670,9 @@ void Tween::_tween_process(float p_delta) { _process_pending_commands(); // If the scale is 0, make no progress on the tweens - if (speed_scale == 0) + if (speed_scale == 0) { return; + } // Update the delta and whether we are pending an update p_delta *= speed_scale; @@ -676,8 +695,9 @@ void Tween::_tween_process(float p_delta) { } // If we are all finished, we can reset all of the tweens - if (repeats_finished) + if (repeats_finished) { reset_all(); + } } // Are all of the tweens complete? @@ -692,20 +712,22 @@ void Tween::_tween_process(float p_delta) { all_finished = all_finished && data.finish; // Is the data not active or already finished? No need to go any further - if (!data.active || data.finish) + if (!data.active || data.finish) { continue; + } // Get the target object for this interpolation Object *object = ObjectDB::get_instance(data.id); - if (object == nullptr) + if (object == nullptr) { continue; + } // Are we still delaying this tween? bool prev_delaying = data.elapsed <= data.delay; data.elapsed += p_delta; - if (data.elapsed < data.delay) + if (data.elapsed < data.delay) { continue; - else if (prev_delaying) { + } else if (prev_delaying) { // We can apply the tween's value to the data and emit that the tween has started _apply_tween_value(data, data.initial_val); emit_signal("tween_started", object, NodePath(Vector<StringName>(), data.key, false)); @@ -778,8 +800,9 @@ void Tween::_tween_process(float p_delta) { emit_signal("tween_completed", object, NodePath(Vector<StringName>(), data.key, false)); // If we are not repeating the tween, remove it - if (!repeat) + if (!repeat) { call_deferred("_remove_by_uid", data.uid); + } } else if (!repeat) { // Check whether all tweens are finished all_finished = all_finished && data.finish; @@ -809,8 +832,9 @@ bool Tween::is_active() const { void Tween::set_active(bool p_active) { // Do nothing if it's the same active mode that we currently are - if (is_active() == p_active) + if (is_active() == p_active) { return; + } // Depending on physics or idle, set processing switch (tween_process_mode) { @@ -860,8 +884,9 @@ void Tween::reset(Object *p_object, StringName p_key) { // Get the target object InterpolateData &data = E->get(); Object *object = ObjectDB::get_instance(data.id); - if (object == nullptr) + if (object == nullptr) { continue; + } // Do we have the correct object and key? if (object == p_object && (data.concatenated_key == p_key || p_key == "")) { @@ -870,8 +895,9 @@ void Tween::reset(Object *p_object, StringName p_key) { data.finish = false; // Also apply the initial state if there isn't a delay - if (data.delay == 0) + if (data.delay == 0) { _apply_tween_value(data, data.initial_val); + } } } pending_update--; @@ -887,8 +913,9 @@ void Tween::reset_all() { data.finish = false; // If there isn't a delay, apply the value to the object - if (data.delay == 0) + if (data.delay == 0) { _apply_tween_value(data, data.initial_val); + } } pending_update--; } @@ -900,13 +927,15 @@ void Tween::stop(Object *p_object, StringName p_key) { // Get the object the tween is targeting InterpolateData &data = E->get(); Object *object = ObjectDB::get_instance(data.id); - if (object == nullptr) + if (object == nullptr) { continue; + } // Is this the correct object and does it have the given key? - if (object == p_object && (data.concatenated_key == p_key || p_key == "")) + if (object == p_object && (data.concatenated_key == p_key || p_key == "")) { // Disable the tween data.active = false; + } } pending_update--; } @@ -936,12 +965,14 @@ void Tween::resume(Object *p_object, StringName p_key) { // Grab the object InterpolateData &data = E->get(); Object *object = ObjectDB::get_instance(data.id); - if (object == nullptr) + if (object == nullptr) { continue; + } // If the object and string key match, activate it - if (object == p_object && (data.concatenated_key == p_key || p_key == "")) + if (object == p_object && (data.concatenated_key == p_key || p_key == "")) { data.active = true; + } } pending_update--; } @@ -974,8 +1005,9 @@ void Tween::remove(Object *p_object, StringName p_key) { // Get the target object InterpolateData &data = E->get(); Object *object = ObjectDB::get_instance(data.id); - if (object == nullptr) + if (object == nullptr) { continue; + } // If the target object and string key match, queue it for removal if (object == p_object && (data.concatenated_key == p_key || p_key == "")) { @@ -1076,9 +1108,10 @@ real_t Tween::tell() const { for (const List<InterpolateData>::Element *E = interpolates.front(); E; E = E->next()) { // Get the data and figure out if it's position is further along than the previous ones const InterpolateData &data = E->get(); - if (data.elapsed > pos) + if (data.elapsed > pos) { // Save it if so pos = data.elapsed; + } } pending_update--; return pos; @@ -1098,9 +1131,10 @@ real_t Tween::get_runtime() const { // Get the tween data and see if it's runtime is greater than the previous tweens const InterpolateData &data = E->get(); real_t t = data.delay + data.duration; - if (t > runtime) + if (t > runtime) { // This is the longest running tween runtime = t; + } } pending_update--; @@ -1305,8 +1339,9 @@ void Tween::_build_interpolation(InterpolateType p_interpolation_type, Object *p } // Is there not a valid delta? - if (!_calc_delta_val(data.initial_val, data.final_val, data.delta_val)) + if (!_calc_delta_val(data.initial_val, data.final_val, data.delta_val)) { return; + } // Add this interpolation to the total _push_interpolate_data(data); @@ -1324,14 +1359,17 @@ void Tween::interpolate_property(Object *p_object, NodePath p_property, Variant // If no initial value given, grab the initial value from the object // TODO: Is this documented? This is very useful and removes a lot of clutter from tweens! - if (p_initial_val.get_type() == Variant::NIL) + if (p_initial_val.get_type() == Variant::NIL) { p_initial_val = p_object->get_indexed(p_property.get_subnames()); + } // Convert any integers into REALs as they are better for interpolation - if (p_initial_val.get_type() == Variant::INT) + if (p_initial_val.get_type() == Variant::INT) { p_initial_val = p_initial_val.operator real_t(); - if (p_final_val.get_type() == Variant::INT) + } + if (p_final_val.get_type() == Variant::INT) { p_final_val = p_final_val.operator real_t(); + } // Build the interpolation data _build_interpolation(INTER_PROPERTY, p_object, &p_property, nullptr, p_initial_val, p_final_val, p_duration, p_trans_type, p_ease_type, p_delay); @@ -1345,10 +1383,12 @@ void Tween::interpolate_method(Object *p_object, StringName p_method, Variant p_ } // Convert any integers into REALs as they are better for interpolation - if (p_initial_val.get_type() == Variant::INT) + if (p_initial_val.get_type() == Variant::INT) { p_initial_val = p_initial_val.operator real_t(); - if (p_final_val.get_type() == Variant::INT) + } + if (p_final_val.get_type() == Variant::INT) { p_final_val = p_final_val.operator real_t(); + } // Build the interpolation data _build_interpolation(INTER_METHOD, p_object, nullptr, &p_method, p_initial_val, p_final_val, p_duration, p_trans_type, p_ease_type, p_delay); @@ -1387,18 +1427,19 @@ void Tween::interpolate_callback(Object *p_object, real_t p_duration, String p_c // Add arguments to the interpolation int args = 0; - if (p_arg5.get_type() != Variant::NIL) + if (p_arg5.get_type() != Variant::NIL) { args = 5; - else if (p_arg4.get_type() != Variant::NIL) + } else if (p_arg4.get_type() != Variant::NIL) { args = 4; - else if (p_arg3.get_type() != Variant::NIL) + } else if (p_arg3.get_type() != Variant::NIL) { args = 3; - else if (p_arg2.get_type() != Variant::NIL) + } else if (p_arg2.get_type() != Variant::NIL) { args = 2; - else if (p_arg1.get_type() != Variant::NIL) + } else if (p_arg1.get_type() != Variant::NIL) { args = 1; - else + } else { args = 0; + } data.args = args; data.arg[0] = p_arg1; @@ -1444,18 +1485,19 @@ void Tween::interpolate_deferred_callback(Object *p_object, real_t p_duration, S // Collect arguments for the callback int args = 0; - if (p_arg5.get_type() != Variant::NIL) + if (p_arg5.get_type() != Variant::NIL) { args = 5; - else if (p_arg4.get_type() != Variant::NIL) + } else if (p_arg4.get_type() != Variant::NIL) { args = 4; - else if (p_arg3.get_type() != Variant::NIL) + } else if (p_arg3.get_type() != Variant::NIL) { args = 3; - else if (p_arg2.get_type() != Variant::NIL) + } else if (p_arg2.get_type() != Variant::NIL) { args = 2; - else if (p_arg1.get_type() != Variant::NIL) + } else if (p_arg1.get_type() != Variant::NIL) { args = 1; - else + } else { args = 0; + } data.args = args; data.arg[0] = p_arg1; @@ -1481,12 +1523,14 @@ void Tween::follow_property(Object *p_object, NodePath p_property, Variant p_ini // If no initial value is given, grab it from the source object // TODO: Is this documented? It's really helpful for decluttering tweens - if (p_initial_val.get_type() == Variant::NIL) + if (p_initial_val.get_type() == Variant::NIL) { p_initial_val = p_object->get_indexed(p_property.get_subnames()); + } // Convert initial INT values to FLOAT as they are better for interpolation - if (p_initial_val.get_type() == Variant::INT) + if (p_initial_val.get_type() == Variant::INT) { p_initial_val = p_initial_val.operator real_t(); + } // Confirm the source and target objects are valid ERR_FAIL_COND(p_object == nullptr); @@ -1512,8 +1556,9 @@ void Tween::follow_property(Object *p_object, NodePath p_property, Variant p_ini ERR_FAIL_COND(!target_prop_valid); // Convert target INT to FLOAT since it is better for interpolation - if (target_val.get_type() == Variant::INT) + if (target_val.get_type() == Variant::INT) { target_val = target_val.operator real_t(); + } // Verify that the target value and initial value are the same type ERR_FAIL_COND(target_val.get_type() != p_initial_val.get_type()); @@ -1548,8 +1593,9 @@ void Tween::follow_method(Object *p_object, StringName p_method, Variant p_initi return; } // Convert initial INT values to FLOAT as they are better for interpolation - if (p_initial_val.get_type() == Variant::INT) + if (p_initial_val.get_type() == Variant::INT) { p_initial_val = p_initial_val.operator real_t(); + } // Verify the source and target objects are valid ERR_FAIL_COND(p_object == nullptr); @@ -1575,8 +1621,9 @@ void Tween::follow_method(Object *p_object, StringName p_method, Variant p_initi ERR_FAIL_COND(error.error != Callable::CallError::CALL_OK); // Convert target INT values to FLOAT as they are better for interpolation - if (target_val.get_type() == Variant::INT) + if (target_val.get_type() == Variant::INT) { target_val = target_val.operator real_t(); + } ERR_FAIL_COND(target_val.get_type() != p_initial_val.get_type()); // Make the new InterpolateData for the method follow @@ -1613,8 +1660,9 @@ void Tween::targeting_property(Object *p_object, NodePath p_property, Object *p_ p_initial_property = p_initial_property.get_as_property_path(); // Convert the initial INT values to FLOAT as they are better for Interpolation - if (p_final_val.get_type() == Variant::INT) + if (p_final_val.get_type() == Variant::INT) { p_final_val = p_final_val.operator real_t(); + } // Verify both objects are valid ERR_FAIL_COND(p_object == nullptr); @@ -1640,8 +1688,9 @@ void Tween::targeting_property(Object *p_object, NodePath p_property, Object *p_ ERR_FAIL_COND(!initial_prop_valid); // Convert the initial INT value to FLOAT as it is better for interpolation - if (initial_val.get_type() == Variant::INT) + if (initial_val.get_type() == Variant::INT) { initial_val = initial_val.operator real_t(); + } ERR_FAIL_COND(initial_val.get_type() != p_final_val.get_type()); // Build the InterpolateData object @@ -1681,8 +1730,9 @@ void Tween::targeting_method(Object *p_object, StringName p_method, Object *p_in } // Convert final INT values to FLOAT as they are better for interpolation - if (p_final_val.get_type() == Variant::INT) + if (p_final_val.get_type() == Variant::INT) { p_final_val = p_final_val.operator real_t(); + } // Make sure the given objects are valid ERR_FAIL_COND(p_object == nullptr); @@ -1708,8 +1758,9 @@ void Tween::targeting_method(Object *p_object, StringName p_method, Object *p_in ERR_FAIL_COND(error.error != Callable::CallError::CALL_OK); // Convert initial INT values to FLOAT as they aer better for interpolation - if (initial_val.get_type() == Variant::INT) + if (initial_val.get_type() == Variant::INT) { initial_val = initial_val.operator real_t(); + } ERR_FAIL_COND(initial_val.get_type() != p_final_val.get_type()); // Build the new InterpolateData object |