Revision 3417ab4e
Added by Leszek Koltunski over 7 years ago
src/main/java/org/distorted/library/main/EffectQueue.java | ||
---|---|---|
26 | 26 |
import org.distorted.library.message.EffectMessage; |
27 | 27 |
|
28 | 28 |
import java.util.ArrayList; |
29 |
import java.util.HashMap; |
|
29 | 30 |
|
30 | 31 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
31 | 32 |
|
... | ... | |
47 | 48 |
protected int mNumListeners=0; // ==mListeners.length(), but we only create mListeners if the first one gets added |
48 | 49 |
protected long mDistortedEffectsID; |
49 | 50 |
|
51 |
private static long mNextID; |
|
52 |
private static HashMap<ArrayList<Long>,Long> mMapID = new HashMap<>(); // maps lists of Effect IDs (longs) to a |
|
53 |
// single long - the queue ID. |
|
54 |
|
|
50 | 55 |
private ArrayList<DistortedNode> mNodes = null; |
51 | 56 |
private long mID; |
52 | 57 |
private static boolean mCreated; |
... | ... | |
97 | 102 |
} |
98 | 103 |
|
99 | 104 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
100 |
// TODO: introduce a Map to return an ID dependant on all Effects in the Queue. |
|
101 |
// For now this is good enough. |
|
102 | 105 |
|
103 | 106 |
private void regenerateID() |
104 | 107 |
{ |
105 |
mID = mNumEffects>0 ? mEffects[0].getID() : 0; |
|
108 |
if( mNumEffects>0 ) |
|
109 |
{ |
|
110 |
ArrayList<Long> list = new ArrayList<>(); |
|
111 |
for (int i = 0; i < mNumEffects; i++) list.add(mEffects[i].getID()); |
|
112 |
Long id = mMapID.get(list); |
|
113 |
|
|
114 |
if( id!=null ) |
|
115 |
{ |
|
116 |
mID = id; |
|
117 |
} |
|
118 |
else |
|
119 |
{ |
|
120 |
mMapID.put(list,mNextID); |
|
121 |
mID = mNextID++; |
|
122 |
} |
|
123 |
} |
|
124 |
else |
|
125 |
{ |
|
126 |
mID = 0; |
|
127 |
} |
|
128 |
/* |
|
129 |
if( mIndex == EffectType.MATRIX.ordinal() ) |
|
130 |
android.util.Log.d("queue", "queueM id="+mID); |
|
131 |
if( mIndex == EffectType.VERTEX.ordinal() ) |
|
132 |
android.util.Log.d("queue", "queueV id="+mID); |
|
133 |
if( mIndex == EffectType.FRAGMENT.ordinal() ) |
|
134 |
android.util.Log.d("queue", "queueF id="+mID); |
|
135 |
if( mIndex == EffectType.POSTPROCESS.ordinal() ) |
|
136 |
android.util.Log.d("queue", "queueP id="+mID); |
|
137 |
*/ |
|
106 | 138 |
} |
107 | 139 |
|
108 | 140 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
176 | 208 |
|
177 | 209 |
static void onDestroy() |
178 | 210 |
{ |
211 |
mNextID = 1; |
|
212 |
mMapID.clear(); |
|
179 | 213 |
EffectType.reset(mMax); |
180 | 214 |
mCreated = false; |
181 | 215 |
} |
... | ... | |
352 | 386 |
} |
353 | 387 |
} |
354 | 388 |
|
355 |
if( num>0 ) |
|
389 |
if( num>0 && mIndex==EffectType.POSTPROCESS.ordinal() )
|
|
356 | 390 |
{ |
357 | 391 |
regenerateID(); |
358 |
|
|
359 |
if( mIndex==EffectType.POSTPROCESS.ordinal() ) |
|
360 |
{ |
|
361 |
int numNodes = (mNodes==null ? 0: mNodes.size()); |
|
362 |
|
|
363 |
for(int i=0; i<numNodes; i++) |
|
364 |
{ |
|
365 |
mNodes.get(i).sort(); |
|
366 |
} |
|
367 |
} |
|
392 |
int numNodes = (mNodes==null ? 0: mNodes.size()); |
|
393 |
for(int i=0; i<numNodes; i++) mNodes.get(i).sort(); |
|
368 | 394 |
} |
369 | 395 |
} |
370 | 396 |
} |
Also available in: Unified diff
Now all Postprocessing EffectQueues have the right IDs regardless of number of effects.