Project

General

Profile

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

distorted-objectlib / src / main / java / org / distorted / objectlib / main / ObjectPreRender.java @ 6f5eb9b3

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.metadata.ListObjects;
23
import org.distorted.objectlib.shape.ShapeDodecahedron;
24
import org.distorted.objectlib.shape.ShapeHexahedron;
25
import org.distorted.objectlib.shape.ShapeOctahedron;
26
import org.distorted.objectlib.shape.ShapeTetrahedron;
27

    
28
///////////////////////////////////////////////////////////////////////////////////////////////////
29

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

    
34
  private final ObjectControl mController;
35
  private InitAssets mAsset;
36
  private int mOrdinal;
37
  private TwistyObject mOldObject, mNewObject;
38
  private OperatingSystemInterface mOS;
39
  private MovesFinished mAddActionListener;
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, mRepaintPuzzleFace;
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
    mRepaintPuzzleFace    = false;
87

    
88
    mOldObject = null;
89
    mNewObject = null;
90

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

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

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

    
101
///////////////////////////////////////////////////////////////////////////////////////////////////
102

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

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

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

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

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

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

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

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

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

    
169
///////////////////////////////////////////////////////////////////////////////////////////////////
170

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

    
177
///////////////////////////////////////////////////////////////////////////////////////////////////
178

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

    
184
    boolean solved = mNewObject.isSolved();
185

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

    
198
    rememberMove(mFinishAxis,mFinishRow,angle);
199

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

    
208
    mIsSolved = solved;
209
    }
210

    
211
///////////////////////////////////////////////////////////////////////////////////////////////////
212

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

    
218
///////////////////////////////////////////////////////////////////////////////////////////////////
219

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

    
225
///////////////////////////////////////////////////////////////////////////////////////////////////
226

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

    
234
///////////////////////////////////////////////////////////////////////////////////////////////////
235

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

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

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

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

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

    
274
///////////////////////////////////////////////////////////////////////////////////////////////////
275

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

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

    
288
///////////////////////////////////////////////////////////////////////////////////////////////////
289

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

    
299
///////////////////////////////////////////////////////////////////////////////////////////////////
300

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

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

    
319
///////////////////////////////////////////////////////////////////////////////////////////////////
320

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

    
329
///////////////////////////////////////////////////////////////////////////////////////////////////
330

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

    
337
///////////////////////////////////////////////////////////////////////////////////////////////////
338

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

    
345
///////////////////////////////////////////////////////////////////////////////////////////////////
346

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

    
355
///////////////////////////////////////////////////////////////////////////////////////////////////
356

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

    
363
///////////////////////////////////////////////////////////////////////////////////////////////////
364

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

    
371
///////////////////////////////////////////////////////////////////////////////////////////////////
372

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

    
379
///////////////////////////////////////////////////////////////////////////////////////////////////
380

    
381
  private void setTextureMapNow()
382
    {
383
    mSetTextureMap = false;
384
    if( mNewObject!=null ) mNewObject.setTextureMap(mCubit,mFace,mNewColor);
385
    }
386

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

    
389
  private void repaintPuzzleFaceNow()
390
    {
391
    mRepaintPuzzleFace = false;
392
    if( mNewObject!=null ) mNewObject.repaintPuzzleFace(mCubit,mFace,mNewColor);
393
    }
394

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

    
397
  private void resetAllTextureMapsNow()
398
    {
399
    mResetAllTextureMaps = false;
400
    if( mNewObject!=null ) mNewObject.resetAllTextureMaps();
401
    }
402

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

    
405
  private void setQuatNow()
406
    {
407
    mSetQuat = false;
408
    mController.setQuat();
409
    }
410

    
411
///////////////////////////////////////////////////////////////////////////////////////////////////
412

    
413
  private int computeRowFromBitmap(int rowBitmap)
414
    {
415
    int index = 0;
416

    
417
    while(index<32)
418
      {
419
      if( (rowBitmap&0x1) != 0 ) return index;
420
      rowBitmap>>=1;
421
      index++;
422
      }
423

    
424
    return 0;
425
    }
426

    
427
///////////////////////////////////////////////////////////////////////////////////////////////////
428

    
429
  private void blockEverything(int place)
430
    {
431
    mScramblingAndSolvingBlocked = true;
432
    mRotationBlocked = true;
433
  //  mBlockController.rotationBlocked(place);
434
  //  mBlockController.scramblingAndSolvingBlocked(place);
435
    }
436

    
437
///////////////////////////////////////////////////////////////////////////////////////////////////
438
// called from ObjectControl; this from app when we switch the screen to READ post-scrambling.
439
// The point: we only unblock having completed the screen switch so that it is impossible to
440
// click the solve button then.
441

    
442
  void unblockEverything()
443
    {
444
    mScramblingAndSolvingBlocked = false;
445
    mRotationBlocked = false;
446
  //  mBlockController.rotationUnblocked();
447
  //  mBlockController.scramblingAndSolvingUnblocked();
448
    }
449

    
450
///////////////////////////////////////////////////////////////////////////////////////////////////
451

    
452
  void finishRotation(int currentAxis, int currentRow, float currentAngle, float avgSpeed)
453
    {
454
    mFinishAxis = currentAxis;
455
    mFinishRow  = currentRow;
456
    mFinishAngle= currentAngle;
457
    mAvgSpeed   = avgSpeed;
458

    
459
    mFinishRotation = true;
460
    }
461

    
462
///////////////////////////////////////////////////////////////////////////////////////////////////
463

    
464
  void setTextureMap(int cubit, int face, int newColor)
465
    {
466
    mSetTextureMap = true;
467

    
468
    mCubit    = cubit;
469
    mFace     = face;
470
    mNewColor = newColor;
471
    }
472

    
473
///////////////////////////////////////////////////////////////////////////////////////////////////
474

    
475
  public void repaintPuzzleFace(int cubit, int face, int newColor)
476
    {
477
    mRepaintPuzzleFace = true;
478

    
479
    mCubit    = cubit;
480
    mFace     = face;
481
    mNewColor = newColor;
482
    }
483

    
484
///////////////////////////////////////////////////////////////////////////////////////////////////
485

    
486
  void setQuatOnNextRender()
487
    {
488
    mSetQuat = true;
489
    }
490

    
491
///////////////////////////////////////////////////////////////////////////////////////////////////
492

    
493
  void setMove(float xmove, float ymove)
494
    {
495
    mMoveX = xmove;
496
    mMoveY = ymove;
497
    }
498

    
499
///////////////////////////////////////////////////////////////////////////////////////////////////
500

    
501
  void setScale(float scale)
502
    {
503
    mScale = scale;
504
    }
505

    
506
///////////////////////////////////////////////////////////////////////////////////////////////////
507
// INTERNAL API
508
///////////////////////////////////////////////////////////////////////////////////////////////////
509

    
510
  public int getNumScrambles()
511
    {
512
    return mScrambleObjectNum;
513
    }
514

    
515
///////////////////////////////////////////////////////////////////////////////////////////////////
516

    
517
  public TwistyObject getOldObject()
518
    {
519
    return mOldObject;
520
    }
521

    
522
///////////////////////////////////////////////////////////////////////////////////////////////////
523

    
524
  public float getMoveX()
525
    {
526
    return mMoveX;
527
    }
528

    
529
///////////////////////////////////////////////////////////////////////////////////////////////////
530

    
531
  public float getMoveY()
532
    {
533
    return mMoveY;
534
    }
535

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

    
538
  public ObjectLibInterface getInterface()
539
    {
540
    return mInterface;
541
    }
542

    
543
///////////////////////////////////////////////////////////////////////////////////////////////////
544
// PUBLIC API
545
///////////////////////////////////////////////////////////////////////////////////////////////////
546

    
547
  public void savePreferences(OperatingSystemInterface os)
548
    {
549
    if( mNewObject!=null )
550
      {
551
      mNewObject.savePreferences(os);
552
      }
553
    }
554

    
555
///////////////////////////////////////////////////////////////////////////////////////////////////
556

    
557
  public void restorePreferences(OperatingSystemInterface os)
558
    {
559
    mOS = os;
560
    }
561

    
562
///////////////////////////////////////////////////////////////////////////////////////////////////
563

    
564
  public void changeObject(int ordinal, int iconMode, InitAssets asset)
565
    {
566
    mChangeObject = true;
567
    mOrdinal    = ordinal;
568
    mIconMode   = iconMode;
569
    mAsset      = asset;
570
    }
571

    
572
///////////////////////////////////////////////////////////////////////////////////////////////////
573

    
574
  public void setDefaultRotation(int numFaces)
575
    {
576
    if( mController!=null && mController.getRotateOnCreation() )
577
      {
578
      switch(numFaces)
579
        {
580
        case  4: mController.rotateNow(ShapeTetrahedron.DEFAULT_ROT ); break;
581
        case  6: mController.rotateNow(ShapeHexahedron.DEFAULT_ROT  ); break;
582
        case  8: mController.rotateNow(ShapeOctahedron.DEFAULT_ROT  ); break;
583
        case 12: mController.rotateNow(ShapeDodecahedron.DEFAULT_ROT); break;
584
        }
585
      }
586
    }
587

    
588
///////////////////////////////////////////////////////////////////////////////////////////////////
589

    
590
  public boolean isRotationBlocked()
591
    {
592
    return mRotationBlocked;
593
    }
594

    
595
///////////////////////////////////////////////////////////////////////////////////////////////////
596

    
597
  public boolean isScramblingAndSolvingNotBlocked()
598
    {
599
    return !mScramblingAndSolvingBlocked;
600
    }
601

    
602
///////////////////////////////////////////////////////////////////////////////////////////////////
603

    
604
  public void blockRotation(int place)
605
    {
606
    mRotationBlocked = true;
607
  //  mBlockController.rotationBlocked(place);
608
    }
609

    
610
///////////////////////////////////////////////////////////////////////////////////////////////////
611

    
612
  public void unblockRotation()
613
    {
614
    mRotationBlocked = false;
615
  //  mBlockController.rotationUnblocked();
616
    }
617

    
618
///////////////////////////////////////////////////////////////////////////////////////////////////
619

    
620
  public void unblockScramblingAndSolving()
621
    {
622
    mScramblingAndSolvingBlocked = false;
623
   // mBlockController.scramblingAndSolvingUnblocked();
624
    }
625

    
626
///////////////////////////////////////////////////////////////////////////////////////////////////
627

    
628
  public void preRender()
629
    {
630
    if( mSolve                    ) solveNow();
631
    if( mSetQuat                  ) setQuatNow();
632
    if( mFinishRotation           ) finishRotationNow();
633
    if( mRemoveManualRotation     ) removeManualRotationNow();
634
    if( mRemoveProgramaticRotation) removeProgramaticRotationNow();
635
    if( mChangeObject             ) changeObjectNow();
636
    if( mSolveObject              ) solveObjectNow();
637
    if( mScrambleObject           ) scrambleObjectNow();
638
    if( mFastScrambleObject       ) fastScrambleObjectNow();
639
    if( mPresentObject            ) presentObjectNow();
640
    if( mAddRotation              ) addRotationNow();
641
    if( mInitializeObject         ) initializeObjectNow();
642
    if( mApplyScrambles           ) applyScramblesNow();
643
    if( mResetAllTextureMaps      ) resetAllTextureMapsNow();
644
    if( mSetTextureMap            ) setTextureMapNow();
645
    if( mResetTextureEffect       ) resetTextureNow();
646
    if( mRepaintPuzzleFace        ) repaintPuzzleFaceNow();
647
    }
648

    
649
///////////////////////////////////////////////////////////////////////////////////////////////////
650

    
651
  public void addRotation(MovesFinished listener, int axis, int rowBitmap, int bareAngle, int millPreDegree)
652
    {
653
    int[][] basicAngles = mNewObject==null ? null : mNewObject.getBasicAngles();
654

    
655
    if( basicAngles!=null && axis<basicAngles.length )
656
      {
657
      int row = computeRowFromBitmap(rowBitmap);
658

    
659
      if( row<basicAngles[axis].length )
660
        {
661
        int basicAngle= basicAngles[axis][row];
662
        int angle     = bareAngle*(360/basicAngle);
663
        int duration  = Math.abs(angle)*millPreDegree;
664

    
665
        mAddActionListener    = listener;
666
        mAddRotationAxis      = axis;
667
        mAddRotationRowBitmap = rowBitmap;
668
        mAddRotationAngle     = angle;
669
        mAddRotationDuration  = duration;
670
        mAddRotationTime      = System.currentTimeMillis();
671
        mAddRotation          = true;
672

    
673
        if( listener instanceof ScrambleEffect )
674
          {
675
          mDebug += (mNewObject==null ? "null" : mNewObject.reportState() );
676
          mDebug += ("(a "+axis+" "+rowBitmap+" "+angle+" "+(mAddRotationTime-mScrambleStartTime))+")";
677
          }
678
        }
679
      }
680
    }
681

    
682
///////////////////////////////////////////////////////////////////////////////////////////////////
683

    
684
  public void initializeObject(int[][] moves)
685
    {
686
    mInitializeObject = true;
687
    mInitMoves = moves;
688
    }
689

    
690
///////////////////////////////////////////////////////////////////////////////////////////////////
691

    
692
  public void applyScrambles(int[][] moves)
693
    {
694
    mApplyScrambles = true;
695
    mScraMoves = moves;
696
    }
697

    
698
///////////////////////////////////////////////////////////////////////////////////////////////////
699

    
700
  public boolean scrambleObject(int num)
701
    {
702
    if( !mScramblingAndSolvingBlocked )
703
      {
704
      mScrambleObject = true;
705
      mScrambleObjectNum = num;
706
      mDebug = "";
707
      mScrambleStartTime = System.currentTimeMillis();
708
      return true;
709
      }
710
    return false;
711
    }
712

    
713
///////////////////////////////////////////////////////////////////////////////////////////////////
714

    
715
  public boolean fastScrambleObject(int duration, int num)
716
    {
717
    if( !mScramblingAndSolvingBlocked )
718
      {
719
      mFastScrambleObject = true;
720
      mScrambleObjectNum = num;
721
      mScrambleObjectDuration = duration;
722
      mDebug = "";
723
      mScrambleStartTime = System.currentTimeMillis();
724
      return true;
725
      }
726
    return false;
727
    }
728

    
729
///////////////////////////////////////////////////////////////////////////////////////////////////
730

    
731
  public void presentObject(int num, int duration)
732
    {
733
    mScrambleObjectNum = num;
734
    mPresentDuration = duration;
735
    mPresentObject = true;
736
    }
737

    
738
///////////////////////////////////////////////////////////////////////////////////////////////////
739
// this starts the Solve Effect
740

    
741
  public void solveObject()
742
    {
743
    if( !mScramblingAndSolvingBlocked )
744
      {
745
      mSolveObject = true;
746
      }
747
    }
748

    
749
///////////////////////////////////////////////////////////////////////////////////////////////////
750
// this only sets the cubits state to solved
751

    
752
  public void solveOnly()
753
    {
754
    mSolve = true;
755
    }
756

    
757
///////////////////////////////////////////////////////////////////////////////////////////////////
758

    
759
  public void resetTextureMapsEffect(int duration)
760
    {
761
    mRestickerDuration = duration;
762
    mResetTextureEffect = true;
763
    }
764

    
765
///////////////////////////////////////////////////////////////////////////////////////////////////
766

    
767
  public void resetAllTextureMaps()
768
    {
769
    mResetAllTextureMaps = true;
770
    }
771

    
772
///////////////////////////////////////////////////////////////////////////////////////////////////
773

    
774
  public TwistyObject getObject()
775
    {
776
    return mNewObject;
777
    }
778

    
779
///////////////////////////////////////////////////////////////////////////////////////////////////
780

    
781
  public TwistyObjectNode getObjectNode()
782
    {
783
    return mController.getNode();
784
    }
785

    
786
///////////////////////////////////////////////////////////////////////////////////////////////////
787

    
788
  public void effectFinished(final long effectID)
789
    {
790
    if( effectID == mRotationFinishedID )
791
      {
792
      mRotationFinishedID = 0;
793
      removeManualRotation();
794
      }
795
    else if( effectID == mAddRotationID )
796
      {
797
      mAddRotationID = 0;
798
      mRemoveProgramaticRotationID = effectID;
799
      removeProgramaticRotation();
800
      }
801
    else
802
      {
803
      for(int i=0; i<BaseEffect.Type.LENGTH; i++)
804
        {
805
        if( effectID == mEffectID[i] )
806
          {
807
          if( i==BaseEffect.Type.SCRAMBLE.ordinal() )
808
            {
809
            mScrambleEndTime = System.currentTimeMillis();
810
            mInterface.onScrambleEffectFinished();
811
            }
812
          else if( i==BaseEffect.Type.FAST_SCRAMBLE.ordinal() )
813
            {
814
            mInterface.onScrambleEffectFinished();
815
            unblockEverything();
816
            }
817
          else if( i==BaseEffect.Type.WIN.ordinal() )
818
            {
819
            mInterface.onWinEffectFinished(mScrambleStartTime,mScrambleEndTime-mScrambleStartTime,mDebug,mScrambleObjectNum);
820
            }
821
          else
822
            {
823
            if( mOldObject!=null ) mOldObject.releaseResources();
824
            unblockEverything();
825
            }
826

    
827
          break;
828
          }
829
        }
830
      }
831
    }
832
  }
(3-3/9)