Project

General

Profile

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

library / src / main / java / org / distorted / library / effect / Effect.java @ 6770ef46

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2017 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.effect;
21

    
22
///////////////////////////////////////////////////////////////////////////////////////////////////
23
/**
24
 * Abstract Effect of any type.
25
 */
26
public abstract class Effect
27
  {
28
  private final static int MAX_UNITY_DIM = 4;
29
  private final static int NUM_EFFECTS = EffectName.LENGTH;
30

    
31
  private final long mID;
32
  private final EffectType mType;
33
  private final EffectName mName;
34
  private final int mDimension;
35
  private final boolean mSupportsR;
36
  private final boolean mSupportsC;
37

    
38
  private static long mNextID = 0;
39

    
40
  private final static float[] mUnity= new float[MAX_UNITY_DIM*NUM_EFFECTS];
41
  private final static int[]   mUnityDim = new int[NUM_EFFECTS];
42

    
43
  static boolean[] mEnabled = new boolean[NUM_EFFECTS];
44

    
45
  static
46
    {
47
    for(int i=0; i<NUM_EFFECTS; i++) mEnabled[i] = false;
48
    }
49

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

    
52
  Effect(EffectName name)
53
    {
54
    mName      = name;
55
    mType      = name.getType();
56
    mDimension = name.getDimension();
57
    mSupportsC = name.supportsCenter();
58
    mSupportsR = name.supportsRegion();
59

    
60
    int n = name.ordinal();
61
    float[] u = name.getUnity();
62
    int l = name.getUnity().length;
63

    
64
    for(int i=0; i<l; i++)
65
      {
66
      mUnity[n*MAX_UNITY_DIM+i] = u[i];
67
      }
68

    
69
    mUnityDim[n] = l;
70

    
71
    mID = ((mNextID++)<<EffectType.LENGTH) + mType.ordinal();
72
    }
73

    
74
///////////////////////////////////////////////////////////////////////////////////////////////////
75
/**
76
 * Only for use by the library itself.
77
 *
78
 * @y.exclude
79
 */
80
  public static void onDestroy()
81
    {
82
    mNextID = 0;
83

    
84
    for(int i=0; i<NUM_EFFECTS; i++) mEnabled[i] = false;
85
    }
86

    
87
///////////////////////////////////////////////////////////////////////////////////////////////////
88
/**
89
 * Only for use by the library itself.
90
 *
91
 * @y.exclude
92
 */
93
  public abstract boolean compute(float[] uniforms, int index, long currentDuration, long step );
94

    
95
///////////////////////////////////////////////////////////////////////////////////////////////////
96
// PUBLIC API
97
///////////////////////////////////////////////////////////////////////////////////////////////////
98
/**
99
 * Do the set of Uniforms written in buffer[index], buffer[index+1], etc represent a Unity, i.e a
100
 * null Effect?
101
 */
102
  public boolean isUnity(float[] buffer, int index)
103
    {
104
    int name = mName.ordinal();
105

    
106
    switch(mUnityDim[name])
107
      {
108
      case 0: return true;
109
      case 1: return buffer[index  ]==mUnity[MAX_UNITY_DIM*name  ];
110
      case 2: return buffer[index  ]==mUnity[MAX_UNITY_DIM*name  ] &&
111
                     buffer[index+1]==mUnity[MAX_UNITY_DIM*name+1];
112
      case 3: return buffer[index  ]==mUnity[MAX_UNITY_DIM*name  ] &&
113
                     buffer[index+1]==mUnity[MAX_UNITY_DIM*name+1] &&
114
                     buffer[index+2]==mUnity[MAX_UNITY_DIM*name+2];
115
      case 4: return buffer[index  ]==mUnity[MAX_UNITY_DIM*name  ] &&
116
                     buffer[index+1]==mUnity[MAX_UNITY_DIM*name+1] &&
117
                     buffer[index+2]==mUnity[MAX_UNITY_DIM*name+2] &&
118
                     buffer[index+3]==mUnity[MAX_UNITY_DIM*name+3];
119
      }
120

    
121
    return false;
122
    }
123
///////////////////////////////////////////////////////////////////////////////////////////////////
124
/**
125
 * Return the EffectType enum corresponding to this Effect.
126
 *
127
 * @see EffectType
128
 */
129
  public EffectType getType()
130
    {
131
    return mType;
132
    }
133

    
134
///////////////////////////////////////////////////////////////////////////////////////////////////
135
/**
136
 * Return the EffectName enum corresponding to this Effect.
137
 *
138
 * @see EffectName
139
 */
140
  public EffectName getName()
141
    {
142
    return mName;
143
    }
144

    
145
///////////////////////////////////////////////////////////////////////////////////////////////////
146
/**
147
 * Return the unique ID of this Effect.
148
 */
149
  public long getID()
150
    {
151
    return mID;
152
    }
153

    
154
///////////////////////////////////////////////////////////////////////////////////////////////////
155
/**
156
 * Return a printable name of this Effect.
157
 */
158
  public String getString()
159
    {
160
    return mName.name();
161
    }
162

    
163
///////////////////////////////////////////////////////////////////////////////////////////////////
164
/**
165
 * Does this effect have a Center?
166
 */
167
  public boolean supportsCenter()
168
    {
169
    return mSupportsC;
170
    }
171

    
172
///////////////////////////////////////////////////////////////////////////////////////////////////
173
/**
174
 * Does this effect support being masked by a Region?
175
 */
176
  public boolean supportsRegion()
177
    {
178
    return mSupportsR;
179
    }
180

    
181
///////////////////////////////////////////////////////////////////////////////////////////////////
182
/**
183
 * Return the number of Uniforms needed to describe this effect.
184
 */
185
  public int getDimension()
186
    {
187
    return mDimension;
188
    }
189
  }
(1-1/26)