Revision 20dbec0e
Added by Leszek Koltunski about 5 years ago
src/main/java/org/distorted/library/effect/Effect.java | ||
---|---|---|
19 | 19 |
|
20 | 20 |
package org.distorted.library.effect; |
21 | 21 |
|
22 |
import org.distorted.library.message.EffectListener; |
|
23 |
|
|
22 | 24 |
import java.lang.reflect.Method; |
25 |
import java.util.ArrayList; |
|
23 | 26 |
|
24 | 27 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
25 | 28 |
/** |
... | ... | |
37 | 40 |
private final int mRegionDim; |
38 | 41 |
private final int mCenterDim; |
39 | 42 |
|
43 |
ArrayList<EffectListener> mListeners =null; |
|
44 |
int mNumListeners=0; // ==mListeners.length(), but we only create mListeners if the first one gets added |
|
45 |
|
|
40 | 46 |
private static long mNextID = 0; |
41 | 47 |
|
42 | 48 |
private final static float[] mUnity= new float[MAX_UNITY_DIM*NUM_EFFECTS]; |
... | ... | |
99 | 105 |
*/ |
100 | 106 |
public abstract boolean compute(float[] uniforms, int index, long currentDuration, long step ); |
101 | 107 |
|
108 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
109 |
/** |
|
110 |
* Only for use by the library itself. |
|
111 |
* |
|
112 |
* @y.exclude |
|
113 |
*/ |
|
114 |
public int getNumListeners() |
|
115 |
{ |
|
116 |
return mNumListeners; |
|
117 |
} |
|
118 |
|
|
119 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
120 |
/** |
|
121 |
* Only for use by the library itself. |
|
122 |
* |
|
123 |
* @y.exclude |
|
124 |
*/ |
|
125 |
public EffectListener removeFirstListener() |
|
126 |
{ |
|
127 |
if( mNumListeners>0 ) |
|
128 |
{ |
|
129 |
mNumListeners--; |
|
130 |
return mListeners.remove(0); |
|
131 |
} |
|
132 |
|
|
133 |
return null; |
|
134 |
} |
|
135 |
|
|
102 | 136 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
103 | 137 |
// PUBLIC API |
104 | 138 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
233 | 267 |
{ |
234 | 268 |
return mDimension; |
235 | 269 |
} |
270 |
|
|
271 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
272 |
/** |
|
273 |
* Adds the calling class to the list of Listeners that get notified when this Effect gets 'finished' |
|
274 |
* i.e. when the Dynamic inside this Effect reaches its final point and stops moving. This will be sent |
|
275 |
* only once, on the first time the Dynamic reaches its final point. |
|
276 |
* |
|
277 |
* If there's no Dynamic, ths message will never be sent. |
|
278 |
* |
|
279 |
* @param el A class implementing the EffectListener interface that wants to get notifications. |
|
280 |
*/ |
|
281 |
public void notifyWhenFinished(EffectListener el) |
|
282 |
{ |
|
283 |
if( mListeners==null ) mListeners = new ArrayList<>(); |
|
284 |
|
|
285 |
if( !mListeners.contains(el) ) |
|
286 |
{ |
|
287 |
mListeners.add(el); |
|
288 |
mNumListeners++; |
|
289 |
} |
|
290 |
} |
|
236 | 291 |
} |
Also available in: Unified diff
Simplify the way applications can get notifications when an effect finishes.
Now, instead of the 'DistortedEffects.(de)registerForNotifications()' 2 APIs, we call a single 'Effect.notifyWhenFinished()'.