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
|
public abstract class Effect
|
25
|
{
|
26
|
private final static int MAX_UNITY_DIM = 4;
|
27
|
private final static int NUM_EFFECTS = EffectName.size();
|
28
|
|
29
|
private final long mID;
|
30
|
private final EffectType mType;
|
31
|
private final EffectName mName;
|
32
|
private final int mDimension;
|
33
|
private final boolean mSupportsR;
|
34
|
private final boolean mSupportsC;
|
35
|
|
36
|
private static long mNextID = 0;
|
37
|
|
38
|
private final static float[] mUnity= new float[MAX_UNITY_DIM*NUM_EFFECTS];
|
39
|
private final static int[] mUnityDim = new int[NUM_EFFECTS];
|
40
|
|
41
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
42
|
|
43
|
public abstract boolean compute(float[] uniforms, int index, long currentDuration, long step );
|
44
|
|
45
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
46
|
|
47
|
public static void onDestroy()
|
48
|
{
|
49
|
mNextID = 0;
|
50
|
}
|
51
|
|
52
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
53
|
|
54
|
public boolean isUnity(float[] buffer, int index)
|
55
|
{
|
56
|
int name = mName.ordinal();
|
57
|
|
58
|
switch(mUnityDim[name])
|
59
|
{
|
60
|
case 0: return true;
|
61
|
case 1: return buffer[index ]==mUnity[MAX_UNITY_DIM*name ];
|
62
|
case 2: return buffer[index ]==mUnity[MAX_UNITY_DIM*name ] &&
|
63
|
buffer[index+1]==mUnity[MAX_UNITY_DIM*name+1];
|
64
|
case 3: return buffer[index ]==mUnity[MAX_UNITY_DIM*name ] &&
|
65
|
buffer[index+1]==mUnity[MAX_UNITY_DIM*name+1] &&
|
66
|
buffer[index+2]==mUnity[MAX_UNITY_DIM*name+2];
|
67
|
case 4: return buffer[index ]==mUnity[MAX_UNITY_DIM*name ] &&
|
68
|
buffer[index+1]==mUnity[MAX_UNITY_DIM*name+1] &&
|
69
|
buffer[index+2]==mUnity[MAX_UNITY_DIM*name+2] &&
|
70
|
buffer[index+3]==mUnity[MAX_UNITY_DIM*name+3];
|
71
|
}
|
72
|
|
73
|
return false;
|
74
|
}
|
75
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
76
|
|
77
|
public EffectType getType()
|
78
|
{
|
79
|
return mType;
|
80
|
}
|
81
|
|
82
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
83
|
|
84
|
public EffectName getName()
|
85
|
{
|
86
|
return mName;
|
87
|
}
|
88
|
|
89
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
90
|
|
91
|
public long getID()
|
92
|
{
|
93
|
return mID;
|
94
|
}
|
95
|
|
96
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
97
|
|
98
|
public String getString()
|
99
|
{
|
100
|
return mName.name();
|
101
|
}
|
102
|
|
103
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
104
|
|
105
|
public boolean supportsCenter()
|
106
|
{
|
107
|
return mSupportsC;
|
108
|
}
|
109
|
|
110
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
111
|
|
112
|
public boolean supportsRegion()
|
113
|
{
|
114
|
return mSupportsR;
|
115
|
}
|
116
|
|
117
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
118
|
|
119
|
public int getDimension()
|
120
|
{
|
121
|
return mDimension;
|
122
|
}
|
123
|
|
124
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
125
|
|
126
|
Effect(EffectType type, EffectName name, int dimension, boolean center, boolean region, float[] unity)
|
127
|
{
|
128
|
mID = mNextID++;
|
129
|
|
130
|
mName = name;
|
131
|
mType = type;
|
132
|
mDimension = dimension;
|
133
|
mSupportsC = center;
|
134
|
mSupportsR = region;
|
135
|
|
136
|
int n = name.ordinal();
|
137
|
int l = unity.length;
|
138
|
|
139
|
for(int i=0; i<l; i++)
|
140
|
{
|
141
|
mUnity[n*MAX_UNITY_DIM+i] = unity[i];
|
142
|
}
|
143
|
|
144
|
mUnityDim[n] = l;
|
145
|
}
|
146
|
}
|