1 |
d333eb6b
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2 |
|
|
// Copyright 2016 Leszek Koltunski //
|
3 |
|
|
// //
|
4 |
46b572b5
|
Leszek Koltunski
|
// This file is part of Distorted. //
|
5 |
d333eb6b
|
Leszek Koltunski
|
// //
|
6 |
46b572b5
|
Leszek Koltunski
|
// Distorted is free software: you can redistribute it and/or modify //
|
7 |
d333eb6b
|
Leszek Koltunski
|
// 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 |
46b572b5
|
Leszek Koltunski
|
// Distorted is distributed in the hope that it will be useful, //
|
12 |
d333eb6b
|
Leszek Koltunski
|
// 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 |
46b572b5
|
Leszek Koltunski
|
// along with Distorted. If not, see <http://www.gnu.org/licenses/>. //
|
18 |
d333eb6b
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
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 |
809dcae3
|
Leszek Koltunski
|
import org.distorted.library.effectqueue.EffectQueue;
|
25 |
da9b3f07
|
Leszek Koltunski
|
import org.distorted.library.effect.EffectType;
|
26 |
c638c1b0
|
Leszek Koltunski
|
|
27 |
6a06a912
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
28 |
b329f352
|
Leszek Koltunski
|
/**
|
29 |
faa3ff56
|
Leszek Koltunski
|
* Class containing Matrix, Vertex, Fragment and Postprocessing effect queues.
|
30 |
b73dcaa7
|
Leszek Koltunski
|
* <p>
|
31 |
715e7726
|
Leszek Koltunski
|
* The queues hold actual effects to be applied to a given (InputSurface,MeshBase) combo.
|
32 |
b329f352
|
Leszek Koltunski
|
*/
|
33 |
86d322b5
|
Leszek Koltunski
|
public class DistortedEffects
|
34 |
d425545a
|
Leszek Koltunski
|
{
|
35 |
8e34674e
|
Leszek Koltunski
|
private static long mNextID =0;
|
36 |
4e2382f3
|
Leszek Koltunski
|
private long mID;
|
37 |
a0397f32
|
Leszek Koltunski
|
private EffectQueue[] mQueues;
|
38 |
3d590d8d
|
Leszek Koltunski
|
|
39 |
c90aca24
|
Leszek Koltunski
|
private int[] mStretchX, mStretchY, mStretchZ;
|
40 |
|
|
|
41 |
55c14a19
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
42 |
809dcae3
|
Leszek Koltunski
|
/**
|
43 |
|
|
* @y.exclude
|
44 |
|
|
*/
|
45 |
|
|
public EffectQueue[] getQueues()
|
46 |
d425545a
|
Leszek Koltunski
|
{
|
47 |
a0397f32
|
Leszek Koltunski
|
return mQueues;
|
48 |
80b3acf6
|
Leszek Koltunski
|
}
|
49 |
|
|
|
50 |
78e89fb5
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
51 |
|
|
|
52 |
|
|
static void onDestroy()
|
53 |
|
|
{
|
54 |
|
|
mNextID = 0;
|
55 |
|
|
}
|
56 |
|
|
|
57 |
8e34674e
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
58 |
|
|
// PUBLIC API
|
59 |
ada90d33
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
60 |
d425545a
|
Leszek Koltunski
|
/**
|
61 |
4e2382f3
|
Leszek Koltunski
|
* Create empty effect queue.
|
62 |
d425545a
|
Leszek Koltunski
|
*/
|
63 |
c90aca24
|
Leszek Koltunski
|
public DistortedEffects(int stretchX, int stretchY, int stretchZ)
|
64 |
|
|
{
|
65 |
|
|
mStretchX = new int[1];
|
66 |
|
|
mStretchY = new int[1];
|
67 |
|
|
mStretchZ = new int[1];
|
68 |
|
|
|
69 |
|
|
mStretchX[0] = stretchX;
|
70 |
|
|
mStretchY[0] = stretchY;
|
71 |
|
|
mStretchZ[0] = stretchZ;
|
72 |
|
|
|
73 |
|
|
mID = ++mNextID;
|
74 |
|
|
mQueues = new EffectQueue[EffectType.LENGTH];
|
75 |
|
|
EffectQueue.allocateQueues(mQueues,null,0);
|
76 |
|
|
}
|
77 |
|
|
|
78 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
79 |
|
|
/**
|
80 |
|
|
* Temporary constructor.
|
81 |
|
|
*/
|
82 |
|
|
public DistortedEffects(int dummy)
|
83 |
d425545a
|
Leszek Koltunski
|
{
|
84 |
c90aca24
|
Leszek Koltunski
|
mStretchX = new int[1];
|
85 |
|
|
mStretchY = new int[1];
|
86 |
|
|
mStretchZ = new int[1];
|
87 |
|
|
|
88 |
|
|
mStretchX[0] = 1;
|
89 |
|
|
mStretchY[0] = 1;
|
90 |
|
|
mStretchZ[0] = 1;
|
91 |
|
|
|
92 |
c7da4e65
|
leszek
|
mID = ++mNextID;
|
93 |
a0397f32
|
Leszek Koltunski
|
mQueues = new EffectQueue[EffectType.LENGTH];
|
94 |
20dbec0e
|
Leszek Koltunski
|
EffectQueue.allocateQueues(mQueues,null,0);
|
95 |
d425545a
|
Leszek Koltunski
|
}
|
96 |
ada90d33
|
Leszek Koltunski
|
|
97 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
98 |
d425545a
|
Leszek Koltunski
|
/**
|
99 |
4e2382f3
|
Leszek Koltunski
|
* Copy constructor.
|
100 |
d425545a
|
Leszek Koltunski
|
* <p>
|
101 |
|
|
* Whatever we do not clone gets created just like in the default constructor.
|
102 |
|
|
*
|
103 |
|
|
* @param dc Source object to create our object from
|
104 |
|
|
* @param flags A bitmask of values specifying what to copy.
|
105 |
e6ab30eb
|
Leszek Koltunski
|
* For example, CLONE_VERTEX | CLONE_MATRIX.
|
106 |
d425545a
|
Leszek Koltunski
|
*/
|
107 |
421c2728
|
Leszek Koltunski
|
public DistortedEffects(DistortedEffects dc, int flags)
|
108 |
d425545a
|
Leszek Koltunski
|
{
|
109 |
c90aca24
|
Leszek Koltunski
|
mStretchX = dc.mStretchX;
|
110 |
|
|
mStretchY = dc.mStretchY;
|
111 |
|
|
mStretchZ = dc.mStretchZ;
|
112 |
|
|
|
113 |
c7da4e65
|
leszek
|
mID = ++mNextID;
|
114 |
a0397f32
|
Leszek Koltunski
|
mQueues = new EffectQueue[EffectType.LENGTH];
|
115 |
20dbec0e
|
Leszek Koltunski
|
EffectQueue.allocateQueues(mQueues,dc.getQueues(),flags);
|
116 |
d425545a
|
Leszek Koltunski
|
}
|
117 |
6a06a912
|
Leszek Koltunski
|
|
118 |
c90aca24
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
119 |
|
|
/**
|
120 |
|
|
* Sets the stretch parameters. Coordinates of all vertices of any Mesh rendered with those Effects
|
121 |
|
|
* will be first pre-multiplied by those.
|
122 |
|
|
*/
|
123 |
|
|
public void setStretch(int sx, int sy, int sz)
|
124 |
|
|
{
|
125 |
|
|
mStretchX[0] = sx;
|
126 |
|
|
mStretchY[0] = sy;
|
127 |
|
|
mStretchZ[0] = sz;
|
128 |
|
|
}
|
129 |
|
|
|
130 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
131 |
|
|
/**
|
132 |
|
|
* X coordinates of all vertices of any Mesh rendered with those Effects will be first pre-multiplied
|
133 |
|
|
* by this parameter.
|
134 |
|
|
*/
|
135 |
|
|
public int getStartchX()
|
136 |
|
|
{
|
137 |
|
|
return mStretchX[0];
|
138 |
|
|
}
|
139 |
|
|
|
140 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
141 |
|
|
/**
|
142 |
|
|
* Y coordinates of all vertices of any Mesh rendered with those Effects will be first pre-multiplied
|
143 |
|
|
* by this parameter.
|
144 |
|
|
*/
|
145 |
|
|
public int getStartchY()
|
146 |
|
|
{
|
147 |
|
|
return mStretchY[0];
|
148 |
|
|
}
|
149 |
|
|
|
150 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
151 |
|
|
/**
|
152 |
|
|
* Z coordinates of all vertices of any Mesh rendered with those Effects will be first pre-multiplied
|
153 |
|
|
* by this parameter.
|
154 |
|
|
*/
|
155 |
|
|
public int getStartchZ()
|
156 |
|
|
{
|
157 |
|
|
return mStretchZ[0];
|
158 |
|
|
}
|
159 |
|
|
|
160 |
6a06a912
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
161 |
|
|
/**
|
162 |
4e2382f3
|
Leszek Koltunski
|
* Returns unique ID of this instance.
|
163 |
|
|
*
|
164 |
|
|
* @return ID of the object.
|
165 |
6a06a912
|
Leszek Koltunski
|
*/
|
166 |
4e2382f3
|
Leszek Koltunski
|
public long getID()
|
167 |
d425545a
|
Leszek Koltunski
|
{
|
168 |
4e2382f3
|
Leszek Koltunski
|
return mID;
|
169 |
d425545a
|
Leszek Koltunski
|
}
|
170 |
4e2382f3
|
Leszek Koltunski
|
|
171 |
6a06a912
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
172 |
|
|
/**
|
173 |
d07f2950
|
Leszek Koltunski
|
* Aborts all Effects.
|
174 |
|
|
* @return Number of effects aborted.
|
175 |
6a06a912
|
Leszek Koltunski
|
*/
|
176 |
d425545a
|
Leszek Koltunski
|
public int abortAllEffects()
|
177 |
13687207
|
leszek
|
{
|
178 |
a0397f32
|
Leszek Koltunski
|
int aborted = 0;
|
179 |
|
|
|
180 |
|
|
for( int i=0; i<EffectType.LENGTH; i++)
|
181 |
|
|
{
|
182 |
|
|
aborted += mQueues[i].abortAll(true);
|
183 |
|
|
}
|
184 |
|
|
|
185 |
|
|
return aborted;
|
186 |
13687207
|
leszek
|
}
|
187 |
6a06a912
|
Leszek Koltunski
|
|
188 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
189 |
|
|
/**
|
190 |
d07f2950
|
Leszek Koltunski
|
* Aborts all Effects of a given type, for example all MATRIX Effects.
|
191 |
6a06a912
|
Leszek Koltunski
|
*
|
192 |
da9b3f07
|
Leszek Koltunski
|
* @param type one of the constants defined in {@link EffectType}
|
193 |
d07f2950
|
Leszek Koltunski
|
* @return Number of effects aborted.
|
194 |
6a06a912
|
Leszek Koltunski
|
*/
|
195 |
da9b3f07
|
Leszek Koltunski
|
public int abortByType(EffectType type)
|
196 |
d425545a
|
Leszek Koltunski
|
{
|
197 |
a0397f32
|
Leszek Koltunski
|
int num = type.ordinal();
|
198 |
|
|
return mQueues[num].abortAll(true);
|
199 |
d425545a
|
Leszek Koltunski
|
}
|
200 |
47316d20
|
leszek
|
|
201 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
202 |
|
|
/**
|
203 |
faa3ff56
|
Leszek Koltunski
|
* Aborts an Effect by its ID.
|
204 |
47316d20
|
leszek
|
*
|
205 |
|
|
* @param id the Id of the Effect to be removed, as returned by getID().
|
206 |
|
|
* @return Number of effects aborted.
|
207 |
|
|
*/
|
208 |
|
|
public int abortById(long id)
|
209 |
|
|
{
|
210 |
a0397f32
|
Leszek Koltunski
|
int num = (int)(id&EffectType.MASK);
|
211 |
|
|
return mQueues[num].removeById(id);
|
212 |
47316d20
|
leszek
|
}
|
213 |
|
|
|
214 |
6a06a912
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
215 |
|
|
/**
|
216 |
|
|
* Aborts a single Effect.
|
217 |
|
|
*
|
218 |
6bb59aad
|
Leszek Koltunski
|
* @param effect the Effect we want to abort.
|
219 |
476bbc81
|
Leszek Koltunski
|
* @return number of Effects aborted. Always either 0 or 1.
|
220 |
6a06a912
|
Leszek Koltunski
|
*/
|
221 |
6bb59aad
|
Leszek Koltunski
|
public int abortEffect(Effect effect)
|
222 |
d425545a
|
Leszek Koltunski
|
{
|
223 |
a0397f32
|
Leszek Koltunski
|
int num = effect.getType().ordinal();
|
224 |
|
|
return mQueues[num].removeEffect(effect);
|
225 |
d425545a
|
Leszek Koltunski
|
}
|
226 |
6a06a912
|
Leszek Koltunski
|
|
227 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
228 |
|
|
/**
|
229 |
e8c81a8e
|
Leszek Koltunski
|
* Abort all Effects of a given name, for example all rotations.
|
230 |
6a06a912
|
Leszek Koltunski
|
*
|
231 |
da9b3f07
|
Leszek Koltunski
|
* @param name one of the constants defined in {@link EffectName}
|
232 |
476bbc81
|
Leszek Koltunski
|
* @return number of Effects aborted.
|
233 |
6a06a912
|
Leszek Koltunski
|
*/
|
234 |
da9b3f07
|
Leszek Koltunski
|
public int abortByName(EffectName name)
|
235 |
d425545a
|
Leszek Koltunski
|
{
|
236 |
a0397f32
|
Leszek Koltunski
|
int num = name.getType().ordinal();
|
237 |
|
|
return mQueues[num].removeByName(name);
|
238 |
d425545a
|
Leszek Koltunski
|
}
|
239 |
432442f9
|
Leszek Koltunski
|
|
240 |
6a06a912
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
241 |
|
|
/**
|
242 |
34e43b0a
|
Leszek Koltunski
|
* Add a new Effect to the tail of our queue.
|
243 |
f2fe7e28
|
Leszek Koltunski
|
*
|
244 |
6bb59aad
|
Leszek Koltunski
|
* @param effect The Effect to add.
|
245 |
ae77d55e
|
Leszek Koltunski
|
* @return <code>true</code> if operation was successful, <code>false</code> otherwise.
|
246 |
6a06a912
|
Leszek Koltunski
|
*/
|
247 |
ae77d55e
|
Leszek Koltunski
|
public boolean apply(Effect effect)
|
248 |
d425545a
|
Leszek Koltunski
|
{
|
249 |
a0397f32
|
Leszek Koltunski
|
int num = effect.getType().ordinal();
|
250 |
|
|
return mQueues[num].add(effect);
|
251 |
4fde55a0
|
Leszek Koltunski
|
}
|
252 |
34e43b0a
|
Leszek Koltunski
|
|
253 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
254 |
|
|
/**
|
255 |
|
|
* Add a new Effect to our queue at a specified position.
|
256 |
|
|
*
|
257 |
|
|
* @param effect The Effect to add.
|
258 |
|
|
* @param position the place in the effects queue where to add the new effect.
|
259 |
|
|
* @return <code>true</code> if operation was successful, <code>false</code> otherwise.
|
260 |
|
|
*/
|
261 |
|
|
public boolean apply(Effect effect, int position)
|
262 |
|
|
{
|
263 |
|
|
int num = effect.getType().ordinal();
|
264 |
|
|
return mQueues[num].add(effect,position);
|
265 |
|
|
}
|
266 |
106ae28d
|
Leszek Koltunski
|
|
267 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
268 |
|
|
/**
|
269 |
|
|
* Return number of effects of the given type currently in the Queue.
|
270 |
|
|
*
|
271 |
|
|
* @param type The EffectType.
|
272 |
|
|
* @return Number of effects of the given type currently in the Queue.
|
273 |
|
|
*/
|
274 |
|
|
public int getNumEffects(EffectType type)
|
275 |
|
|
{
|
276 |
|
|
int num = type.ordinal();
|
277 |
|
|
return mQueues[num].getNumEffects();
|
278 |
|
|
}
|
279 |
f2fe7e28
|
Leszek Koltunski
|
}
|