Project

General

Profile

« Previous | Next » 

Revision ad7907b0

Added by Leszek Koltunski over 3 years ago

Important step towards making the implementation of an individual puzzle code-free (i.e. data-only): move the 'MeshBase[] mMeshes' variable from the individual classes to the parent TwistyObject.

View differences:

src/main/java/org/distorted/helpers/FactoryCubit.java
809 809
      }
810 810
    }
811 811

  
812

  
813
///////////////////////////////////////////////////////////////////////////////////////////////////
814

  
815
  public void createNewFaceTransform(final ObjectShape shape)
816
    {
817
    double[][] vertices = shape.getVertices();
818
    int[][] indices = shape.getVertIndices();
819
    createNewFaceTransform(vertices,indices);
820
    }
821

  
812 822
///////////////////////////////////////////////////////////////////////////////////////////////////
813 823

  
814 824
  private void computeConvexityCenter(double[] out, float[] in, FaceTransform ft)
......
843 853
      }
844 854
    }
845 855

  
856
///////////////////////////////////////////////////////////////////////////////////////////////////
857

  
858
  public MeshBase createRoundedSolid(final ObjectShape shape)
859
    {
860
    double[][] vertices     = shape.getVertices();
861
    int[][] vertIndexes     = shape.getVertIndices();
862
    float[][] bands         = shape.getBands();
863
    int[]   bandIndexes     = shape.getBandIndices();
864
    float[][] corners       = shape.getCorners();
865
    int[]   cornerIndexes   = shape.getCornerIndices();
866
    float[][] centers       = shape.getCenters();
867
    int[]   centerIndexes   = shape.getCenterIndices();
868
    int numComponents       = shape.getNumComponents();
869
    float[] convexityCenter = shape.getConvexityCenter();
870

  
871
    return createRoundedSolid(vertices,vertIndexes,bands,bandIndexes,corners,cornerIndexes,
872
                              centers,centerIndexes,numComponents,convexityCenter);
873
    }
874

  
846 875
///////////////////////////////////////////////////////////////////////////////////////////////////
847 876

  
848 877
  public MeshBase createRoundedSolid(final double[][] vertices, final int[][] vertIndexes,
src/main/java/org/distorted/helpers/ObjectShape.java
26 26
  private final double[][] mVertices;
27 27
  private final int[][] mVertIndices;
28 28
  private final float[][] mBands;
29
  private final int[][] mBandIndices;
29
  private final int[] mBandIndices;
30 30
  private final float[][] mCorners;
31
  private final int[][] mCornerIndices;
31
  private final int[] mCornerIndices;
32 32
  private final float[][] mCenters;
33
  private final int[][] mCenterIndices;
33
  private final int[] mCenterIndices;
34 34
  private final int mNumComponents;
35 35
  private final float[] mConvexityCenter;
36 36

  
37 37
///////////////////////////////////////////////////////////////////////////////////////////////////
38 38

  
39
  public ObjectShape(double[][] vertices, int[][] vertIndices, float[][] bands, int[][] bandIndices,
40
                     float[][] corners, int[][] cornIndices, float[][] centers, int[][] centIndices,
39
  public ObjectShape(double[][] vertices, int[][] vertIndices, float[][] bands, int[] bandIndices,
40
                     float[][] corners, int[] cornIndices, float[][] centers, int[] centIndices,
41 41
                     int numComponents, float[] convexityCenter)
42 42
    {
43 43
    mVertices        = vertices;
......
75 75

  
76 76
///////////////////////////////////////////////////////////////////////////////////////////////////
77 77

  
78
  public int[][] getBandIndices()
78
  public int[] getBandIndices()
79 79
    {
80 80
    return mBandIndices;
81 81
    }
......
89 89

  
90 90
///////////////////////////////////////////////////////////////////////////////////////////////////
91 91

  
92
  public int[][] getCornerIndices()
92
  public int[] getCornerIndices()
93 93
    {
94 94
    return mCornerIndices;
95 95
    }
......
103 103

  
104 104
///////////////////////////////////////////////////////////////////////////////////////////////////
105 105

  
106
  public int[][] getCenterIndices()
106
  public int[] getCenterIndices()
107 107
    {
108 108
    return mCenterIndices;
109 109
    }
src/main/java/org/distorted/objects/TwistyBandagedAbstract.java
130 130

  
131 131
  private static final ObjectSticker[] mStickers;
132 132

  
133
  private static MeshBase[] mMeshes;
134

  
135 133
  static
136 134
    {
137 135
    mStickers = new ObjectSticker[NUM_STICKERS];
......
211 209
    {
212 210
    if( mMeshes==null )
213 211
      {
212
      FactoryCubit factory = FactoryCubit.getInstance();
213
      factory.clear();
214 214
      int LEN = mDimensions.length;
215 215
      mMeshes = new MeshBase[LEN];
216 216

  
......
271 271
                {-0.5f*(X-1),-0.5f*(Y-1),-0.5f*(Z-1)}
272 272
            };
273 273

  
274
        FactoryCubit factory = FactoryCubit.getInstance();
275 274
        factory.createNewFaceTransform(vertices,vert_indices);
276 275
        mMeshes[i] = factory.createRoundedSolid(vertices,vert_indices,
277 276
                                                bands, bandIndexes,
src/main/java/org/distorted/objects/TwistyCube.java
120 120

  
121 121
  private static final ObjectSticker[] mStickers;
122 122

  
123
  private static MeshBase[] mMeshes;
124

  
125 123
  static
126 124
    {
127 125
    final float radius = 0.10f;
......
147 145
      {
148 146
      FactoryCubit factory = FactoryCubit.getInstance();
149 147
      factory.clear();
150
      mMeshes = new MeshBase[ObjectList.CUBE.getNumVariants()];
148
      mMeshes = new MeshBase[1];
151 149
      }
152 150

  
153
    int ordinal= ObjectList.CUBE.ordinal();
154
    int index  = ObjectList.getSizeIndex(ordinal,getNumLayers());
155

  
156
    if( mMeshes[index]==null )
151
    if( mMeshes[0]==null )
157 152
      {
158 153
      int extraI, extraV, num;
159 154
      float height;
......
176 171
      FactoryCubit factory = FactoryCubit.getInstance();
177 172

  
178 173
      factory.createNewFaceTransform(VERTICES,VERT_INDEXES);
179
      mMeshes[index] = factory.createRoundedSolid(VERTICES, VERT_INDEXES,
180
                                                  bands, bandIndexes,
181
                                                  corners, cornerIndexes,
182
                                                  centers, centerIndexes,
183
                                                  getNumCubitFaces(), null );
174
      mMeshes[0] = factory.createRoundedSolid(VERTICES, VERT_INDEXES,
175
                                              bands, bandIndexes,
176
                                              corners, cornerIndexes,
177
                                              centers, centerIndexes,
178
                                              getNumCubitFaces(), null );
184 179
      }
185 180

  
186
    return mMeshes[index].copy(true);
181
    return mMeshes[0].copy(true);
187 182
    }
188 183

  
189 184
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/objects/TwistyDiamond.java
138 138

  
139 139
  private static final ObjectSticker[] mStickers;
140 140

  
141
  private static MeshBase[] mMeshes;
142

  
143 141
  static
144 142
    {
145 143
    float radius = 0.06f;
src/main/java/org/distorted/objects/TwistyDino.java
103 103
             {3,2,0},
104 104
          };
105 105

  
106
  private static MeshBase[] mMeshes;
107

  
108 106
  private static final float[][] STICKERS = new float[][]
109 107
          {
110 108
             { 0.0f, -1.0f/3, 0.5f, 1.0f/6, -0.5f, 1.0f/6 }
src/main/java/org/distorted/objects/TwistyHelicopter.java
221 221
            { 2,0,3 }
222 222
          };
223 223

  
224
  private static MeshBase[] mMeshes;
225

  
226 224
  private static final float[][] STICKERS = new float[][]
227 225
          {
228 226
            { -0.5f, 0.25f, 0.25f, -0.5f, 0.25f, 0.25f }
src/main/java/org/distorted/objects/TwistyIvy.java
94 94
           { 11, 12,12,12,12,12 },
95 95
         };
96 96

  
97
  private static MeshBase[] mMeshes;
98

  
99 97
  private static final ObjectSticker[] mStickers;
100 98

  
101 99
  private static final float[][] STICKERS = new float[][]
src/main/java/org/distorted/objects/TwistyJing.java
200 200
             { 0.0f, -0.5f, 0.43301272f, 0.25f, -0.43301272f, 0.25f },
201 201
          };
202 202

  
203
  private static MeshBase[] mMeshes;
204

  
205 203
  private static final ObjectSticker[] mStickers;
206 204

  
207 205
  static
src/main/java/org/distorted/objects/TwistyKilominx.java
37 37

  
38 38
public class TwistyKilominx extends TwistyMinx
39 39
{
40
  private static MeshBase[][] mMeshes;
41

  
42 40
  private static final int[] mCenterFaceMap = new int[]
43 41
      {
44 42
        0,0,0,0,1,
......
501 499
    int[] sizes = ObjectList.KILO.getSizes();
502 500
    int variants = sizes.length;
503 501
    int highestSize = sizes[variants-1];
504
    int lowestSize = sizes[0];
505
    int indexCornerEdge = (numLayers-lowestSize)/2 - (lowestSize==3 ? 1:0);
506 502
    MeshBase mesh;
507 503

  
508
    if( mMeshes==null ) mMeshes = new MeshBase[variants][highestSize-1];
504
    if( mMeshes==null ) mMeshes = new MeshBase[highestSize-1];
509 505

  
510 506
    if( cubit < NUM_CORNERS*numCubitsPerCorner )
511 507
      {
512
      if( mMeshes[indexCornerEdge][0]==null )
508
      if( mMeshes[0]==null )
513 509
        {
514 510
        float width = (numLayers/3.0f)/(numLayers-1);
515
        mMeshes[indexCornerEdge][0] = createCornerMesh(numLayers,width);
511
        mMeshes[0] = createCornerMesh(numLayers,width);
516 512
        }
517
      mesh = mMeshes[indexCornerEdge][0].copy(true);
513
      mesh = mMeshes[0].copy(true);
518 514
      }
519 515
    else if( cubit<NUM_CORNERS*numCubitsPerCorner + NUM_EDGES*numCubitsPerEdge )
520 516
      {
521 517
      int type = computeEdgeType(cubit,numCubitsPerCorner,numCubitsPerEdge);  // left-top, right-top, left-second, right-second, left-third...
522 518

  
523
      if( mMeshes[indexCornerEdge][1+type]==null )
519
      if( mMeshes[1+type]==null )
524 520
        {
525 521
        float tmp   = (numLayers/3.0f)/(numLayers-1);
526 522
        float height= tmp*COS18;
527 523
        float width = tmp + (type/2)*tmp*SIN18;
528 524

  
529
        mMeshes[indexCornerEdge][1+type] = createEdgeMesh(numLayers,width,height, (type%2)==0 );
525
        mMeshes[1+type] = createEdgeMesh(numLayers,width,height, (type%2)==0 );
530 526
        }
531 527

  
532
      mesh = mMeshes[indexCornerEdge][1+type].copy(true);
528
      mesh = mMeshes[1+type].copy(true);
533 529
      }
534 530
    else
535 531
      {
536
      int indexCenter = (numLayers-3)/2;
537

  
538
      if( mMeshes[indexCenter][highestSize-2]==null )
532
      if( mMeshes[highestSize-2]==null )
539 533
        {
540 534
        float width = (1+0.5f*(numLayers-3)*SIN18)*(numLayers/3.0f)/(numLayers-1);
541
        mMeshes[indexCenter][highestSize-2] = createCenterMesh(width);
535
        mMeshes[highestSize-2] = createCenterMesh(width);
542 536
        }
543 537

  
544
      mesh = mMeshes[indexCenter][highestSize-2].copy(true);
538
      mesh = mMeshes[highestSize-2].copy(true);
545 539
      }
546 540

  
547 541
    Static4D q = QUATS[getQuat(cubit,numCubitsPerCorner,numCubitsPerEdge)];
src/main/java/org/distorted/objects/TwistyMegaminx.java
44 44
        16, 18, 22,  1, 20, 13, 14, 15,  0, 12,  2,  3
45 45
      };
46 46

  
47
  private static MeshBase[][] mMeshes;
48

  
49 47
  private static final float[][] STICKERS = new float[][]
50 48
      {
51 49
        { -0.36327127f, -0.5f, 0.36327127f, -0.26393202f, 0.36327127f, 0.5f, -0.36327127f, 0.26393202f },
......
411 409
    {
412 410
    int numCubitsPerCorner = numCubitsPerCorner(numLayers);
413 411
    int numCubitsPerEdge   = numCubitsPerEdge(numLayers);
414
    int index = (numLayers-3)/2;
415 412
    int[] sizes = ObjectList.MEGA.getSizes();
416 413
    int variants = sizes.length;
417 414
    int numShapes = 2+(sizes[variants-1]-1)/2;
418 415
    MeshBase mesh;
419 416

  
420
    if( mMeshes==null ) mMeshes = new MeshBase[variants][numShapes];
417
    if( mMeshes==null ) mMeshes = new MeshBase[numShapes];
421 418

  
422 419
    if( cubit < NUM_CORNERS*numCubitsPerCorner )
423 420
      {
424
      if( mMeshes[index][0]==null )
421
      if( mMeshes[0]==null )
425 422
        {
426 423
        float width = (numLayers/3.0f)*(0.5f-MEGA_D)/(0.5f*(numLayers-1));
427
        mMeshes[index][0] = createCornerMesh(numLayers, width);
424
        mMeshes[0] = createCornerMesh(numLayers, width);
428 425
        }
429
      mesh = mMeshes[index][0].copy(true);
426
      mesh = mMeshes[0].copy(true);
430 427
      }
431 428
    else if( cubit<NUM_CORNERS*numCubitsPerCorner + NUM_EDGES*numCubitsPerEdge )
432 429
      {
433 430
      int type = computeEdgeType(cubit,numCubitsPerCorner,numCubitsPerEdge);
434 431

  
435
      if( mMeshes[index][1+type]==null )
432
      if( mMeshes[1+type]==null )
436 433
        {
437 434
        float height= (numLayers/3.0f)*(0.5f-MEGA_D)*COS18/((numLayers-1)*0.5f);
438 435
        float width = (numLayers/3.0f)*2*MEGA_D + 2*type*height*SIN18/COS18;
439 436

  
440
        mMeshes[index][1+type] = createEdgeMesh(numLayers,width,height);
437
        mMeshes[1+type] = createEdgeMesh(numLayers,width,height);
441 438
        }
442
      mesh = mMeshes[index][1+type].copy(true);
439
      mesh = mMeshes[1+type].copy(true);
443 440
      }
444 441
    else
445 442
      {
446
      if( mMeshes[index][numShapes-1]==null )
443
      if( mMeshes[numShapes-1]==null )
447 444
        {
448 445
        float width = 2 * (numLayers/3.0f) * (MEGA_D+(0.5f-MEGA_D)*SIN18);
449
        mMeshes[index][numShapes-1] = createCenterMesh(numLayers,width);
446
        mMeshes[numShapes-1] = createCenterMesh(numLayers,width);
450 447
        }
451 448

  
452
      mesh = mMeshes[index][numShapes-1].copy(true);
449
      mesh = mMeshes[numShapes-1].copy(true);
453 450
      }
454 451

  
455 452
    Static4D q = QUATS[getQuat(cubit,numCubitsPerCorner,numCubitsPerEdge)];
src/main/java/org/distorted/objects/TwistyObject.java
86 86
  private static final Static3D CENTER = new Static3D(0,0,0);
87 87
  private static final int POST_ROTATION_MILLISEC = 500;
88 88

  
89
  MeshBase[] mMeshes;
89 90
  final Static4D[] QUATS;
90 91
  final Cubit[] CUBITS;
91 92
  final int NUM_FACES;
src/main/java/org/distorted/objects/TwistyPyraminx.java
115 115
             { -0.4330127f, -0.25f, 0.4330127f, -0.25f, 0.0f, 0.5f }
116 116
          };
117 117

  
118
  private static MeshBase[] mMeshes;
119 118
  private static float[] mRowChances;
120 119

  
121 120
  private static final ObjectSticker[] mStickers;
......
327 326
        int[] centerIndexes = new int[] { 0,0,0,0,0,0 };
328 327

  
329 328
        FactoryCubit factory = FactoryCubit.getInstance();
330

  
331 329
        factory.createNewFaceTransform(VERTICES_OCTA,VERT_INDEXES_OCTA);
332 330
        mMeshes[0] = factory.createRoundedSolid(VERTICES_OCTA, VERT_INDEXES_OCTA,
333 331
                                                bands, bandIndexes,
......
349 347
        int[] centerIndexes = new int[] { 0,0,0,0 };
350 348

  
351 349
        FactoryCubit factory = FactoryCubit.getInstance();
352

  
353 350
        factory.createNewFaceTransform(VERTICES_TETRA,VERT_INDEXES_TETRA);
354 351
        mMeshes[1] = factory.createRoundedSolid(VERTICES_TETRA, VERT_INDEXES_TETRA,
355 352
                                                bands, bandIndexes,
356 353
                                                corners, cornerIndexes,
357 354
                                                centers, centerIndexes,
358 355
                                                getNumCubitFaces(), null );
359

  
360
        factory.printStickerCoords();
361 356
        }
362 357
      mesh = mMeshes[1].copy(true);
363 358
      }
src/main/java/org/distorted/objects/TwistyRedi.java
187 187
             { -0.3125f, 0.4375f, -0.3125f, -0.1875f, 0.0f, -0.5f, 0.3125f, -0.1875f, 0.3125f, 0.4375f }
188 188
          };
189 189

  
190
  private static MeshBase[] mMeshes;
191

  
192 190
  private static int[][] mScrambleTable;
193 191
  private static int[] mPossibleAxis, mPossibleLayers;
194 192
  private static int[] mNumOccurences;
src/main/java/org/distorted/objects/TwistyRex.java
126 126
           { 13,17, 18,18,18,18 },
127 127
         };
128 128

  
129
  private static MeshBase[] mMeshes;
130

  
131 129
  private static final ObjectSticker[] mStickers;
132 130

  
133 131
  private static final float[][] STICKERS = new float[][]
src/main/java/org/distorted/objects/TwistySkewb.java
173 173
             { -0.5f, 0.00f, 0.00f,  -0.5f, 0.50f, 0.0f, 0.0f, 0.5f }
174 174
          };
175 175

  
176
  private static MeshBase[] mMeshes;
177

  
178 176
  private static final ObjectSticker[] mStickers;
179 177

  
180 178
  static
src/main/java/org/distorted/objects/TwistySquare.java
156 156
      { 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10,  9,  8,  7,  6,  5,  4,  3,  2,  1,  0,}
157 157
    };
158 158

  
159
  static MeshBase[] mMeshes;
160 159
  int mLastRot;
161 160

  
162 161
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/objects/TwistyUltimate.java
217 217
           { -0.29389262f, -0.50000000f, 0.29389262f,-0.309017000f, 0.29389262f, 0.30901700f,-0.29389262f, 0.50000000f },                             // Small cubit 1st
218 218
         };
219 219

  
220
  private static MeshBase[] mMeshes;
221

  
222 220
  private static final ObjectSticker[] mStickers;
223 221

  
224 222
  static

Also available in: Unified diff