Revision 4c2c0f44
Added by Leszek Koltunski over 2 years ago
| src/main/java/org/distorted/objectlib/effects/BaseEffect.java | ||
|---|---|---|
| 15 | 15 |
|
| 16 | 16 |
import org.distorted.objectlib.effects.fastscramble.FastScrambleEffect; |
| 17 | 17 |
import org.distorted.objectlib.effects.present.PresentEffect; |
| 18 |
import org.distorted.objectlib.effects.resticker.RestickerEffect; |
|
| 18 | 19 |
import org.distorted.objectlib.effects.scramble.ScrambleEffect; |
| 19 | 20 |
import org.distorted.objectlib.effects.objectchange.ObjectChangeEffect; |
| 20 | 21 |
import org.distorted.objectlib.effects.solve.SolveEffect; |
| ... | ... | |
| 34 | 35 |
FAST_SCRAMBLE ( 20, 0, R.string.fast_scramble_effect, FastScrambleEffect.class), |
| 35 | 36 |
PRESENT (100, 0, R.string.present_effect, PresentEffect.class), |
| 36 | 37 |
WIN ( 20, 1, R.string.win_effect , WinEffect.class ), |
| 38 |
RESTICKER ( 20, 0, R.string.resticker_effect , RestickerEffect.class ), |
|
| 37 | 39 |
; |
| 38 | 40 |
|
| 39 | 41 |
private final int mDefaultPos, mDefaultType; |
| src/main/java/org/distorted/objectlib/effects/resticker/RestickerEffect.java | ||
|---|---|---|
| 1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 2 |
// Copyright 2023 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.effects.resticker; |
|
| 11 |
|
|
| 12 |
import org.distorted.library.effect.Effect; |
|
| 13 |
import org.distorted.library.main.DistortedEffects; |
|
| 14 |
import org.distorted.library.message.EffectListener; |
|
| 15 |
import org.distorted.objectlib.effects.BaseEffect; |
|
| 16 |
import org.distorted.objectlib.main.ObjectPreRender; |
|
| 17 |
import org.distorted.objectlib.main.TwistyObject; |
|
| 18 |
import org.distorted.objectlib.main.TwistyObjectNode; |
|
| 19 |
|
|
| 20 |
import java.lang.reflect.Method; |
|
| 21 |
|
|
| 22 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 23 |
|
|
| 24 |
public abstract class RestickerEffect extends BaseEffect implements EffectListener |
|
| 25 |
{
|
|
| 26 |
public enum Type |
|
| 27 |
{
|
|
| 28 |
SPIN (RestickerEffectSpin.class), |
|
| 29 |
; |
|
| 30 |
|
|
| 31 |
final Class<? extends RestickerEffect> effect; |
|
| 32 |
|
|
| 33 |
Type(Class<? extends RestickerEffect> effect) |
|
| 34 |
{
|
|
| 35 |
this.effect = effect; |
|
| 36 |
} |
|
| 37 |
} |
|
| 38 |
|
|
| 39 |
private static final int NUM_EFFECTS = Type.values().length; |
|
| 40 |
private static final int NUM_PHASES = 2; |
|
| 41 |
private static final int FAKE_EFFECT_ID = -2; |
|
| 42 |
private static final Type[] types; |
|
| 43 |
|
|
| 44 |
static |
|
| 45 |
{
|
|
| 46 |
int i=0; |
|
| 47 |
types = new Type[NUM_EFFECTS]; |
|
| 48 |
|
|
| 49 |
for(Type type: Type.values()) |
|
| 50 |
{
|
|
| 51 |
types[i++] = type; |
|
| 52 |
} |
|
| 53 |
} |
|
| 54 |
|
|
| 55 |
private int mDuration; |
|
| 56 |
private int mEffectReturned; |
|
| 57 |
private final int[] mCubeEffectNumber, mNodeEffectNumber; |
|
| 58 |
private int mPhase; |
|
| 59 |
|
|
| 60 |
ObjectPreRender mPre; |
|
| 61 |
TwistyObject mObject; |
|
| 62 |
TwistyObjectNode mObjectNode; |
|
| 63 |
Effect[][] mCubeEffects; |
|
| 64 |
int[][] mCubeEffectPosition; |
|
| 65 |
Effect[][] mNodeEffects; |
|
| 66 |
int[][] mNodeEffectPosition; |
|
| 67 |
|
|
| 68 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 69 |
|
|
| 70 |
RestickerEffect() |
|
| 71 |
{
|
|
| 72 |
mPhase= 0; |
|
| 73 |
|
|
| 74 |
mCubeEffectNumber = new int[NUM_PHASES]; |
|
| 75 |
mNodeEffectNumber = new int[NUM_PHASES]; |
|
| 76 |
mCubeEffectPosition = new int[NUM_PHASES][]; |
|
| 77 |
mNodeEffectPosition = new int[NUM_PHASES][]; |
|
| 78 |
mCubeEffects = new Effect[NUM_PHASES][]; |
|
| 79 |
mNodeEffects = new Effect[NUM_PHASES][]; |
|
| 80 |
} |
|
| 81 |
|
|
| 82 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 83 |
|
|
| 84 |
abstract void createEffectsPhase0(int duration); |
|
| 85 |
abstract void createEffectsPhase1(int duration); |
|
| 86 |
|
|
| 87 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 88 |
|
|
| 89 |
private void assignEffects(int phase) |
|
| 90 |
{
|
|
| 91 |
mCubeEffectNumber[phase] = ( mCubeEffects[phase]!=null ) ? mCubeEffects[phase].length : 0; |
|
| 92 |
mNodeEffectNumber[phase] = ( mNodeEffects[phase]!=null ) ? mNodeEffects[phase].length : 0; |
|
| 93 |
|
|
| 94 |
if( mCubeEffectNumber[phase]==0 && mNodeEffectNumber[phase]==0 ) |
|
| 95 |
{
|
|
| 96 |
throw new RuntimeException("Cube and Node Effects ("+phase+" phase) both not created!");
|
|
| 97 |
} |
|
| 98 |
|
|
| 99 |
for(int i=0; i<mCubeEffectNumber[phase]; i++) |
|
| 100 |
{
|
|
| 101 |
mObject.applyEffect(mCubeEffects[phase][i],mCubeEffectPosition[phase][i]); |
|
| 102 |
mCubeEffects[phase][i].notifyWhenFinished(this); |
|
| 103 |
} |
|
| 104 |
|
|
| 105 |
DistortedEffects nodeEffects = mObjectNode.getEffects(); |
|
| 106 |
|
|
| 107 |
for(int i=0; i<mNodeEffectNumber[phase]; i++) |
|
| 108 |
{
|
|
| 109 |
nodeEffects.apply(mNodeEffects[phase][i],mNodeEffectPosition[phase][i]); |
|
| 110 |
mNodeEffects[phase][i].notifyWhenFinished(this); |
|
| 111 |
} |
|
| 112 |
} |
|
| 113 |
|
|
| 114 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 115 |
|
|
| 116 |
private void effectAction(int phase) |
|
| 117 |
{
|
|
| 118 |
switch(phase) |
|
| 119 |
{
|
|
| 120 |
case 0: mEffectReturned = 0; |
|
| 121 |
mPhase = 1; |
|
| 122 |
mPre.resetAllTextureMaps(); |
|
| 123 |
createEffectsPhase1(mDuration); |
|
| 124 |
assignEffects(mPhase); |
|
| 125 |
break; |
|
| 126 |
case 1: mPre.effectFinished(FAKE_EFFECT_ID); |
|
| 127 |
break; |
|
| 128 |
} |
|
| 129 |
} |
|
| 130 |
|
|
| 131 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 132 |
// PUBLIC API |
|
| 133 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 134 |
|
|
| 135 |
@SuppressWarnings("unused")
|
|
| 136 |
public static String[] getNames() |
|
| 137 |
{
|
|
| 138 |
String[] names = new String[NUM_EFFECTS]; |
|
| 139 |
|
|
| 140 |
for( int i=0; i<NUM_EFFECTS; i++) |
|
| 141 |
{
|
|
| 142 |
names[i] = types[i].name(); |
|
| 143 |
} |
|
| 144 |
|
|
| 145 |
return names; |
|
| 146 |
} |
|
| 147 |
|
|
| 148 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 149 |
|
|
| 150 |
@SuppressWarnings("unused")
|
|
| 151 |
public static RestickerEffect create(int ordinal) throws InstantiationException, IllegalAccessException |
|
| 152 |
{
|
|
| 153 |
return types[ordinal].effect.newInstance(); |
|
| 154 |
} |
|
| 155 |
|
|
| 156 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 157 |
|
|
| 158 |
public void effectFinished(final long effectID) |
|
| 159 |
{
|
|
| 160 |
int total = mCubeEffectNumber[mPhase]+mNodeEffectNumber[mPhase]; |
|
| 161 |
|
|
| 162 |
for(int i=0; i<mCubeEffectNumber[mPhase]; i++) |
|
| 163 |
{
|
|
| 164 |
long id = mCubeEffects[mPhase][i].getID(); |
|
| 165 |
|
|
| 166 |
if( effectID == id ) |
|
| 167 |
{
|
|
| 168 |
if( ++mEffectReturned == total ) effectAction(mPhase); |
|
| 169 |
mObject.removeEffect(id); |
|
| 170 |
return; |
|
| 171 |
} |
|
| 172 |
} |
|
| 173 |
for(int i=0; i<mNodeEffectNumber[mPhase]; i++) |
|
| 174 |
{
|
|
| 175 |
long id = mNodeEffects[mPhase][i].getID(); |
|
| 176 |
|
|
| 177 |
if( effectID == id ) |
|
| 178 |
{
|
|
| 179 |
if( ++mEffectReturned == total ) effectAction(mPhase); |
|
| 180 |
mObjectNode.getEffects().abortById(id); |
|
| 181 |
return; |
|
| 182 |
} |
|
| 183 |
} |
|
| 184 |
} |
|
| 185 |
|
|
| 186 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 187 |
|
|
| 188 |
@SuppressWarnings("unused")
|
|
| 189 |
public long start(int duration, ObjectPreRender pre) |
|
| 190 |
{
|
|
| 191 |
mObject = pre.getObject(); |
|
| 192 |
mObjectNode = pre.getObjectNode(); |
|
| 193 |
mPre = pre; |
|
| 194 |
mDuration = duration; |
|
| 195 |
|
|
| 196 |
createEffectsPhase0(mDuration); |
|
| 197 |
assignEffects(mPhase); |
|
| 198 |
|
|
| 199 |
return FAKE_EFFECT_ID; |
|
| 200 |
} |
|
| 201 |
|
|
| 202 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 203 |
|
|
| 204 |
@SuppressWarnings("unused")
|
|
| 205 |
public static void enableEffects() |
|
| 206 |
{
|
|
| 207 |
Method method; |
|
| 208 |
|
|
| 209 |
for(Type type: Type.values()) |
|
| 210 |
{
|
|
| 211 |
try |
|
| 212 |
{
|
|
| 213 |
method = type.effect.getDeclaredMethod("enable"); // enable not public, thus getDeclaredMethod
|
|
| 214 |
} |
|
| 215 |
catch(NoSuchMethodException ex) |
|
| 216 |
{
|
|
| 217 |
android.util.Log.e("RestickerEffect", type.effect.getSimpleName()+": exception getting method: "+ex.getMessage());
|
|
| 218 |
method = null; |
|
| 219 |
} |
|
| 220 |
|
|
| 221 |
try |
|
| 222 |
{
|
|
| 223 |
if( method!=null ) method.invoke(null); |
|
| 224 |
} |
|
| 225 |
catch(Exception ex) |
|
| 226 |
{
|
|
| 227 |
android.util.Log.e("RestickerEffect", type.effect.getSimpleName()+": exception invoking method: "+ex.getMessage());
|
|
| 228 |
} |
|
| 229 |
} |
|
| 230 |
} |
|
| 231 |
} |
|
| src/main/java/org/distorted/objectlib/effects/resticker/RestickerEffectSpin.java | ||
|---|---|---|
| 1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 2 |
// Copyright 2019 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.effects.resticker; |
|
| 11 |
|
|
| 12 |
import static org.distorted.library.main.QuatHelper.rotateVectorByInvertedQuat; |
|
| 13 |
|
|
| 14 |
import org.distorted.library.effect.Effect; |
|
| 15 |
import org.distorted.library.effect.MatrixEffectRotate; |
|
| 16 |
import org.distorted.library.type.Dynamic; |
|
| 17 |
import org.distorted.library.type.Dynamic1D; |
|
| 18 |
import org.distorted.library.type.Static1D; |
|
| 19 |
import org.distorted.library.type.Static3D; |
|
| 20 |
import org.distorted.library.type.Static4D; |
|
| 21 |
|
|
| 22 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 23 |
|
|
| 24 |
public class RestickerEffectSpin extends RestickerEffect |
|
| 25 |
{
|
|
| 26 |
private void createEffects(int phase, int duration, int[] points) |
|
| 27 |
{
|
|
| 28 |
mCubeEffectPosition[phase] = new int[] {0};
|
|
| 29 |
mCubeEffects[phase] = new Effect[mCubeEffectPosition[0].length]; |
|
| 30 |
|
|
| 31 |
Static4D quaternion = mObject.getRotationQuat(); // always rotate around |
|
| 32 |
Static4D tmpAxis = new Static4D(0,-1,0,0); // vert axis no matter |
|
| 33 |
Static4D rotated = rotateVectorByInvertedQuat(tmpAxis,quaternion); // how cube is rotated |
|
| 34 |
|
|
| 35 |
Static3D axis = new Static3D(rotated.get0(), rotated.get1(), rotated.get2()); |
|
| 36 |
Static3D center= new Static3D(0,0,0); |
|
| 37 |
|
|
| 38 |
Dynamic1D d = new Dynamic1D(duration/2, 1.0f); |
|
| 39 |
d.setMode(Dynamic.MODE_JUMP); |
|
| 40 |
d.setConvexity(0.0f); // otherwise speed of the rotation would be strangely uneven |
|
| 41 |
|
|
| 42 |
d.add( new Static1D(36*points[0]) ); |
|
| 43 |
d.add( new Static1D(36*points[1]) ); |
|
| 44 |
d.add( new Static1D(36*points[2]) ); |
|
| 45 |
d.add( new Static1D(36*points[3]) ); |
|
| 46 |
d.add( new Static1D(36*points[4]) ); |
|
| 47 |
|
|
| 48 |
mCubeEffects[phase][0] = new MatrixEffectRotate(d,axis,center); |
|
| 49 |
} |
|
| 50 |
|
|
| 51 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 52 |
// PUBLIC API |
|
| 53 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 54 |
|
|
| 55 |
public void createEffectsPhase0(int duration) |
|
| 56 |
{
|
|
| 57 |
createEffects(0,duration,new int[] {0,1,3,6,10});
|
|
| 58 |
} |
|
| 59 |
|
|
| 60 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 61 |
|
|
| 62 |
public void createEffectsPhase1(int duration) |
|
| 63 |
{
|
|
| 64 |
createEffects(1,duration,new int[] {0,4,7,9,10});
|
|
| 65 |
} |
|
| 66 |
|
|
| 67 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 68 |
// Enable all effects used in this Effect. Called by reflection from the parent class. |
|
| 69 |
|
|
| 70 |
@SuppressWarnings("unused")
|
|
| 71 |
static void enable() |
|
| 72 |
{
|
|
| 73 |
|
|
| 74 |
} |
|
| 75 |
} |
|
| src/main/java/org/distorted/objectlib/main/ObjectControl.java | ||
|---|---|---|
| 764 | 764 |
mPreRender.solveOnly(); |
| 765 | 765 |
} |
| 766 | 766 |
|
| 767 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 768 |
|
|
| 769 |
public void resetTextureMapsEffect(int duration) |
|
| 770 |
{
|
|
| 771 |
mPreRender.resetTextureMapsEffect(duration); |
|
| 772 |
} |
|
| 773 |
|
|
| 767 | 774 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 768 | 775 |
|
| 769 | 776 |
public void addRotation(MovesFinished listener, int axis, int rowBitmap, int angle, int duration) |
| src/main/java/org/distorted/objectlib/main/ObjectPreRender.java | ||
|---|---|---|
| 47 | 47 |
private float mScale; |
| 48 | 48 |
|
| 49 | 49 |
private boolean mFinishRotation, mRemoveRotation, mRemovePatternRotation, mAddRotation, |
| 50 |
mSetQuat, mChangeObject, mSolveObject, mScrambleObject, mFastScrambleObject, mPresentObject, |
|
| 51 |
mInitializeObject, mSetTextureMap, mResetAllTextureMaps, mSolve, mApplyScrambles; |
|
| 50 |
mSetQuat, mChangeObject, mSolveObject, mScrambleObject, mFastScrambleObject, |
|
| 51 |
mPresentObject,mInitializeObject, mSetTextureMap, mResetAllTextureMaps, mSolve, |
|
| 52 |
mApplyScrambles, mResetTextureEffect; |
|
| 52 | 53 |
private boolean mScramblingAndSolvingBlocked, mRotationBlocked, mIsSolved; |
| 53 | 54 |
private long mRotationFinishedID; |
| 54 | 55 |
private final long[] mEffectID; |
| ... | ... | |
| 56 | 57 |
private int mScrambleObjectNum, mScrambleObjectDuration; |
| 57 | 58 |
private int mAddRotationAxis, mAddRotationRowBitmap, mAddRotationAngle; |
| 58 | 59 |
private long mAddRotationDuration; |
| 59 |
private int mPresentDuration; |
|
| 60 |
private int mPresentDuration, mRestickerDuration;
|
|
| 60 | 61 |
private long mAddRotationID, mRemoveRotationID; |
| 61 | 62 |
private int mCubit, mFace, mNewColor; |
| 62 | 63 |
private int mNearestAngle; |
| ... | ... | |
| 84 | 85 |
mScrambleObject = false; |
| 85 | 86 |
mFastScrambleObject = false; |
| 86 | 87 |
mPresentObject = false; |
| 88 |
mResetTextureEffect = false; |
|
| 87 | 89 |
|
| 88 | 90 |
mOldObject = null; |
| 89 | 91 |
mNewObject = null; |
| ... | ... | |
| 308 | 310 |
doEffectNow( BaseEffect.Type.FAST_SCRAMBLE, mScrambleObjectDuration ); |
| 309 | 311 |
} |
| 310 | 312 |
|
| 313 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 314 |
|
|
| 315 |
private void resetTextureNow() |
|
| 316 |
{
|
|
| 317 |
mResetTextureEffect = false; |
|
| 318 |
doEffectNow( BaseEffect.Type.RESTICKER, mRestickerDuration ); |
|
| 319 |
} |
|
| 320 |
|
|
| 311 | 321 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 312 | 322 |
|
| 313 | 323 |
private void presentObjectNow() |
| ... | ... | |
| 604 | 614 |
if( mApplyScrambles ) applyScramblesNow(); |
| 605 | 615 |
if( mResetAllTextureMaps ) resetAllTextureMapsNow(); |
| 606 | 616 |
if( mSetTextureMap ) setTextureMapNow(); |
| 617 |
if( mResetTextureEffect ) resetTextureNow(); |
|
| 607 | 618 |
} |
| 608 | 619 |
|
| 609 | 620 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 715 | 726 |
mSolve = true; |
| 716 | 727 |
} |
| 717 | 728 |
|
| 729 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 730 |
|
|
| 731 |
public void resetTextureMapsEffect(int duration) |
|
| 732 |
{
|
|
| 733 |
mRestickerDuration = duration; |
|
| 734 |
mResetTextureEffect = true; |
|
| 735 |
} |
|
| 736 |
|
|
| 718 | 737 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 719 | 738 |
|
| 720 | 739 |
public void resetAllTextureMaps() |
| src/main/res/values/strings.xml | ||
|---|---|---|
| 5 | 5 |
<string name="fast_scramble_effect">Fast Scramble Effect</string> |
| 6 | 6 |
<string name="present_effect">Present Effect</string> |
| 7 | 7 |
<string name="win_effect">Win Effect</string> |
| 8 |
<string name="resticker_effect">Resticker Effect</string> |
|
| 8 | 9 |
</resources> |
Also available in: Unified diff
New button in the solver screen: reset all textures.