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 java.io.InputStream;
|
13
|
|
14
|
import android.app.Activity;
|
15
|
import android.content.SharedPreferences;
|
16
|
|
17
|
import org.distorted.library.message.EffectListener;
|
18
|
import org.distorted.library.type.Static3D;
|
19
|
|
20
|
import org.distorted.library.type.Static4D;
|
21
|
import org.distorted.objectlib.helpers.ObjectLibInterface;
|
22
|
import org.distorted.objectlib.effects.BaseEffect;
|
23
|
import org.distorted.objectlib.effects.scramble.ScrambleEffect;
|
24
|
import org.distorted.objectlib.helpers.BlockController;
|
25
|
import org.distorted.objectlib.helpers.MovesFinished;
|
26
|
import org.distorted.objectlib.shape.ShapeDodecahedron;
|
27
|
import org.distorted.objectlib.shape.ShapeHexahedron;
|
28
|
import org.distorted.objectlib.shape.ShapeOctahedron;
|
29
|
import org.distorted.objectlib.shape.ShapeTetrahedron;
|
30
|
|
31
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
32
|
|
33
|
public class ObjectPreRender implements EffectListener
|
34
|
{
|
35
|
private static final int MAX_SLOW_SCRAMBLE = 50;
|
36
|
|
37
|
private final ObjectControl mController;
|
38
|
private InputStream mJsonStream, mMeshStream;
|
39
|
private int mOrdinal;
|
40
|
private TwistyObject mOldObject, mNewObject;
|
41
|
private SharedPreferences mPreferences;
|
42
|
private MovesFinished mAddActionListener;
|
43
|
private final BlockController mBlockController;
|
44
|
private final ObjectLibInterface mInterface;
|
45
|
private String mDebug;
|
46
|
private float mMoveX, mMoveY;
|
47
|
private float mScale;
|
48
|
|
49
|
private boolean mFinishRotation, mRemoveRotation, mRemovePatternRotation, mAddRotation,
|
50
|
mSetQuat, mChangeObject, mSolveObject, mScrambleObject, mFastScrambleObject, mPresentObject,
|
51
|
mInitializeObject, mSetTextureMap, mResetAllTextureMaps, mSolve, mApplyScrambles;
|
52
|
private boolean mScramblingAndSolvingBlocked, mRotationBlocked, mIsSolved;
|
53
|
private long mRotationFinishedID;
|
54
|
private final long[] mEffectID;
|
55
|
private int[][] mNextMoves;
|
56
|
private int mScrambleObjectNum, mScrambleObjectDuration;
|
57
|
private int mAddRotationAxis, mAddRotationRowBitmap, mAddRotationAngle;
|
58
|
private long mAddRotationDuration;
|
59
|
private int mPresentDuration;
|
60
|
private long mAddRotationID, mRemoveRotationID;
|
61
|
private int mCubit, mFace, mNewColor;
|
62
|
private int mNearestAngle;
|
63
|
private long mScrambleStartTime, mScrambleEndTime;
|
64
|
private int mMeshState, mIconMode;
|
65
|
|
66
|
// debugging only
|
67
|
private long mAddRotationTime;
|
68
|
|
69
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
70
|
|
71
|
public ObjectPreRender(Activity act, ObjectControl controller, ObjectLibInterface actioner)
|
72
|
{
|
73
|
mInterface = actioner;
|
74
|
mController = controller;
|
75
|
|
76
|
mFinishRotation = false;
|
77
|
mRemoveRotation = false;
|
78
|
mRemovePatternRotation= false;
|
79
|
mAddRotation = false;
|
80
|
mSetQuat = false;
|
81
|
mChangeObject = false;
|
82
|
mSolveObject = false;
|
83
|
mSolve = false;
|
84
|
mScrambleObject = false;
|
85
|
mFastScrambleObject = false;
|
86
|
mPresentObject = 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, InputStream jsonStream, InputStream meshStream)
|
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( jsonStream==null )
|
112
|
{
|
113
|
tmp = ObjectType.create( ordinal, meshState, iconMode, quat, move, mScale, meshStream);
|
114
|
}
|
115
|
else
|
116
|
{
|
117
|
tmp = new TwistyJson( jsonStream, meshState, iconMode, quat, move, mScale, meshStream);
|
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,mJsonStream,mMeshStream);
|
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 presentObjectNow()
|
314
|
{
|
315
|
mPresentObject = false;
|
316
|
doEffectNow( BaseEffect.Type.PRESENT, mPresentDuration );
|
317
|
}
|
318
|
|
319
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
320
|
|
321
|
private void solveObjectNow()
|
322
|
{
|
323
|
mSolveObject = false;
|
324
|
blockEverything(BlockController.PLACE_4);
|
325
|
int duration = BaseEffect.Type.SOLVE.getDuration();
|
326
|
doEffectNow( BaseEffect.Type.SOLVE, duration );
|
327
|
}
|
328
|
|
329
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
330
|
|
331
|
private void solveNow()
|
332
|
{
|
333
|
mSolve = false;
|
334
|
if( mNewObject!=null ) mNewObject.solve();
|
335
|
}
|
336
|
|
337
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
338
|
|
339
|
private void initializeObjectNow()
|
340
|
{
|
341
|
mInitializeObject = false;
|
342
|
mNewObject.initializeObject(mNextMoves);
|
343
|
}
|
344
|
|
345
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
346
|
|
347
|
private void applyScramblesNow()
|
348
|
{
|
349
|
mApplyScrambles = false;
|
350
|
mNewObject.applyScrambles(mNextMoves);
|
351
|
}
|
352
|
|
353
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
354
|
|
355
|
private void setTextureMapNow()
|
356
|
{
|
357
|
mSetTextureMap = false;
|
358
|
|
359
|
if( mNewObject!=null ) mNewObject.setTextureMap(mCubit,mFace,mNewColor);
|
360
|
}
|
361
|
|
362
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
363
|
|
364
|
private void resetAllTextureMapsNow()
|
365
|
{
|
366
|
mResetAllTextureMaps = false;
|
367
|
if( mNewObject!=null ) mNewObject.resetAllTextureMaps();
|
368
|
}
|
369
|
|
370
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
371
|
|
372
|
private void setQuatNow()
|
373
|
{
|
374
|
mSetQuat = false;
|
375
|
mController.setQuat();
|
376
|
}
|
377
|
|
378
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
379
|
|
380
|
private int computeRowFromBitmap(int rowBitmap)
|
381
|
{
|
382
|
int index = 0;
|
383
|
|
384
|
while(index<32)
|
385
|
{
|
386
|
if( (rowBitmap&0x1) != 0 ) return index;
|
387
|
rowBitmap>>=1;
|
388
|
index++;
|
389
|
}
|
390
|
|
391
|
return 0;
|
392
|
}
|
393
|
|
394
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
395
|
|
396
|
private void blockEverything(int place)
|
397
|
{
|
398
|
mScramblingAndSolvingBlocked = true;
|
399
|
mRotationBlocked = true;
|
400
|
mBlockController.rotationBlocked(place);
|
401
|
mBlockController.scramblingAndSolvingBlocked(place);
|
402
|
}
|
403
|
|
404
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
405
|
// called from ObjectControl; this from app when we switch the screen to READ post-scrambling.
|
406
|
// The point: we only unblock having completed the screen switch so that it is impossible to
|
407
|
// click the solve button then.
|
408
|
|
409
|
void unblockEverything()
|
410
|
{
|
411
|
mScramblingAndSolvingBlocked = false;
|
412
|
mRotationBlocked = false;
|
413
|
mBlockController.rotationUnblocked();
|
414
|
mBlockController.scramblingAndSolvingUnblocked();
|
415
|
}
|
416
|
|
417
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
418
|
|
419
|
void rememberMove(int axis, int row, int angle)
|
420
|
{
|
421
|
mDebug += (mNewObject==null ? "[null]" : mNewObject.reportState() );
|
422
|
mDebug += ("(m "+axis+" "+(1<<row)+" "+angle+" "+(System.currentTimeMillis()-mScrambleEndTime))+")";
|
423
|
}
|
424
|
|
425
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
426
|
|
427
|
void finishRotation(int nearestAngle)
|
428
|
{
|
429
|
mNearestAngle = nearestAngle;
|
430
|
mFinishRotation = true;
|
431
|
}
|
432
|
|
433
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
434
|
|
435
|
void setTextureMap(int cubit, int face, int newColor)
|
436
|
{
|
437
|
mSetTextureMap = true;
|
438
|
|
439
|
mCubit = cubit;
|
440
|
mFace = face;
|
441
|
mNewColor = newColor;
|
442
|
}
|
443
|
|
444
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
445
|
|
446
|
void setQuatOnNextRender()
|
447
|
{
|
448
|
mSetQuat = true;
|
449
|
}
|
450
|
|
451
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
452
|
|
453
|
void setMove(float xmove, float ymove)
|
454
|
{
|
455
|
mMoveX = xmove;
|
456
|
mMoveY = ymove;
|
457
|
}
|
458
|
|
459
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
460
|
|
461
|
void setScale(float scale)
|
462
|
{
|
463
|
mScale = scale;
|
464
|
}
|
465
|
|
466
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
467
|
// INTERNAL API
|
468
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
469
|
|
470
|
public int getNumScrambles()
|
471
|
{
|
472
|
return mScrambleObjectNum;
|
473
|
}
|
474
|
|
475
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
476
|
|
477
|
public TwistyObject getOldObject()
|
478
|
{
|
479
|
return mOldObject;
|
480
|
}
|
481
|
|
482
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
483
|
|
484
|
public float getMoveX()
|
485
|
{
|
486
|
return mMoveX;
|
487
|
}
|
488
|
|
489
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
490
|
|
491
|
public float getMoveY()
|
492
|
{
|
493
|
return mMoveY;
|
494
|
}
|
495
|
|
496
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
497
|
|
498
|
public ObjectLibInterface getInterface()
|
499
|
{
|
500
|
return mInterface;
|
501
|
}
|
502
|
|
503
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
504
|
// PUBLIC API
|
505
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
506
|
|
507
|
public void savePreferences(SharedPreferences.Editor editor)
|
508
|
{
|
509
|
if( mNewObject!=null )
|
510
|
{
|
511
|
mNewObject.savePreferences(editor);
|
512
|
}
|
513
|
}
|
514
|
|
515
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
516
|
|
517
|
public void restorePreferences(SharedPreferences preferences)
|
518
|
{
|
519
|
mPreferences = preferences;
|
520
|
}
|
521
|
|
522
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
523
|
|
524
|
public void changeObject(int ordinal, int meshState, int iconMode, InputStream jsonStream, InputStream meshStream)
|
525
|
{
|
526
|
mChangeObject = true;
|
527
|
mOrdinal = ordinal;
|
528
|
mMeshState = meshState;
|
529
|
mIconMode = iconMode;
|
530
|
mJsonStream = jsonStream;
|
531
|
mMeshStream = meshStream;
|
532
|
}
|
533
|
|
534
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
535
|
|
536
|
public void setDefaultRotation(int numFaces)
|
537
|
{
|
538
|
if( mController!=null && mController.getRotateOnCreation() )
|
539
|
{
|
540
|
switch(numFaces)
|
541
|
{
|
542
|
case 4: mController.rotateNow(ShapeTetrahedron.DEFAULT_ROT ); break;
|
543
|
case 6: mController.rotateNow(ShapeHexahedron.DEFAULT_ROT ); break;
|
544
|
case 8: mController.rotateNow(ShapeOctahedron.DEFAULT_ROT ); break;
|
545
|
case 12: mController.rotateNow(ShapeDodecahedron.DEFAULT_ROT); break;
|
546
|
}
|
547
|
}
|
548
|
}
|
549
|
|
550
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
551
|
|
552
|
public boolean isRotationBlocked()
|
553
|
{
|
554
|
return mRotationBlocked;
|
555
|
}
|
556
|
|
557
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
558
|
|
559
|
public boolean isScramblingAndSolvingNotBlocked()
|
560
|
{
|
561
|
return !mScramblingAndSolvingBlocked;
|
562
|
}
|
563
|
|
564
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
565
|
|
566
|
public void blockRotation(int place)
|
567
|
{
|
568
|
mRotationBlocked = true;
|
569
|
mBlockController.rotationBlocked(place);
|
570
|
}
|
571
|
|
572
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
573
|
|
574
|
public void unblockRotation()
|
575
|
{
|
576
|
mRotationBlocked = false;
|
577
|
mBlockController.rotationUnblocked();
|
578
|
}
|
579
|
|
580
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
581
|
|
582
|
public void unblockScramblingAndSolving()
|
583
|
{
|
584
|
mScramblingAndSolvingBlocked = false;
|
585
|
mBlockController.scramblingAndSolvingUnblocked();
|
586
|
}
|
587
|
|
588
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
589
|
|
590
|
public void preRender()
|
591
|
{
|
592
|
if( mSolve ) solveNow();
|
593
|
if( mSetQuat ) setQuatNow();
|
594
|
if( mFinishRotation ) finishRotationNow();
|
595
|
if( mRemoveRotation ) removeRotationNow();
|
596
|
if( mRemovePatternRotation ) removePatternRotationNow();
|
597
|
if( mChangeObject ) changeObjectNow();
|
598
|
if( mSolveObject ) solveObjectNow();
|
599
|
if( mScrambleObject ) scrambleObjectNow();
|
600
|
if( mFastScrambleObject ) fastScrambleObjectNow();
|
601
|
if( mPresentObject ) presentObjectNow();
|
602
|
if( mAddRotation ) addRotationNow();
|
603
|
if( mInitializeObject ) initializeObjectNow();
|
604
|
if( mApplyScrambles ) applyScramblesNow();
|
605
|
if( mResetAllTextureMaps ) resetAllTextureMapsNow();
|
606
|
if( mSetTextureMap ) setTextureMapNow();
|
607
|
}
|
608
|
|
609
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
610
|
|
611
|
public void addRotation(MovesFinished listener, int axis, int rowBitmap, int bareAngle, int millPreDegree)
|
612
|
{
|
613
|
int[][] basicAngles = mNewObject==null ? null : mNewObject.getBasicAngles();
|
614
|
int length = basicAngles==null ? 0 : basicAngles.length;
|
615
|
|
616
|
if( axis<length )
|
617
|
{
|
618
|
int row = computeRowFromBitmap(rowBitmap);
|
619
|
|
620
|
if( row<basicAngles[axis].length )
|
621
|
{
|
622
|
int basicAngle= basicAngles[axis][row];
|
623
|
int angle = bareAngle*(360/basicAngle);
|
624
|
int duration = Math.abs(angle)*millPreDegree;
|
625
|
|
626
|
mAddActionListener = listener;
|
627
|
mAddRotationAxis = axis;
|
628
|
mAddRotationRowBitmap = rowBitmap;
|
629
|
mAddRotationAngle = angle;
|
630
|
mAddRotationDuration = duration;
|
631
|
mAddRotationTime = System.currentTimeMillis();
|
632
|
mAddRotation = true;
|
633
|
|
634
|
if( listener instanceof ScrambleEffect )
|
635
|
{
|
636
|
mDebug += (mNewObject==null ? "null" : mNewObject.reportState() );
|
637
|
mDebug += ("(a "+axis+" "+rowBitmap+" "+angle+" "+(mAddRotationTime-mScrambleStartTime))+")";
|
638
|
}
|
639
|
}
|
640
|
}
|
641
|
}
|
642
|
|
643
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
644
|
|
645
|
public void initializeObject(int[][] moves)
|
646
|
{
|
647
|
mInitializeObject = true;
|
648
|
mNextMoves = moves;
|
649
|
}
|
650
|
|
651
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
652
|
|
653
|
public void applyScrambles(int[][] moves)
|
654
|
{
|
655
|
mApplyScrambles = true;
|
656
|
mNextMoves = moves;
|
657
|
}
|
658
|
|
659
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
660
|
|
661
|
public boolean scrambleObject(int num)
|
662
|
{
|
663
|
if( !mScramblingAndSolvingBlocked )
|
664
|
{
|
665
|
mScrambleObject = true;
|
666
|
mScrambleObjectNum = num;
|
667
|
mDebug = "";
|
668
|
mScrambleStartTime = System.currentTimeMillis();
|
669
|
return true;
|
670
|
}
|
671
|
return false;
|
672
|
}
|
673
|
|
674
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
675
|
|
676
|
public boolean fastScrambleObject(int duration, int num)
|
677
|
{
|
678
|
if( !mScramblingAndSolvingBlocked )
|
679
|
{
|
680
|
mFastScrambleObject = true;
|
681
|
mScrambleObjectNum = num;
|
682
|
mScrambleObjectDuration = duration;
|
683
|
mDebug = "";
|
684
|
mScrambleStartTime = System.currentTimeMillis();
|
685
|
return true;
|
686
|
}
|
687
|
return false;
|
688
|
}
|
689
|
|
690
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
691
|
|
692
|
public void presentObject(int num, int duration)
|
693
|
{
|
694
|
mScrambleObjectNum = num;
|
695
|
mPresentDuration = duration;
|
696
|
mPresentObject = true;
|
697
|
}
|
698
|
|
699
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
700
|
// this starts the Solve Effect
|
701
|
|
702
|
public void solveObject()
|
703
|
{
|
704
|
if( !mScramblingAndSolvingBlocked )
|
705
|
{
|
706
|
mSolveObject = true;
|
707
|
}
|
708
|
}
|
709
|
|
710
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
711
|
// this only sets the cubits state to solved
|
712
|
|
713
|
public void solveOnly()
|
714
|
{
|
715
|
mSolve = true;
|
716
|
}
|
717
|
|
718
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
719
|
|
720
|
public void resetAllTextureMaps()
|
721
|
{
|
722
|
mResetAllTextureMaps = true;
|
723
|
}
|
724
|
|
725
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
726
|
|
727
|
public TwistyObject getObject()
|
728
|
{
|
729
|
return mNewObject;
|
730
|
}
|
731
|
|
732
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
733
|
|
734
|
public TwistyObjectNode getObjectNode()
|
735
|
{
|
736
|
return mController.getNode();
|
737
|
}
|
738
|
|
739
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
740
|
|
741
|
public void effectFinished(final long effectID)
|
742
|
{
|
743
|
if( effectID == mRotationFinishedID )
|
744
|
{
|
745
|
mRotationFinishedID = 0;
|
746
|
removeRotation();
|
747
|
}
|
748
|
else if( effectID == mAddRotationID )
|
749
|
{
|
750
|
mAddRotationID = 0;
|
751
|
mRemoveRotationID = effectID;
|
752
|
removePatternRotation();
|
753
|
}
|
754
|
else
|
755
|
{
|
756
|
for(int i=0; i<BaseEffect.Type.LENGTH; i++)
|
757
|
{
|
758
|
if( effectID == mEffectID[i] )
|
759
|
{
|
760
|
if( i==BaseEffect.Type.SCRAMBLE.ordinal() )
|
761
|
{
|
762
|
mScrambleEndTime = System.currentTimeMillis();
|
763
|
mInterface.onScrambleEffectFinished();
|
764
|
}
|
765
|
else if( i==BaseEffect.Type.WIN.ordinal() )
|
766
|
{
|
767
|
mInterface.onWinEffectFinished(mScrambleStartTime,mScrambleEndTime-mScrambleStartTime,mDebug,mScrambleObjectNum);
|
768
|
}
|
769
|
else
|
770
|
{
|
771
|
unblockEverything();
|
772
|
}
|
773
|
|
774
|
break;
|
775
|
}
|
776
|
}
|
777
|
}
|
778
|
}
|
779
|
}
|