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 android.app.Activity;
|
13
|
import android.content.SharedPreferences;
|
14
|
|
15
|
import org.distorted.library.message.EffectListener;
|
16
|
import org.distorted.library.type.Static3D;
|
17
|
|
18
|
import org.distorted.library.type.Static4D;
|
19
|
import org.distorted.objectlib.helpers.ObjectLibInterface;
|
20
|
import org.distorted.objectlib.effects.BaseEffect;
|
21
|
import org.distorted.objectlib.effects.scramble.ScrambleEffect;
|
22
|
import org.distorted.objectlib.helpers.BlockController;
|
23
|
import org.distorted.objectlib.helpers.MovesFinished;
|
24
|
import org.distorted.objectlib.shape.ShapeDodecahedron;
|
25
|
import org.distorted.objectlib.shape.ShapeHexahedron;
|
26
|
import org.distorted.objectlib.shape.ShapeOctahedron;
|
27
|
import org.distorted.objectlib.shape.ShapeTetrahedron;
|
28
|
|
29
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
30
|
|
31
|
public class ObjectPreRender implements EffectListener
|
32
|
{
|
33
|
private static final int MAX_SLOW_SCRAMBLE = 50;
|
34
|
|
35
|
private final ObjectControl mController;
|
36
|
private InitAssets mAsset;
|
37
|
private int mOrdinal;
|
38
|
private TwistyObject mOldObject, mNewObject;
|
39
|
private SharedPreferences mPreferences;
|
40
|
private MovesFinished mAddActionListener;
|
41
|
private final BlockController mBlockController;
|
42
|
private final ObjectLibInterface mInterface;
|
43
|
private String mDebug;
|
44
|
private float mMoveX, mMoveY;
|
45
|
private float mScale;
|
46
|
|
47
|
private boolean mFinishRotation, mRemoveRotation, mRemovePatternRotation, mAddRotation,
|
48
|
mSetQuat, mChangeObject, mSolveObject, mScrambleObject, mFastScrambleObject,
|
49
|
mPresentObject,mInitializeObject, mSetTextureMap, mResetAllTextureMaps, mSolve,
|
50
|
mApplyScrambles, mResetTextureEffect;
|
51
|
private boolean mScramblingAndSolvingBlocked, mRotationBlocked, mIsSolved;
|
52
|
private long mRotationFinishedID;
|
53
|
private final long[] mEffectID;
|
54
|
private int[][] mNextMoves;
|
55
|
private int mScrambleObjectNum, mScrambleObjectDuration;
|
56
|
private int mAddRotationAxis, mAddRotationRowBitmap, mAddRotationAngle;
|
57
|
private long mAddRotationDuration;
|
58
|
private int mPresentDuration, mRestickerDuration;
|
59
|
private long mAddRotationID, mRemoveRotationID;
|
60
|
private int mCubit, mFace, mNewColor;
|
61
|
private int mNearestAngle;
|
62
|
private long mScrambleStartTime, mScrambleEndTime;
|
63
|
private int mMeshState, mIconMode;
|
64
|
|
65
|
// debugging only
|
66
|
private long mAddRotationTime;
|
67
|
|
68
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
69
|
|
70
|
public ObjectPreRender(Activity act, ObjectControl controller, ObjectLibInterface actioner)
|
71
|
{
|
72
|
mInterface = actioner;
|
73
|
mController = controller;
|
74
|
|
75
|
mFinishRotation = false;
|
76
|
mRemoveRotation = false;
|
77
|
mRemovePatternRotation= false;
|
78
|
mAddRotation = false;
|
79
|
mSetQuat = false;
|
80
|
mChangeObject = false;
|
81
|
mSolveObject = false;
|
82
|
mSolve = false;
|
83
|
mScrambleObject = false;
|
84
|
mFastScrambleObject = false;
|
85
|
mPresentObject = false;
|
86
|
mResetTextureEffect = 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(act,this);
|
98
|
unblockEverything();
|
99
|
}
|
100
|
|
101
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
102
|
|
103
|
private void createObjectNow(int ordinal, int meshState, 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 = ObjectType.create( ordinal, meshState, iconMode, quat, move, mScale, assets);
|
114
|
}
|
115
|
else
|
116
|
{
|
117
|
tmp = new TwistyJson( meshState, 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( mPreferences!=null )
|
142
|
{
|
143
|
mNewObject.restorePreferences(mPreferences);
|
144
|
mPreferences = 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 removeRotationNow()
|
172
|
{
|
173
|
mRemoveRotation=false;
|
174
|
mNewObject.removeRotationNow();
|
175
|
|
176
|
boolean solved = mNewObject.isSolved();
|
177
|
|
178
|
if( solved && !mIsSolved )
|
179
|
{
|
180
|
mInterface.onSolved();
|
181
|
unblockEverything();
|
182
|
int duration = BaseEffect.Type.WIN.getDuration();
|
183
|
doEffectNow( BaseEffect.Type.WIN, duration );
|
184
|
}
|
185
|
else
|
186
|
{
|
187
|
unblockEverything();
|
188
|
}
|
189
|
|
190
|
mIsSolved = solved;
|
191
|
}
|
192
|
|
193
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
194
|
|
195
|
private void removeRotation()
|
196
|
{
|
197
|
mRemoveRotation = true;
|
198
|
}
|
199
|
|
200
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
201
|
|
202
|
private void removePatternRotation()
|
203
|
{
|
204
|
mRemovePatternRotation = true;
|
205
|
}
|
206
|
|
207
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
208
|
|
209
|
private void removePatternRotationNow()
|
210
|
{
|
211
|
mRemovePatternRotation=false;
|
212
|
mNewObject.removeRotationNow();
|
213
|
mAddActionListener.onActionFinished(mRemoveRotationID);
|
214
|
}
|
215
|
|
216
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
217
|
|
218
|
private void addRotationNow()
|
219
|
{
|
220
|
mAddRotation = false;
|
221
|
|
222
|
if( mNewObject.getNumAxis() > mAddRotationAxis )
|
223
|
{
|
224
|
mAddRotationID = mNewObject.addNewRotation( mAddRotationAxis, mAddRotationRowBitmap,
|
225
|
mAddRotationAngle, mAddRotationDuration, this);
|
226
|
|
227
|
// failed to add effect (previous rotation hasn't been removed yet)
|
228
|
if( mAddRotationID==0 )
|
229
|
{
|
230
|
mAddActionListener.onActionFinished(0);
|
231
|
}
|
232
|
// the rotation we have just added has forced a finish() of an ongoing
|
233
|
// manual rotation. So the effect that's going to finish is not the manual
|
234
|
// rotation (we have just removed it) but the rotation we have just added
|
235
|
// here - so set mRotationFinishedID to 0
|
236
|
else if( mAddRotationID<0 )
|
237
|
{
|
238
|
mAddRotationID = -mAddRotationID;
|
239
|
mRotationFinishedID = 0;
|
240
|
}
|
241
|
}
|
242
|
else // should never happen but Firebase says it sometimes does
|
243
|
{
|
244
|
long timeNow = System.currentTimeMillis();
|
245
|
Class<? extends MovesFinished> clazz = mAddActionListener.getClass();
|
246
|
String name = clazz.getSimpleName();
|
247
|
|
248
|
String error = "time now: "+timeNow+" add time: "+mAddRotationTime+" axis="+mAddRotationAxis+
|
249
|
"object: "+mNewObject.getShortName()+" "+name;
|
250
|
|
251
|
mInterface.reportProblem(error,true);
|
252
|
unblockEverything();
|
253
|
}
|
254
|
}
|
255
|
|
256
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
257
|
|
258
|
private void finishRotationNow()
|
259
|
{
|
260
|
mFinishRotation = false;
|
261
|
blockEverything(BlockController.PLACE_0);
|
262
|
mRotationFinishedID = mNewObject.finishRotationNow(this, mNearestAngle);
|
263
|
|
264
|
if( mRotationFinishedID==0 ) // failed to add effect - should never happen
|
265
|
{
|
266
|
unblockEverything();
|
267
|
}
|
268
|
}
|
269
|
|
270
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
271
|
|
272
|
private void changeObjectNow()
|
273
|
{
|
274
|
mChangeObject = false;
|
275
|
blockEverything(BlockController.PLACE_1);
|
276
|
createObjectNow(mOrdinal,mMeshState,mIconMode,mAsset);
|
277
|
int duration = BaseEffect.Type.SIZECHANGE.getDuration();
|
278
|
doEffectNow( BaseEffect.Type.SIZECHANGE, duration );
|
279
|
}
|
280
|
|
281
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
282
|
|
283
|
private void scrambleObjectNow()
|
284
|
{
|
285
|
mScrambleObject = false;
|
286
|
mIsSolved = false;
|
287
|
blockEverything(BlockController.PLACE_3);
|
288
|
|
289
|
if( mScrambleObjectNum<MAX_SLOW_SCRAMBLE )
|
290
|
{
|
291
|
int duration = BaseEffect.Type.SCRAMBLE.getDuration();
|
292
|
doEffectNow( BaseEffect.Type.SCRAMBLE, duration );
|
293
|
}
|
294
|
else
|
295
|
{
|
296
|
int duration = BaseEffect.Type.FAST_SCRAMBLE.getDuration();
|
297
|
doEffectNow( BaseEffect.Type.FAST_SCRAMBLE, duration );
|
298
|
}
|
299
|
}
|
300
|
|
301
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
302
|
|
303
|
private void fastScrambleObjectNow()
|
304
|
{
|
305
|
mFastScrambleObject = false;
|
306
|
mIsSolved = false;
|
307
|
blockEverything(BlockController.PLACE_5);
|
308
|
doEffectNow( BaseEffect.Type.FAST_SCRAMBLE, mScrambleObjectDuration );
|
309
|
}
|
310
|
|
311
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
312
|
|
313
|
private void resetTextureNow()
|
314
|
{
|
315
|
mResetTextureEffect = false;
|
316
|
doEffectNow( BaseEffect.Type.RESTICKER, mRestickerDuration );
|
317
|
}
|
318
|
|
319
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
320
|
|
321
|
private void presentObjectNow()
|
322
|
{
|
323
|
mPresentObject = false;
|
324
|
doEffectNow( BaseEffect.Type.PRESENT, mPresentDuration );
|
325
|
}
|
326
|
|
327
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
328
|
|
329
|
private void solveObjectNow()
|
330
|
{
|
331
|
mSolveObject = false;
|
332
|
blockEverything(BlockController.PLACE_4);
|
333
|
int duration = BaseEffect.Type.SOLVE.getDuration();
|
334
|
doEffectNow( BaseEffect.Type.SOLVE, duration );
|
335
|
}
|
336
|
|
337
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
338
|
|
339
|
private void solveNow()
|
340
|
{
|
341
|
mSolve = false;
|
342
|
if( mNewObject!=null ) mNewObject.solve();
|
343
|
}
|
344
|
|
345
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
346
|
|
347
|
private void initializeObjectNow()
|
348
|
{
|
349
|
mInitializeObject = false;
|
350
|
mNewObject.initializeObject(mNextMoves);
|
351
|
}
|
352
|
|
353
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
354
|
|
355
|
private void applyScramblesNow()
|
356
|
{
|
357
|
mApplyScrambles = false;
|
358
|
mNewObject.applyScrambles(mNextMoves);
|
359
|
}
|
360
|
|
361
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
362
|
|
363
|
private void setTextureMapNow()
|
364
|
{
|
365
|
mSetTextureMap = false;
|
366
|
|
367
|
if( mNewObject!=null ) mNewObject.setTextureMap(mCubit,mFace,mNewColor);
|
368
|
}
|
369
|
|
370
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
371
|
|
372
|
private void resetAllTextureMapsNow()
|
373
|
{
|
374
|
mResetAllTextureMaps = false;
|
375
|
if( mNewObject!=null ) mNewObject.resetAllTextureMaps();
|
376
|
}
|
377
|
|
378
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
379
|
|
380
|
private void setQuatNow()
|
381
|
{
|
382
|
mSetQuat = false;
|
383
|
mController.setQuat();
|
384
|
}
|
385
|
|
386
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
387
|
|
388
|
private int computeRowFromBitmap(int rowBitmap)
|
389
|
{
|
390
|
int index = 0;
|
391
|
|
392
|
while(index<32)
|
393
|
{
|
394
|
if( (rowBitmap&0x1) != 0 ) return index;
|
395
|
rowBitmap>>=1;
|
396
|
index++;
|
397
|
}
|
398
|
|
399
|
return 0;
|
400
|
}
|
401
|
|
402
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
403
|
|
404
|
private void blockEverything(int place)
|
405
|
{
|
406
|
mScramblingAndSolvingBlocked = true;
|
407
|
mRotationBlocked = true;
|
408
|
mBlockController.rotationBlocked(place);
|
409
|
mBlockController.scramblingAndSolvingBlocked(place);
|
410
|
}
|
411
|
|
412
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
413
|
// called from ObjectControl; this from app when we switch the screen to READ post-scrambling.
|
414
|
// The point: we only unblock having completed the screen switch so that it is impossible to
|
415
|
// click the solve button then.
|
416
|
|
417
|
void unblockEverything()
|
418
|
{
|
419
|
mScramblingAndSolvingBlocked = false;
|
420
|
mRotationBlocked = false;
|
421
|
mBlockController.rotationUnblocked();
|
422
|
mBlockController.scramblingAndSolvingUnblocked();
|
423
|
}
|
424
|
|
425
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
426
|
|
427
|
void rememberMove(int axis, int row, int angle)
|
428
|
{
|
429
|
mDebug += (mNewObject==null ? "[null]" : mNewObject.reportState() );
|
430
|
mDebug += ("(m "+axis+" "+(1<<row)+" "+angle+" "+(System.currentTimeMillis()-mScrambleEndTime))+")";
|
431
|
}
|
432
|
|
433
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
434
|
|
435
|
void finishRotation(int nearestAngle)
|
436
|
{
|
437
|
mNearestAngle = nearestAngle;
|
438
|
mFinishRotation = true;
|
439
|
}
|
440
|
|
441
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
442
|
|
443
|
void setTextureMap(int cubit, int face, int newColor)
|
444
|
{
|
445
|
mSetTextureMap = true;
|
446
|
|
447
|
mCubit = cubit;
|
448
|
mFace = face;
|
449
|
mNewColor = newColor;
|
450
|
}
|
451
|
|
452
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
453
|
|
454
|
void setQuatOnNextRender()
|
455
|
{
|
456
|
mSetQuat = true;
|
457
|
}
|
458
|
|
459
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
460
|
|
461
|
void setMove(float xmove, float ymove)
|
462
|
{
|
463
|
mMoveX = xmove;
|
464
|
mMoveY = ymove;
|
465
|
}
|
466
|
|
467
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
468
|
|
469
|
void setScale(float scale)
|
470
|
{
|
471
|
mScale = scale;
|
472
|
}
|
473
|
|
474
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
475
|
// INTERNAL API
|
476
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
477
|
|
478
|
public int getNumScrambles()
|
479
|
{
|
480
|
return mScrambleObjectNum;
|
481
|
}
|
482
|
|
483
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
484
|
|
485
|
public TwistyObject getOldObject()
|
486
|
{
|
487
|
return mOldObject;
|
488
|
}
|
489
|
|
490
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
491
|
|
492
|
public float getMoveX()
|
493
|
{
|
494
|
return mMoveX;
|
495
|
}
|
496
|
|
497
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
498
|
|
499
|
public float getMoveY()
|
500
|
{
|
501
|
return mMoveY;
|
502
|
}
|
503
|
|
504
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
505
|
|
506
|
public ObjectLibInterface getInterface()
|
507
|
{
|
508
|
return mInterface;
|
509
|
}
|
510
|
|
511
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
512
|
// PUBLIC API
|
513
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
514
|
|
515
|
public void savePreferences(SharedPreferences.Editor editor)
|
516
|
{
|
517
|
if( mNewObject!=null )
|
518
|
{
|
519
|
mNewObject.savePreferences(editor);
|
520
|
}
|
521
|
}
|
522
|
|
523
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
524
|
|
525
|
public void restorePreferences(SharedPreferences preferences)
|
526
|
{
|
527
|
mPreferences = preferences;
|
528
|
}
|
529
|
|
530
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
531
|
|
532
|
public void changeObject(int ordinal, int meshState, int iconMode, InitAssets asset)
|
533
|
{
|
534
|
mChangeObject = true;
|
535
|
mOrdinal = ordinal;
|
536
|
mMeshState = meshState;
|
537
|
mIconMode = iconMode;
|
538
|
mAsset = asset;
|
539
|
}
|
540
|
|
541
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
542
|
|
543
|
public void setDefaultRotation(int numFaces)
|
544
|
{
|
545
|
if( mController!=null && mController.getRotateOnCreation() )
|
546
|
{
|
547
|
switch(numFaces)
|
548
|
{
|
549
|
case 4: mController.rotateNow(ShapeTetrahedron.DEFAULT_ROT ); break;
|
550
|
case 6: mController.rotateNow(ShapeHexahedron.DEFAULT_ROT ); break;
|
551
|
case 8: mController.rotateNow(ShapeOctahedron.DEFAULT_ROT ); break;
|
552
|
case 12: mController.rotateNow(ShapeDodecahedron.DEFAULT_ROT); break;
|
553
|
}
|
554
|
}
|
555
|
}
|
556
|
|
557
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
558
|
|
559
|
public boolean isRotationBlocked()
|
560
|
{
|
561
|
return mRotationBlocked;
|
562
|
}
|
563
|
|
564
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
565
|
|
566
|
public boolean isScramblingAndSolvingNotBlocked()
|
567
|
{
|
568
|
return !mScramblingAndSolvingBlocked;
|
569
|
}
|
570
|
|
571
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
572
|
|
573
|
public void blockRotation(int place)
|
574
|
{
|
575
|
mRotationBlocked = true;
|
576
|
mBlockController.rotationBlocked(place);
|
577
|
}
|
578
|
|
579
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
580
|
|
581
|
public void unblockRotation()
|
582
|
{
|
583
|
mRotationBlocked = false;
|
584
|
mBlockController.rotationUnblocked();
|
585
|
}
|
586
|
|
587
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
588
|
|
589
|
public void unblockScramblingAndSolving()
|
590
|
{
|
591
|
mScramblingAndSolvingBlocked = false;
|
592
|
mBlockController.scramblingAndSolvingUnblocked();
|
593
|
}
|
594
|
|
595
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
596
|
|
597
|
public void preRender()
|
598
|
{
|
599
|
if( mSolve ) solveNow();
|
600
|
if( mSetQuat ) setQuatNow();
|
601
|
if( mFinishRotation ) finishRotationNow();
|
602
|
if( mRemoveRotation ) removeRotationNow();
|
603
|
if( mRemovePatternRotation ) removePatternRotationNow();
|
604
|
if( mChangeObject ) changeObjectNow();
|
605
|
if( mSolveObject ) solveObjectNow();
|
606
|
if( mScrambleObject ) scrambleObjectNow();
|
607
|
if( mFastScrambleObject ) fastScrambleObjectNow();
|
608
|
if( mPresentObject ) presentObjectNow();
|
609
|
if( mAddRotation ) addRotationNow();
|
610
|
if( mInitializeObject ) initializeObjectNow();
|
611
|
if( mApplyScrambles ) applyScramblesNow();
|
612
|
if( mResetAllTextureMaps ) resetAllTextureMapsNow();
|
613
|
if( mSetTextureMap ) setTextureMapNow();
|
614
|
if( mResetTextureEffect ) resetTextureNow();
|
615
|
}
|
616
|
|
617
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
618
|
|
619
|
public void addRotation(MovesFinished listener, int axis, int rowBitmap, int bareAngle, int millPreDegree)
|
620
|
{
|
621
|
int[][] basicAngles = mNewObject==null ? null : mNewObject.getBasicAngles();
|
622
|
int length = basicAngles==null ? 0 : basicAngles.length;
|
623
|
|
624
|
if( axis<length )
|
625
|
{
|
626
|
int row = computeRowFromBitmap(rowBitmap);
|
627
|
|
628
|
if( row<basicAngles[axis].length )
|
629
|
{
|
630
|
int basicAngle= basicAngles[axis][row];
|
631
|
int angle = bareAngle*(360/basicAngle);
|
632
|
int duration = Math.abs(angle)*millPreDegree;
|
633
|
|
634
|
mAddActionListener = listener;
|
635
|
mAddRotationAxis = axis;
|
636
|
mAddRotationRowBitmap = rowBitmap;
|
637
|
mAddRotationAngle = angle;
|
638
|
mAddRotationDuration = duration;
|
639
|
mAddRotationTime = System.currentTimeMillis();
|
640
|
mAddRotation = true;
|
641
|
|
642
|
if( listener instanceof ScrambleEffect )
|
643
|
{
|
644
|
mDebug += (mNewObject==null ? "null" : mNewObject.reportState() );
|
645
|
mDebug += ("(a "+axis+" "+rowBitmap+" "+angle+" "+(mAddRotationTime-mScrambleStartTime))+")";
|
646
|
}
|
647
|
}
|
648
|
}
|
649
|
}
|
650
|
|
651
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
652
|
|
653
|
public void initializeObject(int[][] moves)
|
654
|
{
|
655
|
mInitializeObject = true;
|
656
|
mNextMoves = moves;
|
657
|
}
|
658
|
|
659
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
660
|
|
661
|
public void applyScrambles(int[][] moves)
|
662
|
{
|
663
|
mApplyScrambles = true;
|
664
|
mNextMoves = moves;
|
665
|
}
|
666
|
|
667
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
668
|
|
669
|
public boolean scrambleObject(int num)
|
670
|
{
|
671
|
if( !mScramblingAndSolvingBlocked )
|
672
|
{
|
673
|
mScrambleObject = true;
|
674
|
mScrambleObjectNum = num;
|
675
|
mDebug = "";
|
676
|
mScrambleStartTime = System.currentTimeMillis();
|
677
|
return true;
|
678
|
}
|
679
|
return false;
|
680
|
}
|
681
|
|
682
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
683
|
|
684
|
public boolean fastScrambleObject(int duration, int num)
|
685
|
{
|
686
|
if( !mScramblingAndSolvingBlocked )
|
687
|
{
|
688
|
mFastScrambleObject = true;
|
689
|
mScrambleObjectNum = num;
|
690
|
mScrambleObjectDuration = duration;
|
691
|
mDebug = "";
|
692
|
mScrambleStartTime = System.currentTimeMillis();
|
693
|
return true;
|
694
|
}
|
695
|
return false;
|
696
|
}
|
697
|
|
698
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
699
|
|
700
|
public void presentObject(int num, int duration)
|
701
|
{
|
702
|
mScrambleObjectNum = num;
|
703
|
mPresentDuration = duration;
|
704
|
mPresentObject = true;
|
705
|
}
|
706
|
|
707
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
708
|
// this starts the Solve Effect
|
709
|
|
710
|
public void solveObject()
|
711
|
{
|
712
|
if( !mScramblingAndSolvingBlocked )
|
713
|
{
|
714
|
mSolveObject = true;
|
715
|
}
|
716
|
}
|
717
|
|
718
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
719
|
// this only sets the cubits state to solved
|
720
|
|
721
|
public void solveOnly()
|
722
|
{
|
723
|
mSolve = true;
|
724
|
}
|
725
|
|
726
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
727
|
|
728
|
public void resetTextureMapsEffect(int duration)
|
729
|
{
|
730
|
mRestickerDuration = duration;
|
731
|
mResetTextureEffect = true;
|
732
|
}
|
733
|
|
734
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
735
|
|
736
|
public void resetAllTextureMaps()
|
737
|
{
|
738
|
mResetAllTextureMaps = true;
|
739
|
}
|
740
|
|
741
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
742
|
|
743
|
public TwistyObject getObject()
|
744
|
{
|
745
|
return mNewObject;
|
746
|
}
|
747
|
|
748
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
749
|
|
750
|
public TwistyObjectNode getObjectNode()
|
751
|
{
|
752
|
return mController.getNode();
|
753
|
}
|
754
|
|
755
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
756
|
|
757
|
public void effectFinished(final long effectID)
|
758
|
{
|
759
|
if( effectID == mRotationFinishedID )
|
760
|
{
|
761
|
mRotationFinishedID = 0;
|
762
|
removeRotation();
|
763
|
}
|
764
|
else if( effectID == mAddRotationID )
|
765
|
{
|
766
|
mAddRotationID = 0;
|
767
|
mRemoveRotationID = effectID;
|
768
|
removePatternRotation();
|
769
|
}
|
770
|
else
|
771
|
{
|
772
|
for(int i=0; i<BaseEffect.Type.LENGTH; i++)
|
773
|
{
|
774
|
if( effectID == mEffectID[i] )
|
775
|
{
|
776
|
if( i==BaseEffect.Type.SCRAMBLE.ordinal() )
|
777
|
{
|
778
|
mScrambleEndTime = System.currentTimeMillis();
|
779
|
mInterface.onScrambleEffectFinished();
|
780
|
}
|
781
|
else if( i==BaseEffect.Type.FAST_SCRAMBLE.ordinal() )
|
782
|
{
|
783
|
mInterface.onScrambleEffectFinished();
|
784
|
unblockEverything();
|
785
|
}
|
786
|
else if( i==BaseEffect.Type.WIN.ordinal() )
|
787
|
{
|
788
|
mInterface.onWinEffectFinished(mScrambleStartTime,mScrambleEndTime-mScrambleStartTime,mDebug,mScrambleObjectNum);
|
789
|
}
|
790
|
else
|
791
|
{
|
792
|
unblockEverything();
|
793
|
}
|
794
|
|
795
|
break;
|
796
|
}
|
797
|
}
|
798
|
}
|
799
|
}
|
800
|
}
|