1
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
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
|
package org.distorted.library.main;
|
21
|
|
22
|
import org.distorted.library.effect.Effect;
|
23
|
import org.distorted.library.effect.EffectName;
|
24
|
import org.distorted.library.effectqueue.EffectQueue;
|
25
|
import org.distorted.library.effect.EffectType;
|
26
|
import org.distorted.library.effectqueue.EffectQueueVertex;
|
27
|
|
28
|
import java.util.ArrayList;
|
29
|
|
30
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
31
|
/**
|
32
|
* Class containing Matrix, Vertex, Fragment and Postprocessing effect queues.
|
33
|
* <p>
|
34
|
* The queues hold actual effects to be applied to a given (InputSurface,MeshBase) combo.
|
35
|
*/
|
36
|
public class DistortedEffects
|
37
|
{
|
38
|
private static ArrayList<DistortedEffects> mAllEffectQueues = new ArrayList<>();
|
39
|
private static long mNextID =0;
|
40
|
private long mID;
|
41
|
private EffectQueue[] mQueues;
|
42
|
|
43
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
44
|
/**
|
45
|
* @y.exclude
|
46
|
*/
|
47
|
public EffectQueue[] getQueues()
|
48
|
{
|
49
|
return mQueues;
|
50
|
}
|
51
|
|
52
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
53
|
|
54
|
static void onDestroy()
|
55
|
{
|
56
|
mNextID = 0;
|
57
|
mAllEffectQueues.clear();
|
58
|
}
|
59
|
|
60
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
61
|
/**
|
62
|
* @y.exclude
|
63
|
*/
|
64
|
public static void setAssociation(long effectID)
|
65
|
{
|
66
|
EffectQueue[] queues;
|
67
|
int numQueues = mAllEffectQueues.size();
|
68
|
|
69
|
for(int i=0; i<numQueues; i++)
|
70
|
{
|
71
|
queues = mAllEffectQueues.get(i).getQueues();
|
72
|
((EffectQueueVertex)queues[1]).setAssociation(effectID);
|
73
|
}
|
74
|
}
|
75
|
|
76
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
77
|
// PUBLIC API
|
78
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
79
|
/**
|
80
|
* Create empty effect queue.
|
81
|
*/
|
82
|
public DistortedEffects()
|
83
|
{
|
84
|
mID = ++mNextID;
|
85
|
mQueues = new EffectQueue[EffectType.LENGTH];
|
86
|
EffectQueue.allocateQueues(mQueues,null,0);
|
87
|
mAllEffectQueues.add(this);
|
88
|
}
|
89
|
|
90
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
91
|
/**
|
92
|
* Copy constructor.
|
93
|
* <p>
|
94
|
* Whatever we do not clone gets created just like in the default constructor.
|
95
|
*
|
96
|
* @param dc Source object to create our object from
|
97
|
* @param flags A bitmask of values specifying what to copy.
|
98
|
* For example, CLONE_VERTEX | CLONE_MATRIX.
|
99
|
*/
|
100
|
public DistortedEffects(DistortedEffects dc, int flags)
|
101
|
{
|
102
|
mID = ++mNextID;
|
103
|
mQueues = new EffectQueue[EffectType.LENGTH];
|
104
|
EffectQueue.allocateQueues(mQueues,dc.getQueues(),flags);
|
105
|
mAllEffectQueues.add(this);
|
106
|
}
|
107
|
|
108
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
109
|
/**
|
110
|
* Returns unique ID of this instance.
|
111
|
*
|
112
|
* @return ID of the object.
|
113
|
*/
|
114
|
public long getID()
|
115
|
{
|
116
|
return mID;
|
117
|
}
|
118
|
|
119
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
120
|
/**
|
121
|
* Aborts all Effects.
|
122
|
* @return Number of effects aborted.
|
123
|
*/
|
124
|
public int abortAllEffects()
|
125
|
{
|
126
|
int aborted = 0;
|
127
|
|
128
|
for( int i=0; i<EffectType.LENGTH; i++)
|
129
|
{
|
130
|
aborted += mQueues[i].removeAll(true);
|
131
|
}
|
132
|
|
133
|
return aborted;
|
134
|
}
|
135
|
|
136
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
137
|
/**
|
138
|
* Aborts all Effects of a given type, for example all MATRIX Effects.
|
139
|
*
|
140
|
* @param type one of the constants defined in {@link EffectType}
|
141
|
* @return Number of effects aborted.
|
142
|
*/
|
143
|
public int abortByType(EffectType type)
|
144
|
{
|
145
|
int num = type.ordinal();
|
146
|
return mQueues[num].removeAll(true);
|
147
|
}
|
148
|
|
149
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
150
|
/**
|
151
|
* Aborts an Effect by its ID.
|
152
|
*
|
153
|
* @param id the Id of the Effect to be removed, as returned by getID().
|
154
|
* @return Number of effects aborted.
|
155
|
*/
|
156
|
public int abortById(long id)
|
157
|
{
|
158
|
int num = (int)(id&EffectType.MASK);
|
159
|
return mQueues[num].removeById(id);
|
160
|
}
|
161
|
|
162
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
163
|
/**
|
164
|
* Aborts a single Effect.
|
165
|
*
|
166
|
* @param effect the Effect we want to abort.
|
167
|
* @return number of Effects aborted. Always either 0 or 1.
|
168
|
*/
|
169
|
public int abortEffect(Effect effect)
|
170
|
{
|
171
|
int num = effect.getType().ordinal();
|
172
|
return mQueues[num].removeEffect(effect);
|
173
|
}
|
174
|
|
175
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
176
|
/**
|
177
|
* Abort all Effects of a given name, for example all rotations.
|
178
|
*
|
179
|
* @param name one of the constants defined in {@link EffectName}
|
180
|
* @return number of Effects aborted.
|
181
|
*/
|
182
|
public int abortByName(EffectName name)
|
183
|
{
|
184
|
int num = name.getType().ordinal();
|
185
|
return mQueues[num].removeByName(name);
|
186
|
}
|
187
|
|
188
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
189
|
/**
|
190
|
* Add a new Effect to the tail of our queue.
|
191
|
*
|
192
|
* @param effect The Effect to add.
|
193
|
* @return <code>true</code> if operation was successful, <code>false</code> otherwise.
|
194
|
*/
|
195
|
public boolean apply(Effect effect)
|
196
|
{
|
197
|
int num = effect.getType().ordinal();
|
198
|
return mQueues[num].add(effect);
|
199
|
}
|
200
|
|
201
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
202
|
/**
|
203
|
* Add a new Effect to our queue at a specified position.
|
204
|
*
|
205
|
* @param effect The Effect to add.
|
206
|
* @param position the place in the effects queue where to add the new effect.
|
207
|
* @return <code>true</code> if operation was successful, <code>false</code> otherwise.
|
208
|
*/
|
209
|
public boolean apply(Effect effect, int position)
|
210
|
{
|
211
|
int num = effect.getType().ordinal();
|
212
|
return mQueues[num].add(effect,position);
|
213
|
}
|
214
|
|
215
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
216
|
/**
|
217
|
* Return number of effects of the given type currently in the Queue.
|
218
|
*
|
219
|
* @param type The EffectType.
|
220
|
* @return Number of effects of the given type currently in the Queue.
|
221
|
*/
|
222
|
public int getNumEffects(EffectType type)
|
223
|
{
|
224
|
int num = type.ordinal();
|
225
|
return mQueues[num].getNumEffects();
|
226
|
}
|
227
|
}
|