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