commit 665e2c458e00cbda3af13a723973cf5bb1d484d0
Author: Leszek Koltunski <leszek@distorted.org>
Date:   Tue Oct 18 15:34:17 2016 +0100

    New constructor to DistortedCubes - easily create a hole-less Cuboid.

diff --git a/src/main/java/org/distorted/library/DistortedCubes.java b/src/main/java/org/distorted/library/DistortedCubes.java
index ee10af6..ea8998b 100644
--- a/src/main/java/org/distorted/library/DistortedCubes.java
+++ b/src/main/java/org/distorted/library/DistortedCubes.java
@@ -103,6 +103,24 @@ public class DistortedCubes extends DistortedObject
    initializeData();
    }
 
+///////////////////////////////////////////////////////////////////////////////////////////////////
+/**
+ * Creates internal memory representation of a full, hole-less cuboid subset.
+ *
+ * @param cols Number of columns
+ * @param rows Number of rows
+ * @param cubeSize size, in pixels, of the single 1x1x1 cube our cuboid is built from
+ * @param frontOnly Only create the front wall or side and back as well?
+ */
+ public DistortedCubes(int cols, int rows, int cubeSize, boolean frontOnly)
+   {
+   mSizeX= cubeSize*cols;
+   mSizeY= cubeSize*rows;
+   mSizeZ= frontOnly ? 1 : cubeSize;
+   mGrid = DistortedGridFactory.getGrid(cols,rows, frontOnly);
+   initializeData();
+   }
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 /**
  * Convenience constructor.
diff --git a/src/main/java/org/distorted/library/DistortedCubesGrid.java b/src/main/java/org/distorted/library/DistortedCubesGrid.java
index 902fe4d..e7a06df 100644
--- a/src/main/java/org/distorted/library/DistortedCubesGrid.java
+++ b/src/main/java/org/distorted/library/DistortedCubesGrid.java
@@ -228,7 +228,31 @@ class DistortedCubesGrid extends DistortedObjectGrid
        remainingVert = dataLength;
        }
      }
- 
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// full grid
+
+   private void prepareDataStructures(int cols, int rows, boolean frontOnly)
+     {
+     mRows     =rows;
+     mCols     =cols;
+     dataLength=   0;
+
+     if( cols>0 && rows>0 )
+       {
+       mCubes = new short[mRows][mCols];
+
+       for(int j=0; j<mCols; j++)
+         for(int i=0; i<mRows; i++)
+           mCubes[i][j] = (short)1;
+
+       markRegions();
+       dataLength = computeDataLength(frontOnly);
+
+       remainingVert = dataLength;
+       }
+     }
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 // Mark all the 'regions' of our grid  - i.e. separate pieces of 'land' (connected blocks that will 
 // be rendered) and 'water' (connected holes in between) with integers. Each connected block of land
@@ -714,10 +738,59 @@ class DistortedCubesGrid extends DistortedObjectGrid
      if(texture[2*vertex+1]<0.0f) texture[2*vertex+1] =    -texture[2*vertex+1];
      }
 
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+   private void build(boolean frontOnly)
+     {
+     int numVertices=0;
+     float[] positionData= new float[POSITION_DATA_SIZE*dataLength];
+     float[] normalData  = new float[NORMAL_DATA_SIZE  *dataLength];
+     float[] textureData = new float[TEX_DATA_SIZE     *dataLength];
+
+     //android.util.Log.d("CUBES","building front grid...");
+
+     numVertices = buildFrontBackGrid(true, numVertices,positionData,normalData,textureData);
+
+     if( !frontOnly )
+       {
+       numVertices = repeatLast(numVertices,positionData,normalData,textureData);
+       if( numVertices%2==1 )
+         {
+         //android.util.Log.d("CUBES","repeating winding1 vertex");
+
+         numVertices = repeatLast(numVertices,positionData,normalData,textureData);
+         }
+
+       //android.util.Log.d("CUBES","building side grid...");
+
+       numVertices = buildSideGrid (numVertices,positionData,normalData,textureData);
+
+       //android.util.Log.d("CUBES","building back grid...");
+
+       numVertices = buildFrontBackGrid (false,numVertices,positionData,normalData,textureData);
+       }
+
+     /*
+     android.util.Log.e("CUBES","dataLen="+dataLength+" vertex="+numVertices);
+     android.util.Log.d("CUBES", "position: "+debug(positionData,3) );
+     android.util.Log.d("CUBES", "normal: "  +debug(  normalData,3) );
+     android.util.Log.d("CUBES", "texture: " +debug( textureData,2) );
+     */
+     android.util.Log.d("CUBES", "remainingVert " +remainingVert );
+
+     mGridPositions = ByteBuffer.allocateDirect(POSITION_DATA_SIZE*dataLength*BYTES_PER_FLOAT).order(ByteOrder.nativeOrder()).asFloatBuffer();
+     mGridPositions.put(positionData).position(0);
+
+     mGridNormals = ByteBuffer.allocateDirect(NORMAL_DATA_SIZE*dataLength*BYTES_PER_FLOAT).order(ByteOrder.nativeOrder()).asFloatBuffer();
+     mGridNormals.put(normalData).position(0);
+
+     mGridTexture = ByteBuffer.allocateDirect(TEX_DATA_SIZE*dataLength*BYTES_PER_FLOAT).order(ByteOrder.nativeOrder()).asFloatBuffer();
+     mGridTexture.put(textureData).position(0);
+     }
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 // PUBLIC API
 ///////////////////////////////////////////////////////////////////////////////////////////////////
-   
 /**
  * Creates the underlying grid of vertices, normals, texture coords and colors.
  *    
@@ -725,56 +798,24 @@ class DistortedCubesGrid extends DistortedObjectGrid
  * @param desc      See {@link DistortedCubes#DistortedCubes(int,String,int,boolean)}
  * @param frontOnly See {@link DistortedCubes#DistortedCubes(int,String,int,boolean)}
  */
-   public DistortedCubesGrid(int cols, String desc, boolean frontOnly)
+   DistortedCubesGrid(int cols, String desc, boolean frontOnly)
       {
-      //android.util.Log.d("CUBES","calculating dataLength...");
-
       prepareDataStructures(cols,desc,frontOnly);
-       
-      int numVertices=0;
-      float[] positionData= new float[POSITION_DATA_SIZE*dataLength];
-      float[] normalData  = new float[NORMAL_DATA_SIZE  *dataLength];
-      float[] textureData = new float[TEX_DATA_SIZE     *dataLength];
-
-      //android.util.Log.d("CUBES","building front grid...");
-
-      numVertices = buildFrontBackGrid(true, numVertices,positionData,normalData,textureData);
-      
-      if( !frontOnly )
-        {
-        numVertices = repeatLast(numVertices,positionData,normalData,textureData);
-        if( numVertices%2==1 )
-          {
-          //android.util.Log.d("CUBES","repeating winding1 vertex");
-
-          numVertices = repeatLast(numVertices,positionData,normalData,textureData);
-          }
-
-        //android.util.Log.d("CUBES","building side grid...");
-
-        numVertices = buildSideGrid (numVertices,positionData,normalData,textureData);
-
-        //android.util.Log.d("CUBES","building back grid...");
-
-        numVertices = buildFrontBackGrid (false,numVertices,positionData,normalData,textureData);
-        }
-      
-      /*
-      android.util.Log.e("CUBES","dataLen="+dataLength+" vertex="+numVertices);
-      android.util.Log.d("CUBES", "position: "+debug(positionData,3) );
-      android.util.Log.d("CUBES", "normal: "  +debug(  normalData,3) );
-      android.util.Log.d("CUBES", "texture: " +debug( textureData,2) );
-      */
-      android.util.Log.d("CUBES", "remainingVert " +remainingVert );
-
-      mGridPositions = ByteBuffer.allocateDirect(POSITION_DATA_SIZE*dataLength*BYTES_PER_FLOAT).order(ByteOrder.nativeOrder()).asFloatBuffer();                                                        
-      mGridPositions.put(positionData).position(0); 
-      
-      mGridNormals = ByteBuffer.allocateDirect(NORMAL_DATA_SIZE*dataLength*BYTES_PER_FLOAT).order(ByteOrder.nativeOrder()).asFloatBuffer();                                                        
-      mGridNormals.put(normalData).position(0); 
+      build(frontOnly);
+      }
 
-      mGridTexture = ByteBuffer.allocateDirect(TEX_DATA_SIZE*dataLength*BYTES_PER_FLOAT).order(ByteOrder.nativeOrder()).asFloatBuffer();                                                        
-      mGridTexture.put(textureData).position(0); 
+///////////////////////////////////////////////////////////////////////////////////////////////////
+/**
+ * Creates a full, hole-less underlying grid of vertices, normals, texture coords and colors.
+ *
+ * @param cols      See {@link DistortedCubes#DistortedCubes(int,int,int,boolean)}
+ * @param rows      See {@link DistortedCubes#DistortedCubes(int,int,int,boolean)}
+ * @param frontOnly See {@link DistortedCubes#DistortedCubes(int,int,int,boolean)}
+ */
+   DistortedCubesGrid(int cols, int rows, boolean frontOnly)
+      {
+      prepareDataStructures(cols,rows,frontOnly);
+      build(frontOnly);
       }
    }
 ///////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/main/java/org/distorted/library/DistortedGridFactory.java b/src/main/java/org/distorted/library/DistortedGridFactory.java
index 28c8b9f..d786c9a 100644
--- a/src/main/java/org/distorted/library/DistortedGridFactory.java
+++ b/src/main/java/org/distorted/library/DistortedGridFactory.java
@@ -35,7 +35,7 @@ final class DistortedGridFactory
 
   static synchronized DistortedObjectGrid getGrid(int cols, String desc, boolean frontOnly)
     {
-    String d = desc+("_"+cols+"_"+(frontOnly?"1":"0"));
+    String d = "1_"+cols+"_"+desc+"_"+(frontOnly?"1":"0");
     Object o = mGrids.get(d);
 
     if( o!=null )
@@ -50,6 +50,26 @@ final class DistortedGridFactory
       }
     }
 
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// DistortedCubesGrid (full)
+
+  static synchronized DistortedObjectGrid getGrid(int cols, int rows, boolean frontOnly)
+    {
+    String d = "2_"+cols+"_"+rows+"_"+(frontOnly?"1":"0");
+    Object o = mGrids.get(d);
+
+    if( o!=null )
+      {
+      return (DistortedObjectGrid)o;
+      }
+    else
+      {
+      DistortedObjectGrid grid = new DistortedCubesGrid(cols,rows,frontOnly);
+      mGrids.put(d,grid);
+      return grid;
+      }
+    }
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 // DistortedBitmapGrid
 
