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