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