commit e8c81a8e3c4d34a400e02dbe6ef90f19f31f8382
Author: Leszek Koltunski <leszek@distoretedandroid.org>
Date:   Wed Jun 22 12:21:10 2016 +0100

    Cleanup, consistent variable names, minor details.

diff --git a/src/main/java/org/distorted/library/Distorted.java b/src/main/java/org/distorted/library/Distorted.java
index ae0e8e7..d6fe66a 100644
--- a/src/main/java/org/distorted/library/Distorted.java
+++ b/src/main/java/org/distorted/library/Distorted.java
@@ -38,7 +38,7 @@ import org.distorted.library.exception.*;
 public class Distorted 
 {
   /**
-   * When creating an instance of a DistortedBitmap from another instance, do not clone anything.
+   * When creating an instance of a DistortedObject from another instance, do not clone anything.
    * Used in the copy constructor.
    */
   public static final int CLONE_NOTHING = 0x0;
@@ -297,7 +297,7 @@ public class Distorted
     mFOV = fov;
    
     if( mProjection.width>0 && mProjection.height>0 )
-      mProjection.onSurfaceChanged( (int)mProjection.width, (int)mProjection.height);
+      mProjection.onSurfaceChanged( mProjection.width, mProjection.height);
     }
   
 ///////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/main/java/org/distorted/library/DistortedObject.java b/src/main/java/org/distorted/library/DistortedObject.java
index 058a10d..ec471a9 100644
--- a/src/main/java/org/distorted/library/DistortedObject.java
+++ b/src/main/java/org/distorted/library/DistortedObject.java
@@ -415,7 +415,7 @@ public abstract class DistortedObject
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 /**
- * Abort all Effects of a given type, for example all rotations.
+ * Abort all Effects of a given name, for example all rotations.
  * 
  * @param name one of the constants defined in {@link EffectNames}
  * @return number of Effects aborted.
@@ -457,7 +457,7 @@ public abstract class DistortedObject
 // Matrix-based effects
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 /**
- * Moves the Object by a vector that changes in time as interpolated by the Dynamic.
+ * Moves the Object by a (possibly changing in time) vector.
  * 
  * @param vector 3-dimensional Data which at any given time will return a Static3D
  *               representing the current coordinates of the vector we want to move the Object with.
@@ -470,7 +470,7 @@ public abstract class DistortedObject
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 /**
- * Scales the Object by factors that change in time as returned by the Dynamic.
+ * Scales the Object by (possibly changing in time) 3D scale factors.
  * 
  * @param scale 3-dimensional Dynamic which at any given time returns a Static3D
  *              representing the current x- , y- and z- scale factors.
@@ -483,7 +483,7 @@ public abstract class DistortedObject
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 /**
- * Scales the Object by one uniform factor in all 3 dimensions. Convenience function.
+ * Scales the Object by one uniform, constant factor in all 3 dimensions. Convenience function.
  *
  * @param scale The factor to scale all 3 dimensions with.
  * @return      ID of the effect added, or -1 if we failed to add one.
diff --git a/src/main/java/org/distorted/library/EffectMessageSender.java b/src/main/java/org/distorted/library/EffectMessageSender.java
index 976f6c3..921415e 100644
--- a/src/main/java/org/distorted/library/EffectMessageSender.java
+++ b/src/main/java/org/distorted/library/EffectMessageSender.java
@@ -105,7 +105,8 @@ final class EffectMessageSender extends Thread
       while( mList.size()>0 )
         {
         tmp = mList.remove(0);
-        tmp.mListener.effectMessage(tmp.mMessage, tmp.mEffectID, tmp.mEffectName, tmp.mBitmapID, tmp.mStr);
+        tmp.mListener.effectMessage(tmp.mMessage, tmp.mEffectID, EffectNames.getName(tmp.mEffectName),
+                                    tmp.mBitmapID, tmp.mStr);
         }
 
       synchronized(mThis)
diff --git a/src/main/java/org/distorted/library/EffectNames.java b/src/main/java/org/distorted/library/EffectNames.java
index 009889d..a73f0bc 100644
--- a/src/main/java/org/distorted/library/EffectNames.java
+++ b/src/main/java/org/distorted/library/EffectNames.java
@@ -93,7 +93,7 @@ public enum EffectNames
    * Uniforms: (forceX,forceY,forceZ,regionX,regionY,regionRX,regionRY,centerX,centerY)
    * Unity: (forceX,forceY,forceZ) = (0,0,0)
    */
-  DISTORT          ( EffectTypes.VERTEX  ,   new float[] {0.0f,0.0f,0.0f} ),      // keep this the first VERT effect (reason: getType)
+  DISTORT          ( EffectTypes.VERTEX  ,   new float[] {0.0f,0.0f,0.0f} ),
  /**
    * Deform the whole Object by applying a 2D vector of force to a center point.
    * <p>
@@ -126,7 +126,7 @@ public enum EffectNames
    * Uniforms: (macroblockSize,UNUSED,UNUSED,UNUSED, regionX, regionY, regionRX, regionRY)
    * Unity: macroblockSize = 1
    */
-  MACROBLOCK       ( EffectTypes.FRAGMENT,   new float[] {1.0f}           ),      // keep this the first FRAG effect (reason: getType)
+  MACROBLOCK       ( EffectTypes.FRAGMENT,   new float[] {1.0f}           ),
  /**
    * Make a given Region (partially) transparent.
    * <p>
@@ -204,12 +204,13 @@ public enum EffectNames
   
   private static final int MAXDIM = 4;  // maximum supported dimension of an effect  
   
-  private EffectTypes type;
-  private float[] unity;
-  
-  static private float[] unities;
-  static private int[] dimensions;
+  private final EffectTypes type;
+  private final float[] unity;
   
+  private static final float[] unities;
+  private static final int[] dimensions;
+  private static final EffectNames[] names;
+
   static
     {
     int len = values().length;
@@ -217,11 +218,13 @@ public enum EffectNames
     
     dimensions = new int[len];
     unities    = new float[MAXDIM*len];
-    
+    names      = new EffectNames[len];
+
     for(EffectNames name: EffectNames.values())
       {
       dimensions[i] = (name.unity==null ? 0 : name.unity.length);
-      
+      names[i]      = name;
+
       switch(dimensions[i])
         {
         case 4: unities[MAXDIM*i+3] = name.unity[3];
@@ -244,14 +247,17 @@ public enum EffectNames
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
-// yes, I know we could have used values(i) but that allocates a new copy each time!
 
   static EffectTypes getType(int ordinal)
     {
-    if( ordinal<DISTORT.ordinal()     ) return EffectTypes.MATRIX;
-    if( ordinal<MACROBLOCK.ordinal()  ) return EffectTypes.VERTEX;
+    return names[ordinal].type;
+    }
 
-    return EffectTypes.FRAGMENT;
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  static EffectNames getName(int ordinal)
+    {
+    return names[ordinal];
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/main/java/org/distorted/library/EffectQueue.java b/src/main/java/org/distorted/library/EffectQueue.java
index 87f7729..e7b388d 100644
--- a/src/main/java/org/distorted/library/EffectQueue.java
+++ b/src/main/java/org/distorted/library/EffectQueue.java
@@ -32,7 +32,7 @@ abstract class EffectQueue
   protected byte mNumEffects;   // number of effects at the moment
   protected long mTotalEffects; // total number of effects ever created
   
-  protected int[] mType;
+  protected int[] mName;
   protected float[] mUniforms;
   protected Dynamic[][] mInter;  // center of the effect
   protected long[] mCurrentDuration;
@@ -76,7 +76,7 @@ abstract class EffectQueue
 
     if( mMax[mMaxIndex]>0 )
       {
-      mType            = new int[mMax[mMaxIndex]];
+      mName            = new int[mMax[mMaxIndex]];
       mUniforms        = new float[numUniforms*mMax[mMaxIndex]];
       mInter           = new Dynamic[3][mMax[mMaxIndex]];
       mCurrentDuration = new long[mMax[mMaxIndex]];
@@ -175,7 +175,7 @@ abstract class EffectQueue
      
     for(int i=0; i<mNumEffects; i++)
       {
-      if( mType[i]==ord )
+      if( mName[i]==ord )
         {
         remove(i);
         i--;
@@ -202,7 +202,7 @@ abstract class EffectQueue
     {
     int ret = mNumEffects;
     long removedID;
-    int removedType;
+    int removedName;
 
     for(int i=0; i<ret; i++ )
       {
@@ -213,13 +213,13 @@ abstract class EffectQueue
       if( notify )
         {
         removedID = mID[i];
-        removedType= mType[i];
+        removedName= mName[i];
 
         for(int j=0; j<mNumListeners; j++)
           EffectMessageSender.newMessage( mListeners.elementAt(j),
                                           EffectMessage.EFFECT_REMOVED,
-                                          (removedID<<EffectTypes.LENGTH)+EffectNames.getType(removedType).type,
-                                          removedType,
+                                          (removedID<<EffectTypes.LENGTH)+EffectNames.getType(removedName).type,
+                                          removedName,
                                           mBitmapID,
                                           null);
         }
@@ -242,7 +242,7 @@ abstract class EffectQueue
     mFreeIndexes[mNumEffects] = removedIndex;
     
     long removedID = mID[effect];
-    int removedType= mType[effect];
+    int removedName= mName[effect];
     
     for(int j=0; j<mMax[mMaxIndex]; j++)
       {
@@ -251,7 +251,7 @@ abstract class EffectQueue
          
     for(int j=effect; j<mNumEffects; j++ ) 
       {
-      mType[j]            = mType[j+1];
+      mName[j]            = mName[j+1];
       mInter[0][j]        = mInter[0][j+1];
       mInter[1][j]        = mInter[1][j+1];
       mInter[2][j]        = mInter[2][j+1];
@@ -268,17 +268,17 @@ abstract class EffectQueue
     for(int i=0; i<mNumListeners; i++) 
       EffectMessageSender.newMessage( mListeners.elementAt(i),
                                       EffectMessage.EFFECT_REMOVED,
-                                      (removedID<<EffectTypes.LENGTH)+EffectNames.getType(removedType).type,
-                                      removedType,
+                                      (removedID<<EffectTypes.LENGTH)+EffectNames.getType(removedName).type,
+                                      removedName,
                                       mBitmapID,
                                       null);
     }
   
 ///////////////////////////////////////////////////////////////////////////////////////////////////
   
-  protected long addBase(EffectNames eln)
+  protected long addBase(EffectNames name)
     {    
-    mType[mNumEffects]  = eln.ordinal();  
+    mName[mNumEffects]  = name.ordinal();
     mCurrentDuration[mNumEffects] = 0;
     
     int index = mFreeIndexes[mNumEffects];
@@ -289,7 +289,7 @@ abstract class EffectQueue
     mNumEffects++; 
     mTotalEffects++;
    
-    return (id<<EffectTypes.LENGTH)+eln.getType().type;
+    return (id<<EffectTypes.LENGTH)+name.getType().type;
     }
     
 ///////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/main/java/org/distorted/library/EffectQueueFragment.java b/src/main/java/org/distorted/library/EffectQueueFragment.java
index fb19694..346f523 100644
--- a/src/main/java/org/distorted/library/EffectQueueFragment.java
+++ b/src/main/java/org/distorted/library/EffectQueueFragment.java
@@ -80,16 +80,17 @@ class EffectQueueFragment extends EffectQueue
           EffectMessageSender.newMessage( mListeners.elementAt(j),
                                           EffectMessage.EFFECT_FINISHED,
                                           (mID[i]<<EffectTypes.LENGTH)+EffectTypes.FRAGMENT.type,
-                                          mType[i], 
+                                          mName[i],
                                           mBitmapID,
                                           null);
       
-        if( EffectNames.isUnity(mType[i], mUniforms, NUM_UNIFORMS*i) )
+        if( EffectNames.isUnity(mName[i], mUniforms, NUM_UNIFORMS*i) )
           {
           remove(i);
           i--;
           continue;
           }
+        else mInter[0][i] = null;
         }
 
       if( mInter[1][i]!=null ) mInter[1][i].interpolateMain(     mBuf,            4*i  , mCurrentDuration[i]);
@@ -125,7 +126,7 @@ class EffectQueueFragment extends EffectQueue
       
     if( mNumEffects>0 )
       {     
-      GLES20.glUniform1iv( mTypeH    ,  mNumEffects, mType    ,0);
+      GLES20.glUniform1iv( mTypeH    ,  mNumEffects, mName,0);
       GLES20.glUniform4fv( mUniformsH,2*mNumEffects, mUniforms,0);
       }  
     }
@@ -160,7 +161,7 @@ class EffectQueueFragment extends EffectQueue
         mUniforms[NUM_UNIFORMS*i+6] = w*mBuf[4*i+2];                                  // in fragment shader rx and ry radii are the last two values of the second vec4
         mUniforms[NUM_UNIFORMS*i+7] = h*mBuf[4*i+3];                                  //
 
-        if( mType[i]==EffectNames.MACROBLOCK.ordinal() ) // fill up the .y and .z components of the Interpolated values already to avoid having to compute this in the fragment shader
+        if( mName[i]==EffectNames.MACROBLOCK.ordinal() ) // fill up the .y and .z components of the Interpolated values already to avoid having to compute this in the fragment shader
           {
           mUniforms[NUM_UNIFORMS*i+1] = 2.0f*mObjHalfX/mUniforms[NUM_UNIFORMS*i];
           mUniforms[NUM_UNIFORMS*i+2] = 2.0f*mObjHalfY/mUniforms[NUM_UNIFORMS*i];
diff --git a/src/main/java/org/distorted/library/EffectQueueMatrix.java b/src/main/java/org/distorted/library/EffectQueueMatrix.java
index 5504189..4144a4d 100644
--- a/src/main/java/org/distorted/library/EffectQueueMatrix.java
+++ b/src/main/java/org/distorted/library/EffectQueueMatrix.java
@@ -111,16 +111,17 @@ class EffectQueueMatrix extends EffectQueue
           EffectMessageSender.newMessage( mListeners.elementAt(j),
                                           EffectMessage.EFFECT_FINISHED,
                                          (mID[i]<<EffectTypes.LENGTH)+EffectTypes.MATRIX.type,
-                                          mType[i],
+                                          mName[i],
                                           mBitmapID,
                                           null);
 
-        if( EffectNames.isUnity(mType[i], mUniforms, NUM_UNIFORMS*i) )
+        if( EffectNames.isUnity(mName[i], mUniforms, NUM_UNIFORMS*i) )
           {
           remove(i);
           i--;
           continue;
           }
+        else mInter[0][i] = null;
         }
 
       if( mInter[1][i]!=null )
@@ -159,7 +160,7 @@ class EffectQueueMatrix extends EffectQueue
    
     for(int i=0; i<mNumEffects; i++)
       {
-      if (mType[i] == EffectNames.ROTATE.ordinal() )
+      if (mName[i] == EffectNames.ROTATE.ordinal() )
         {
         x = mUniforms[NUM_UNIFORMS*i+4];
         y = mUniforms[NUM_UNIFORMS*i+5];
@@ -169,7 +170,7 @@ class EffectQueueMatrix extends EffectQueue
         Matrix.rotateM( viewMatrix, 0, mUniforms[NUM_UNIFORMS*i], mUniforms[NUM_UNIFORMS*i+1], mUniforms[NUM_UNIFORMS*i+2], mUniforms[NUM_UNIFORMS*i+3]);
         Matrix.translateM(viewMatrix, 0,-x, y,-z);  
         }
-      else if(mType[i] == EffectNames.QUATERNION.ordinal() )
+      else if(mName[i] == EffectNames.QUATERNION.ordinal() )
         {
         x = mUniforms[NUM_UNIFORMS*i+4];
         y = mUniforms[NUM_UNIFORMS*i+5];
@@ -179,7 +180,7 @@ class EffectQueueMatrix extends EffectQueue
         multiplyByQuat(viewMatrix, mUniforms[NUM_UNIFORMS*i], mUniforms[NUM_UNIFORMS*i+1], mUniforms[NUM_UNIFORMS*i+2], mUniforms[NUM_UNIFORMS*i+3]);
         Matrix.translateM(viewMatrix, 0,-x, y,-z);  
         }
-      else if(mType[i] == EffectNames.MOVE.ordinal() )
+      else if(mName[i] == EffectNames.MOVE.ordinal() )
         {
         sx = mUniforms[NUM_UNIFORMS*i  ];
         sy = mUniforms[NUM_UNIFORMS*i+1];
@@ -187,7 +188,7 @@ class EffectQueueMatrix extends EffectQueue
         
         Matrix.translateM(viewMatrix, 0, sx,-sy, sz);   
         }
-      else if(mType[i] == EffectNames.SCALE.ordinal() )
+      else if(mName[i] == EffectNames.SCALE.ordinal() )
         {
         sx = mUniforms[NUM_UNIFORMS*i  ];
         sy = mUniforms[NUM_UNIFORMS*i+1];
@@ -195,7 +196,7 @@ class EffectQueueMatrix extends EffectQueue
 
         Matrix.scaleM(viewMatrix, 0, sx, sy, sz);  
         }
-      else if(mType[i] == EffectNames.SHEAR.ordinal() )
+      else if(mName[i] == EffectNames.SHEAR.ordinal() )
         {
         sx = mUniforms[NUM_UNIFORMS*i  ];
         sy = mUniforms[NUM_UNIFORMS*i+1];
diff --git a/src/main/java/org/distorted/library/EffectQueueVertex.java b/src/main/java/org/distorted/library/EffectQueueVertex.java
index 43c3eb6..e82edba 100644
--- a/src/main/java/org/distorted/library/EffectQueueVertex.java
+++ b/src/main/java/org/distorted/library/EffectQueueVertex.java
@@ -77,16 +77,17 @@ class EffectQueueVertex extends EffectQueue
           EffectMessageSender.newMessage( mListeners.elementAt(j),
                                           EffectMessage.EFFECT_FINISHED,
                                          (mID[i]<<EffectTypes.LENGTH)+EffectTypes.VERTEX.type,
-                                          mType[i],
+                                          mName[i],
                                           mBitmapID,
                                           null);
 
-        if( EffectNames.isUnity(mType[i], mUniforms, NUM_UNIFORMS*i) )
+        if( EffectNames.isUnity(mName[i], mUniforms, NUM_UNIFORMS*i) )
           {
           remove(i);
           i--;
           continue;
           }
+        else mInter[0][i] = null;
         }
 
       if( mInter[1][i]!=null )
@@ -100,8 +101,6 @@ class EffectQueueVertex extends EffectQueue
 
         mUniforms[NUM_UNIFORMS*i+7] = mUniforms[NUM_UNIFORMS*i+7]-mObjHalfX;
         mUniforms[NUM_UNIFORMS*i+8] =-mUniforms[NUM_UNIFORMS*i+8]+mObjHalfY;
-
-        //android.util.Log.e("queue", "computing dynamic center, x="+(mUniforms[NUM_UNIFORMS*i+7]));
         }
 
       mCurrentDuration[i] += step;
@@ -133,7 +132,7 @@ class EffectQueueVertex extends EffectQueue
       
     if( mNumEffects>0 )
       {     
-      GLES20.glUniform1iv( mTypeH    ,  mNumEffects, mType    ,0);
+      GLES20.glUniform1iv( mTypeH    ,  mNumEffects, mName,0);
       GLES20.glUniform3fv( mUniformsH,3*mNumEffects, mUniforms,0);
       }
     }
@@ -156,7 +155,7 @@ class EffectQueueVertex extends EffectQueue
      
     for(int i=0; i<mNumEffects; i++)
       {      
-      if( mType[i]==EffectNames.SWIRL.ordinal() )
+      if( mName[i]==EffectNames.SWIRL.ordinal() )
         {
         d = Math.PI*mUniforms[NUM_UNIFORMS*i]/180;  
         mUniforms[NUM_UNIFORMS*i+1] = (float)Math.sin(d);
diff --git a/src/main/java/org/distorted/library/message/EffectListener.java b/src/main/java/org/distorted/library/message/EffectListener.java
index d2b49ec..ebd9d13 100644
--- a/src/main/java/org/distorted/library/message/EffectListener.java
+++ b/src/main/java/org/distorted/library/message/EffectListener.java
@@ -37,8 +37,8 @@ public interface EffectListener
  * @param eventType  Type of event that happened.
  * @param effectID   ID of the effect the event happened to. This ID must have been previously returned by one
  *                   of the DistortedObject.{deform,distort,move,...} functions.
- * @param effectName Name of the effect as defined by EffectNames.ordinal()
- * @param bitmapID   the ID of the DistortedObject object, as returned by {@link org.distorted.library.DistortedObject#getID()},
+ * @param effectName Name of the effect as defined by EffectNames.
+ * @param objectID   the ID of the DistortedObject object, as returned by {@link org.distorted.library.DistortedObject#getID()},
  *                   this event happened to. If the Object has been created using a copy constructor
  *                   from another instance of DistortedObject, the ID here will be the one of the original object.
  * @param message    Any message string associated with it. 'Failed' event types have one.
@@ -46,7 +46,7 @@ public interface EffectListener
  * @see EffectNames
  */
    
-  void effectMessage(final EffectMessage eventType, final long effectID, final int effectName, final long bitmapID, final String message);
+  void effectMessage(final EffectMessage eventType, final long effectID, final EffectNames effectName, final long objectID, final String message);
   }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/main/java/org/distorted/library/message/EffectMessage.java b/src/main/java/org/distorted/library/message/EffectMessage.java
index ff9d292..1e7f4ee 100644
--- a/src/main/java/org/distorted/library/message/EffectMessage.java
+++ b/src/main/java/org/distorted/library/message/EffectMessage.java
@@ -21,9 +21,6 @@ package org.distorted.library.message;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-import org.distorted.library.DistortedBitmap;
-import org.distorted.library.type.Dynamic;
-
 /**
 * Defines all possible events a class implementing the {@link EffectListener} interface can receive.
 */
@@ -33,7 +30,8 @@ public enum EffectMessage
 /**
  * The effect has been removed. This can happen if:
  * <ul>
- * <li> someone explicitly removed the effect with a call to {@link DistortedBitmap#abortEffect(long)} (or one of the other 'abort' methods)
+ * <li> someone explicitly removed the effect with a call to {@link org.distorted.library.DistortedObject#abortEffect(long)}
+ *      (or one of the other 'abort' methods)
  * <li> the interpolation of the effect has finished and the end result is equal to the effect's unity.
  * </ul>    
  */
@@ -43,10 +41,10 @@ public enum EffectMessage
  * Interpolation of the effect has finished. 
  * <p>
  * If you set up an interpolated effect and set its Dynamic to do 3.5 interpolations of 1000 ms each
- * with calls to {@link Dynamic#setCount(float)} and {@link Dynamic#setDuration(long)},
+ * with calls to {@link org.distorted.library.type.Dynamic#setCount(float)} and {@link org.distorted.library.type.Dynamic#setDuration(long)},
  * then you are going to get this message exactly once after 3.5*1000 = 3500 milliseconds when the interpolation 
  * finishes. You will never get this message if you set the effect to go on indefinitely with a call to 
- * {@link Dynamic#setCount(float)}.
+ * {@link org.distorted.library.type.Dynamic#setCount(float)} where float=0.0f.
  * <p>  
  * If then the end effect is equal to the effect's unity, then immediately after this message you
  * will also get a EFFECT_REMOVED message.
