Project

General

Profile

Download (9.2 KB) Statistics
| Branch: | Revision:

library / src / main / java / org / distorted / library / main / DistortedEffects.java @ c90aca24

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
  private int[] mStretchX, mStretchY, mStretchZ;
40

    
41
///////////////////////////////////////////////////////////////////////////////////////////////////
42
/**
43
 * @y.exclude
44
 */
45
  public EffectQueue[] getQueues()
46
    {
47
    return mQueues;
48
    }
49

    
50
///////////////////////////////////////////////////////////////////////////////////////////////////
51

    
52
  static void onDestroy()
53
    {
54
    mNextID =  0;
55
    }
56

    
57
///////////////////////////////////////////////////////////////////////////////////////////////////
58
// PUBLIC API
59
///////////////////////////////////////////////////////////////////////////////////////////////////
60
/**
61
 * Create empty effect queue.
62
 */
63
  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
    {
84
    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
    mID = ++mNextID;
93
    mQueues = new EffectQueue[EffectType.LENGTH];
94
    EffectQueue.allocateQueues(mQueues,null,0);
95
    }
96

    
97
///////////////////////////////////////////////////////////////////////////////////////////////////
98
/**
99
 * Copy constructor.
100
 * <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
 *              For example, CLONE_VERTEX | CLONE_MATRIX.
106
 */
107
  public DistortedEffects(DistortedEffects dc, int flags)
108
    {
109
    mStretchX = dc.mStretchX;
110
    mStretchY = dc.mStretchY;
111
    mStretchZ = dc.mStretchZ;
112

    
113
    mID = ++mNextID;
114
    mQueues = new EffectQueue[EffectType.LENGTH];
115
    EffectQueue.allocateQueues(mQueues,dc.getQueues(),flags);
116
    }
117

    
118
///////////////////////////////////////////////////////////////////////////////////////////////////
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
///////////////////////////////////////////////////////////////////////////////////////////////////
161
/**
162
 * Returns unique ID of this instance.
163
 *
164
 * @return ID of the object.
165
 */
166
  public long getID()
167
      {
168
      return mID;
169
      }
170

    
171
///////////////////////////////////////////////////////////////////////////////////////////////////
172
/**
173
 * Aborts all Effects.
174
 * @return Number of effects aborted.
175
 */
176
  public int abortAllEffects()
177
    {
178
    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
    }
187

    
188
///////////////////////////////////////////////////////////////////////////////////////////////////
189
/**
190
 * Aborts all Effects of a given type, for example all MATRIX Effects.
191
 * 
192
 * @param type one of the constants defined in {@link EffectType}
193
 * @return Number of effects aborted.
194
 */
195
  public int abortByType(EffectType type)
196
    {
197
    int num = type.ordinal();
198
    return mQueues[num].abortAll(true);
199
    }
200

    
201
///////////////////////////////////////////////////////////////////////////////////////////////////
202
/**
203
 * Aborts an Effect by its ID.
204
 *
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
    int num = (int)(id&EffectType.MASK);
211
    return mQueues[num].removeById(id);
212
    }
213

    
214
///////////////////////////////////////////////////////////////////////////////////////////////////
215
/**
216
 * Aborts a single Effect.
217
 * 
218
 * @param effect the Effect we want to abort.
219
 * @return number of Effects aborted. Always either 0 or 1.
220
 */
221
  public int abortEffect(Effect effect)
222
    {
223
    int num = effect.getType().ordinal();
224
    return mQueues[num].removeEffect(effect);
225
    }
226

    
227
///////////////////////////////////////////////////////////////////////////////////////////////////
228
/**
229
 * Abort all Effects of a given name, for example all rotations.
230
 * 
231
 * @param name one of the constants defined in {@link EffectName}
232
 * @return number of Effects aborted.
233
 */
234
  public int abortByName(EffectName name)
235
    {
236
    int num = name.getType().ordinal();
237
    return mQueues[num].removeByName(name);
238
    }
239

    
240
///////////////////////////////////////////////////////////////////////////////////////////////////
241
/**
242
 * Add a new Effect to the tail of our queue.
243
 *
244
 * @param effect The Effect to add.
245
 * @return <code>true</code> if operation was successful, <code>false</code> otherwise.
246
 */
247
  public boolean apply(Effect effect)
248
    {
249
    int num = effect.getType().ordinal();
250
    return mQueues[num].add(effect);
251
    }
252

    
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

    
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
  }
(1-1/14)