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, mRemoveRotation, mRemovePatternRotation, 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, mRemoveRotationID;
|
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
|
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 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 removeRotationNow()
|
179
|
{
|
180
|
mRemoveRotation=false;
|
181
|
float angle = mNewObject.removeRotationNow();
|
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 removeRotation()
|
213
|
{
|
214
|
mRemoveRotation = true;
|
215
|
}
|
216
|
|
217
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
218
|
|
219
|
private void removePatternRotation()
|
220
|
{
|
221
|
mRemovePatternRotation = true;
|
222
|
}
|
223
|
|
224
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
225
|
|
226
|
private void removePatternRotationNow()
|
227
|
{
|
228
|
mRemovePatternRotation=false;
|
229
|
mNewObject.removeRotationNow();
|
230
|
mAddActionListener.onActionFinished(mRemoveRotationID);
|
231
|
}
|
232
|
|
233
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
234
|
|
235
|
private void addRotationNow()
|
236
|
{
|
237
|
mAddRotation = false;
|
238
|
|
239
|
if( mNewObject.getNumAxis() > mAddRotationAxis )
|
240
|
{
|
241
|
mAddRotationID = mNewObject.addNewRotation( 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.finishRotationNow(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( mRemoveRotation ) removeRotationNow();
|
615
|
if( mRemovePatternRotation ) removePatternRotationNow();
|
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
|
int length = basicAngles==null ? 0 : basicAngles.length;
|
635
|
|
636
|
if( axis<length )
|
637
|
{
|
638
|
int row = computeRowFromBitmap(rowBitmap);
|
639
|
|
640
|
if( row<basicAngles[axis].length )
|
641
|
{
|
642
|
int basicAngle= basicAngles[axis][row];
|
643
|
int angle = bareAngle*(360/basicAngle);
|
644
|
int duration = Math.abs(angle)*millPreDegree;
|
645
|
|
646
|
mAddActionListener = listener;
|
647
|
mAddRotationAxis = axis;
|
648
|
mAddRotationRowBitmap = rowBitmap;
|
649
|
mAddRotationAngle = angle;
|
650
|
mAddRotationDuration = duration;
|
651
|
mAddRotationTime = System.currentTimeMillis();
|
652
|
mAddRotation = true;
|
653
|
|
654
|
if( listener instanceof ScrambleEffect )
|
655
|
{
|
656
|
mDebug += (mNewObject==null ? "null" : mNewObject.reportState() );
|
657
|
mDebug += ("(a "+axis+" "+rowBitmap+" "+angle+" "+(mAddRotationTime-mScrambleStartTime))+")";
|
658
|
}
|
659
|
}
|
660
|
}
|
661
|
}
|
662
|
|
663
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
664
|
|
665
|
public void initializeObject(int[][] moves)
|
666
|
{
|
667
|
mInitializeObject = true;
|
668
|
mInitMoves = moves;
|
669
|
}
|
670
|
|
671
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
672
|
|
673
|
public void applyScrambles(int[][] moves)
|
674
|
{
|
675
|
mApplyScrambles = true;
|
676
|
mScraMoves = moves;
|
677
|
}
|
678
|
|
679
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
680
|
|
681
|
public boolean scrambleObject(int num)
|
682
|
{
|
683
|
if( !mScramblingAndSolvingBlocked )
|
684
|
{
|
685
|
mScrambleObject = true;
|
686
|
mScrambleObjectNum = num;
|
687
|
mDebug = "";
|
688
|
mScrambleStartTime = System.currentTimeMillis();
|
689
|
return true;
|
690
|
}
|
691
|
return false;
|
692
|
}
|
693
|
|
694
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
695
|
|
696
|
public boolean fastScrambleObject(int duration, int num)
|
697
|
{
|
698
|
if( !mScramblingAndSolvingBlocked )
|
699
|
{
|
700
|
mFastScrambleObject = true;
|
701
|
mScrambleObjectNum = num;
|
702
|
mScrambleObjectDuration = duration;
|
703
|
mDebug = "";
|
704
|
mScrambleStartTime = System.currentTimeMillis();
|
705
|
return true;
|
706
|
}
|
707
|
return false;
|
708
|
}
|
709
|
|
710
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
711
|
|
712
|
public void presentObject(int num, int duration)
|
713
|
{
|
714
|
mScrambleObjectNum = num;
|
715
|
mPresentDuration = duration;
|
716
|
mPresentObject = true;
|
717
|
}
|
718
|
|
719
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
720
|
// this starts the Solve Effect
|
721
|
|
722
|
public void solveObject()
|
723
|
{
|
724
|
if( !mScramblingAndSolvingBlocked )
|
725
|
{
|
726
|
mSolveObject = true;
|
727
|
}
|
728
|
}
|
729
|
|
730
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
731
|
// this only sets the cubits state to solved
|
732
|
|
733
|
public void solveOnly()
|
734
|
{
|
735
|
mSolve = true;
|
736
|
}
|
737
|
|
738
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
739
|
|
740
|
public void resetTextureMapsEffect(int duration)
|
741
|
{
|
742
|
mRestickerDuration = duration;
|
743
|
mResetTextureEffect = true;
|
744
|
}
|
745
|
|
746
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
747
|
|
748
|
public void resetAllTextureMaps()
|
749
|
{
|
750
|
mResetAllTextureMaps = true;
|
751
|
}
|
752
|
|
753
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
754
|
|
755
|
public TwistyObject getObject()
|
756
|
{
|
757
|
return mNewObject;
|
758
|
}
|
759
|
|
760
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
761
|
|
762
|
public TwistyObjectNode getObjectNode()
|
763
|
{
|
764
|
return mController.getNode();
|
765
|
}
|
766
|
|
767
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
768
|
|
769
|
public void effectFinished(final long effectID)
|
770
|
{
|
771
|
if( effectID == mRotationFinishedID )
|
772
|
{
|
773
|
mRotationFinishedID = 0;
|
774
|
removeRotation();
|
775
|
}
|
776
|
else if( effectID == mAddRotationID )
|
777
|
{
|
778
|
mAddRotationID = 0;
|
779
|
mRemoveRotationID = effectID;
|
780
|
removePatternRotation();
|
781
|
}
|
782
|
else
|
783
|
{
|
784
|
for(int i=0; i<BaseEffect.Type.LENGTH; i++)
|
785
|
{
|
786
|
if( effectID == mEffectID[i] )
|
787
|
{
|
788
|
if( i==BaseEffect.Type.SCRAMBLE.ordinal() )
|
789
|
{
|
790
|
mScrambleEndTime = System.currentTimeMillis();
|
791
|
mInterface.onScrambleEffectFinished();
|
792
|
}
|
793
|
else if( i==BaseEffect.Type.FAST_SCRAMBLE.ordinal() )
|
794
|
{
|
795
|
mInterface.onScrambleEffectFinished();
|
796
|
unblockEverything();
|
797
|
}
|
798
|
else if( i==BaseEffect.Type.WIN.ordinal() )
|
799
|
{
|
800
|
mInterface.onWinEffectFinished(mScrambleStartTime,mScrambleEndTime-mScrambleStartTime,mDebug,mScrambleObjectNum);
|
801
|
}
|
802
|
else
|
803
|
{
|
804
|
if( mOldObject!=null ) mOldObject.releaseResources();
|
805
|
unblockEverything();
|
806
|
}
|
807
|
|
808
|
break;
|
809
|
}
|
810
|
}
|
811
|
}
|
812
|
}
|
813
|
}
|