[Bf-blender-cvs] [1f5331ee870] master: Cleanup: animation, simplify `anim_flush_channel_setting_up()`

Sybren A. Stüvel noreply at git.blender.org
Mon Sep 28 11:23:49 CEST 2020


Commit: 1f5331ee87018cb51a029d786ef138653815e56e
Author: Sybren A. Stüvel
Date:   Fri Sep 25 16:30:01 2020 +0200
Branches: master
https://developer.blender.org/rB1f5331ee87018cb51a029d786ef138653815e56e

Cleanup: animation, simplify `anim_flush_channel_setting_up()`

Simplify `anim_flush_channel_setting_up()` by flipping conditions and
returning early. This makes it easier to understand what is actually
happening in the code.

No functional changes.

===================================================================

M	source/blender/editors/animation/anim_channels_edit.c

===================================================================

diff --git a/source/blender/editors/animation/anim_channels_edit.c b/source/blender/editors/animation/anim_channels_edit.c
index be4ee859f89..80976d150c0 100644
--- a/source/blender/editors/animation/anim_channels_edit.c
+++ b/source/blender/editors/animation/anim_channels_edit.c
@@ -468,8 +468,6 @@ static void anim_flush_channel_setting_up(bAnimContext *ac,
                                           bAnimListElem *const match,
                                           const int matchLevel)
 {
-  int prevLevel = matchLevel;
-
   /* flush up?
    *
    * For Visibility:
@@ -480,49 +478,57 @@ static void anim_flush_channel_setting_up(bAnimContext *ac,
    * - only flush up if the current state is now disabled (negative 'off' state is default)
    *   (otherwise, it's too much work to force the parents to be active too)
    */
-  if (((setting == ACHANNEL_SETTING_VISIBLE) && (mode != ACHANNEL_SETFLAG_CLEAR)) ||
-      ((setting != ACHANNEL_SETTING_VISIBLE) && (mode == ACHANNEL_SETFLAG_CLEAR))) {
-    /* Go backwards in the list, until the highest-ranking element
-     * (by indention has been covered). */
-    for (bAnimListElem *ale = match->prev; ale; ale = ale->prev) {
-      const bAnimChannelType *acf = ANIM_channel_get_typeinfo(ale);
+  if (setting == ACHANNEL_SETTING_VISIBLE) {
+    if (mode == ACHANNEL_SETFLAG_CLEAR) {
+      return;
+    }
+  }
+  else {
+    if (mode != ACHANNEL_SETFLAG_CLEAR) {
+      return;
+    }
+  }
 
-      /* if no channel info was found, skip, since this type might not have any useful info */
-      if (acf == NULL) {
-        continue;
-      }
+  /* Go backwards in the list, until the highest-ranking element
+   * (by indention has been covered). */
+  int prevLevel = matchLevel;
+  for (bAnimListElem *ale = match->prev; ale; ale = ale->prev) {
+    const bAnimChannelType *acf = ANIM_channel_get_typeinfo(ale);
 
-      /* get the level of the current channel traversed
-       *   - we define the level as simply being the offset for the start of the channel
-       */
-      const int level = (acf->get_offset) ? acf->get_offset(ac, ale) : 0;
+    /* if no channel info was found, skip, since this type might not have any useful info */
+    if (acf == NULL) {
+      continue;
+    }
 
-      /* if the level is 'less than' (i.e. more important) the level we're matching
-       * but also 'less than' the level just tried (i.e. only the 1st group above grouped F-Curves,
-       * when toggling visibility of F-Curves, gets flushed, which should happen if we don't let
-       * prevLevel get updated below once the first 1st group is found).
-       */
-      if (level < prevLevel) {
-        /* flush the new status... */
-        ANIM_channel_setting_set(ac, ale, setting, mode);
+    /* Get the level of the current channel traversed
+     *   - we define the level as simply being the offset for the start of the channel
+     */
+    const int level = (acf->get_offset) ? acf->get_offset(ac, ale) : 0;
 
-        /* store this level as the 'old' level now */
-        prevLevel = level;
-      }
-      /* if the level is 'greater than' (i.e. less important) than the previous level... */
-      else if (level > prevLevel) {
-        /* if previous level was a base-level (i.e. 0 offset / root of one hierarchy),
-         * stop here
-         */
-        if (prevLevel == 0) {
-          break;
-          /* otherwise, this level weaves into another sibling hierarchy to the previous one just
-           * finished, so skip until we get to the parent of this level
-           */
-        }
-        continue;
+    if (level == prevLevel) {
+      /* Don't influence siblings. */
+      continue;
+    }
+
+    if (level > prevLevel) {
+      /* If previous level was a base-level (i.e. 0 offset / root of one hierarchy), stop here. */
+      if (prevLevel == 0) {
+        return;
       }
+
+      /* Otherwise, this level weaves into another sibling hierarchy to the previous one just
+       * finished, so skip until we get to the parent of this level. */
+      continue;
     }
+
+    /* The level is 'less than' (i.e. more important) the level we're matching but also 'less
+     * than' the level just tried (i.e. only the 1st group above grouped F-Curves, when toggling
+     * visibility of F-Curves, gets flushed, which should happen if we don't let prevLevel get
+     * updated below once the first 1st group is found). */
+    ANIM_channel_setting_set(ac, ale, setting, mode);
+
+    /* store this level as the 'old' level now */
+    prevLevel = level;
   }
 }



More information about the Bf-blender-cvs mailing list