~uriboni/compiz/unminimize-configurable-independently

« back to all changes in this revision

Viewing changes to plugins/cubeaddon/src/cubeaddon.cpp

Fixed various problems described in bug 1030473.
Optimized performance and style following suggestions reported by cppcheck:

1. Reduced the scope of various variables.

2. Used prefix ++ operators for non-primitive types, because those can be more efficient than post-increment. Post-increment usually keeps a copy of the previous value, adds extra code and is slower.. Fixes: https://bugs.launchpad.net/bugs/1030473. Approved by Daniel van Vugt, Sam Spilsbury.

Show diffs side-by-side

added added

removed removed

Lines of Context:
611
611
        int                i, oldVCount = geometry.vCount;
612
612
        GLfloat            *v;
613
613
        int                offX = 0, offY = 0;
614
 
        int                sx1, sx2, sw, sy1, sy2, sh, cLast;
615
 
        float              lastX, lastZ = 0.0, radSquare, last[2][4];
 
614
        int                sx1, sx2, sw, sy1, sy2, sh;
 
615
        float              radSquare, last[2][4];
616
616
        float              inv = (cubeScreen->invert () == 1) ? 1.0 : -1.0;
617
617
 
618
 
        float              a1, a2, ang, vpx, vpy, sx1g, sx2g, sy1g, sy2g;
619
 
        int                iang;
 
618
        float              ang, sx1g, sx2g, sy1g, sy2g;
620
619
        
621
620
        CubeScreen::MultioutputMode   cMOM = cubeScreen->multioutputMode ();
622
621
        int                           caD = caScreen->optionGetDeformation ();
696
695
 
697
696
        if (caD == CubeaddonScreen::DeformationCylinder || cubeScreen->unfolded ())
698
697
        {
699
 
            lastX = -1000000000.0;
 
698
            float lastX = std::numeric_limits <float>::min (), lastZ = 0.0;
700
699
        
701
700
            for (i = oldVCount; i < geometry.vCount; i++)
702
701
            {
728
727
            last[0][0] = -1000000000.0;
729
728
            last[1][0] = -1000000000.0;
730
729
 
731
 
            cLast = 0;
 
730
            int cLast = 0;
732
731
            for (i = oldVCount; i < geometry.vCount; i++)
733
732
            {
734
733
                if (last[0][0] == v[0] && last[0][1] == v[1])
746
745
                    continue;
747
746
                }
748
747
                
749
 
                vpx = v[0] + offX;
750
 
                vpy = v[1] + offY;
 
748
                float vpx = v[0] + offX;
 
749
                float vpy = v[1] + offY;
751
750
                
752
751
                if (vpx >= sx1g && vpx < sx2g &&
753
752
                    vpy >= sy1g && vpy < sy2g)
754
753
                {
755
754
                    last[cLast][0] = v[0];
756
755
                    last[cLast][1] = v[1];
757
 
                    a1 = (((vpx - sx1) / (float)sw) - 0.5);
758
 
                    a2 = (((vpy - sy1) / (float)sh) - 0.5);
 
756
                    float a1 = (((vpx - sx1) / (float)sw) - 0.5);
 
757
                    float a2 = (((vpy - sy1) / (float)sh) - 0.5);
759
758
                    a2 *= a2;
760
759
 
761
760
                    ang = atanf (a1 / cDist);
762
761
                    a2 = sqrtf (radSquare - a2);
763
 
                    iang = (((int)(ang * RAD2I1024)) + 1024) & 0x3ff;
 
762
                    int iang = (((int)(ang * RAD2I1024)) + 1024) & 0x3ff;
764
763
 
765
764
                    v[2] += ((caScreen->mCosT [iang] * a2) - cDist) * caScreen->mDeform * inv;
766
765
                    v[0] += ((caScreen->mSinT [iang] * a2) - a1) * sw * caScreen->mDeform;
1001
1000
        mCapDeformType != optionGetDeformation ())
1002
1001
    {
1003
1002
        float       *quad;
1004
 
        int         i, j;
1005
 
        float       rS, r, x, y, z, w;
 
1003
        int         j;
 
1004
        float       rS, r, x, y, z;
1006
1005
        if (optionGetDeformation () != DeformationSphere ||
1007
1006
            !optionGetDeformCaps ())
1008
1007
        {
1039
1038
        }
1040
1039
        else
1041
1040
        {
 
1041
            int i;
 
1042
            float w;
1042
1043
            rS = cDist2 + 0.5;
1043
1044
 
1044
1045
            mCapFill[0] = 0.0;