commit 8e34674e911c7e24deb8a6af26b436e3508a533e
Author: Leszek Koltunski <leszek@distorted.org>
Date:   Wed Dec 7 00:22:39 2016 +0000

    Move the *List classes into static members of DistortedFramebuffer and DistortedObject.

diff --git a/src/main/java/org/distorted/library/Distorted.java b/src/main/java/org/distorted/library/Distorted.java
index d178bc1..220b3f2 100644
--- a/src/main/java/org/distorted/library/Distorted.java
+++ b/src/main/java/org/distorted/library/Distorted.java
@@ -115,7 +115,7 @@ public class Distorted
     Log.d(TAG, "Max vectors in vertex shader: "+maxV);
     Log.d(TAG, "Max vectors in fragment shader: "+maxF);
     
-    if( Build.FINGERPRINT.contains("generic") == false )
+    if( !Build.FINGERPRINT.contains("generic") )
       {
       int realMaxV = (maxV-11)/4;   // adjust this in case of changes to the shaders...
       int realMaxF = (maxF- 2)/4;   //
@@ -347,7 +347,7 @@ public class Distorted
     GLES20.glEnableVertexAttribArray(mNormalH);
     GLES20.glEnableVertexAttribArray(mTextureCoordH);
    
-    DistortedObjectList.reset();
+    DistortedObject.reset();
     DistortedNode.reset();
     EffectMessageSender.startSending();
     }
@@ -373,10 +373,10 @@ public class Distorted
   public static void onDestroy()
     {
     DistortedGridFactory.release();
-    DistortedObjectList.release();
-    DistortedFramebufferList.release();
+    DistortedObject.release();
+    DistortedFramebuffer.release();
     DistortedNode.release();
-    EffectQueue.reset();
+    EffectQueue.release();
     EffectMessageSender.stopSending();
    
     mInitialized = false;
diff --git a/src/main/java/org/distorted/library/DistortedFramebuffer.java b/src/main/java/org/distorted/library/DistortedFramebuffer.java
index 1a0e5f3..158212f 100644
--- a/src/main/java/org/distorted/library/DistortedFramebuffer.java
+++ b/src/main/java/org/distorted/library/DistortedFramebuffer.java
@@ -22,6 +22,9 @@ package org.distorted.library;
 import android.opengl.GLES20;
 import android.opengl.Matrix;
 
+import java.util.Iterator;
+import java.util.LinkedList;
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 /**
  * Class which represents a OpenGL Framebuffer object.
@@ -29,6 +32,12 @@ import android.opengl.Matrix;
  * User is able to create either WRITE-only Framebuffers from objects already constructed outside
  * of the library (the first constructor; primary use case: the screen) or an offscreen READ-WRITE
  * FBOs (used by the DistortedNode, but also can be used by external users of the library)
+ *
+ * Also, keep all objects created in a static LinkedList. The point: we need to be able to mark
+ * Framebuffers for deletion, and delete all marked objects later at a convenient time (that's
+ * because we can only delete from a thread that holds the OpenGL context so here we provide a
+ * framework where one is able to mark for deletion at any place and actual deletion takes place
+ * on the next render).
  */
 public class DistortedFramebuffer
   {
@@ -36,15 +45,19 @@ public class DistortedFramebuffer
   private static final int TEXTURE_NOT_CREATED_YET  = -2;
   private static final int TEXTURE_DONT_CREATE      = -3;
 
+  private static boolean mListMarked = false;
+  private static LinkedList<DistortedFramebuffer> mList = new LinkedList<>();
+
   private float mX, mY;
   private float mFOV;
 
   private int[] texIds = new int[1];
   private int[] fboIds = new int[1];
 
+  private boolean mMarked;
+
   int mWidth,mHeight,mDepth,mDistance;
   float[] mProjectionMatrix;
-  boolean mMarked;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
@@ -112,7 +125,7 @@ public class DistortedFramebuffer
       return false;
       }
 
-    DistortedFramebufferList.add(this);
+    mList.add(this);
     android.util.Log.e("FBO", "created ("+mWidth+","+mHeight+") "+fboIds[0]);
 
     return true;
@@ -135,7 +148,7 @@ public class DistortedFramebuffer
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 // must be called from a thread holding OpenGL Context
 
-  void release()
+  private void delete()
     {
     if( texIds[0]>=0 ) deleteFBO();
 
@@ -150,6 +163,38 @@ public class DistortedFramebuffer
     texIds[0] = TEXTURE_NOT_CREATED_YET;
     }
 
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  static synchronized void release()
+    {
+    mListMarked = false;
+    mList.clear();
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// must be called form a thread holding OpenGL Context
+
+  static synchronized void deleteAllMarked()
+    {
+    if( mListMarked )
+      {
+      DistortedFramebuffer tmp;
+      Iterator<DistortedFramebuffer> iterator = mList.iterator();
+
+      while(iterator.hasNext())
+        {
+        tmp = iterator.next();
+
+        if( tmp.mMarked )
+          {
+          tmp.delete();
+          iterator.remove();
+          }
+        }
+
+      mListMarked = false;
+      }
+    }
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 // PUBLIC API
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -203,8 +248,8 @@ public class DistortedFramebuffer
     {
     android.util.Log.e("FBO", "marking for deletion ("+mWidth+","+mHeight+") "+fboIds[0]);
 
-    DistortedFramebufferList.markForDeletion();
-    mMarked = true;
+    mListMarked = true;
+    mMarked     = true;
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/main/java/org/distorted/library/DistortedFramebufferList.java b/src/main/java/org/distorted/library/DistortedFramebufferList.java
deleted file mode 100644
index 9f98ffa..0000000
--- a/src/main/java/org/distorted/library/DistortedFramebufferList.java
+++ /dev/null
@@ -1,87 +0,0 @@
-///////////////////////////////////////////////////////////////////////////////////////////////////
-// Copyright 2016 Leszek Koltunski                                                               //
-//                                                                                               //
-// This file is part of Distorted.                                                               //
-//                                                                                               //
-// Distorted is free software: you can redistribute it and/or modify                             //
-// it under the terms of the GNU General Public License as published by                          //
-// the Free Software Foundation, either version 2 of the License, or                             //
-// (at your option) any later version.                                                           //
-//                                                                                               //
-// Distorted is distributed in the hope that it will be useful,                                  //
-// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
-// GNU General Public License for more details.                                                  //
-//                                                                                               //
-// You should have received a copy of the GNU General Public License                             //
-// along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                            //
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-package org.distorted.library;
-
-import java.util.LinkedList;
-import java.util.Iterator;
-
-/**
- * List of all DistortedFramebuffer objects currently created by the application.
- *
- * The point: we need to be able to mark Framebuffers for deletion, and delete all marked
- * objects later at a convenient time (that's because we can only delete from a thread that
- * holds the OpenGL context so here we provide a framework where one is able to mark for deletion
- * at any place and actual deletion takes place on the next render).
- */
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-final class DistortedFramebufferList
-  {
-  private static boolean mMarked = false;
-  private static LinkedList<DistortedFramebuffer> mList = new LinkedList<>();
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-  static synchronized void add(DistortedFramebuffer drt)
-    {
-    mList.add(drt);
-    }
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-  static synchronized void markForDeletion()
-    {
-    mMarked = true;
-    }
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-  static synchronized void release()
-    {
-    mMarked = false;
-    mList.clear();
-    }
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-// must be called form a thread holding OpenGL Context
-
-  static synchronized void deleteAllMarked()
-    {
-    if( mMarked )
-      {
-      DistortedFramebuffer tmp;
-      Iterator<DistortedFramebuffer> iterator = mList.iterator();
-
-      while(iterator.hasNext())
-        {
-        tmp = iterator.next();
-
-        if( tmp.mMarked )
-          {
-          tmp.release();
-          iterator.remove();
-          }
-        }
-
-      mMarked = false;
-      }
-    }
-  }
diff --git a/src/main/java/org/distorted/library/DistortedNode.java b/src/main/java/org/distorted/library/DistortedNode.java
index ca11e73..8b57aac 100644
--- a/src/main/java/org/distorted/library/DistortedNode.java
+++ b/src/main/java/org/distorted/library/DistortedNode.java
@@ -90,7 +90,7 @@ public class DistortedNode
       }
     else
       {
-      if( mData.mRendered==false )
+      if( !mData.mRendered )
         {
         mData.mRendered = true;
         mData.mDF.setOutput();
diff --git a/src/main/java/org/distorted/library/DistortedObject.java b/src/main/java/org/distorted/library/DistortedObject.java
index 1e7c7ed..c0941c9 100644
--- a/src/main/java/org/distorted/library/DistortedObject.java
+++ b/src/main/java/org/distorted/library/DistortedObject.java
@@ -32,12 +32,22 @@ import org.distorted.library.type.Data4D;
 import org.distorted.library.type.Data5D;
 import org.distorted.library.type.Static3D;
 
+import java.util.HashMap;
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 /**
  * All Objects to which Distorted Graphics effects can be applied need to be extended from here.
+ *
+ * Just like in DistortedNode and DistortedFramebuffer, we need to have a static list of all
+ * DistortedObjects currently created by the application so that we can implement the 'mark for
+ * deletion now - actually delete on next render' thing.
+ * We need to be able to quickly retrieve an Object by its ID, thus a HashMap.
  */
 public abstract class DistortedObject 
   {
+  private static long mNextID =0;
+  private static HashMap<Long,DistortedObject> mObjects = new HashMap<>();
+
   private EffectQueueMatrix    mM;
   private EffectQueueFragment  mF;
   private EffectQueueVertex    mV;
@@ -82,7 +92,9 @@ public abstract class DistortedObject
     mSizeY= y;
     mSizeZ= z;
 
-    mID             = DistortedObjectList.add(this);
+    mID = mNextID++;
+    mObjects.put(mID,this);
+
     mTextureDataH   = new int[1];
     mTextureDataH[0]= 0;
     mBmp            = new Bitmap[1];
@@ -137,7 +149,7 @@ public abstract class DistortedObject
 // this will be called on startup and every time OpenGL context has been lost
 // also call this from the constructor if the OpenGL context has been created already.
     
-  void resetTexture()
+  private void resetTexture()
     {
     if( mTextureDataH!=null )
       {
@@ -161,7 +173,7 @@ public abstract class DistortedObject
    
   void drawPriv(long currTime, DistortedFramebuffer df)
     {
-    DistortedFramebufferList.deleteAllMarked();
+    DistortedFramebuffer.deleteAllMarked();
 
     GLES20.glViewport(0, 0, df.mWidth, df.mHeight);
       
@@ -190,11 +202,11 @@ public abstract class DistortedObject
     
 ///////////////////////////////////////////////////////////////////////////////////////////////////
    
-  void releasePriv()
+  private void releasePriv()
     {
-    if( matrixCloned  ==false) mM.abortAll(false);
-    if( vertexCloned  ==false) mV.abortAll(false);
-    if( fragmentCloned==false) mF.abortAll(false);
+    if( !matrixCloned  ) mM.abortAll(false);
+    if( !vertexCloned  ) mV.abortAll(false);
+    if( !fragmentCloned) mF.abortAll(false);
 
     mBmp          = null;
     mGrid         = null;
@@ -207,10 +219,35 @@ public abstract class DistortedObject
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   long getBitmapID()
+    {
+    return mBmp==null ? 0 : mBmp.hashCode();
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  static synchronized void reset()
+    {
+    for(long id: mObjects.keySet())
       {
-      return mBmp==null ? 0 : mBmp.hashCode();
+      mObjects.get(id).resetTexture();
+      }
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  static synchronized void release()
+    {
+    for(long id: mObjects.keySet())
+      {
+      mObjects.get(id).releasePriv();
       }
 
+    mObjects.clear();
+    mNextID = 0;
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// PUBLIC API
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 /**
  * Default empty constructor so that derived classes can call it
@@ -236,7 +273,8 @@ public abstract class DistortedObject
     {
     initializeEffectLists(dc,flags);
 
-    mID = DistortedObjectList.add(this);
+    mID = mNextID++;
+    mObjects.put(mID,this);
 
     mSizeX = dc.mSizeX;
     mSizeY = dc.mSizeY;
@@ -284,10 +322,10 @@ public abstract class DistortedObject
 /**
  * Releases all resources.
  */
-  public synchronized void release()
+  public synchronized void delete()
     {
     releasePriv();
-    DistortedObjectList.remove(this);
+    mObjects.remove(this);
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/main/java/org/distorted/library/DistortedObjectList.java b/src/main/java/org/distorted/library/DistortedObjectList.java
deleted file mode 100644
index 9a6f120..0000000
--- a/src/main/java/org/distorted/library/DistortedObjectList.java
+++ /dev/null
@@ -1,81 +0,0 @@
-///////////////////////////////////////////////////////////////////////////////////////////////////
-// Copyright 2016 Leszek Koltunski                                                               //
-//                                                                                               //
-// This file is part of Distorted.                                                               //
-//                                                                                               //
-// Distorted is free software: you can redistribute it and/or modify                             //
-// it under the terms of the GNU General Public License as published by                          //
-// the Free Software Foundation, either version 2 of the License, or                             //
-// (at your option) any later version.                                                           //
-//                                                                                               //
-// Distorted is distributed in the hope that it will be useful,                                  //
-// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
-// GNU General Public License for more details.                                                  //
-//                                                                                               //
-// You should have received a copy of the GNU General Public License                             //
-// along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                            //
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-package org.distorted.library;
-
-import java.util.HashMap;
-/**
- * List of all DistortedObjects currently created by the application.
- * We need to be able to quickly retrieve an Object by its ID, thus a HashMap.
- */
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-final class DistortedObjectList 
-  {
-  private static long id =0;  
-  private static HashMap<Long,DistortedObject> mObjects = new HashMap<>();
-  
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-  static synchronized long add(DistortedObject obj)
-    {
-    long ret = id++;  
-    mObjects.put(ret,obj);
-    return ret;
-    }
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-  static synchronized void remove(DistortedObject obj)
-    {
-    mObjects.remove(obj);
-    }
-  
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-  static DistortedObject get(long id)
-    {
-    return mObjects.get(id);
-    }
-  
-///////////////////////////////////////////////////////////////////////////////////////////////////
-  
-  static synchronized void reset()
-    {
-    for(long id: mObjects.keySet())
-      {
-      get(id).resetTexture();  
-      }
-    }
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-  static synchronized void release()
-    {
-    for(long id: mObjects.keySet())
-      {
-      get(id).releasePriv();  
-      }
-   
-    mObjects.clear();
-    id = 0;
-    }
-  
-///////////////////////////////////////////////////////////////////////////////////////////////////
-  }
diff --git a/src/main/java/org/distorted/library/EffectQueue.java b/src/main/java/org/distorted/library/EffectQueue.java
index 960978c..56441d8 100644
--- a/src/main/java/org/distorted/library/EffectQueue.java
+++ b/src/main/java/org/distorted/library/EffectQueue.java
@@ -54,7 +54,7 @@ abstract class EffectQueue
 
   static
     {
-    reset();
+    release();
     }
   
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -104,7 +104,7 @@ abstract class EffectQueue
 
   static boolean setMax(int index, int m)
     {
-    if( (mCreated==false && !Distorted.isInitialized()) || m<=mMax[index] )
+    if( (!mCreated && !Distorted.isInitialized()) || m<=mMax[index] )
       {
       if( m<0              ) m = 0;
       else if( m>Byte.MAX_VALUE ) m = Byte.MAX_VALUE;
@@ -146,7 +146,7 @@ abstract class EffectQueue
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  static void reset()
+  static void release()
     {
     EffectTypes.reset(mMax);
     mCreated = false;  
@@ -341,15 +341,15 @@ abstract class EffectQueue
       android.util.Log.e("EffectQueue", "numEffects="+mNumEffects+" effect id="+id+" index="+index+
                          " duration="+mCurrentDuration[index]+" inter[0] null="+inter0+" inter[1] null="+inter1+" inter[2] null="+inter2);
       
-      if( inter0==false )
+      if( !inter0 )
         {
         android.util.Log.e("EffectQueue","inter[0]: "+mInter[0][index].print());
         }
-      if( inter1==false )
+      if( !inter1 )
         {
         android.util.Log.e("EffectQueue","inter[1]: "+mInter[1][index].print());
         }
-      if( inter2==false )
+      if( !inter2 )
         {
         android.util.Log.e("EffectQueue","inter[2]: "+mInter[2][index].print());
         }
