41 |
41 |
|
42 |
42 |
private static final int NUM_EFFECTS = PresentEffect.Type.values().length;
|
43 |
43 |
private static final int FAKE_EFFECT_ID = -6;
|
44 |
|
private static final int EXTRA_DURATION = 5000;
|
|
44 |
private static final int EXTRA_DURATION = 3000;
|
45 |
45 |
private static final PresentEffect.Type[] types;
|
46 |
46 |
|
47 |
47 |
static
|
... | ... | |
55 |
55 |
}
|
56 |
56 |
}
|
57 |
57 |
|
58 |
|
private int mEffectReturned;
|
59 |
|
private int mNumScramblesLeft;
|
60 |
58 |
private int mDurationPerDegree;
|
61 |
59 |
private final Random mRnd;
|
62 |
60 |
private int[][] mBasicAngle;
|
63 |
|
private boolean mRotReady, mPluginReady;
|
|
61 |
private boolean mScrambleForward;
|
|
62 |
private int mTotalDuration;
|
64 |
63 |
|
65 |
64 |
ObjectPreRender mPre;
|
66 |
65 |
TwistyObject mObject;
|
... | ... | |
70 |
69 |
Effect[] mCubeEffects;
|
71 |
70 |
int[] mCubeEffectPosition;
|
72 |
71 |
int mCubeEffectNumber, mNodeEffectNumber;
|
73 |
|
int mNumScrambles;
|
|
72 |
int mNumScrambles, mCurrScramble;
|
74 |
73 |
int[][] mScrambles;
|
75 |
74 |
|
76 |
75 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
... | ... | |
83 |
82 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
84 |
83 |
|
85 |
84 |
abstract void createEffects(int duration, int numScrambles);
|
86 |
|
abstract void effectFinishedPlugin(final long effectID);
|
87 |
85 |
|
88 |
86 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
89 |
87 |
|
90 |
|
private void createBaseEffects(int duration, int numScrambles)
|
|
88 |
private void createBaseEffects(int numScrambles)
|
|
89 |
{
|
|
90 |
mNumScrambles = numScrambles;
|
|
91 |
mCurrScramble = 0;
|
|
92 |
mScrambleForward = true;
|
|
93 |
randomizeScrambles();
|
|
94 |
addNewScramble();
|
|
95 |
}
|
|
96 |
|
|
97 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
98 |
|
|
99 |
private void randomizeScrambles()
|
91 |
100 |
{
|
92 |
|
mNumScramblesLeft = numScrambles;
|
93 |
101 |
int absAngle, angle, axis, row, basicDegrees, totalDegrees = 0;
|
94 |
102 |
|
95 |
|
for(int scramble=0; scramble<mNumScramblesLeft; scramble++)
|
|
103 |
for(int scramble=0; scramble<mNumScrambles; scramble++)
|
96 |
104 |
{
|
97 |
|
mObject.randomizeNewScramble(mScrambles, mRnd, scramble, numScrambles);
|
|
105 |
mObject.randomizeNewScramble(mScrambles, mRnd, scramble, mNumScrambles);
|
98 |
106 |
axis = mScrambles[scramble][0];
|
99 |
107 |
row = mScrambles[scramble][1];
|
100 |
108 |
angle = mScrambles[scramble][2];
|
... | ... | |
103 |
111 |
totalDegrees += absAngle*basicDegrees;
|
104 |
112 |
}
|
105 |
113 |
|
106 |
|
mDurationPerDegree = duration/(2*totalDegrees);
|
107 |
|
mNumScrambles = 0;
|
108 |
|
|
109 |
|
mRotReady = false;
|
110 |
|
mPluginReady = false;
|
111 |
|
|
112 |
|
addNewScramble();
|
|
114 |
mDurationPerDegree = mTotalDuration/(2*totalDegrees);
|
113 |
115 |
}
|
114 |
116 |
|
115 |
117 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
116 |
118 |
|
117 |
119 |
private void addNewScramble()
|
118 |
120 |
{
|
119 |
|
if( mNumScramblesLeft>0 )
|
|
121 |
if( mScrambleForward )
|
120 |
122 |
{
|
121 |
|
addRotation(true);
|
|
123 |
if( mCurrScramble==0 )
|
|
124 |
{
|
|
125 |
Thread thread = new Thread()
|
|
126 |
{
|
|
127 |
public void run()
|
|
128 |
{
|
|
129 |
randomizeScrambles();
|
|
130 |
try { sleep(EXTRA_DURATION); }
|
|
131 |
catch(InterruptedException ex) { }
|
|
132 |
addRotation(true);
|
|
133 |
}
|
|
134 |
};
|
|
135 |
|
|
136 |
thread.start();
|
|
137 |
}
|
|
138 |
else
|
|
139 |
{
|
|
140 |
addRotation(true);
|
|
141 |
}
|
122 |
142 |
}
|
123 |
143 |
else
|
124 |
144 |
{
|
125 |
|
if( mNumScrambles>0 )
|
|
145 |
if( mCurrScramble>=mNumScrambles )
|
126 |
146 |
{
|
127 |
|
if( mNumScramblesLeft==0 )
|
|
147 |
Thread thread = new Thread()
|
128 |
148 |
{
|
129 |
|
Thread thread = new Thread()
|
|
149 |
public void run()
|
130 |
150 |
{
|
131 |
|
public void run()
|
132 |
|
{
|
133 |
|
try { sleep(EXTRA_DURATION); }
|
134 |
|
catch(InterruptedException ex) { }
|
135 |
|
addRotation(false);
|
136 |
|
}
|
137 |
|
};
|
138 |
|
|
139 |
|
thread.start();
|
140 |
|
}
|
141 |
|
else
|
142 |
|
{
|
143 |
|
addRotation(false);
|
144 |
|
}
|
|
151 |
try { sleep(EXTRA_DURATION); }
|
|
152 |
catch(InterruptedException ex) { }
|
|
153 |
addRotation(false);
|
|
154 |
}
|
|
155 |
};
|
|
156 |
|
|
157 |
thread.start();
|
145 |
158 |
}
|
146 |
159 |
else
|
147 |
160 |
{
|
148 |
|
mRotReady = true;
|
149 |
|
if( mPluginReady ) mPre.effectFinished(FAKE_EFFECT_ID);
|
|
161 |
addRotation(false);
|
150 |
162 |
}
|
151 |
163 |
}
|
152 |
164 |
}
|
... | ... | |
155 |
167 |
|
156 |
168 |
private void addRotation(boolean forward)
|
157 |
169 |
{
|
158 |
|
if( !forward )
|
159 |
|
{
|
160 |
|
mNumScrambles--;
|
161 |
|
mNumScramblesLeft--;
|
162 |
|
}
|
|
170 |
if( !forward ) mCurrScramble--;
|
163 |
171 |
|
164 |
|
int axis = mScrambles[mNumScrambles][0];
|
165 |
|
int row = mScrambles[mNumScrambles][1];
|
166 |
|
int angle= mScrambles[mNumScrambles][2];
|
|
172 |
int axis = mScrambles[mCurrScramble][0];
|
|
173 |
int row = mScrambles[mCurrScramble][1];
|
|
174 |
int angle= mScrambles[mCurrScramble][2];
|
167 |
175 |
|
168 |
176 |
if( !forward ) angle = -angle;
|
169 |
177 |
|
170 |
178 |
mPre.addRotation(this, axis, (1<<row), angle, mDurationPerDegree);
|
171 |
179 |
|
172 |
|
if( forward )
|
173 |
|
{
|
174 |
|
mNumScrambles++;
|
175 |
|
mNumScramblesLeft--;
|
176 |
|
}
|
|
180 |
if( forward ) mCurrScramble++;
|
|
181 |
|
|
182 |
if( mCurrScramble>=mNumScrambles ) mScrambleForward=false;
|
|
183 |
if( mCurrScramble<=0 ) mScrambleForward=true;
|
177 |
184 |
}
|
178 |
185 |
|
179 |
186 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
... | ... | |
195 |
202 |
}
|
196 |
203 |
}
|
197 |
204 |
|
198 |
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
199 |
|
|
200 |
|
private void disassignEffects()
|
201 |
|
{
|
202 |
|
for(int i=0; i<mCubeEffectNumber; i++)
|
203 |
|
{
|
204 |
|
mObject.removeEffect(mCubeEffects[i].getID());
|
205 |
|
}
|
206 |
|
|
207 |
|
DistortedEffects nodeEffects = mObjectNode.getEffects();
|
208 |
|
|
209 |
|
for(int i=0; i<mNodeEffectNumber; i++)
|
210 |
|
{
|
211 |
|
nodeEffects.abortById(mNodeEffects[i].getID());
|
212 |
|
}
|
213 |
|
}
|
214 |
|
|
215 |
205 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
216 |
206 |
// PUBLIC API
|
217 |
207 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
... | ... | |
244 |
234 |
addNewScramble();
|
245 |
235 |
}
|
246 |
236 |
|
247 |
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
248 |
|
|
249 |
|
private void effectFinishedAction(final long effectID)
|
250 |
|
{
|
251 |
|
mEffectReturned++;
|
252 |
|
effectFinishedPlugin(effectID);
|
253 |
|
|
254 |
|
if( mEffectReturned == mCubeEffectNumber+mNodeEffectNumber )
|
255 |
|
{
|
256 |
|
disassignEffects();
|
257 |
|
|
258 |
|
mPluginReady = true;
|
259 |
|
if( mRotReady ) mPre.effectFinished(FAKE_EFFECT_ID);
|
260 |
|
}
|
261 |
|
}
|
262 |
|
|
263 |
237 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
264 |
238 |
|
265 |
239 |
public void effectFinished(final long effectID)
|
266 |
240 |
{
|
267 |
|
for(int i=0; i<mCubeEffectNumber; i++)
|
268 |
|
{
|
269 |
|
long id = mCubeEffects[i].getID();
|
270 |
|
|
271 |
|
if( effectID == id )
|
272 |
|
{
|
273 |
|
effectFinishedAction(effectID);
|
274 |
|
return;
|
275 |
|
}
|
276 |
|
}
|
277 |
|
|
278 |
|
for(int i=0; i<mNodeEffectNumber; i++)
|
279 |
|
{
|
280 |
|
long id = mNodeEffects[i].getID();
|
281 |
241 |
|
282 |
|
if( effectID == id )
|
283 |
|
{
|
284 |
|
effectFinishedAction(effectID);
|
285 |
|
return;
|
286 |
|
}
|
287 |
|
}
|
288 |
242 |
}
|
289 |
243 |
|
290 |
244 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
... | ... | |
306 |
260 |
|
307 |
261 |
int numScrambles = pre.getNumScrambles();
|
308 |
262 |
mScrambles = new int[numScrambles][3];
|
309 |
|
int dura = (int)(duration*Math.pow(numScrambles,0.66f));
|
310 |
|
createBaseEffects(dura,numScrambles);
|
311 |
|
createEffects (dura+EXTRA_DURATION,numScrambles);
|
|
263 |
mTotalDuration = (int)(duration*Math.pow(numScrambles,0.66f));
|
|
264 |
createBaseEffects(numScrambles);
|
|
265 |
createEffects(mTotalDuration,numScrambles);
|
312 |
266 |
|
313 |
267 |
if( mCubeEffectNumber==0 && mNodeEffectNumber==0 )
|
314 |
268 |
{
|
IAP: finish the 'Purschase' activity.