Project

General

Profile

Download (25 KB) Statistics
| Branch: | Revision:

distorted-objectlib / src / main / java / org / distorted / objectlib / main / ObjectPreRender.java @ ae9d9227

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2020 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is proprietary software licensed under an EULA which you should have received      //
7
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html        //
8
///////////////////////////////////////////////////////////////////////////////////////////////////
9

    
10
package org.distorted.objectlib.main;
11

    
12
import org.distorted.library.message.EffectListener;
13
import org.distorted.library.type.Static3D;
14

    
15
import org.distorted.library.type.Static4D;
16
import org.distorted.objectlib.helpers.ObjectLibInterface;
17
import org.distorted.objectlib.effects.BaseEffect;
18
import org.distorted.objectlib.effects.scramble.ScrambleEffect;
19
import org.distorted.objectlib.helpers.BlockController;
20
import org.distorted.objectlib.helpers.MovesFinished;
21
import org.distorted.objectlib.helpers.OperatingSystemInterface;
22
import org.distorted.objectlib.shape.ShapeDodecahedron;
23
import org.distorted.objectlib.shape.ShapeHexahedron;
24
import org.distorted.objectlib.shape.ShapeOctahedron;
25
import org.distorted.objectlib.shape.ShapeTetrahedron;
26

    
27
///////////////////////////////////////////////////////////////////////////////////////////////////
28

    
29
public class ObjectPreRender implements EffectListener
30
  {
31
  private static final int MAX_SLOW_SCRAMBLE = 50;
32

    
33
  private final ObjectControl mController;
34
  private InitAssets mAsset;
35
  private int mOrdinal;
36
  private TwistyObject mOldObject, mNewObject;
37
  private OperatingSystemInterface mOS;
38
  private MovesFinished mAddActionListener;
39
//  private final BlockController mBlockController;
40
  private final ObjectLibInterface mInterface;
41
  private String mDebug;
42
  private float mMoveX, mMoveY;
43
  private float mScale;
44

    
45
  private boolean mFinishRotation, mRemoveManualRotation, mRemoveProgramaticRotation, mAddRotation,
46
                  mSetQuat, mChangeObject, mSolveObject, mScrambleObject, mFastScrambleObject,
47
                  mPresentObject,mInitializeObject, mSetTextureMap, mResetAllTextureMaps, mSolve,
48
                  mApplyScrambles, mResetTextureEffect;
49
  private boolean mScramblingAndSolvingBlocked, mRotationBlocked, mIsSolved;
50
  private long mRotationFinishedID;
51
  private final long[] mEffectID;
52
  private int[][] mInitMoves, mScraMoves;
53
  private int mScrambleObjectNum, mScrambleObjectDuration;
54
  private int mAddRotationAxis, mAddRotationRowBitmap, mAddRotationAngle;
55
  private long mAddRotationDuration;
56
  private int mPresentDuration, mRestickerDuration;
57
  private long mAddRotationID, mRemoveProgramaticRotationID;
58
  private int mCubit, mFace, mNewColor;
59
  private int mFinishAxis, mFinishRow;
60
  private float mFinishAngle, mAvgSpeed;
61
  private long mScrambleStartTime, mScrambleEndTime;
62
  private int mIconMode;
63

    
64
  // debugging only
65
  private long mAddRotationTime;
66

    
67
///////////////////////////////////////////////////////////////////////////////////////////////////
68

    
69
  public ObjectPreRender(ObjectControl controller, ObjectLibInterface actioner)
70
    {
71
    mInterface = actioner;
72
    mController = controller;
73

    
74
    mFinishRotation       = false;
75
    mRemoveManualRotation = false;
76
    mRemoveProgramaticRotation = false;
77
    mAddRotation          = false;
78
    mSetQuat              = false;
79
    mChangeObject         = false;
80
    mSolveObject          = false;
81
    mSolve                = false;
82
    mScrambleObject       = false;
83
    mFastScrambleObject   = false;
84
    mPresentObject        = false;
85
    mResetTextureEffect   = false;
86

    
87
    mOldObject = null;
88
    mNewObject = null;
89

    
90
    mDebug = "";
91
    mScrambleObjectNum = 0;
92
    mScale = 1.0f;
93

    
94
    mEffectID = new long[BaseEffect.Type.LENGTH];
95

    
96
  //  mBlockController = new BlockController(this);
97
    unblockEverything();
98
    }
99

    
100
///////////////////////////////////////////////////////////////////////////////////////////////////
101

    
102
  private void createObjectNow(int ordinal, int iconMode, InitAssets assets)
103
    {
104
    long time1 = System.currentTimeMillis();
105
    Static3D move = new Static3D(mMoveX,mMoveY,0);
106
    Static4D quat = mController.getQuat();
107
    TwistyObject tmp;
108
    boolean error = false;
109

    
110
    if( assets==null || assets.noJsonStream() )
111
      {
112
      tmp = ObjectType.create( ordinal, iconMode, quat, move, mScale, assets);
113
      }
114
    else
115
      {
116
      tmp = new TwistyJson( iconMode, quat, move, mScale, assets);
117
      error = tmp.getError();
118
      }
119

    
120
    if( error )
121
      {
122
      String errorString = tmp.getErrorString();
123
      mInterface.reportJSONError(errorString,ordinal);
124
      }
125
    else
126
      {
127
      if( mOldObject!=null ) mOldObject.releaseResources();
128
      mOldObject = mNewObject;
129
      mNewObject = tmp;
130

    
131
      long time2 = System.currentTimeMillis();
132
      mInterface.onObjectCreated(time2-time1);
133

    
134
      if( mNewObject!=null )
135
        {
136
        mNewObject.setLibInterface(mInterface);
137
        mController.setTouchControl(mNewObject);
138
        mNewObject.setObjectRatioNow(mScale, mController.getScalingSize() );
139

    
140
        if( mOS!=null )
141
          {
142
          mNewObject.restorePreferences(mOS);
143
          mOS = null;
144
          }
145

    
146
        mIsSolved = mNewObject.isSolved();
147
        }
148
      }
149
    }
150

    
151
///////////////////////////////////////////////////////////////////////////////////////////////////
152
// do all 'adjustable' effects (SizeChange, Solve, Scramble)
153

    
154
  private void doEffectNow(BaseEffect.Type type, int duration)
155
    {
156
    try
157
      {
158
      int index = type.ordinal();
159
      mEffectID[index] = type.startEffect(this,duration);
160
      }
161
    catch( Exception ex )
162
      {
163
      android.util.Log.e("renderer", "exception starting effect: "+ex.getMessage());
164
      unblockEverything();
165
      }
166
    }
167

    
168
///////////////////////////////////////////////////////////////////////////////////////////////////
169

    
170
  private void rememberMove(int axis, int row, float angle)
171
    {
172
    mDebug += (mNewObject==null ? "[null]" : mNewObject.reportState() );
173
    mDebug += ("(m "+axis+" "+(1<<row)+" "+angle+" "+(System.currentTimeMillis()-mScrambleEndTime))+")";
174
    }
175

    
176
///////////////////////////////////////////////////////////////////////////////////////////////////
177

    
178
  private void removeManualRotationNow()
179
    {
180
    mRemoveManualRotation =false;
181
    float angle = mNewObject.removeRotation();
182

    
183
    boolean solved = mNewObject.isSolved();
184

    
185
    if( solved && !mIsSolved )
186
      {
187
      mInterface.onSolved();
188
      unblockEverything();
189
      int duration = BaseEffect.Type.WIN.getDuration();
190
      doEffectNow( BaseEffect.Type.WIN, duration );
191
      }
192
    else
193
      {
194
      unblockEverything();
195
      }
196

    
197
    rememberMove(mFinishAxis,mFinishRow,angle);
198

    
199
    if( angle!=0 )
200
      {
201
      int[][] basicAngles = mNewObject.getBasicAngles();
202
      int basic = basicAngles[mFinishAxis][mFinishRow];
203
      int realAngle = (int)((angle*basic)/360);
204
      mInterface.onRemoveRotation(mFinishAxis,mFinishRow,realAngle);
205
      }
206

    
207
    mIsSolved = solved;
208
    }
209

    
210
///////////////////////////////////////////////////////////////////////////////////////////////////
211

    
212
  private void removeManualRotation()
213
    {
214
    mRemoveManualRotation = true;
215
    }
216

    
217
///////////////////////////////////////////////////////////////////////////////////////////////////
218

    
219
  private void removeProgramaticRotation()
220
    {
221
    mRemoveProgramaticRotation = true;
222
    }
223

    
224
///////////////////////////////////////////////////////////////////////////////////////////////////
225

    
226
  private void removeProgramaticRotationNow()
227
    {
228
    mRemoveProgramaticRotation =false;
229
    mNewObject.removeRotation();
230
    mAddActionListener.onActionFinished(mRemoveProgramaticRotationID);
231
    }
232

    
233
///////////////////////////////////////////////////////////////////////////////////////////////////
234

    
235
  private void addRotationNow()
236
    {
237
    mAddRotation = false;
238

    
239
    if( mNewObject.getNumAxis() > mAddRotationAxis )
240
      {
241
      mAddRotationID = mNewObject.addRotation( this, mAddRotationAxis, mAddRotationRowBitmap,
242
                                                     mAddRotationAngle, mAddRotationDuration);
243

    
244
      // failed to add effect (previous rotation hasn't been removed yet)
245
      if( mAddRotationID==0 )
246
        {
247
        mAddActionListener.onActionFinished(0);
248
        }
249
      // the rotation we have just added has forced a finish() of an ongoing
250
      // manual rotation. So the effect that's going to finish is not the manual
251
      // rotation (we have just removed it) but the rotation we have just added
252
      // here - so set mRotationFinishedID to 0
253
      else if( mAddRotationID<0 )
254
        {
255
        mAddRotationID = -mAddRotationID;
256
        mRotationFinishedID = 0;
257
        }
258
      }
259
    else // should never happen but Firebase says it sometimes does
260
      {
261
      long timeNow = System.currentTimeMillis();
262
      Class<? extends MovesFinished> clazz = mAddActionListener.getClass();
263
      String name = clazz.getSimpleName();
264

    
265
      String error = "time now: "+timeNow+" add time: "+mAddRotationTime+" axis="+mAddRotationAxis+
266
                      "object: "+mNewObject.getShortName()+" "+name;
267

    
268
      mInterface.reportProblem(error,true);
269
      unblockEverything();
270
      }
271
    }
272

    
273
///////////////////////////////////////////////////////////////////////////////////////////////////
274

    
275
  private void finishRotationNow()
276
    {
277
    mFinishRotation = false;
278
    blockEverything(BlockController.PLACE_0);
279
    mRotationFinishedID = mNewObject.finishRotation(this,mFinishAxis,mFinishRow,mFinishAngle,mAvgSpeed);
280

    
281
    if( mRotationFinishedID==0 ) // failed to add effect - should never happen
282
      {
283
      unblockEverything();
284
      }
285
    }
286

    
287
///////////////////////////////////////////////////////////////////////////////////////////////////
288

    
289
  private void changeObjectNow()
290
    {
291
    mChangeObject = false;
292
    blockEverything(BlockController.PLACE_1);
293
    createObjectNow(mOrdinal,mIconMode,mAsset);
294
    int duration = BaseEffect.Type.SIZECHANGE.getDuration();
295
    doEffectNow( BaseEffect.Type.SIZECHANGE, duration );
296
    }
297

    
298
///////////////////////////////////////////////////////////////////////////////////////////////////
299

    
300
  private void scrambleObjectNow()
301
    {
302
    mScrambleObject = false;
303
    mIsSolved       = false;
304
    blockEverything(BlockController.PLACE_3);
305

    
306
    if( mScrambleObjectNum<MAX_SLOW_SCRAMBLE )
307
      {
308
      int duration = BaseEffect.Type.SCRAMBLE.getDuration();
309
      doEffectNow( BaseEffect.Type.SCRAMBLE, duration );
310
      }
311
    else
312
      {
313
      int duration = BaseEffect.Type.FAST_SCRAMBLE.getDuration();
314
      doEffectNow( BaseEffect.Type.FAST_SCRAMBLE, duration );
315
      }
316
    }
317

    
318
///////////////////////////////////////////////////////////////////////////////////////////////////
319

    
320
  private void fastScrambleObjectNow()
321
    {
322
    mFastScrambleObject = false;
323
    mIsSolved           = false;
324
    blockEverything(BlockController.PLACE_5);
325
    doEffectNow( BaseEffect.Type.FAST_SCRAMBLE, mScrambleObjectDuration );
326
    }
327

    
328
///////////////////////////////////////////////////////////////////////////////////////////////////
329

    
330
  private void resetTextureNow()
331
    {
332
    mResetTextureEffect = false;
333
    doEffectNow( BaseEffect.Type.RESTICKER, mRestickerDuration );
334
    }
335

    
336
///////////////////////////////////////////////////////////////////////////////////////////////////
337

    
338
  private void presentObjectNow()
339
    {
340
    mPresentObject = false;
341
    doEffectNow( BaseEffect.Type.PRESENT, mPresentDuration );
342
    }
343

    
344
///////////////////////////////////////////////////////////////////////////////////////////////////
345

    
346
  private void solveObjectNow()
347
    {
348
    mSolveObject = false;
349
    blockEverything(BlockController.PLACE_4);
350
    int duration = BaseEffect.Type.SOLVE.getDuration();
351
    doEffectNow( BaseEffect.Type.SOLVE, duration );
352
    }
353

    
354
///////////////////////////////////////////////////////////////////////////////////////////////////
355

    
356
  private void solveNow()
357
    {
358
    mSolve = false;
359
    if( mNewObject!=null ) mNewObject.solve();
360
    }
361

    
362
///////////////////////////////////////////////////////////////////////////////////////////////////
363

    
364
  private void initializeObjectNow()
365
    {
366
    mInitializeObject = false;
367
    mNewObject.initializeObject(mInitMoves);
368
    }
369

    
370
///////////////////////////////////////////////////////////////////////////////////////////////////
371

    
372
  private void applyScramblesNow()
373
    {
374
    mApplyScrambles = false;
375
    mNewObject.applyScrambles(mScraMoves);
376
    }
377

    
378
///////////////////////////////////////////////////////////////////////////////////////////////////
379

    
380
  private void setTextureMapNow()
381
    {
382
    mSetTextureMap = false;
383

    
384
    if( mNewObject!=null ) mNewObject.setTextureMap(mCubit,mFace,mNewColor);
385
    }
386

    
387
///////////////////////////////////////////////////////////////////////////////////////////////////
388

    
389
  private void resetAllTextureMapsNow()
390
    {
391
    mResetAllTextureMaps = false;
392
    if( mNewObject!=null ) mNewObject.resetAllTextureMaps();
393
    }
394

    
395
///////////////////////////////////////////////////////////////////////////////////////////////////
396

    
397
  private void setQuatNow()
398
    {
399
    mSetQuat = false;
400
    mController.setQuat();
401
    }
402

    
403
///////////////////////////////////////////////////////////////////////////////////////////////////
404

    
405
  private int computeRowFromBitmap(int rowBitmap)
406
    {
407
    int index = 0;
408

    
409
    while(index<32)
410
      {
411
      if( (rowBitmap&0x1) != 0 ) return index;
412
      rowBitmap>>=1;
413
      index++;
414
      }
415

    
416
    return 0;
417
    }
418

    
419
///////////////////////////////////////////////////////////////////////////////////////////////////
420

    
421
  private void blockEverything(int place)
422
    {
423
    mScramblingAndSolvingBlocked = true;
424
    mRotationBlocked = true;
425
  //  mBlockController.rotationBlocked(place);
426
  //  mBlockController.scramblingAndSolvingBlocked(place);
427
    }
428

    
429
///////////////////////////////////////////////////////////////////////////////////////////////////
430
// called from ObjectControl; this from app when we switch the screen to READ post-scrambling.
431
// The point: we only unblock having completed the screen switch so that it is impossible to
432
// click the solve button then.
433

    
434
  void unblockEverything()
435
    {
436
    mScramblingAndSolvingBlocked = false;
437
    mRotationBlocked = false;
438
  //  mBlockController.rotationUnblocked();
439
  //  mBlockController.scramblingAndSolvingUnblocked();
440
    }
441

    
442
///////////////////////////////////////////////////////////////////////////////////////////////////
443

    
444
  void finishRotation(int currentAxis, int currentRow, float currentAngle, float avgSpeed)
445
    {
446
    mFinishAxis = currentAxis;
447
    mFinishRow  = currentRow;
448
    mFinishAngle= currentAngle;
449
    mAvgSpeed   = avgSpeed;
450

    
451
    mFinishRotation = true;
452
    }
453

    
454
///////////////////////////////////////////////////////////////////////////////////////////////////
455

    
456
  void setTextureMap(int cubit, int face, int newColor)
457
    {
458
    mSetTextureMap = true;
459

    
460
    mCubit    = cubit;
461
    mFace     = face;
462
    mNewColor = newColor;
463
    }
464

    
465
///////////////////////////////////////////////////////////////////////////////////////////////////
466

    
467
  void setQuatOnNextRender()
468
    {
469
    mSetQuat = true;
470
    }
471

    
472
///////////////////////////////////////////////////////////////////////////////////////////////////
473

    
474
  void setMove(float xmove, float ymove)
475
    {
476
    mMoveX = xmove;
477
    mMoveY = ymove;
478
    }
479

    
480
///////////////////////////////////////////////////////////////////////////////////////////////////
481

    
482
  void setScale(float scale)
483
    {
484
    mScale = scale;
485
    }
486

    
487
///////////////////////////////////////////////////////////////////////////////////////////////////
488
// INTERNAL API
489
///////////////////////////////////////////////////////////////////////////////////////////////////
490

    
491
  public int getNumScrambles()
492
    {
493
    return mScrambleObjectNum;
494
    }
495

    
496
///////////////////////////////////////////////////////////////////////////////////////////////////
497

    
498
  public TwistyObject getOldObject()
499
    {
500
    return mOldObject;
501
    }
502

    
503
///////////////////////////////////////////////////////////////////////////////////////////////////
504

    
505
  public float getMoveX()
506
    {
507
    return mMoveX;
508
    }
509

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

    
512
  public float getMoveY()
513
    {
514
    return mMoveY;
515
    }
516

    
517
///////////////////////////////////////////////////////////////////////////////////////////////////
518

    
519
  public ObjectLibInterface getInterface()
520
    {
521
    return mInterface;
522
    }
523

    
524
///////////////////////////////////////////////////////////////////////////////////////////////////
525
// PUBLIC API
526
///////////////////////////////////////////////////////////////////////////////////////////////////
527

    
528
  public void savePreferences(OperatingSystemInterface os)
529
    {
530
    if( mNewObject!=null )
531
      {
532
      mNewObject.savePreferences(os);
533
      }
534
    }
535

    
536
///////////////////////////////////////////////////////////////////////////////////////////////////
537

    
538
  public void restorePreferences(OperatingSystemInterface os)
539
    {
540
    mOS = os;
541
    }
542

    
543
///////////////////////////////////////////////////////////////////////////////////////////////////
544

    
545
  public void changeObject(int ordinal, int iconMode, InitAssets asset)
546
    {
547
    mChangeObject = true;
548
    mOrdinal    = ordinal;
549
    mIconMode   = iconMode;
550
    mAsset      = asset;
551
    }
552

    
553
///////////////////////////////////////////////////////////////////////////////////////////////////
554

    
555
  public void setDefaultRotation(int numFaces)
556
    {
557
    if( mController!=null && mController.getRotateOnCreation() )
558
      {
559
      switch(numFaces)
560
        {
561
        case  4: mController.rotateNow(ShapeTetrahedron.DEFAULT_ROT ); break;
562
        case  6: mController.rotateNow(ShapeHexahedron.DEFAULT_ROT  ); break;
563
        case  8: mController.rotateNow(ShapeOctahedron.DEFAULT_ROT  ); break;
564
        case 12: mController.rotateNow(ShapeDodecahedron.DEFAULT_ROT); break;
565
        }
566
      }
567
    }
568

    
569
///////////////////////////////////////////////////////////////////////////////////////////////////
570

    
571
  public boolean isRotationBlocked()
572
    {
573
    return mRotationBlocked;
574
    }
575

    
576
///////////////////////////////////////////////////////////////////////////////////////////////////
577

    
578
  public boolean isScramblingAndSolvingNotBlocked()
579
    {
580
    return !mScramblingAndSolvingBlocked;
581
    }
582

    
583
///////////////////////////////////////////////////////////////////////////////////////////////////
584

    
585
  public void blockRotation(int place)
586
    {
587
    mRotationBlocked = true;
588
  //  mBlockController.rotationBlocked(place);
589
    }
590

    
591
///////////////////////////////////////////////////////////////////////////////////////////////////
592

    
593
  public void unblockRotation()
594
    {
595
    mRotationBlocked = false;
596
  //  mBlockController.rotationUnblocked();
597
    }
598

    
599
///////////////////////////////////////////////////////////////////////////////////////////////////
600

    
601
  public void unblockScramblingAndSolving()
602
    {
603
    mScramblingAndSolvingBlocked = false;
604
   // mBlockController.scramblingAndSolvingUnblocked();
605
    }
606

    
607
///////////////////////////////////////////////////////////////////////////////////////////////////
608

    
609
  public void preRender()
610
    {
611
    if( mSolve                    ) solveNow();
612
    if( mSetQuat                  ) setQuatNow();
613
    if( mFinishRotation           ) finishRotationNow();
614
    if( mRemoveManualRotation     ) removeManualRotationNow();
615
    if( mRemoveProgramaticRotation) removeProgramaticRotationNow();
616
    if( mChangeObject             ) changeObjectNow();
617
    if( mSolveObject              ) solveObjectNow();
618
    if( mScrambleObject           ) scrambleObjectNow();
619
    if( mFastScrambleObject       ) fastScrambleObjectNow();
620
    if( mPresentObject            ) presentObjectNow();
621
    if( mAddRotation              ) addRotationNow();
622
    if( mInitializeObject         ) initializeObjectNow();
623
    if( mApplyScrambles           ) applyScramblesNow();
624
    if( mResetAllTextureMaps      ) resetAllTextureMapsNow();
625
    if( mSetTextureMap            ) setTextureMapNow();
626
    if( mResetTextureEffect       ) resetTextureNow();
627
    }
628

    
629
///////////////////////////////////////////////////////////////////////////////////////////////////
630

    
631
  public void addRotation(MovesFinished listener, int axis, int rowBitmap, int bareAngle, int millPreDegree)
632
    {
633
    int[][] basicAngles = mNewObject==null ? null : mNewObject.getBasicAngles();
634

    
635
    if( basicAngles!=null && axis<basicAngles.length )
636
      {
637
      int row = computeRowFromBitmap(rowBitmap);
638

    
639
      if( row<basicAngles[axis].length )
640
        {
641
        int basicAngle= basicAngles[axis][row];
642
        int angle     = bareAngle*(360/basicAngle);
643
        int duration  = Math.abs(angle)*millPreDegree;
644

    
645
        mAddActionListener    = listener;
646
        mAddRotationAxis      = axis;
647
        mAddRotationRowBitmap = rowBitmap;
648
        mAddRotationAngle     = angle;
649
        mAddRotationDuration  = duration;
650
        mAddRotationTime      = System.currentTimeMillis();
651
        mAddRotation          = true;
652

    
653
        if( listener instanceof ScrambleEffect )
654
          {
655
          mDebug += (mNewObject==null ? "null" : mNewObject.reportState() );
656
          mDebug += ("(a "+axis+" "+rowBitmap+" "+angle+" "+(mAddRotationTime-mScrambleStartTime))+")";
657
          }
658
        }
659
      }
660
    }
661

    
662
///////////////////////////////////////////////////////////////////////////////////////////////////
663

    
664
  public void initializeObject(int[][] moves)
665
    {
666
    mInitializeObject = true;
667
    mInitMoves = moves;
668
    }
669

    
670
///////////////////////////////////////////////////////////////////////////////////////////////////
671

    
672
  public void applyScrambles(int[][] moves)
673
    {
674
    mApplyScrambles = true;
675
    mScraMoves = moves;
676
    }
677

    
678
///////////////////////////////////////////////////////////////////////////////////////////////////
679

    
680
  public boolean scrambleObject(int num)
681
    {
682
    if( !mScramblingAndSolvingBlocked )
683
      {
684
      mScrambleObject = true;
685
      mScrambleObjectNum = num;
686
      mDebug = "";
687
      mScrambleStartTime = System.currentTimeMillis();
688
      return true;
689
      }
690
    return false;
691
    }
692

    
693
///////////////////////////////////////////////////////////////////////////////////////////////////
694

    
695
  public boolean fastScrambleObject(int duration, int num)
696
    {
697
    if( !mScramblingAndSolvingBlocked )
698
      {
699
      mFastScrambleObject = true;
700
      mScrambleObjectNum = num;
701
      mScrambleObjectDuration = duration;
702
      mDebug = "";
703
      mScrambleStartTime = System.currentTimeMillis();
704
      return true;
705
      }
706
    return false;
707
    }
708

    
709
///////////////////////////////////////////////////////////////////////////////////////////////////
710

    
711
  public void presentObject(int num, int duration)
712
    {
713
    mScrambleObjectNum = num;
714
    mPresentDuration = duration;
715
    mPresentObject = true;
716
    }
717

    
718
///////////////////////////////////////////////////////////////////////////////////////////////////
719
// this starts the Solve Effect
720

    
721
  public void solveObject()
722
    {
723
    if( !mScramblingAndSolvingBlocked )
724
      {
725
      mSolveObject = true;
726
      }
727
    }
728

    
729
///////////////////////////////////////////////////////////////////////////////////////////////////
730
// this only sets the cubits state to solved
731

    
732
  public void solveOnly()
733
    {
734
    mSolve = true;
735
    }
736

    
737
///////////////////////////////////////////////////////////////////////////////////////////////////
738

    
739
  public void resetTextureMapsEffect(int duration)
740
    {
741
    mRestickerDuration = duration;
742
    mResetTextureEffect = true;
743
    }
744

    
745
///////////////////////////////////////////////////////////////////////////////////////////////////
746

    
747
  public void resetAllTextureMaps()
748
    {
749
    mResetAllTextureMaps = true;
750
    }
751

    
752
///////////////////////////////////////////////////////////////////////////////////////////////////
753

    
754
  public TwistyObject getObject()
755
    {
756
    return mNewObject;
757
    }
758

    
759
///////////////////////////////////////////////////////////////////////////////////////////////////
760

    
761
  public TwistyObjectNode getObjectNode()
762
    {
763
    return mController.getNode();
764
    }
765

    
766
///////////////////////////////////////////////////////////////////////////////////////////////////
767

    
768
  public void effectFinished(final long effectID)
769
    {
770
    if( effectID == mRotationFinishedID )
771
      {
772
      mRotationFinishedID = 0;
773
      removeManualRotation();
774
      }
775
    else if( effectID == mAddRotationID )
776
      {
777
      mAddRotationID = 0;
778
      mRemoveProgramaticRotationID = effectID;
779
      removeProgramaticRotation();
780
      }
781
    else
782
      {
783
      for(int i=0; i<BaseEffect.Type.LENGTH; i++)
784
        {
785
        if( effectID == mEffectID[i] )
786
          {
787
          if( i==BaseEffect.Type.SCRAMBLE.ordinal() )
788
            {
789
            mScrambleEndTime = System.currentTimeMillis();
790
            mInterface.onScrambleEffectFinished();
791
            }
792
          else if( i==BaseEffect.Type.FAST_SCRAMBLE.ordinal() )
793
            {
794
            mInterface.onScrambleEffectFinished();
795
            unblockEverything();
796
            }
797
          else if( i==BaseEffect.Type.WIN.ordinal() )
798
            {
799
            mInterface.onWinEffectFinished(mScrambleStartTime,mScrambleEndTime-mScrambleStartTime,mDebug,mScrambleObjectNum);
800
            }
801
          else
802
            {
803
            if( mOldObject!=null ) mOldObject.releaseResources();
804
            unblockEverything();
805
            }
806

    
807
          break;
808
          }
809
        }
810
      }
811
    }
812
  }
(3-3/10)