Project

General

Profile

« Previous | Next » 

Revision 5043d5d0

Added by Leszek Koltunski about 3 years ago

Refactor the automatic scrambling. From now on, it is not needed to care about single and double turns when randomizing a new turn.

View differences:

src/main/java/org/distorted/effects/scramble/ScrambleEffect.java
26 26
import org.distorted.library.message.EffectListener;
27 27
import org.distorted.main.RubikPreRender;
28 28
import org.distorted.effects.EffectController;
29
import org.distorted.objects.ObjectList;
29 30
import org.distorted.objects.TwistyObject;
30 31

  
31 32
import java.lang.reflect.Method;
......
64 65
      }
65 66
    }
66 67

  
67
  private static final int START_AXIS = -2;
68
  private static final int STOP_AXIS  = -1;
69

  
70 68
  private EffectController mController;
71 69
  private int mEffectReturned;
72 70
  private int mNumDoubleScramblesLeft, mNumScramblesLeft;
73
  private int mLastRotAxis, mLastRow;
74 71
  private long mDurationSingleTurn;
75 72
  private final Random mRnd;
76 73
  private int mBasicAngle;
......
82 79
  int[] mCubeEffectPosition;
83 80
  int mCubeEffectNumber, mNodeEffectNumber;
84 81
  int mNumScrambles;
85
  int[] mScramble;
82
  int[][] mScrambles;
86 83

  
87 84
///////////////////////////////////////////////////////////////////////////////////////////////////
88 85

  
89 86
  ScrambleEffect()
90 87
    {
91 88
    mRnd = new Random( System.currentTimeMillis() );
92
    mScramble = new int[3];
93
    mLastRotAxis = START_AXIS;
89
    mScrambles = new int[ObjectList.MAX_LEVEL][3];
94 90
    }
95 91

  
96 92
///////////////////////////////////////////////////////////////////////////////////////////////////
......
111 107
  private void createBaseEffects(int duration, int numScrambles)
112 108
    {
113 109
    mNumScramblesLeft = numScrambles;
114

  
115 110
    mNumDoubleScramblesLeft=0;
116 111

  
117
    if( mBasicAngle>=4 )
112
    for(int scramble=0; scramble<mNumScramblesLeft; scramble++)
118 113
      {
119
      int chance = mBasicAngle==4 ? 3:2;
120

  
121
      for(int i=0; i<numScrambles; i++)
122
        {
123
        if( (mRnd.nextInt() % chance) == 0 )
124
          {
125
          mNumDoubleScramblesLeft++;
126
          }
127
        }
114
      mObject.randomizeNewScramble(mScrambles, mRnd, scramble);
115
      int angle = mScrambles[scramble][2];
116
      if( angle==2 || angle==-2 ) mNumDoubleScramblesLeft++;
128 117
      }
129 118

  
130 119
    mDurationSingleTurn = duration/(mNumScramblesLeft+mNumDoubleScramblesLeft);
......
140 129
    {
141 130
    if( mNumScramblesLeft>0 )
142 131
      {
143
      mNumScrambles++;
144

  
145
      mObject.randomizeNewScramble(mScramble, mRnd,mLastRotAxis, mLastRow, mNumScrambles,
146
                                  mNumScramblesLeft, mNumDoubleScramblesLeft);
147
      mLastRotAxis = mScramble[0];
148
      mLastRow     = mScramble[1];
149
      int angle    = mScramble[2];
132
      int axis = mScrambles[mNumScrambles][0];
133
      int row  = mScrambles[mNumScrambles][1];
134
      int angle= mScrambles[mNumScrambles][2];
150 135

  
151
      int rowBitmap  = (1<<mLastRow);
136
      int rowBitmap  = (1<<row);
152 137
      int absAngle = (angle<0 ? -angle : angle);
153 138
      long durationMillis = absAngle*mDurationSingleTurn;
154 139

  
......
160 145
        android.util.Log.e("effect", "ERROR: "+mNumDoubleScramblesLeft);
161 146
        }
162 147

  
163
      mController.addRotation(this, mLastRotAxis, rowBitmap, angle*(360/mBasicAngle), durationMillis);
148
      mController.addRotation(this, axis, rowBitmap, angle*(360/mBasicAngle), durationMillis);
149

  
150
      mNumScrambles++;
164 151
      }
165 152
    else
166 153
      {
167
      mLastRotAxis = STOP_AXIS;
168

  
169 154
      if( mEffectReturned == mCubeEffectNumber+mNodeEffectNumber )
170 155
        {
171 156
        mController.effectFinished(FAKE_EFFECT_ID);

Also available in: Unified diff