1 |
d333eb6b
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2 |
|
|
// Copyright 2016 Leszek Koltunski //
|
3 |
|
|
// //
|
4 |
|
|
// This file is part of Distorted. //
|
5 |
|
|
// //
|
6 |
|
|
// Distorted is free software: you can redistribute it and/or modify //
|
7 |
|
|
// it under the terms of the GNU General Public License as published by //
|
8 |
|
|
// the Free Software Foundation, either version 2 of the License, or //
|
9 |
|
|
// (at your option) any later version. //
|
10 |
|
|
// //
|
11 |
|
|
// Distorted is distributed in the hope that it will be useful, //
|
12 |
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
13 |
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
14 |
|
|
// GNU General Public License for more details. //
|
15 |
|
|
// //
|
16 |
|
|
// You should have received a copy of the GNU General Public License //
|
17 |
|
|
// along with Distorted. If not, see <http://www.gnu.org/licenses/>. //
|
18 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
19 |
|
|
|
20 |
fe82a979
|
Leszek Koltunski
|
package org.distorted.library.main;
|
21 |
6a06a912
|
Leszek Koltunski
|
|
22 |
fe82a979
|
Leszek Koltunski
|
import org.distorted.library.effect.Effect;
|
23 |
da9b3f07
|
Leszek Koltunski
|
import org.distorted.library.effect.EffectName;
|
24 |
|
|
import org.distorted.library.effect.EffectType;
|
25 |
e458a4ba
|
Leszek Koltunski
|
import org.distorted.library.message.EffectListener;
|
26 |
|
|
import org.distorted.library.message.EffectMessage;
|
27 |
ed06301f
|
Leszek Koltunski
|
import org.distorted.library.message.EffectMessageSender;
|
28 |
a4835695
|
Leszek Koltunski
|
|
29 |
26a4e5f6
|
leszek
|
import java.util.ArrayList;
|
30 |
3417ab4e
|
leszek
|
import java.util.HashMap;
|
31 |
6a06a912
|
Leszek Koltunski
|
|
32 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
33 |
|
|
|
34 |
86d322b5
|
Leszek Koltunski
|
abstract class EffectQueue implements DistortedMaster.Slave
|
35 |
6a06a912
|
Leszek Koltunski
|
{
|
36 |
1418a5eb
|
Leszek Koltunski
|
private static final int CREATE = 0;
|
37 |
|
|
private static final int ATTACH = 1;
|
38 |
|
|
private static final int DETACH = 2;
|
39 |
|
|
private static final int DETALL = 3;
|
40 |
26a4e5f6
|
leszek
|
|
41 |
8bfefd68
|
Leszek Koltunski
|
int mNumEffects; // 'ToBe' will be more than mNumEffects if doWork() hasn't
|
42 |
|
|
private int mNumEffectsToBe; // added them yet (or less if it hasn't removed some yet)
|
43 |
13981586
|
Leszek Koltunski
|
float[] mUniforms;
|
44 |
|
|
long[] mCurrentDuration;
|
45 |
|
|
Effect[] mEffects;
|
46 |
|
|
int[] mName;
|
47 |
|
|
long mTime=0;
|
48 |
|
|
ArrayList<EffectListener> mListeners =null;
|
49 |
|
|
int mNumListeners=0; // ==mListeners.length(), but we only create mListeners if the first one gets added
|
50 |
|
|
long mDistortedEffectsID;
|
51 |
71887484
|
Leszek Koltunski
|
|
52 |
13981586
|
Leszek Koltunski
|
private static int[] mMax = new int[EffectType.LENGTH];
|
53 |
3417ab4e
|
leszek
|
private static long mNextID;
|
54 |
|
|
private static HashMap<ArrayList<Long>,Long> mMapID = new HashMap<>(); // maps lists of Effect IDs (longs) to a
|
55 |
|
|
// single long - the queue ID.
|
56 |
26a4e5f6
|
leszek
|
private ArrayList<DistortedNode> mNodes = null;
|
57 |
|
|
private long mID;
|
58 |
15aa7d94
|
Leszek Koltunski
|
private int mIndex;
|
59 |
06dbccad
|
Leszek Koltunski
|
private boolean mCreated;
|
60 |
71887484
|
Leszek Koltunski
|
|
61 |
26a4e5f6
|
leszek
|
private class Job
|
62 |
|
|
{
|
63 |
|
|
int type;
|
64 |
1418a5eb
|
Leszek Koltunski
|
int num;
|
65 |
26a4e5f6
|
leszek
|
boolean notify;
|
66 |
|
|
Effect effect;
|
67 |
|
|
|
68 |
1418a5eb
|
Leszek Koltunski
|
Job(int t, int m, boolean n, Effect e)
|
69 |
26a4e5f6
|
leszek
|
{
|
70 |
|
|
type = t;
|
71 |
1418a5eb
|
Leszek Koltunski
|
num = m;
|
72 |
26a4e5f6
|
leszek
|
notify= n;
|
73 |
|
|
effect= e;
|
74 |
|
|
}
|
75 |
|
|
}
|
76 |
|
|
|
77 |
|
|
private ArrayList<Job> mJobs = new ArrayList<>();
|
78 |
|
|
|
79 |
6a06a912
|
Leszek Koltunski
|
static
|
80 |
|
|
{
|
81 |
7b8086eb
|
Leszek Koltunski
|
onDestroy();
|
82 |
6a06a912
|
Leszek Koltunski
|
}
|
83 |
|
|
|
84 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
85 |
|
|
|
86 |
15aa7d94
|
Leszek Koltunski
|
EffectQueue(long id, int numUniforms, int index)
|
87 |
6a06a912
|
Leszek Koltunski
|
{
|
88 |
06dbccad
|
Leszek Koltunski
|
mCreated = false;
|
89 |
26a4e5f6
|
leszek
|
mID = 0;
|
90 |
fe6fe99a
|
leszek
|
mNumEffects = 0;
|
91 |
26a4e5f6
|
leszek
|
mNumEffectsToBe = 0;
|
92 |
fe6fe99a
|
leszek
|
mDistortedEffectsID = id;
|
93 |
|
|
mIndex = index;
|
94 |
1e438fc7
|
Leszek Koltunski
|
|
95 |
1418a5eb
|
Leszek Koltunski
|
mJobs.add(new Job(CREATE,numUniforms,false,null)); // create the stuff that depends on max number
|
96 |
|
|
DistortedMaster.newSlave(this); // of uniforms later, on first render.
|
97 |
6a06a912
|
Leszek Koltunski
|
}
|
98 |
|
|
|
99 |
a0397f32
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
100 |
|
|
// queues - guaranteed to be an array of EffectType.LENGTH length.
|
101 |
|
|
// Change this when creating a new ty[e of effect!
|
102 |
|
|
|
103 |
|
|
static void allocateQueues(EffectQueue[] queues, EffectQueue[] from, int flags, long id)
|
104 |
|
|
{
|
105 |
|
|
queues[0] = (flags & Distorted.CLONE_MATRIX ) != 0 ? from[0] : new EffectQueueMatrix(id);
|
106 |
|
|
queues[1] = (flags & Distorted.CLONE_VERTEX ) != 0 ? from[1] : new EffectQueueVertex(id);
|
107 |
|
|
queues[2] = (flags & Distorted.CLONE_FRAGMENT ) != 0 ? from[2] : new EffectQueueFragment(id);
|
108 |
|
|
queues[3] = (flags & Distorted.CLONE_POSTPROCESS) != 0 ? from[3] : new EffectQueuePostprocess(id);
|
109 |
|
|
}
|
110 |
|
|
|
111 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
112 |
|
|
// queues - guaranteed to be an array of EffectType.LENGTH length.
|
113 |
|
|
// Change this when creating a new ty[e of effect!
|
114 |
|
|
|
115 |
|
|
static void compute(EffectQueue[] queues, long currTime, float halfW, float halfH, float halfZ )
|
116 |
|
|
{
|
117 |
|
|
((EffectQueueMatrix )queues[0]).compute(currTime);
|
118 |
|
|
((EffectQueueVertex )queues[1]).compute(currTime,halfW,halfH,halfZ);
|
119 |
|
|
((EffectQueueFragment )queues[2]).compute(currTime,halfW,halfH,halfZ);
|
120 |
|
|
((EffectQueuePostprocess)queues[3]).compute(currTime);
|
121 |
|
|
}
|
122 |
|
|
|
123 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
124 |
|
|
// queues - guaranteed to be an array of EffectType.LENGTH length.
|
125 |
|
|
// Change this when creating a new ty[e of effect!
|
126 |
|
|
|
127 |
|
|
static void send(EffectQueue[] queues, DistortedOutputSurface surface, float inflate, float halfW, float halfH, float halfZ, int variant )
|
128 |
|
|
{
|
129 |
|
|
((EffectQueueMatrix )queues[0]).send(surface,halfW,halfH,halfZ, variant);
|
130 |
|
|
((EffectQueueVertex )queues[1]).send(inflate, variant);
|
131 |
|
|
((EffectQueueFragment)queues[2]).send(variant);
|
132 |
|
|
}
|
133 |
|
|
|
134 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
135 |
|
|
// queues - guaranteed to be an array of EffectType.LENGTH length.
|
136 |
|
|
// Change this when creating a new ty[e of effect!
|
137 |
|
|
|
138 |
|
|
static float[] getMVP(EffectQueue[] queues)
|
139 |
|
|
{
|
140 |
|
|
return ((EffectQueueMatrix )queues[0]).getMVP();
|
141 |
|
|
}
|
142 |
|
|
|
143 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
144 |
|
|
// queues - guaranteed to be an array of EffectType.LENGTH length.
|
145 |
|
|
// Change this when creating a new ty[e of effect!
|
146 |
|
|
|
147 |
|
|
static void newNode(EffectQueue[] queues, DistortedNode node)
|
148 |
|
|
{
|
149 |
|
|
queues[3].newNode(node);
|
150 |
|
|
}
|
151 |
|
|
|
152 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
153 |
|
|
// queues - guaranteed to be an array of EffectType.LENGTH length.
|
154 |
|
|
// Change this when creating a new ty[e of effect!
|
155 |
|
|
|
156 |
|
|
static void removeNode(EffectQueue[] queues, DistortedNode node)
|
157 |
|
|
{
|
158 |
|
|
queues[3].removeNode(node);
|
159 |
|
|
}
|
160 |
|
|
|
161 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
162 |
|
|
// queues - guaranteed to be an array of EffectType.LENGTH length.
|
163 |
|
|
// Change this when creating a new ty[e of effect!
|
164 |
|
|
|
165 |
|
|
static void getUniforms(int programH, int variant)
|
166 |
|
|
{
|
167 |
|
|
EffectQueueFragment.getUniforms(programH,variant);
|
168 |
|
|
EffectQueueVertex .getUniforms(programH,variant);
|
169 |
|
|
EffectQueueMatrix .getUniforms(programH,variant);
|
170 |
|
|
}
|
171 |
|
|
|
172 |
26a4e5f6
|
leszek
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
173 |
9455da17
|
Leszek Koltunski
|
// Every effect queue has an ID, which should be the same iff two queues hold the same effects.
|
174 |
|
|
// (this is a speedup: then both queues can be applied once, which seriously speeds up stuff -
|
175 |
|
|
// especially important in case of postprocessing)
|
176 |
26a4e5f6
|
leszek
|
|
177 |
8bfefd68
|
Leszek Koltunski
|
private void regenerateIDandSort()
|
178 |
26a4e5f6
|
leszek
|
{
|
179 |
3417ab4e
|
leszek
|
if( mNumEffects>0 )
|
180 |
|
|
{
|
181 |
|
|
ArrayList<Long> list = new ArrayList<>();
|
182 |
|
|
for (int i = 0; i < mNumEffects; i++) list.add(mEffects[i].getID());
|
183 |
|
|
Long id = mMapID.get(list);
|
184 |
|
|
|
185 |
|
|
if( id!=null )
|
186 |
|
|
{
|
187 |
|
|
mID = id;
|
188 |
|
|
}
|
189 |
|
|
else
|
190 |
|
|
{
|
191 |
|
|
mMapID.put(list,mNextID);
|
192 |
|
|
mID = mNextID++;
|
193 |
|
|
}
|
194 |
|
|
}
|
195 |
|
|
else
|
196 |
|
|
{
|
197 |
|
|
mID = 0;
|
198 |
|
|
}
|
199 |
1149be8f
|
leszek
|
|
200 |
|
|
int numNodes = (mNodes==null ? 0: mNodes.size());
|
201 |
|
|
for(int i=0; i<numNodes; i++) mNodes.get(i).sort();
|
202 |
26a4e5f6
|
leszek
|
}
|
203 |
|
|
|
204 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
205 |
|
|
|
206 |
a0397f32
|
Leszek Koltunski
|
private void newNode(DistortedNode node)
|
207 |
26a4e5f6
|
leszek
|
{
|
208 |
|
|
if( mNodes==null ) mNodes = new ArrayList<>();
|
209 |
|
|
|
210 |
|
|
mNodes.add(node);
|
211 |
|
|
}
|
212 |
|
|
|
213 |
c43abe6c
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
214 |
|
|
|
215 |
a0397f32
|
Leszek Koltunski
|
private void removeNode(DistortedNode node)
|
216 |
c43abe6c
|
Leszek Koltunski
|
{
|
217 |
|
|
mNodes.remove(node);
|
218 |
|
|
}
|
219 |
|
|
|
220 |
6a06a912
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
221 |
|
|
|
222 |
24d22f93
|
Leszek Koltunski
|
@SuppressWarnings("unused")
|
223 |
6a06a912
|
Leszek Koltunski
|
int getNumEffects()
|
224 |
|
|
{
|
225 |
|
|
return mNumEffects;
|
226 |
|
|
}
|
227 |
|
|
|
228 |
71887484
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
229 |
26a4e5f6
|
leszek
|
|
230 |
|
|
long getID()
|
231 |
|
|
{
|
232 |
|
|
return mID;
|
233 |
|
|
}
|
234 |
|
|
|
235 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
236 |
71887484
|
Leszek Koltunski
|
|
237 |
|
|
static boolean setMax(int index, int m)
|
238 |
|
|
{
|
239 |
1418a5eb
|
Leszek Koltunski
|
if( !Distorted.isInitialized() || m<=mMax[index] )
|
240 |
71887484
|
Leszek Koltunski
|
{
|
241 |
26a4e5f6
|
leszek
|
mMax[index] = m<0 ? 0:m;
|
242 |
71887484
|
Leszek Koltunski
|
return true;
|
243 |
|
|
}
|
244 |
|
|
|
245 |
|
|
return false;
|
246 |
|
|
}
|
247 |
|
|
|
248 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
249 |
|
|
|
250 |
|
|
static int getMax(int index)
|
251 |
|
|
{
|
252 |
|
|
return mMax[index];
|
253 |
|
|
}
|
254 |
|
|
|
255 |
6a06a912
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
256 |
|
|
|
257 |
3fc994b2
|
Leszek Koltunski
|
void registerForMessages(EffectListener el)
|
258 |
6a06a912
|
Leszek Koltunski
|
{
|
259 |
26a4e5f6
|
leszek
|
if( mListeners==null ) mListeners = new ArrayList<>();
|
260 |
452f8632
|
Leszek Koltunski
|
|
261 |
|
|
if( !mListeners.contains(el) )
|
262 |
|
|
{
|
263 |
|
|
mListeners.add(el);
|
264 |
|
|
mNumListeners++;
|
265 |
|
|
}
|
266 |
6a06a912
|
Leszek Koltunski
|
}
|
267 |
|
|
|
268 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
269 |
|
|
|
270 |
3fc994b2
|
Leszek Koltunski
|
void deregisterForMessages(EffectListener el)
|
271 |
6a06a912
|
Leszek Koltunski
|
{
|
272 |
452f8632
|
Leszek Koltunski
|
if( mListeners.remove(el) )
|
273 |
6a06a912
|
Leszek Koltunski
|
{
|
274 |
|
|
mNumListeners--;
|
275 |
|
|
}
|
276 |
|
|
}
|
277 |
|
|
|
278 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
279 |
|
|
|
280 |
7b8086eb
|
Leszek Koltunski
|
static void onDestroy()
|
281 |
6a06a912
|
Leszek Koltunski
|
{
|
282 |
3417ab4e
|
leszek
|
mNextID = 1;
|
283 |
|
|
mMapID.clear();
|
284 |
da9b3f07
|
Leszek Koltunski
|
EffectType.reset(mMax);
|
285 |
6a06a912
|
Leszek Koltunski
|
}
|
286 |
|
|
|
287 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
288 |
26a4e5f6
|
leszek
|
// this assumes 0<=effect<mNumEffects
|
289 |
6a06a912
|
Leszek Koltunski
|
|
290 |
26a4e5f6
|
leszek
|
protected void remove(int effect)
|
291 |
6bb59aad
|
Leszek Koltunski
|
{
|
292 |
26a4e5f6
|
leszek
|
mNumEffects--;
|
293 |
|
|
|
294 |
|
|
long removedID = mEffects[effect].getID();
|
295 |
|
|
|
296 |
|
|
for(int j=effect; j<mNumEffects; j++ )
|
297 |
|
|
{
|
298 |
|
|
mEffects[j] = mEffects[j+1];
|
299 |
|
|
mCurrentDuration[j] = mCurrentDuration[j+1];
|
300 |
|
|
mName[j] = mName[j+1];
|
301 |
|
|
}
|
302 |
|
|
|
303 |
|
|
mEffects[mNumEffects] = null;
|
304 |
|
|
|
305 |
|
|
for(int i=0; i<mNumListeners; i++)
|
306 |
|
|
EffectMessageSender.newMessage( mListeners.get(i), EffectMessage.EFFECT_REMOVED, removedID, mDistortedEffectsID);
|
307 |
|
|
}
|
308 |
6bb59aad
|
Leszek Koltunski
|
|
309 |
26a4e5f6
|
leszek
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
310 |
|
|
|
311 |
|
|
synchronized int removeByName(EffectName name)
|
312 |
|
|
{
|
313 |
6b0b4f60
|
leszek
|
int ret = 0;
|
314 |
|
|
|
315 |
6bb59aad
|
Leszek Koltunski
|
for(int i=0; i<mNumEffects; i++)
|
316 |
|
|
{
|
317 |
|
|
if( mEffects[i].getName() == name )
|
318 |
|
|
{
|
319 |
1418a5eb
|
Leszek Koltunski
|
mJobs.add(new Job(DETACH,0,true,mEffects[i]));
|
320 |
6b0b4f60
|
leszek
|
ret++;
|
321 |
6bb59aad
|
Leszek Koltunski
|
}
|
322 |
|
|
}
|
323 |
|
|
|
324 |
6b0b4f60
|
leszek
|
if( ret>0 )
|
325 |
|
|
{
|
326 |
|
|
DistortedMaster.newSlave(this);
|
327 |
|
|
mNumEffectsToBe-=ret;
|
328 |
|
|
}
|
329 |
|
|
|
330 |
|
|
return ret;
|
331 |
6bb59aad
|
Leszek Koltunski
|
}
|
332 |
|
|
|
333 |
2ef5dd9e
|
leszek
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
334 |
|
|
|
335 |
|
|
synchronized int removeById(long id)
|
336 |
|
|
{
|
337 |
|
|
for(int i=0; i<mNumEffects; i++)
|
338 |
|
|
{
|
339 |
|
|
if( mEffects[i].getID() == id )
|
340 |
|
|
{
|
341 |
1418a5eb
|
Leszek Koltunski
|
mJobs.add(new Job(DETACH,0,true,mEffects[i]));
|
342 |
26a4e5f6
|
leszek
|
DistortedMaster.newSlave(this);
|
343 |
|
|
mNumEffectsToBe--;
|
344 |
|
|
return 1;
|
345 |
2ef5dd9e
|
leszek
|
}
|
346 |
|
|
}
|
347 |
|
|
|
348 |
26a4e5f6
|
leszek
|
return 0;
|
349 |
2ef5dd9e
|
leszek
|
}
|
350 |
|
|
|
351 |
6bb59aad
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
352 |
|
|
|
353 |
|
|
synchronized int removeEffect(Effect effect)
|
354 |
6a06a912
|
Leszek Koltunski
|
{
|
355 |
|
|
for(int i=0; i<mNumEffects; i++)
|
356 |
|
|
{
|
357 |
15aa7d94
|
Leszek Koltunski
|
if( mEffects[i]==effect )
|
358 |
6a06a912
|
Leszek Koltunski
|
{
|
359 |
1418a5eb
|
Leszek Koltunski
|
mJobs.add(new Job(DETACH,0,true,mEffects[i]));
|
360 |
26a4e5f6
|
leszek
|
DistortedMaster.newSlave(this);
|
361 |
|
|
mNumEffectsToBe--;
|
362 |
|
|
return 1;
|
363 |
6a06a912
|
Leszek Koltunski
|
}
|
364 |
|
|
}
|
365 |
|
|
|
366 |
26a4e5f6
|
leszek
|
return 0;
|
367 |
6a06a912
|
Leszek Koltunski
|
}
|
368 |
|
|
|
369 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
370 |
0df17fad
|
Leszek Koltunski
|
// we do want to notify Listeners if they called 'abortAll' themselves but don't want to notify
|
371 |
|
|
// them if it is the library itself which is releasing resources.
|
372 |
|
|
|
373 |
|
|
synchronized int abortAll(boolean notify)
|
374 |
6a06a912
|
Leszek Koltunski
|
{
|
375 |
1418a5eb
|
Leszek Koltunski
|
mJobs.add(new Job(DETALL,0,notify,null));
|
376 |
26a4e5f6
|
leszek
|
DistortedMaster.newSlave(this);
|
377 |
|
|
mNumEffectsToBe = 0;
|
378 |
|
|
return mNumEffects;
|
379 |
|
|
}
|
380 |
d07f2950
|
Leszek Koltunski
|
|
381 |
26a4e5f6
|
leszek
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
382 |
|
|
|
383 |
|
|
boolean add(Effect effect)
|
384 |
|
|
{
|
385 |
06dbccad
|
Leszek Koltunski
|
if( mMax[mIndex]>mNumEffectsToBe || !mCreated )
|
386 |
6a06a912
|
Leszek Koltunski
|
{
|
387 |
1418a5eb
|
Leszek Koltunski
|
mJobs.add(new Job(ATTACH,0,false,effect));
|
388 |
26a4e5f6
|
leszek
|
DistortedMaster.newSlave(this);
|
389 |
|
|
mNumEffectsToBe++;
|
390 |
|
|
return true;
|
391 |
d07f2950
|
Leszek Koltunski
|
}
|
392 |
|
|
|
393 |
26a4e5f6
|
leszek
|
return false;
|
394 |
6a06a912
|
Leszek Koltunski
|
}
|
395 |
|
|
|
396 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
397 |
26a4e5f6
|
leszek
|
/**
|
398 |
|
|
* This is not really part of the public API. Has to be public only because it is a part of the
|
399 |
|
|
* DistortedSlave interface, which should really be a class that we extend here instead but
|
400 |
|
|
* Java has no multiple inheritance.
|
401 |
|
|
*
|
402 |
|
|
* @y.exclude
|
403 |
|
|
*/
|
404 |
|
|
public void doWork()
|
405 |
6a06a912
|
Leszek Koltunski
|
{
|
406 |
11845a9e
|
Leszek Koltunski
|
boolean changed = false;
|
407 |
26a4e5f6
|
leszek
|
int num = mJobs.size();
|
408 |
|
|
Job job;
|
409 |
15aa7d94
|
Leszek Koltunski
|
|
410 |
26a4e5f6
|
leszek
|
for(int i=0; i<num; i++)
|
411 |
6a06a912
|
Leszek Koltunski
|
{
|
412 |
26a4e5f6
|
leszek
|
job = mJobs.remove(0);
|
413 |
15aa7d94
|
Leszek Koltunski
|
|
414 |
26a4e5f6
|
leszek
|
switch(job.type)
|
415 |
|
|
{
|
416 |
1418a5eb
|
Leszek Koltunski
|
case CREATE: int max = mMax[mIndex];
|
417 |
|
|
if( max>0 )
|
418 |
|
|
{
|
419 |
|
|
mUniforms = new float[max*job.num];
|
420 |
|
|
mCurrentDuration = new long[max];
|
421 |
|
|
mEffects = new Effect[max];
|
422 |
|
|
mName = new int[max];
|
423 |
|
|
}
|
424 |
06dbccad
|
Leszek Koltunski
|
mCreated = true;
|
425 |
|
|
|
426 |
1418a5eb
|
Leszek Koltunski
|
break;
|
427 |
|
|
case ATTACH: if( mMax[mIndex]>mNumEffects ) // it is possible that we have first
|
428 |
|
|
{ // added effects and then lowered mMax
|
429 |
|
|
mCurrentDuration[mNumEffects] = 0;
|
430 |
|
|
mEffects[mNumEffects] = job.effect;
|
431 |
|
|
mName[mNumEffects] = job.effect.getName().ordinal();
|
432 |
|
|
mNumEffects++;
|
433 |
11845a9e
|
Leszek Koltunski
|
changed = true;
|
434 |
1418a5eb
|
Leszek Koltunski
|
}
|
435 |
|
|
else
|
436 |
|
|
{
|
437 |
|
|
android.util.Log.e("queue", "failed to add effect "+job.effect.getName());
|
438 |
|
|
}
|
439 |
26a4e5f6
|
leszek
|
break;
|
440 |
1418a5eb
|
Leszek Koltunski
|
case DETACH: for(int j=0; j<mNumEffects; j++)
|
441 |
6b0b4f60
|
leszek
|
{
|
442 |
|
|
if (mEffects[j] == job.effect)
|
443 |
|
|
{
|
444 |
|
|
remove(j);
|
445 |
11845a9e
|
Leszek Koltunski
|
changed = true;
|
446 |
6b0b4f60
|
leszek
|
break;
|
447 |
|
|
}
|
448 |
|
|
}
|
449 |
26a4e5f6
|
leszek
|
break;
|
450 |
|
|
case DETALL: for(int j=0; j<mNumEffects; j++ )
|
451 |
|
|
{
|
452 |
11845a9e
|
Leszek Koltunski
|
changed = true;
|
453 |
|
|
|
454 |
26a4e5f6
|
leszek
|
if( job.notify )
|
455 |
|
|
{
|
456 |
|
|
for(int k=0; k<mNumListeners; k++)
|
457 |
|
|
EffectMessageSender.newMessage( mListeners.get(k), EffectMessage.EFFECT_REMOVED, mEffects[j].getID(), mDistortedEffectsID);
|
458 |
|
|
}
|
459 |
|
|
|
460 |
|
|
mEffects[j] = null;
|
461 |
|
|
}
|
462 |
|
|
|
463 |
|
|
mNumEffects= 0;
|
464 |
|
|
break;
|
465 |
|
|
}
|
466 |
6a06a912
|
Leszek Koltunski
|
}
|
467 |
d425545a
|
Leszek Koltunski
|
|
468 |
11845a9e
|
Leszek Koltunski
|
if( changed && mIndex==EffectType.POSTPROCESS.ordinal() ) regenerateIDandSort();
|
469 |
6a06a912
|
Leszek Koltunski
|
}
|
470 |
|
|
}
|