From f6c7a8935762c5bf7ff77a0e7d5d63554c5eb80d Mon Sep 17 00:00:00 2001 From: Kent Mein Date: Wed, 30 Oct 2002 00:37:19 +0000 Subject: some small optimizations --- source/blender/blenkernel/intern/action.c | 20 +++++----- source/blender/blenkernel/intern/anim.c | 12 +++--- source/blender/blenkernel/intern/curve.c | 63 ++++++++++++++++++------------ source/blender/blenkernel/intern/effect.c | 5 ++- source/blender/blenkernel/intern/exotic.c | 23 ++++++----- source/blender/blenkernel/intern/lattice.c | 8 ++-- source/blender/blenkernel/intern/mesh.c | 8 ++-- 7 files changed, 80 insertions(+), 59 deletions(-) (limited to 'source') diff --git a/source/blender/blenkernel/intern/action.c b/source/blender/blenkernel/intern/action.c index 9f5de3f34fa..ccaabbff144 100644 --- a/source/blender/blenkernel/intern/action.c +++ b/source/blender/blenkernel/intern/action.c @@ -218,12 +218,14 @@ blend_poses ( /* Do the transformation blend */ for (i=0; i<3; i++){ - if (schan->flag & POSE_LOC) + if (schan->flag) { + if (POSE_LOC) dchan->loc[i] = (dchan->loc[i]*dstweight) + (schan->loc[i]*srcweight); - if (schan->flag & POSE_SIZE) + if (POSE_SIZE) dchan->size[i] = 1.0f + ((dchan->size[i]-1.0f)*dstweight) + ((schan->size[i]-1.0f)*srcweight); - if (schan->flag & POSE_ROT) + if (POSE_ROT) dchan->quat[i+1] = (dquat[i+1]*dstweight) + (squat[i+1]*srcweight); + } } /* Do one more iteration for the quaternions only and normalize the quaternion if needed */ @@ -850,15 +852,16 @@ bPoseChannel *set_pose_channel (bPose *pose, bPoseChannel *chan){ /* Determine if an equivalent channel exists already */ for (curChan=pose->chanbase.first; curChan; curChan=curChan->next){ if (!strcmp (curChan->name, chan->name)){ - if (chan->flag & POSE_ROT) + if (chan->flag) { + if (POSE_ROT) memcpy (curChan->quat, chan->quat, sizeof(chan->quat)); - if (chan->flag & POSE_SIZE) + if (POSE_SIZE) memcpy (curChan->size, chan->size, sizeof(chan->size)); - if (chan->flag & POSE_LOC) + if (POSE_LOC) memcpy (curChan->loc, chan->loc, sizeof(chan->loc)); - if (chan->flag & PCHAN_DONE) + if (PCHAN_DONE) Mat4CpyMat4 (curChan->obmat, chan->obmat); - + } curChan->flag |= chan->flag; MEM_freeN (chan); return curChan; @@ -870,4 +873,3 @@ bPoseChannel *set_pose_channel (bPose *pose, bPoseChannel *chan){ /* If an equivalent channel doesn't exist, then don't bother setting it. */ } - diff --git a/source/blender/blenkernel/intern/anim.c b/source/blender/blenkernel/intern/anim.c index 0fa358b30a0..afaf8b4ae66 100644 --- a/source/blender/blenkernel/intern/anim.c +++ b/source/blender/blenkernel/intern/anim.c @@ -70,7 +70,7 @@ void free_path(Path *path) void calc_curvepath(Object *ob) { BevList *bl; - BevPoint *bevp, *bevpn, *bevpfirst, *bevplast; + BevPoint *bevp, *bevpn, *bevpfirst, *bevplast, *tempbevp; Curve *cu; Nurb *nu; Path *path; @@ -125,9 +125,10 @@ void calc_curvepath(Object *ob) z= bevpfirst->z - bevp->z; } else { - x= (bevp+1)->x - bevp->x; - y= (bevp+1)->y - bevp->y; - z= (bevp+1)->z - bevp->z; + tempbevp = bevp+1; + x= (tempbevp)->x - bevp->x; + y= (tempbevp)->y - bevp->y; + z= (tempbevp)->z - bevp->z; } *fp= *(fp-1)+ (float)sqrt(x*x+y*y+z*z); @@ -146,10 +147,11 @@ void calc_curvepath(Object *ob) fp= dist+1; maxdist= dist+tot; fac= 1.0f/((float)path->len-1.0f); + fac = fac * path->totdist; for(a=0; alen; a++) { - d= ((float)a)*fac*path->totdist; + d= ((float)a)*fac; /* we zoeken plek 'd' in het array */ while((d>= *fp) && fp= oldy; y--) { + ttt = y * newx; for (x = newx - 1; x >= 0; x--) { - newp = new + 3 * (y * newx + x); + newp = new + 3 * (ttt + x); newp[0] = 0.0; newp[1] = 0.0; newp[2] = 0.0; } } for (; y >= 0; y--) { - + ttt = y * newx; + ooo = y * oldx; for (x = newx - 1; x >= oldx; x--) { - newp = new + 3 * (y * newx + x); + newp = new + 3 * (ttt + x); newp[0] = 0.0; newp[1] = 0.0; newp[2] = 0.0; } for (; x >= 0; x--) { - oldp = old + 3 * (y * oldx + x); - newp = new + 3 * (y * newx + x); + oldp = old + 3 * (ooo + x); + newp = new + 3 * (ttt + x); VECCOPY(newp, oldp); } } @@ -525,11 +528,13 @@ void extend_spline(float * pnts, int in, int out) { float *_pnts; double * add; - int i, j, k; + int i, j, k, in2; _pnts = pnts; add = (double*)MEM_mallocN((in)* sizeof(double), "extend_spline"); + in2 = in -1; + for (k = 3; k > 0; k--){ pnts = _pnts; @@ -540,8 +545,8 @@ void extend_spline(float * pnts, int in, int out) } /* inverse forward differencen */ - for (i = 0; i < in - 1; i++){ - for (j = in - 1; j > i; j--){ + for (i = 0; i < in2; i++){ + for (j = in2; j > i; j--){ add[j] -= add[j - 1]; } } @@ -550,7 +555,7 @@ void extend_spline(float * pnts, int in, int out) for (i = out; i > 0; i--){ *pnts = (float)(add[0]); pnts += 3; - for (j = 0; j < in - 1; j++){ + for (j = 0; j < in2; j++){ add[j] += add[j+1]; } } @@ -567,16 +572,18 @@ void calcknots(float *knots, short aantal, short order, short type) /* aantal, order, type; 0: uniform, 1: endpoints, 2: bezier */ { float k; - int a; + int a, t; + t = aantal+order; if(type==0) { - for(a=0;a=order && a<=aantal) k+= 1.0; } @@ -584,14 +591,14 @@ void calcknots(float *knots, short aantal, short order, short type) else if(type==2) { if(order==4) { k= 0.34; - for(a=0;a=order && a<=aantal) k+= (0.5); knots[a]= (float)floor(k); } @@ -602,21 +609,23 @@ void calcknots(float *knots, short aantal, short order, short type) void makecyclicknots(float *knots, short pnts, short order) /* pnts, order: aantal pnts NIET gecorrigeerd voor cyclic */ { - int a, b; + int a, b, order2, c; if(knots==0) return; + order2=order-1; /* eerst lange rijen (order -1) dezelfde knots aan uiteinde verwijderen */ if(order>2) { - b= pnts+order-1; - for(a=1; a knots[orderpluspnts-1]) t= knots[orderpluspnts-1]; + else if(t > knots[opp2]) t= knots[opp2]; /* dit stuk is order '1' */ - for(i=0;i= knots[i] && t<=knots[i+1]) { basis[i]= 1.0; - i1= i-order+1; + i1= i-o2; if(i1<0) i1= 0; i2= i; i++; - while(i= orderpluspnts) i2= orderpluspnts-j-1; + if(i2+j>= orderpluspnts) i2= opp2-j; for(i= i1; i<=i2; i++) { if(basis[i]!=0.0) diff --git a/source/blender/blenkernel/intern/effect.c b/source/blender/blenkernel/intern/effect.c index c39ad72ecdf..bdcb17e2d54 100644 --- a/source/blender/blenkernel/intern/effect.c +++ b/source/blender/blenkernel/intern/effect.c @@ -435,7 +435,7 @@ void make_particle_keys(int depth, int nr, PartEff *paf, Particle *part, float * void init_mv_jit(float *jit, int num) { float *jit2, x, rad1, rad2, rad3; - int i; + int i, num2; if(num==0) return; @@ -445,7 +445,8 @@ void init_mv_jit(float *jit, int num) BLI_srand(31415926 + num); x= 0; - for(i=0; i<2*num; i+=2) { + num2 = 2 * num; + for(i=0; idata[0]; - for(a=0; adatalen[0]-1; a++) { + lll = iv->datalen[0]-1; + for(a=0; adata[0]; - for(a=0; adatalen[0]-1; a++) { + for(a=0; adata[0], index, 2, coordtype); data+= 6; @@ -1252,7 +1253,8 @@ static void read_inventor(char *str, struct ListBase *listb) } /* indices */ - for(b=0; bdata[0]; - for(a=0; adatalen[0]-2; a++) { + lll = iv->datalen[0]-2; + for(a=0; lll; a++) { if(index[0]!= -1 && index[1]!= -1 && index[2]!= -1) face++; index++; } @@ -1319,8 +1322,8 @@ static void read_inventor(char *str, struct ListBase *listb) index= iv->data[0]; idata= dl->index; first= 1; - - for(a=0; adatalen[0]-2; a++) { + lll=iv->datalen[0]-2; + for(a=0; adata[0]; - for(a=0; adatalen[0]-2; a++) { + lll=iv->datalen[0]-2; + for(a=0; adata[0]; idata= dl->index; - for(a=iv->datalen[0]-2; a>0; a--) { + lll=iv->datalen[0]-2; + for(a=lll; a>0; a--) { if(index[0]!= -1 && index[1]!= -1 && index[2]!= -1) { idata[0]= (int) index[0]; diff --git a/source/blender/blenkernel/intern/lattice.c b/source/blender/blenkernel/intern/lattice.c index a6895d2a8ea..64d4ca367b2 100644 --- a/source/blender/blenkernel/intern/lattice.c +++ b/source/blender/blenkernel/intern/lattice.c @@ -280,7 +280,7 @@ void calc_latt_deform(float *co) Lattice *lt; float fu, du, u, v, w, tu[4], tv[4], tw[4]; float *fpw, *fpv, *fpu, vec[3]; - int ui, vi, wi, uu, vv, ww; + int ui, vi, wi, uu, vv, ww, end, end2; if(latticedata==0) return; @@ -329,7 +329,8 @@ void calc_latt_deform(float *co) wi= 0; } - for(ww= wi-1; ww<=wi+2; ww++) { + end = wi+2; + for(ww= wi-1; ww<=end; ww++) { w= tw[ww-wi+1]; if(w!=0.0) { @@ -339,7 +340,8 @@ void calc_latt_deform(float *co) } else fpw= latticedata; - for(vv= vi-1; vv<=vi+2; vv++) { + end2 = vi+2; + for(vv= vi-1; vv<=end; vv++) { v= w*tv[vv-vi+1]; if(v!=0.0) { diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c index 720d02ee7bb..b691441f099 100644 --- a/source/blender/blenkernel/intern/mesh.c +++ b/source/blender/blenkernel/intern/mesh.c @@ -463,13 +463,11 @@ void make_orco_displist_mesh(Object *ob, int subdivlvl) me->orco= MEM_mallocN(dlm->totvert*3*sizeof(float), "mesh displist orco"); - for (i=0; itotvert; i++) { - float *fp= &me->orco[i*3]; - VECCOPY(fp, dlm->mvert[i].co); - } - for(i=0; itotvert; i++) { float *fp= &me->orco[i*3]; + + VECCOPY(fp, dlm->mvert[i].co); + fp[0]= (fp[0]-me->loc[0])/me->size[0]; fp[1]= (fp[1]-me->loc[1])/me->size[1]; fp[2]= (fp[2]-me->loc[2])/me->size[2]; -- cgit v1.2.3