Project

General

Profile

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

library / src / main / java / org / distorted / library / main / DistortedEffects.java @ 8b36dabf

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 final long mID;
36
  private final EffectQueue[] mQueues;
37

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

    
47
///////////////////////////////////////////////////////////////////////////////////////////////////
48
// PUBLIC API
49
///////////////////////////////////////////////////////////////////////////////////////////////////
50
/**
51
 * Create empty effect queue.
52
 */
53
 public DistortedEffects()
54
    {
55
    mID = InternalStackFrameList.getNextEffectsID();
56
    mQueues = new EffectQueue[EffectType.LENGTH];
57
    EffectQueue.allocateQueues(mQueues,null,0);
58
    }
59

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

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

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

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

    
102
    return aborted;
103
    }
104

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

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

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

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

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

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

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