[Bf-blender-cvs] [b5a1c194c5d] master: Cleanup: early return from smoothview when the view is unchanged

Campbell Barton noreply at git.blender.org
Sun Sep 12 11:54:06 CEST 2021


Commit: b5a1c194c5dde20b13e3dd3372055d8b5e58a18e
Author: Campbell Barton
Date:   Sun Sep 12 19:51:17 2021 +1000
Branches: master
https://developer.blender.org/rBb5a1c194c5dde20b13e3dd3372055d8b5e58a18e

Cleanup: early return from smoothview when the view is unchanged

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

M	source/blender/editors/space_view3d/view3d_view.c

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

diff --git a/source/blender/editors/space_view3d/view3d_view.c b/source/blender/editors/space_view3d/view3d_view.c
index a6dd95cac04..f5da7c14a88 100644
--- a/source/blender/editors/space_view3d/view3d_view.c
+++ b/source/blender/editors/space_view3d/view3d_view.c
@@ -199,105 +199,91 @@ void ED_view3d_smooth_view_ex(
     sms.to_camera = true; /* restore view3d values in end */
   }
 
-  bool changed = false; /* zero means no difference */
-
-  if (sview->camera_old != sview->camera) {
-    changed = true;
-  }
-  else if (sms.dst.dist != rv3d->dist) {
-    changed = true;
-  }
-  else if (sms.dst.lens != v3d->lens) {
-    changed = true;
-  }
-  else if (!equals_v3v3(sms.dst.ofs, rv3d->ofs)) {
-    changed = true;
-  }
-  else if (!equals_v4v4(sms.dst.quat, rv3d->viewquat)) {
-    changed = true;
+  if ((sview->camera_old == sview->camera) &&   /* Camera. */
+      (sms.dst.dist == rv3d->dist) &&           /* Distance. */
+      (sms.dst.lens == v3d->lens) &&            /* Lens. */
+      equals_v3v3(sms.dst.ofs, rv3d->ofs) &&    /* Offset. */
+      equals_v4v4(sms.dst.quat, rv3d->viewquat) /* Rotation. */
+  ) {
+    /* Early return if nothing changed. */
+    return;
   }
 
-  /* The new view is different from the previous state. */
-  if (changed) {
-
-    /* Skip smooth viewing for external render engine draw. */
-    if (smooth_viewtx && !(v3d->shading.type == OB_RENDER && rv3d->render_engine)) {
+  /* Skip smooth viewing for external render engine draw. */
+  if (smooth_viewtx && !(v3d->shading.type == OB_RENDER && rv3d->render_engine)) {
 
-      /* original values */
-      if (sview->camera_old) {
-        Object *ob_camera_old_eval = DEG_get_evaluated_object(depsgraph, sview->camera_old);
-        if (sview->ofs != NULL) {
-          sms.src.dist = ED_view3d_offset_distance(ob_camera_old_eval->obmat, sview->ofs, 0.0f);
-        }
-        ED_view3d_from_object(
-            ob_camera_old_eval, sms.src.ofs, sms.src.quat, &sms.src.dist, &sms.src.lens);
-      }
-      /* grid draw as floor */
-      if ((RV3D_LOCK_FLAGS(rv3d) & RV3D_LOCK_ROTATION) == 0) {
-        /* use existing if exists, means multiple calls to smooth view
-         * won't lose the original 'view' setting */
-        rv3d->view = RV3D_VIEW_USER;
+    /* original values */
+    if (sview->camera_old) {
+      Object *ob_camera_old_eval = DEG_get_evaluated_object(depsgraph, sview->camera_old);
+      if (sview->ofs != NULL) {
+        sms.src.dist = ED_view3d_offset_distance(ob_camera_old_eval->obmat, sview->ofs, 0.0f);
       }
+      ED_view3d_from_object(
+          ob_camera_old_eval, sms.src.ofs, sms.src.quat, &sms.src.dist, &sms.src.lens);
+    }
+    /* grid draw as floor */
+    if ((RV3D_LOCK_FLAGS(rv3d) & RV3D_LOCK_ROTATION) == 0) {
+      /* use existing if exists, means multiple calls to smooth view
+       * won't lose the original 'view' setting */
+      rv3d->view = RV3D_VIEW_USER;
+    }
 
-      sms.time_allowed = (double)smooth_viewtx / 1000.0;
-
-      /* if this is view rotation only
-       * we can decrease the time allowed by
-       * the angle between quats
-       * this means small rotations won't lag */
-      if (sview->quat && !sview->ofs && !sview->dist) {
-        /* scale the time allowed by the rotation */
-        /* 180deg == 1.0 */
-        sms.time_allowed *= (double)fabsf(
-                                angle_signed_normalized_qtqt(sms.dst.quat, sms.src.quat)) /
-                            M_PI;
-      }
+    sms.time_allowed = (double)smooth_viewtx / 1000.0;
 
-      /* ensure it shows correct */
-      if (sms.to_camera) {
-        /* use ortho if we move from an ortho view to an ortho camera */
-        Object *ob_camera_eval = DEG_get_evaluated_object(depsgraph, sview->camera);
-        rv3d->persp = (((rv3d->is_persp == false) && (ob_camera_eval->type == OB_CAMERA) &&
-                        (((Camera *)ob_camera_eval->data)->type == CAM_ORTHO)) ?
-                           RV3D_ORTHO :
-                           RV3D_PERSP);
-      }
+    /* If this is view rotation only we can decrease the time allowed by the angle between quats
+     * this means small rotations won't lag. */
+    if (sview->quat && !sview->ofs && !sview->dist) {
+      /* scale the time allowed by the rotation */
+      /* 180deg == 1.0 */
+      sms.time_allowed *= (double)fabsf(angle_signed_normalized_qtqt(sms.dst.quat, sms.src.quat)) /
+                          M_PI;
+    }
 
-      rv3d->rflag |= RV3D_NAVIGATING;
+    /* ensure it shows correct */
+    if (sms.to_camera) {
+      /* use ortho if we move from an ortho view to an ortho camera */
+      Object *ob_camera_eval = DEG_get_evaluated_object(depsgraph, sview->camera);
+      rv3d->persp = (((rv3d->is_persp == false) && (ob_camera_eval->type == OB_CAMERA) &&
+                      (((Camera *)ob_camera_eval->data)->type == CAM_ORTHO)) ?
+                         RV3D_ORTHO :
+                         RV3D_PERSP);
+    }
 
-      /* not essential but in some cases the caller will tag the area for redraw, and in that
-       * case we can get a flicker of the 'org' user view but we want to see 'src' */
-      view3d_smooth_view_state_restore(&sms.src, v3d, rv3d);
+    rv3d->rflag |= RV3D_NAVIGATING;
 
-      /* keep track of running timer! */
-      if (rv3d->sms == NULL) {
-        rv3d->sms = MEM_mallocN(sizeof(struct SmoothView3DStore), "smoothview v3d");
-      }
-      *rv3d->sms = sms;
-      if (rv3d->smooth_timer) {
-        WM_event_remove_timer(wm, win, rv3d->smooth_timer);
-      }
-      /* #TIMER1 is hard-coded in key-map. */
-      rv3d->smooth_timer = WM_event_add_timer(wm, win, TIMER1, 1.0 / 100.0);
+    /* not essential but in some cases the caller will tag the area for redraw, and in that
+     * case we can get a flicker of the 'org' user view but we want to see 'src' */
+    view3d_smooth_view_state_restore(&sms.src, v3d, rv3d);
+
+    /* keep track of running timer! */
+    if (rv3d->sms == NULL) {
+      rv3d->sms = MEM_mallocN(sizeof(struct SmoothView3DStore), "smoothview v3d");
     }
-    else {
-      if (sms.to_camera == false) {
-        copy_v3_v3(rv3d->ofs, sms.dst.ofs);
-        copy_qt_qt(rv3d->viewquat, sms.dst.quat);
-        rv3d->dist = sms.dst.dist;
-        v3d->lens = sms.dst.lens;
+    *rv3d->sms = sms;
+    if (rv3d->smooth_timer) {
+      WM_event_remove_timer(wm, win, rv3d->smooth_timer);
+    }
+    /* #TIMER1 is hard-coded in key-map. */
+    rv3d->smooth_timer = WM_event_add_timer(wm, win, TIMER1, 1.0 / 100.0);
+  }
+  else {
+    /* Animation is disabled, apply immediately. */
+    if (sms.to_camera == false) {
+      copy_v3_v3(rv3d->ofs, sms.dst.ofs);
+      copy_qt_qt(rv3d->viewquat, sms.dst.quat);
+      rv3d->dist = sms.dst.dist;
+      v3d->lens = sms.dst.lens;
 
-        ED_view3d_camera_lock_sync(depsgraph, v3d, rv3d);
-      }
+      ED_view3d_camera_lock_sync(depsgraph, v3d, rv3d);
+    }
 
-      if (RV3D_LOCK_FLAGS(rv3d) & RV3D_BOXVIEW) {
-        view3d_boxview_copy(area, region);
-      }
+    if (RV3D_LOCK_FLAGS(rv3d) & RV3D_BOXVIEW) {
+      view3d_boxview_copy(area, region);
+    }
 
-      ED_region_tag_redraw(region);
+    ED_region_tag_redraw(region);
 
-      WM_event_add_mousemove(win);
-    }
+    WM_event_add_mousemove(win);
   }
 }



More information about the Bf-blender-cvs mailing list