Revision 985f3dfa
Added by Leszek Koltunski over 3 years ago
src/main/java/org/distorted/main/RubikPreRender.java | ||
---|---|---|
55 | 55 |
void onActionFinished(long effectID); |
56 | 56 |
} |
57 | 57 |
|
58 |
private RubikSurfaceView mView; |
|
58 |
private final RubikSurfaceView mView;
|
|
59 | 59 |
private boolean mFinishRotation, mRemoveRotation, mRemovePatternRotation, mAddRotation, |
60 | 60 |
mSetQuat, mChangeObject, mSetupObject, mSolveObject, mScrambleObject, |
61 | 61 |
mInitializeObject, mSetTextureMap, mResetAllTextureMaps; |
... | ... | |
64 | 64 |
private ObjectList mNextObject; |
65 | 65 |
private int mNextSize; |
66 | 66 |
private long mRotationFinishedID; |
67 |
private long[] mEffectID; |
|
67 |
private final long[] mEffectID;
|
|
68 | 68 |
private boolean mIsNewRecord; |
69 | 69 |
private long mNewRecord; |
70 | 70 |
private int mScreenWidth; |
... | ... | |
230 | 230 |
mAddRotation = false; |
231 | 231 |
mAddRotationID = mNewObject.addNewRotation( mAddRotationAxis, mAddRotationRowBitmap, |
232 | 232 |
mAddRotationAngle, mAddRotationDuration, this); |
233 |
|
|
234 |
if( mAddRotationID==0 ) // failed to add effect - should never happen |
|
235 |
{ |
|
236 |
mCanRotate = true; |
|
237 |
mCanPlay = true; |
|
238 |
} |
|
233 | 239 |
} |
234 | 240 |
|
235 | 241 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/objects/TwistyObject.java | ||
---|---|---|
290 | 290 |
return NUM_CUTS; |
291 | 291 |
} |
292 | 292 |
|
293 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
294 |
|
|
295 |
private boolean wasRotateApplied() |
|
296 |
{ |
|
297 |
return mEffects.exists(mRotateEffect.getID()); |
|
298 |
} |
|
299 |
|
|
293 | 300 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
294 | 301 |
|
295 | 302 |
private boolean belongsToRotation( int cubit, int axis, int rowBitmap) |
... | ... | |
618 | 625 |
|
619 | 626 |
public synchronized long addNewRotation( int axis, int rowBitmap, int angle, long durationMillis, EffectListener listener ) |
620 | 627 |
{ |
621 |
mRotAxis = axis; |
|
622 |
mRotRowBitmap= rowBitmap; |
|
623 |
|
|
624 |
mRotationAngleStatic.set0(0.0f); |
|
625 |
mRotationAxis.set( ROTATION_AXIS[axis] ); |
|
626 |
mRotationAngle.setDuration(durationMillis); |
|
627 |
mRotationAngle.resetToBeginning(); |
|
628 |
mRotationAngle.add(new Static1D(0)); |
|
629 |
mRotationAngle.add(new Static1D(angle)); |
|
630 |
mRotateEffect.setMeshAssociation( mRotRowBitmap<<(axis* ObjectList.MAX_OBJECT_SIZE) , -1); |
|
631 |
mRotateEffect.notifyWhenFinished(listener); |
|
628 |
if( wasRotateApplied() ) |
|
629 |
{ |
|
630 |
mRotAxis = axis; |
|
631 |
mRotRowBitmap= rowBitmap; |
|
632 |
|
|
633 |
mRotationAngleStatic.set0(0.0f); |
|
634 |
mRotationAxis.set( ROTATION_AXIS[axis] ); |
|
635 |
mRotationAngle.setDuration(durationMillis); |
|
636 |
mRotationAngle.resetToBeginning(); |
|
637 |
mRotationAngle.add(new Static1D(0)); |
|
638 |
mRotationAngle.add(new Static1D(angle)); |
|
639 |
mRotateEffect.setMeshAssociation( mRotRowBitmap<<(axis* ObjectList.MAX_OBJECT_SIZE) , -1); |
|
640 |
mRotateEffect.notifyWhenFinished(listener); |
|
641 |
|
|
642 |
return mRotateEffect.getID(); |
|
643 |
} |
|
632 | 644 |
|
633 |
return mRotateEffect.getID();
|
|
645 |
return 0;
|
|
634 | 646 |
} |
635 | 647 |
|
636 | 648 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
637 | 649 |
|
638 | 650 |
public long finishRotationNow(EffectListener listener, int nearestAngleInDegrees) |
639 | 651 |
{ |
640 |
float angle = getAngle(); |
|
641 |
mRotationAngleStatic.set0(angle); |
|
642 |
mRotationAngleFinal.set0(nearestAngleInDegrees); |
|
643 |
mRotationAngleMiddle.set0( nearestAngleInDegrees + (nearestAngleInDegrees-angle)*0.2f ); |
|
644 |
|
|
645 |
mRotationAngle.setDuration(POST_ROTATION_MILLISEC); |
|
646 |
mRotationAngle.resetToBeginning(); |
|
647 |
mRotationAngle.removeAll(); |
|
648 |
mRotationAngle.add(mRotationAngleStatic); |
|
649 |
mRotationAngle.add(mRotationAngleMiddle); |
|
650 |
mRotationAngle.add(mRotationAngleFinal); |
|
651 |
mRotateEffect.notifyWhenFinished(listener); |
|
652 |
if( wasRotateApplied() ) |
|
653 |
{ |
|
654 |
float angle = getAngle(); |
|
655 |
mRotationAngleStatic.set0(angle); |
|
656 |
mRotationAngleFinal.set0(nearestAngleInDegrees); |
|
657 |
mRotationAngleMiddle.set0( nearestAngleInDegrees + (nearestAngleInDegrees-angle)*0.2f ); |
|
658 |
|
|
659 |
mRotationAngle.setDuration(POST_ROTATION_MILLISEC); |
|
660 |
mRotationAngle.resetToBeginning(); |
|
661 |
mRotationAngle.removeAll(); |
|
662 |
mRotationAngle.add(mRotationAngleStatic); |
|
663 |
mRotationAngle.add(mRotationAngleMiddle); |
|
664 |
mRotationAngle.add(mRotationAngleFinal); |
|
665 |
mRotateEffect.notifyWhenFinished(listener); |
|
666 |
|
|
667 |
return mRotateEffect.getID(); |
|
668 |
} |
|
652 | 669 |
|
653 |
return mRotateEffect.getID();
|
|
670 |
return 0;
|
|
654 | 671 |
} |
655 | 672 |
|
656 |
|
|
657 | 673 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
658 | 674 |
|
659 | 675 |
private float getAngle() |
src/main/java/org/distorted/states/RubikStateBase.java | ||
---|---|---|
42 | 42 |
|
43 | 43 |
private static class Move |
44 | 44 |
{ |
45 |
private int mAxis, mRow, mAngle; |
|
45 |
private final int mAxis, mRow, mAngle;
|
|
46 | 46 |
|
47 | 47 |
Move(int axis, int row, int angle) |
48 | 48 |
{ |
src/main/java/org/distorted/states/RubikStatePlay.java | ||
---|---|---|
49 | 49 |
public static final int DEF_OBJECT= ObjectList.CUBE.ordinal(); |
50 | 50 |
public static final int DEF_SIZE = 3; |
51 | 51 |
|
52 |
private static int[] BUTTON_LABELS = { R.string.scores, R.string.patterns, R.string.solver, R.string.tutorials, R.string.about }; |
|
52 |
private static final int[] BUTTON_LABELS = { R.string.scores, R.string.patterns, R.string.solver, R.string.tutorials, R.string.about };
|
|
53 | 53 |
private static final int NUM_BUTTONS = BUTTON_LABELS.length; |
54 | 54 |
|
55 | 55 |
private ImageButton mObjButton, mMenuButton, mSolveButton; |
src/main/java/org/distorted/tutorial/TutorialPreRender.java | ||
---|---|---|
168 | 168 |
mAddRotation = false; |
169 | 169 |
mAddRotationID = mNewObject.addNewRotation( mAddRotationAxis, mAddRotationRowBitmap, |
170 | 170 |
mAddRotationAngle, mAddRotationDuration, this); |
171 |
|
|
172 |
if( mAddRotationID==0 ) // failed to add effect - should never happen |
|
173 |
{ |
|
174 |
mCanPlay = true; |
|
175 |
} |
|
171 | 176 |
} |
172 | 177 |
|
173 | 178 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
180 | 185 |
|
181 | 186 |
if( mRotationFinishedID==0 ) // failed to add effect - should never happen |
182 | 187 |
{ |
183 |
mCanPlay = true;
|
|
188 |
mCanPlay = true; |
|
184 | 189 |
} |
185 | 190 |
} |
186 | 191 |
|
Also available in: Unified diff
Do not block the UI if, for some reason, some of the effects failed to get added to the Queue. Just fail to rotate.