Project

General

Profile

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

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

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
// PUBLIC API
50
///////////////////////////////////////////////////////////////////////////////////////////////////
51
/**
52
 * Create empty effect queue.
53
 */
54
 public DistortedEffects()
55
    {
56
    mID = ++mNextID;
57
    mQueues = new EffectQueue[EffectType.LENGTH];
58
    EffectQueue.allocateQueues(mQueues,null,0);
59
    }
60

    
61
///////////////////////////////////////////////////////////////////////////////////////////////////
62
/**
63
 * Copy constructor.
64
 * <p>
65
 * Whatever we do not clone gets created just like in the default constructor.
66
 *
67
 * @param dc    Source object to create our object from
68
 * @param flags A bitmask of values specifying what to copy.
69
 *              For example, CLONE_VERTEX | CLONE_MATRIX.
70
 */
71
  public DistortedEffects(DistortedEffects dc, int flags)
72
    {
73
    mID = ++mNextID;
74
    mQueues = new EffectQueue[EffectType.LENGTH];
75
    EffectQueue.allocateQueues(mQueues,dc.getQueues(),flags);
76
    }
77

    
78
///////////////////////////////////////////////////////////////////////////////////////////////////
79
/**
80
 * Returns unique ID of this instance.
81
 *
82
 * @return ID of the object.
83
 */
84
  public long getID()
85
      {
86
      return mID;
87
      }
88

    
89
///////////////////////////////////////////////////////////////////////////////////////////////////
90
/**
91
 * Aborts all Effects.
92
 * @return Number of effects aborted.
93
 */
94
  public int abortAllEffects()
95
    {
96
    int aborted = 0;
97

    
98
    for( int i=0; i<EffectType.LENGTH; i++)
99
      {
100
      aborted += mQueues[i].removeAll(true);
101
      }
102

    
103
    return aborted;
104
    }
105

    
106
///////////////////////////////////////////////////////////////////////////////////////////////////
107
/**
108
 * Aborts all Effects of a given type, for example all MATRIX Effects.
109
 * 
110
 * @param type one of the constants defined in {@link EffectType}
111
 * @return Number of effects aborted.
112
 */
113
  public int abortByType(EffectType type)
114
    {
115
    int num = type.ordinal();
116
    return mQueues[num].removeAll(true);
117
    }
118

    
119
///////////////////////////////////////////////////////////////////////////////////////////////////
120
/**
121
 * Aborts an Effect by its ID.
122
 *
123
 * @param id the Id of the Effect to be removed, as returned by getID().
124
 * @return Number of effects aborted.
125
 */
126
  public int abortById(long id)
127
    {
128
    int num = (int)(id&EffectType.MASK);
129
    return mQueues[num].removeById(id);
130
    }
131

    
132
///////////////////////////////////////////////////////////////////////////////////////////////////
133
/**
134
 * Aborts a single Effect.
135
 * 
136
 * @param effect the Effect we want to abort.
137
 * @return number of Effects aborted. Always either 0 or 1.
138
 */
139
  public int abortEffect(Effect effect)
140
    {
141
    int num = effect.getType().ordinal();
142
    return mQueues[num].removeEffect(effect);
143
    }
144

    
145
///////////////////////////////////////////////////////////////////////////////////////////////////
146
/**
147
 * Abort all Effects of a given name, for example all rotations.
148
 * 
149
 * @param name one of the constants defined in {@link EffectName}
150
 * @return number of Effects aborted.
151
 */
152
  public int abortByName(EffectName name)
153
    {
154
    int num = name.getType().ordinal();
155
    return mQueues[num].removeByName(name);
156
    }
157

    
158
///////////////////////////////////////////////////////////////////////////////////////////////////
159
/**
160
 * Add a new Effect to the tail of our queue.
161
 *
162
 * @param effect The Effect to add.
163
 * @return <code>true</code> if operation was successful, <code>false</code> otherwise.
164
 */
165
  public boolean apply(Effect effect)
166
    {
167
    int num = effect.getType().ordinal();
168
    return mQueues[num].add(effect);
169
    }
170

    
171
///////////////////////////////////////////////////////////////////////////////////////////////////
172
/**
173
 * Add a new Effect to our queue at a specified position.
174
 *
175
 * @param effect The Effect to add.
176
 * @param position the place in the effects queue where to add the new effect.
177
 * @return <code>true</code> if operation was successful, <code>false</code> otherwise.
178
 */
179
  public boolean apply(Effect effect, int position)
180
    {
181
    int num = effect.getType().ordinal();
182
    return mQueues[num].add(effect,position);
183
    }
184

    
185
///////////////////////////////////////////////////////////////////////////////////////////////////
186
/**
187
 * Return number of effects of the given type currently in the Queue.
188
 *
189
 * @param type The EffectType.
190
 * @return Number of effects of the given type currently in the Queue.
191
 */
192
  public int getNumEffects(EffectType type)
193
    {
194
    int num = type.ordinal();
195
    return mQueues[num].getNumEffects();
196
    }
197
  }
(1-1/16)