New Transform 3D view recalculate scheme.
authorMartin Poirier <theeth@yahoo.com>
Wed, 3 Feb 2010 21:01:41 +0000 (21:01 +0000)
committerMartin Poirier <theeth@yahoo.com>
Wed, 3 Feb 2010 21:01:41 +0000 (21:01 +0000)
Only recalculate changes when absolutely necessary (mouse move triggers a soft recalc that will only happen before the next redraw other events trigger hard recalcs). The problem was that mouse moves are reported as lots of events (with small dx,dy) between each redraw which would trigger often heavy recalculations every time while only the last one was really important (the one before the redraw).

This makes snap project (retopo) much more manageable but induces a very small lag equal to one refresh cycle. Confirming transform does a hard refresh, so the final result is always consistent with mouse position.

source/blender/editors/transform/transform.c
source/blender/editors/transform/transform.h
source/blender/editors/transform/transform_generics.c
source/blender/editors/transform/transform_input.c

index e8b1e6e0de13049a28ab07ec061183c80be14424..938c0ba7cfad000e6081ab5a1dad1e3f8d519a2e 100644 (file)
 
 #include "transform.h"
 
 
 #include "transform.h"
 
+void drawTransformApply(const struct bContext *C, struct ARegion *ar, void *arg);
+
 /* ************************** SPACE DEPENDANT CODE **************************** */
 
 void setTransformViewMatrices(TransInfo *t)
 /* ************************** SPACE DEPENDANT CODE **************************** */
 
 void setTransformViewMatrices(TransInfo *t)
@@ -297,7 +299,7 @@ void removeAspectRatio(TransInfo *t, float *vec)
        }
 }
 
        }
 }
 
-static void viewRedrawForce(bContext *C, TransInfo *t)
+static void viewRedrawForce(const bContext *C, TransInfo *t)
 {
        if (t->spacetype == SPACE_VIEW3D)
        {
 {
        if (t->spacetype == SPACE_VIEW3D)
        {
@@ -546,7 +548,7 @@ int transformEvent(TransInfo *t, wmEvent *event)
                t->mval[0] = event->x - t->ar->winrct.xmin;
                t->mval[1] = event->y - t->ar->winrct.ymin;
 
                t->mval[0] = event->x - t->ar->winrct.xmin;
                t->mval[1] = event->y - t->ar->winrct.ymin;
 
-               t->redraw = 1;
+               t->redraw |= TREDRAW_SOFT;
 
                if (t->state == TRANS_STARTING) {
                    t->state = TRANS_RUNNING;
 
                if (t->state == TRANS_STARTING) {
                    t->state = TRANS_RUNNING;
@@ -571,7 +573,7 @@ int transformEvent(TransInfo *t, wmEvent *event)
                                        restoreTransObjects(t);
                                        initTranslation(t);
                                        initSnapping(t, NULL); // need to reinit after mode change
                                        restoreTransObjects(t);
                                        initTranslation(t);
                                        initSnapping(t, NULL); // need to reinit after mode change
-                                       t->redraw = 1;
+                                       t->redraw |= TREDRAW_HARD;
                                }
                                break;
                        case TFM_MODAL_ROTATE:
                                }
                                break;
                        case TFM_MODAL_ROTATE:
@@ -589,7 +591,7 @@ int transformEvent(TransInfo *t, wmEvent *event)
                                                initRotation(t);
                                        }
                                        initSnapping(t, NULL); // need to reinit after mode change
                                                initRotation(t);
                                        }
                                        initSnapping(t, NULL); // need to reinit after mode change
-                                       t->redraw = 1;
+                                       t->redraw |= TREDRAW_HARD;
                                }
                                break;
                        case TFM_MODAL_RESIZE:
                                }
                                break;
                        case TFM_MODAL_RESIZE:
@@ -599,21 +601,21 @@ int transformEvent(TransInfo *t, wmEvent *event)
                                        restoreTransObjects(t);
                                        initResize(t);
                                        initSnapping(t, NULL); // need to reinit after mode change
                                        restoreTransObjects(t);
                                        initResize(t);
                                        initSnapping(t, NULL); // need to reinit after mode change
-                                       t->redraw = 1;
+                                       t->redraw |= TREDRAW_HARD;
                                }
                                break;
                                
                        case TFM_MODAL_SNAP_INV_ON:
                                t->modifiers |= MOD_SNAP_INVERT;
                                }
                                break;
                                
                        case TFM_MODAL_SNAP_INV_ON:
                                t->modifiers |= MOD_SNAP_INVERT;
-                               t->redraw = 1;
+                               t->redraw |= TREDRAW_HARD;
                                break;
                        case TFM_MODAL_SNAP_INV_OFF:
                                t->modifiers &= ~MOD_SNAP_INVERT;
                                break;
                        case TFM_MODAL_SNAP_INV_OFF:
                                t->modifiers &= ~MOD_SNAP_INVERT;
-                               t->redraw = 1;
+                               t->redraw |= TREDRAW_HARD;
                                break;
                        case TFM_MODAL_SNAP_TOGGLE:
                                t->modifiers ^= MOD_SNAP;
                                break;
                        case TFM_MODAL_SNAP_TOGGLE:
                                t->modifiers ^= MOD_SNAP;
-                               t->redraw = 1;
+                               t->redraw |= TREDRAW_HARD;
                                break;
                        case TFM_MODAL_AXIS_X:
                                if ((t->flag & T_NO_CONSTRAINT)==0) {
                                break;
                        case TFM_MODAL_AXIS_X:
                                if ((t->flag & T_NO_CONSTRAINT)==0) {
@@ -628,7 +630,7 @@ int transformEvent(TransInfo *t, wmEvent *event)
                                                        setUserConstraint(t, t->current_orientation, (CON_AXIS0), "along %s X");
                                                }
                                        }
                                                        setUserConstraint(t, t->current_orientation, (CON_AXIS0), "along %s X");
                                                }
                                        }
-                                       t->redraw = 1;
+                                       t->redraw |= TREDRAW_HARD;
                                }
                                break;
                        case TFM_MODAL_AXIS_Y:
                                }
                                break;
                        case TFM_MODAL_AXIS_Y:
@@ -644,7 +646,7 @@ int transformEvent(TransInfo *t, wmEvent *event)
                                                        setUserConstraint(t, t->current_orientation, (CON_AXIS1), "along %s Y");
                                                }
                                        }
                                                        setUserConstraint(t, t->current_orientation, (CON_AXIS1), "along %s Y");
                                                }
                                        }
-                                       t->redraw = 1;
+                                       t->redraw |= TREDRAW_HARD;
                                }
                                break;
                        case TFM_MODAL_AXIS_Z:
                                }
                                break;
                        case TFM_MODAL_AXIS_Z:
@@ -655,7 +657,7 @@ int transformEvent(TransInfo *t, wmEvent *event)
                                        else {
                                                setUserConstraint(t, t->current_orientation, (CON_AXIS2), "along %s Z");
                                        }
                                        else {
                                                setUserConstraint(t, t->current_orientation, (CON_AXIS2), "along %s Z");
                                        }
-                                       t->redraw = 1;
+                                       t->redraw |= TREDRAW_HARD;
                                }
                                break;
                        case TFM_MODAL_PLANE_X:
                                }
                                break;
                        case TFM_MODAL_PLANE_X:
@@ -666,7 +668,7 @@ int transformEvent(TransInfo *t, wmEvent *event)
                                        else {
                                                setUserConstraint(t, t->current_orientation, (CON_AXIS1|CON_AXIS2), "locking %s X");
                                        }
                                        else {
                                                setUserConstraint(t, t->current_orientation, (CON_AXIS1|CON_AXIS2), "locking %s X");
                                        }
-                                       t->redraw = 1;
+                                       t->redraw |= TREDRAW_HARD;
                                }
                                break;
                        case TFM_MODAL_PLANE_Y:
                                }
                                break;
                        case TFM_MODAL_PLANE_Y:
@@ -677,7 +679,7 @@ int transformEvent(TransInfo *t, wmEvent *event)
                                        else {
                                                setUserConstraint(t, t->current_orientation, (CON_AXIS0|CON_AXIS2), "locking %s Y");
                                        }
                                        else {
                                                setUserConstraint(t, t->current_orientation, (CON_AXIS0|CON_AXIS2), "locking %s Y");
                                        }
-                                       t->redraw = 1;
+                                       t->redraw |= TREDRAW_HARD;
                                }
                                break;
                        case TFM_MODAL_PLANE_Z:
                                }
                                break;
                        case TFM_MODAL_PLANE_Z:
@@ -688,22 +690,22 @@ int transformEvent(TransInfo *t, wmEvent *event)
                                        else {
                                                setUserConstraint(t, t->current_orientation, (CON_AXIS0|CON_AXIS1), "locking %s Z");
                                        }
                                        else {
                                                setUserConstraint(t, t->current_orientation, (CON_AXIS0|CON_AXIS1), "locking %s Z");
                                        }
-                                       t->redraw = 1;
+                                       t->redraw |= TREDRAW_HARD;
                                }
                                break;
                        case TFM_MODAL_CONS_OFF:
                                if ((t->flag & T_NO_CONSTRAINT)==0) {
                                        stopConstraint(t);
                                }
                                break;
                        case TFM_MODAL_CONS_OFF:
                                if ((t->flag & T_NO_CONSTRAINT)==0) {
                                        stopConstraint(t);
-                                       t->redraw = 1;
+                                       t->redraw |= TREDRAW_HARD;
                                }
                                break;
                        case TFM_MODAL_ADD_SNAP:
                                addSnapPoint(t);
                                }
                                break;
                        case TFM_MODAL_ADD_SNAP:
                                addSnapPoint(t);
-                               t->redraw = 1;
+                               t->redraw |= TREDRAW_HARD;
                                break;
                        case TFM_MODAL_REMOVE_SNAP:
                                removeSnapPoint(t);
                                break;
                        case TFM_MODAL_REMOVE_SNAP:
                                removeSnapPoint(t);
-                               t->redraw = 1;
+                               t->redraw |= TREDRAW_HARD;
                                break;
                        default:
                                handled = 0;
                                break;
                        default:
                                handled = 0;
@@ -723,7 +725,7 @@ int transformEvent(TransInfo *t, wmEvent *event)
                case LEFTSHIFTKEY:
                case RIGHTSHIFTKEY:
                        t->modifiers |= MOD_CONSTRAINT_PLANE;
                case LEFTSHIFTKEY:
                case RIGHTSHIFTKEY:
                        t->modifiers |= MOD_CONSTRAINT_PLANE;
-                       t->redraw = 1;
+                       t->redraw |= TREDRAW_HARD;
                        break;
 
                case SPACEKEY:
                        break;
 
                case SPACEKEY:
@@ -771,7 +773,7 @@ int transformEvent(TransInfo *t, wmEvent *event)
                                                postSelectConstraint(t);
                                        }
                                }
                                                postSelectConstraint(t);
                                        }
                                }
-                               t->redraw = 1;
+                               t->redraw |= TREDRAW_HARD;
                        }
                        break;
                case ESCKEY:
                        }
                        break;
                case ESCKEY:
@@ -788,7 +790,7 @@ int transformEvent(TransInfo *t, wmEvent *event)
                                restoreTransObjects(t);
                                initTranslation(t);
                                initSnapping(t, NULL); // need to reinit after mode change
                                restoreTransObjects(t);
                                initTranslation(t);
                                initSnapping(t, NULL); // need to reinit after mode change
-                               t->redraw = 1;
+                               t->redraw |= TREDRAW_HARD;
                        }
                        break;
                case SKEY:
                        }
                        break;
                case SKEY:
@@ -798,7 +800,7 @@ int transformEvent(TransInfo *t, wmEvent *event)
                                restoreTransObjects(t);
                                initResize(t);
                                initSnapping(t, NULL); // need to reinit after mode change
                                restoreTransObjects(t);
                                initResize(t);
                                initSnapping(t, NULL); // need to reinit after mode change
-                               t->redraw = 1;
+                               t->redraw |= TREDRAW_HARD;
                        }
                        break;
                case RKEY:
                        }
                        break;
                case RKEY:
@@ -816,7 +818,7 @@ int transformEvent(TransInfo *t, wmEvent *event)
                                        initRotation(t);
                                }
                                initSnapping(t, NULL); // need to reinit after mode change
                                        initRotation(t);
                                }
                                initSnapping(t, NULL); // need to reinit after mode change
-                               t->redraw = 1;
+                               t->redraw |= TREDRAW_HARD;
                        }
                        break;
                case CKEY:
                        }
                        break;
                case CKEY:
@@ -828,7 +830,7 @@ int transformEvent(TransInfo *t, wmEvent *event)
                        }
                        else {
                                stopConstraint(t);
                        }
                        else {
                                stopConstraint(t);
-                               t->redraw = 1;
+                               t->redraw |= TREDRAW_HARD;
                        }
                        break;
                case XKEY:
                        }
                        break;
                case XKEY:
@@ -857,7 +859,7 @@ int transformEvent(TransInfo *t, wmEvent *event)
                                                        setUserConstraint(t, V3D_MANIP_GLOBAL, (CON_AXIS1|CON_AXIS2), "locking %s X");
                                        }
                                }
                                                        setUserConstraint(t, V3D_MANIP_GLOBAL, (CON_AXIS1|CON_AXIS2), "locking %s X");
                                        }
                                }
-                               t->redraw = 1;
+                               t->redraw |= TREDRAW_HARD;
                        }
                        break;
                case YKEY:
                        }
                        break;
                case YKEY:
@@ -886,7 +888,7 @@ int transformEvent(TransInfo *t, wmEvent *event)
                                                        setUserConstraint(t, V3D_MANIP_GLOBAL, (CON_AXIS0|CON_AXIS2), "locking %s Y");
                                        }
                                }
                                                        setUserConstraint(t, V3D_MANIP_GLOBAL, (CON_AXIS0|CON_AXIS2), "locking %s Y");
                                        }
                                }
-                               t->redraw = 1;
+                               t->redraw |= TREDRAW_HARD;
                        }
                        break;
                case ZKEY:
                        }
                        break;
                case ZKEY:
@@ -907,14 +909,14 @@ int transformEvent(TransInfo *t, wmEvent *event)
                                        else if (t->modifiers & MOD_CONSTRAINT_PLANE)
                                                setUserConstraint(t, V3D_MANIP_GLOBAL, (CON_AXIS0|CON_AXIS1), "locking %s Z");
                                }
                                        else if (t->modifiers & MOD_CONSTRAINT_PLANE)
                                                setUserConstraint(t, V3D_MANIP_GLOBAL, (CON_AXIS0|CON_AXIS1), "locking %s Z");
                                }
-                               t->redraw = 1;
+                               t->redraw |= TREDRAW_HARD;
                        }
                        break;
                case OKEY:
                        if (t->flag & T_PROP_EDIT && event->shift) {
                                t->prop_mode = (t->prop_mode + 1) % 6;
                                calculatePropRatio(t);
                        }
                        break;
                case OKEY:
                        if (t->flag & T_PROP_EDIT && event->shift) {
                                t->prop_mode = (t->prop_mode + 1) % 6;
                                calculatePropRatio(t);
-                               t->redraw = 1;
+                               t->redraw |= TREDRAW_HARD;
                        }
                        break;
                case PADPLUSKEY:
                        }
                        break;
                case PADPLUSKEY:
@@ -985,7 +987,7 @@ int transformEvent(TransInfo *t, wmEvent *event)
                                else
                                {
                                        /* Otherwise, just redraw, NDof input was cancelled */
                                else
                                {
                                        /* Otherwise, just redraw, NDof input was cancelled */
-                                       t->redraw = 1;
+                                       t->redraw |= TREDRAW_HARD;
                                }
                                break;
                        case NDOF_NOMOVE:
                                }
                                break;
                        case NDOF_NOMOVE:
@@ -996,7 +998,7 @@ int transformEvent(TransInfo *t, wmEvent *event)
                                }
                                break;
                        case NDOF_REFRESH:
                                }
                                break;
                        case NDOF_REFRESH:
-                               t->redraw = 1;
+                               t->redraw |= TREDRAW_HARD;
                                break;
                        default:
                                handled = 0;
                                break;
                        default:
                                handled = 0;
@@ -1013,14 +1015,14 @@ int transformEvent(TransInfo *t, wmEvent *event)
                case LEFTSHIFTKEY:
                case RIGHTSHIFTKEY:
                        t->modifiers &= ~MOD_CONSTRAINT_PLANE;
                case LEFTSHIFTKEY:
                case RIGHTSHIFTKEY:
                        t->modifiers &= ~MOD_CONSTRAINT_PLANE;
-                       t->redraw = 1;
+                       t->redraw |= TREDRAW_HARD;
                        break;
 
                case MIDDLEMOUSE:
                        if ((t->flag & T_NO_CONSTRAINT)==0) {
                                t->modifiers &= ~MOD_CONSTRAINT_SELECT;
                                postSelectConstraint(t);
                        break;
 
                case MIDDLEMOUSE:
                        if ((t->flag & T_NO_CONSTRAINT)==0) {
                                t->modifiers &= ~MOD_CONSTRAINT_SELECT;
                                postSelectConstraint(t);
-                               t->redraw = 1;
+                               t->redraw |= TREDRAW_HARD;
                        }
                        break;
 //             case LEFTMOUSE:
                        }
                        break;
 //             case LEFTMOUSE:
@@ -1456,6 +1458,7 @@ int initTransform(bContext *C, TransInfo *t, wmOperator *op, wmEvent *event, int
                //calc_manipulator_stats(curarea);
                initTransformOrientation(C, t);
 
                //calc_manipulator_stats(curarea);
                initTransformOrientation(C, t);
 
+               t->draw_handle_apply = ED_region_draw_cb_activate(t->ar->type, drawTransformApply, t, REGION_DRAW_PRE_VIEW);
                t->draw_handle_view = ED_region_draw_cb_activate(t->ar->type, drawTransformView, t, REGION_DRAW_POST_VIEW);
                //t->draw_handle_pixel = ED_region_draw_cb_activate(t->ar->type, drawTransformPixel, t, REGION_DRAW_POST_PIXEL);
                t->draw_handle_cursor = WM_paint_cursor_activate(CTX_wm_manager(C), NULL, drawHelpline, t);
                t->draw_handle_view = ED_region_draw_cb_activate(t->ar->type, drawTransformView, t, REGION_DRAW_POST_VIEW);
                //t->draw_handle_pixel = ED_region_draw_cb_activate(t->ar->type, drawTransformPixel, t, REGION_DRAW_POST_PIXEL);
                t->draw_handle_cursor = WM_paint_cursor_activate(CTX_wm_manager(C), NULL, drawHelpline, t);
@@ -1627,16 +1630,18 @@ int initTransform(bContext *C, TransInfo *t, wmOperator *op, wmEvent *event, int
        return 1;
 }
 
        return 1;
 }
 
-void transformApply(bContext *C, TransInfo *t)
+void transformApply(const bContext *C, TransInfo *t)
 {
 {
-       if (t->redraw)
+       if ((t->redraw & TREDRAW_HARD) || (t->draw_handle_apply == NULL && (t->redraw & TREDRAW_SOFT)))
        {
                selectConstraint(t);
                if (t->transform) {
                        t->transform(t, t->mval);  // calls recalcData()
                        viewRedrawForce(C, t);
                }
        {
                selectConstraint(t);
                if (t->transform) {
                        t->transform(t, t->mval);  // calls recalcData()
                        viewRedrawForce(C, t);
                }
-               t->redraw = 0;
+               t->redraw = TREDRAW_NOTHING;
+       } else if (t->redraw & TREDRAW_SOFT) {
+               viewRedrawForce(C, t);
        }
 
        /* If auto confirm is on, break after one pass */
        }
 
        /* If auto confirm is on, break after one pass */
@@ -1649,7 +1654,17 @@ void transformApply(bContext *C, TransInfo *t)
        {
                // TRANSFORM_FIX_ME
                //do_screenhandlers(G.curscreen);
        {
                // TRANSFORM_FIX_ME
                //do_screenhandlers(G.curscreen);
-               t->redraw = 1;
+               t->redraw |= TREDRAW_HARD;
+       }
+}
+
+void drawTransformApply(const struct bContext *C, struct ARegion *ar, void *arg)
+{
+       TransInfo *t = arg;
+
+       if (t->redraw & TREDRAW_SOFT) {
+               t->redraw |= TREDRAW_HARD;
+               transformApply(C, t);
        }
 }
 
        }
 }
 
index 231a01b86d75aab126517dd45c97e0d93a6813a6..6885e87c6a3018a58b09f32c7531c2f0b2b3cfbe 100644 (file)
@@ -325,6 +325,7 @@ typedef struct TransInfo {
        struct wmTimer *animtimer;
     short       mval[2];        /* current mouse position               */
     struct Object   *obedit;
        struct wmTimer *animtimer;
     short       mval[2];        /* current mouse position               */
     struct Object   *obedit;
+    void               *draw_handle_apply;
     void               *draw_handle_view;
     void               *draw_handle_pixel;
     void               *draw_handle_cursor;
     void               *draw_handle_view;
     void               *draw_handle_pixel;
     void               *draw_handle_cursor;
@@ -349,6 +350,12 @@ typedef struct TransInfo {
 #define TRANS_CONFIRM  2
 #define TRANS_CANCEL   3
 
 #define TRANS_CONFIRM  2
 #define TRANS_CANCEL   3
 
+/* transinfo->redraw */
+#define TREDRAW_NOTHING        0
+#define TREDRAW_HARD           1
+#define TREDRAW_SOFT           2
+
+
 /* transinfo->flag */
 #define T_OBJECT               (1 << 0)
 #define T_EDIT                 (1 << 1)
 /* transinfo->flag */
 #define T_OBJECT               (1 << 0)
 #define T_EDIT                 (1 << 1)
@@ -440,7 +447,7 @@ void TRANSFORM_OT_transform(struct wmOperatorType *ot);
 int initTransform(struct bContext *C, struct TransInfo *t, struct wmOperator *op, struct wmEvent *event, int mode);
 void saveTransform(struct bContext *C, struct TransInfo *t, struct wmOperator *op);
 int  transformEvent(TransInfo *t, struct wmEvent *event);
 int initTransform(struct bContext *C, struct TransInfo *t, struct wmOperator *op, struct wmEvent *event, int mode);
 void saveTransform(struct bContext *C, struct TransInfo *t, struct wmOperator *op);
 int  transformEvent(TransInfo *t, struct wmEvent *event);
-void transformApply(struct bContext *C, TransInfo *t);
+void transformApply(const struct bContext *C, TransInfo *t);
 int  transformEnd(struct bContext *C, TransInfo *t);
 
 void setTransformViewMatrices(TransInfo *t);
 int  transformEnd(struct bContext *C, TransInfo *t);
 
 void setTransformViewMatrices(TransInfo *t);
index 4299529836b930eea80815f8c744ed25efadb48d..2d32b81de33564f32d3050006244e4b7a386513c 100644 (file)
@@ -1072,6 +1072,8 @@ void postTrans (bContext *C, TransInfo *t)
        
        if (t->draw_handle_view)
                ED_region_draw_cb_exit(t->ar->type, t->draw_handle_view);
        
        if (t->draw_handle_view)
                ED_region_draw_cb_exit(t->ar->type, t->draw_handle_view);
+       if (t->draw_handle_apply)
+               ED_region_draw_cb_exit(t->ar->type, t->draw_handle_apply);
        if (t->draw_handle_pixel)
                ED_region_draw_cb_exit(t->ar->type, t->draw_handle_pixel);
        if (t->draw_handle_cursor)
        if (t->draw_handle_pixel)
                ED_region_draw_cb_exit(t->ar->type, t->draw_handle_pixel);
        if (t->draw_handle_cursor)
index fbc7f0dd7468c79ebb6562ac7226350fbe021587..879967da8374598ecdbe741c89fb1abf19dd1f77 100644 (file)
@@ -364,7 +364,7 @@ void applyMouseInput(TransInfo *t, MouseInput *mi, short mval[2], float output[3
 
 int handleMouseInput(TransInfo *t, MouseInput *mi, wmEvent *event)
 {
 
 int handleMouseInput(TransInfo *t, MouseInput *mi, wmEvent *event)
 {
-       int redraw = 0;
+       int redraw = TREDRAW_NOTHING;
 
        switch (event->type)
        {
 
        switch (event->type)
        {
@@ -384,7 +384,7 @@ int handleMouseInput(TransInfo *t, MouseInput *mi, wmEvent *event)
                        t->modifiers &= ~MOD_PRECISION;
                        mi->precision = 0;
                }
                        t->modifiers &= ~MOD_PRECISION;
                        mi->precision = 0;
                }
-               redraw = 1;
+               redraw = TREDRAW_HARD;
                break;
        }
 
                break;
        }