[Bf-committers] PATCH: Add->Armature uses 100% CPU and causes massive flickering.

Kester Maddock bf-committers@blender.org
Wed, 26 Nov 2003 16:52:39 +1300


This is a multi-part message in MIME format.
--------------090502040700010209030701
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit


The Add->Armatures loop has no BIF_wait_for_statechange().  This causes 
100% cpu usage.

Also, the front buffer & back buffer are different for the SPACE_BUTS 
window.  Combined with the above, this causes massive flickering.  This 
might be window size/fullscreen dependant. :-(
I added a force_draw_plus(SPACE_BUTS) after adding each bone, which 
fixes this.  The buttons window is updated for every bone too.

Kester

--------------090502040700010209030701
Content-Type: text/plain;
 name="arm-cpu-patch.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="arm-cpu-patch.diff"

Index: source/blender/src/editarmature.c
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/src/editarmature.c,v
retrieving revision 1.19
diff -u -3 -r1.19 editarmature.c
--- source/blender/src/editarmature.c   21 Nov 2003 04:07:45 -0000      1.19
+++ source/blender/src/editarmature.c   26 Nov 2003 03:51:45 -0000
@@ -1515,6 +1515,7 @@

                make_editArmature();
                setcursor_space(SPACE_VIEW3D, CURSOR_EDIT);
+
        }

        switch (type){
@@ -1542,7 +1543,7 @@
 {
        float           *cursLoc, cent[3], dx, dy;
        float           mat[3][3], curs[3],     cmat[3][3], imat[3][3], rmat[4][4], itmat[4][4];
-       short           xo, yo, mval[2], afbreek=0;
+       short           xo, yo, mval[2], omval[2], afbreek=0;
        short           val;
        float           restmat[4][4], tempVec[4];
        EditBone        *bone;
@@ -1553,6 +1554,7 @@
        float   newEnd[4];
        int                     addbones=1;
        float           dvec[3], dvecp[3];
+       char            location[48];

        cursLoc= give_cursor();

@@ -1599,76 +1601,85 @@

                /*      Project cursor center to screenspace. */
                getmouseco_areawin(mval);
-               xo= mval[0];
-               yo= mval[1];
+               xo= omval[0] = mval[0];
+               yo= omval[1] = mval[1];
                window_to_3d(dvecp, xo, yo);
+               force_draw_plus(SPACE_BUTS);

                while (1) {

                        getmouseco_areawin(mval);
-                       window_to_3d(dvec, mval[0], mval[1]);
-
-                       scale=1000;
-
-                       dx=     ((float)mval[0]-(float)xo)*scale;
-                       dy= ((float)mval[1]-(float)yo)*scale;
-
-                       /*              Calc bone length*/
-                       lengths= sqrt((dx*dx)+(dy*dy));
-                       length = sqrt(((dvec[0]-dvecp[0])*(dvec[0]-dvecp[0]))+((dvec[1]-dvecp[1])*(dvec[1]-dvecp[1]))+((dvec[2]-dvecp[2])*(dvec[2]-dvecp[2])));
-
-                       /*              Find rotation around screen normal */
-                       if (lengths>0.0F) {
-                               angle= acos(dy/lengths);
-                               if (dx<0.0F)
-                                       angle*= -1.0F;
+                       if (mval[0] == omval[0] && mval[1] == omval[1]) {
+                               BIF_wait_for_statechange();
+                       } else {
+                               omval[0] = mval[0];
+                               omval[1] = mval[1];
+                               window_to_3d(dvec, mval[0], mval[1]);
+
+                               scale=1000;
+
+                               dx=     ((float)mval[0]-(float)xo)*scale;
+                               dy= ((float)mval[1]-(float)yo)*scale;
+
+                               /*              Calc bone length*/
+                               lengths= sqrt((dx*dx)+(dy*dy));
+                               length = sqrt(((dvec[0]-dvecp[0])*(dvec[0]-dvecp[0]))+((dvec[1]-dvecp[1])*(dvec[1]-dvecp[1]))+((dvec[2]-dvecp[2])*(dvec[2]-dvecp[2])));
+
+                               /*              Find rotation around screen normal */
+                               if (lengths>0.0F) {
+                                       angle= acos(dy/lengths);
+                                       if (dx<0.0F)
+                                               angle*= -1.0F;
+                               }
+                               else angle= 0.0F;
+
+                               /*              FIXME:  Is there a blender-defined way of making rot and trans matrices? */
+                               rmat[0][0]= cos (angle);
+                               rmat[0][1]= -sin (angle);
+                               rmat[0][2]= 0.0F;
+                               rmat[0][3]= 0.0F;
+                               rmat[1][0]= sin (angle);
+                               rmat[1][1]= cos (angle);
+                               rmat[1][2]= 0.0F;
+                               rmat[1][3]= 0.0F;
+                               rmat[2][0]= 0.0F;
+                               rmat[2][1]= 0.0F;
+                               rmat[2][2]= 1.0F;
+                               rmat[2][3]= 0.0F;
+                               rmat[3][0]= cent[0];
+                               rmat[3][1]= cent[1];
+                               rmat[3][2]= cent[2];
+                               rmat[3][3]= 1.0F;
+
+                               /*              Rotate object's inversemat by the bone's rotation
+                               to get the coordinate space of the bone */
+                               Mat4CpyMat3     (itmat, imat);
+                               Mat4MulMat4 (restmat, rmat, itmat);
+
+                               /*      Find the bone head */
+                               tempVec[0]=0; tempVec[1]=0.0F; tempVec[2]=0.0F; tempVec[3]=1.0F;
+                               Mat4MulVec4fl (restmat, tempVec);
+                               VECCOPY (bone->head, tempVec);
+
+                               /*      Find the bone tail */
+                               tempVec[0]=0; tempVec[1]=length; tempVec[2]=0.0F; tempVec[3]=1.0F;
+                               Mat4MulVec4fl (restmat, tempVec);
+                               VECCOPY (bone->tail, tempVec);
+
+                               /*      IF we're a child of something, add the parents' translates      */
+
+                               /*      Offset of child is new cursor*/
+
+                               VECCOPY (newEnd,bone->tail); newEnd[3]=1;
+
+                               /*      Set the bone's transformations  */
+                               Mat4One (bone->obmat);
+                               bone->size[0]=bone->size[1]=bone->size[2]=1.0F;
+                               sprintf(location, "Dx: %.4f   Dy: %.4f  Dz: %.4f", dvec[0], dvec[1], dvec[2]);
+                               headerprint(location);
+                               force_draw();
                        }
-                       else angle= 0.0F;
-
-                       /*              FIXME:  Is there a blender-defined way of making rot and trans matrices? */
-                       rmat[0][0]= cos (angle);
-                       rmat[0][1]= -sin (angle);
-                       rmat[0][2]= 0.0F;
-                       rmat[0][3]= 0.0F;
-                       rmat[1][0]= sin (angle);
-                       rmat[1][1]= cos (angle);
-                       rmat[1][2]= 0.0F;
-                       rmat[1][3]= 0.0F;
-                       rmat[2][0]= 0.0F;
-                       rmat[2][1]= 0.0F;
-                       rmat[2][2]= 1.0F;
-                       rmat[2][3]= 0.0F;
-                       rmat[3][0]= cent[0];
-                       rmat[3][1]= cent[1];
-                       rmat[3][2]= cent[2];
-                       rmat[3][3]= 1.0F;
-
-                       /*              Rotate object's inversemat by the bone's rotation
-                       to get the coordinate space of the bone */
-                       Mat4CpyMat3     (itmat, imat);
-                       Mat4MulMat4 (restmat, rmat, itmat);

-                       /*      Find the bone head */
-                       tempVec[0]=0; tempVec[1]=0.0F; tempVec[2]=0.0F; tempVec[3]=1.0F;
-                       Mat4MulVec4fl (restmat, tempVec);
-                       VECCOPY (bone->head, tempVec);
-
-                       /*      Find the bone tail */
-                       tempVec[0]=0; tempVec[1]=length; tempVec[2]=0.0F; tempVec[3]=1.0F;
-                       Mat4MulVec4fl (restmat, tempVec);
-                       VECCOPY (bone->tail, tempVec);
-
-                       /*      IF we're a child of something, add the parents' translates      */
-
-                       /*      Offset of child is new cursor*/
-
-                       VECCOPY (newEnd,bone->tail); newEnd[3]=1;
-
-                       /*      Set the bone's transformations  */
-                       Mat4One (bone->obmat);
-                       bone->size[0]=bone->size[1]=bone->size[2]=1.0F;
-
-                       force_draw();
                        while(qtest()) {
                                event= extern_qread(&val);
                                if(val) {

--------------090502040700010209030701--