Project

General

Profile

« Previous | Next » 

Revision 91792184

Added by Leszek Koltunski over 2 years ago

Make object scrambling abstract (well, almost - with exception of Square-1 - this theoretically could also be done the generic way, but this would require almost 20000 'ScrambleStates')

View differences:

src/main/java/org/distorted/objects/TwistyDiamond.java
31 31
import org.distorted.library.type.Static4D;
32 32
import org.distorted.main.R;
33 33

  
34
import java.util.Random;
35

  
36 34
///////////////////////////////////////////////////////////////////////////////////////////////////
37 35

  
38 36
public class TwistyDiamond extends TwistyObject
......
57 55
  private static final float DIST = 0.50f;
58 56
  private static final int FACES_PER_CUBIT =8;
59 57

  
60
  private int mCurrState;
61
  private int mIndexExcluded;
62
  private final ScrambleState[] mStates;
63
  private int[][] mScrambleTable;
64
  private int[] mNumOccurences;
58
  private ScrambleState[] mStates;
65 59
  private int[] mBasicAngle;
66 60
  private int[] mFaceMap;
67 61
  private Static4D[] mQuats;
......
74 68
                MeshSquare mesh, DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
75 69
    {
76 70
    super(size, size, quat, texture, mesh, effects, moves, ObjectList.DIAM, res, scrWidth);
71
    }
77 72

  
78
    int[] tmp = new int[3*2*size];
73
///////////////////////////////////////////////////////////////////////////////////////////////////
79 74

  
80
    for(int i=0; i<2*size; i++)
75
  ScrambleState[] getScrambleStates()
76
    {
77
    if( mStates==null )
81 78
      {
82
      tmp[3*i  ] = (i<size) ?  i:i-size;
83
      tmp[3*i+1] = (i%2==0) ? -1:1;
84
      tmp[3*i+2] = 0;
79
      int size = getNumLayers();
80
      int[] tmp = new int[3*2*size];
81

  
82
      for(int i=0; i<2*size; i++)
83
        {
84
        tmp[3*i  ] = (i<size) ?  i:i-size;
85
        tmp[3*i+1] = (i%2==0) ? -1:1;
86
        tmp[3*i+2] = 0;
87
        }
88

  
89
      mStates = new ScrambleState[]
90
        {
91
        new ScrambleState( new int[][] {tmp,tmp,tmp,tmp} )
92
        };
85 93
      }
86 94

  
87
    mStates = new ScrambleState[]
88
      {
89
      new ScrambleState( new int[][] {tmp,tmp,tmp,tmp} )
90
      };
95
    return mStates;
91 96
    }
92 97

  
93 98
///////////////////////////////////////////////////////////////////////////////////////////////////
......
507 512
    return 1.5f;
508 513
    }
509 514

  
510
///////////////////////////////////////////////////////////////////////////////////////////////////
511

  
512
  private void initializeScrambling()
513
    {
514
    int numLayers = getNumLayers();
515

  
516
    if( mScrambleTable ==null )
517
      {
518
      mScrambleTable = new int[NUM_AXIS][numLayers];
519
      }
520
    if( mNumOccurences ==null )
521
      {
522
      int max=0;
523

  
524
      for (ScrambleState mState : mStates)
525
        {
526
        int tmp = mState.getTotal(-1);
527
        if (max < tmp) max = tmp;
528
        }
529

  
530
      mNumOccurences = new int[max];
531
      }
532

  
533
    for(int i=0; i<NUM_AXIS; i++)
534
      for(int j=0; j<numLayers; j++) mScrambleTable[i][j] = 0;
535
    }
536

  
537 515
///////////////////////////////////////////////////////////////////////////////////////////////////
538 516
// PUBLIC API
539 517

  
540
  public void randomizeNewScramble(int[][] scramble, Random rnd, int curr, int totalScrambles)
541
    {
542
    if( curr==0 )
543
      {
544
      mCurrState     = 0;
545
      mIndexExcluded =-1;
546
      initializeScrambling();
547
      }
548

  
549
    int[] info= mStates[mCurrState].getRandom(rnd, mIndexExcluded, mScrambleTable, mNumOccurences);
550

  
551
    scramble[curr][0] = info[0];
552
    scramble[curr][1] = info[1];
553
    scramble[curr][2] = info[2];
554

  
555
    mCurrState     = info[3];
556
    mIndexExcluded = info[0];
557
    }
558

  
559
///////////////////////////////////////////////////////////////////////////////////////////////////
560

  
561 518
  public Static3D[] getRotationAxis()
562 519
    {
563 520
    return ROT_AXIS;

Also available in: Unified diff