Project

General

Profile

« Previous | Next » 

Revision 27a70eae

Added by Leszek Koltunski about 4 years ago

Make RubikCube and RubikCubeMovement generic and not visible outside of their package.

View differences:

src/main/java/org/distorted/magic/RubikRenderer.java
30 30
import org.distorted.library.main.DistortedTexture;
31 31
import org.distorted.library.mesh.MeshFlat;
32 32
import org.distorted.library.message.EffectListener;
33
import org.distorted.object.RubikCube;
34 33
import org.distorted.object.RubikObject;
34
import org.distorted.object.RubikObjectList;
35 35
import org.distorted.uistate.RubikState;
36
import org.distorted.uistate.RubikStatePlay;
37 36
import org.distorted.uistate.RubikStateSolving;
38 37

  
39 38
import javax.microedition.khronos.egl.EGLConfig;
......
48 47

  
49 48
    private RubikSurfaceView mView;
50 49
    private DistortedScreen mScreen;
51
    private int mNextCubeSize, mScrambleCubeNum;
50
    private RubikObjectList mNextObject;
51
    private int mScrambleObjectNum;
52 52
    private long mRotationFinishedID;
53 53
    private long[] mEffectID;
54 54
    private boolean mFinishRotation, mRemoveRotation, mSetQuatCurrent, mSetQuatAccumulated;
55
    private boolean mSizeChangeCube, mSolveCube, mScrambleCube;
55
    private boolean mChangeObject, mSolveObject, mScrambleObject;
56 56
    private boolean mCanRotate, mCanDrag, mCanUI;
57 57
    private boolean mIsSolved;
58
    private RubikCube mOldCube, mNewCube;
58
    private RubikObject mOldObject, mNewObject;
59 59
    private int mScreenWidth, mScreenHeight;
60 60
    private MeshFlat mMesh;
61 61
    private SharedPreferences mPreferences;
......
67 67
      mView = v;
68 68
      mScreen = new DistortedScreen();
69 69

  
70
      mOldCube = null;
71
      mNewCube = null;
70
      mOldObject = null;
71
      mNewObject = null;
72 72

  
73 73
      mScreenWidth = mScreenHeight = 0;
74
      mScrambleCubeNum = 0;
74
      mScrambleObjectNum = 0;
75 75

  
76 76
      mFinishRotation     = false;
77 77
      mRemoveRotation     = false;
78 78
      mSetQuatCurrent     = false;
79 79
      mSetQuatAccumulated = false;
80
      mSizeChangeCube     = true;
81
      mSolveCube          = false;
82
      mScrambleCube       = false;
80
      mChangeObject       = false;
81
      mSolveObject        = false;
82
      mScrambleObject     = false;
83 83

  
84 84
      mCanRotate   = true;
85 85
      mCanDrag     = true;
......
88 88
      mEffectID = new long[BaseEffect.Type.LENGTH];
89 89

  
90 90
      mMesh= new MeshFlat(20,20);
91

  
92
      RubikStatePlay play = (RubikStatePlay) RubikState.PLAY.getStateClass();
93
      int size = play.getButton();
94
      mNextCubeSize = RubikObject.getObject(size).getObjectSize();
95 91
      }
96 92

  
97 93
///////////////////////////////////////////////////////////////////////////////////////////////////
98 94

  
99
   private void createCubeNow(int newSize)
95
   private void createObjectNow(RubikObjectList object)
100 96
     {
101
     boolean firstTime = (mOldCube==null && mNewCube==null);
97
     boolean firstTime = (mNewObject==null);
102 98

  
103
     if( mOldCube!=null ) mOldCube.releaseResources();
104
     mOldCube = mNewCube;
99
     if( mOldObject!=null ) mOldObject.releaseResources();
100
     mOldObject = mNewObject;
105 101

  
106 102
     DistortedTexture texture = new DistortedTexture(TEXTURE_SIZE,TEXTURE_SIZE);
107 103
     DistortedEffects effects = new DistortedEffects();
108 104

  
109
     mNewCube = new RubikCube(newSize, mView.getQuatCurrent(), mView.getQuatAccumulated(), texture, mMesh, effects);
110
     mNewCube.createTexture();
111
     if( firstTime ) mNewCube.restorePreferences(mPreferences);
105
     mNewObject = object.create(mView.getQuatCurrent(), mView.getQuatAccumulated(), texture, mMesh, effects);
106
     mNewObject.createTexture();
107
     mView.setMovement(object.getObjectMovementClass());
108

  
109
     if( firstTime ) mNewObject.restorePreferences(mPreferences);
112 110

  
113 111
     if( mScreenWidth!=0 )
114 112
       {
115
       mNewCube.recomputeScaleFactor(mScreenWidth, mScreenHeight);
113
       mNewObject.recomputeScaleFactor(mScreenWidth, mScreenHeight);
116 114
       }
117 115

  
118 116
     mIsSolved = true;
......
143 141

  
144 142
   void savePreferences(SharedPreferences.Editor editor)
145 143
     {
146
     mNewCube.savePreferences(editor);
144
     mNewObject.savePreferences(editor);
147 145
     }
148 146

  
149 147
///////////////////////////////////////////////////////////////////////////////////////////////////
......
163 161

  
164 162
///////////////////////////////////////////////////////////////////////////////////////////////////
165 163

  
166
   boolean createCube(int newSize)
164
   boolean createObject(RubikObjectList object)
167 165
     {
168
     if( mCanDrag && mCanRotate && (mNewCube==null || newSize != mNewCube.getSize()) )
166
     if( mCanDrag && mCanRotate && object!=mNextObject )
169 167
       {
170
       mSizeChangeCube = true;
171
       mNextCubeSize = newSize;
168
       mChangeObject = true;
169
       mNextObject = object;
172 170
       return true;
173 171
       }
174 172

  
......
177 175

  
178 176
///////////////////////////////////////////////////////////////////////////////////////////////////
179 177

  
180
   void scrambleCube(int num)
178
   void scrambleObject(int num)
181 179
     {
182 180
     if( mCanUI )
183 181
       {
184
       mScrambleCube = true;
185
       mScrambleCubeNum = num;
182
       mScrambleObject = true;
183
       mScrambleObjectNum = num;
186 184
       }
187 185
     }
188 186

  
189 187
///////////////////////////////////////////////////////////////////////////////////////////////////
190 188

  
191
   void solveCube()
189
   void solveObject()
192 190
     {
193 191
     if( mCanUI )
194 192
       {
195
       mSolveCube = true;
193
       mSolveObject = true;
196 194
       }
197 195
     }
198 196

  
......
250 248
       mFinishRotation = false;
251 249
       mCanRotate      = false;
252 250
       mCanUI          = false;
253
       mRotationFinishedID = mNewCube.finishRotationNow(this);
251
       mRotationFinishedID = mNewObject.finishRotationNow(this);
254 252
       }
255 253

  
256 254
     if( mRemoveRotation )
257 255
       {
258 256
       mRemoveRotation=false;
259
       mNewCube.removeRotationNow();
257
       mNewObject.removeRotationNow();
260 258

  
261
       boolean solved = mNewCube.isSolved();
259
       boolean solved = mNewObject.isSolved();
262 260

  
263 261
       if( solved && !mIsSolved )
264 262
         {
......
283 281
       mIsSolved = solved;
284 282
       }
285 283

  
286
     if( mSizeChangeCube )
284
     if( mChangeObject )
287 285
       {
288
       mSizeChangeCube = false;
289
       mCanDrag        = false;
290
       mCanRotate      = false;
291
       mCanUI          = false;
292
       createCubeNow(mNextCubeSize);
286
       mChangeObject = false;
287
       mCanDrag      = false;
288
       mCanRotate    = false;
289
       mCanUI        = false;
290
       createObjectNow(mNextObject);
293 291
       doEffectNow( BaseEffect.Type.SIZECHANGE );
294 292
       }
295 293

  
296
     if( mSolveCube )
294
     if( mSolveObject )
297 295
       {
298
       mSolveCube      = false;
296
       mSolveObject    = false;
299 297
       mCanDrag        = false;
300 298
       mCanRotate      = false;
301 299
       mCanUI          = false;
302 300
       doEffectNow( BaseEffect.Type.SOLVE );
303 301
       }
304 302

  
305
     if( mScrambleCube )
303
     if( mScrambleObject )
306 304
       {
307
       mScrambleCube = false;
308
       mCanDrag      = false;
309
       mCanRotate    = false;
310
       mCanUI        = false;
305
       mScrambleObject = false;
306
       mCanDrag        = false;
307
       mCanRotate      = false;
308
       mCanUI          = false;
311 309
       doEffectNow( BaseEffect.Type.SCRAMBLE );
312 310
       }
313 311
     }
......
317 315
   @Override
318 316
   public void onSurfaceChanged(GL10 glUnused, int width, int height)
319 317
      {
320
      if( mNewCube!=null ) mNewCube.createTexture();
318
      if( mNewObject!=null ) mNewObject.createTexture();
321 319

  
322 320
      double halfFOVInRadians = Math.atan( 1.0f/(2*CAMERA_DISTANCE) );
323 321
      float fovInDegrees = (float)(2*halfFOVInRadians*(180/Math.PI));
......
326 324
      mScreen.resize(width, height);
327 325
      mView.setScreenSize(width,height);
328 326

  
329
      if( mNewCube!=null )
327
      if( mNewObject!=null )
330 328
        {
331
        mNewCube.recomputeScaleFactor(width,height);
329
        mNewObject.recomputeScaleFactor(width,height);
332 330
        }
333 331

  
334 332
      mScreenHeight = height;
......
394 392

  
395 393
///////////////////////////////////////////////////////////////////////////////////////////////////
396 394

  
397
   public RubikCube getCube()
395
   public RubikObject getObject()
398 396
     {
399
     return mNewCube;
397
     return mNewObject;
400 398
     }
401 399

  
402 400
///////////////////////////////////////////////////////////////////////////////////////////////////
403 401

  
404
   public RubikCube getOldCube()
402
   public RubikObject getOldObject()
405 403
     {
406
     return mOldCube;
404
     return mOldObject;
407 405
     }
408 406

  
409 407
///////////////////////////////////////////////////////////////////////////////////////////////////
......
417 415

  
418 416
   public int getNumScrambles()
419 417
     {
420
     return mScrambleCubeNum;
418
     return mScrambleObjectNum;
421 419
     }
422 420
}

Also available in: Unified diff