Project

General

Profile

« Previous | Next » 

Revision b547aaba

Added by Leszek Koltunski over 7 years ago

Some progress with Effect classes.

View differences:

src/main/java/org/distorted/library/Distorted.java
25 25
import android.content.res.Resources;
26 26
import org.distorted.library.program.*;
27 27

  
28
import org.distorted.library.effect.*;
29

  
30

  
31 28
///////////////////////////////////////////////////////////////////////////////////////////////////
32 29
/**
33 30
 * A singleton class used to control various global settings.
......
122 119
    EffectQueuePostprocess.createProgram(resources);
123 120
    EffectMessageSender.startSending();
124 121

  
125
    Effect.reset();
126

  
127
    String[] classes = Effect.getClassesOfPackage(context,"org.distorted.library.effect");
128
    int len = classes.length;
129

  
130
    android.util.Log.e("Distorted", "Number of classes found: "+len);
131

  
132
    for(int i=0; i<len; i++)
133
      {
134
      android.util.Log.e("Distorted", "Class found: "+classes[i]);
135
      }
136

  
137

  
138 122
    mInitialized = true;
139 123
    }
140 124

  
src/main/java/org/distorted/library/EffectNames.java
334 334
    return names[ordinal];
335 335
    }
336 336

  
337
///////////////////////////////////////////////////////////////////////////////////////////////////
338

  
339
  static void fillWithUnities(int ordinal, float[] buffer, int index)
340
    {
341
    switch(unityDimensions[ordinal])
342
      {
343
      case 0: break;
344
      case 1: buffer[index  ]=unities[MAXDIM*ordinal  ];
345
              break;
346
      case 2: buffer[index  ]=unities[MAXDIM*ordinal  ];
347
              buffer[index+1]=unities[MAXDIM*ordinal+1];
348
              break;
349
      case 3: buffer[index  ]=unities[MAXDIM*ordinal  ];
350
              buffer[index+1]=unities[MAXDIM*ordinal+1]; 
351
              buffer[index+2]=unities[MAXDIM*ordinal+2];
352
              break;
353
      case 4: buffer[index  ]=unities[MAXDIM*ordinal  ];
354
              buffer[index+1]=unities[MAXDIM*ordinal+1]; 
355
              buffer[index+2]=unities[MAXDIM*ordinal+2];
356
              buffer[index+3]=unities[MAXDIM*ordinal+3];
357
              break;
358
      }  
359
    }
360
  
361 337
///////////////////////////////////////////////////////////////////////////////////////////////////
362 338
  
363 339
  static boolean isUnity(int ordinal, float[] buffer, int index)
src/main/java/org/distorted/library/EffectQueueFragment.java
139 139
    {
140 140
    if( mMax[INDEX]>mNumEffects )
141 141
      {
142
      EffectNames.fillWithUnities(eln.ordinal(), mUniforms, NUM_UNIFORMS*mNumEffects); 
143

  
144 142
      if( data instanceof Dynamic1D)
145 143
        {
146 144
        mInter[0][mNumEffects] = (Dynamic1D)data;
......
171 169
    {
172 170
    if( mMax[INDEX]>mNumEffects )
173 171
      {
174
      EffectNames.fillWithUnities(eln.ordinal(), mUniforms, NUM_UNIFORMS*mNumEffects);
175

  
176 172
      if( data instanceof Dynamic1D)
177 173
        {
178 174
        mInter[0][mNumEffects] = (Dynamic1D)data;
......
213 209
    {
214 210
    if( mMax[INDEX]>mNumEffects )
215 211
      {
216
      EffectNames.fillWithUnities(eln.ordinal(), mUniforms, NUM_UNIFORMS*mNumEffects);
217

  
218 212
      if( level instanceof Dynamic1D)
219 213
        {
220 214
        mInter[0][mNumEffects] = (Dynamic1D)level;
......
266 260
    {
267 261
    if( mMax[INDEX]>mNumEffects )
268 262
      {
269
      EffectNames.fillWithUnities(eln.ordinal(), mUniforms, NUM_UNIFORMS*mNumEffects);
270

  
271 263
      if( level instanceof Dynamic1D)
272 264
        {
273 265
        mInter[0][mNumEffects] = (Dynamic1D)level;
src/main/java/org/distorted/library/EffectQueueVertex.java
187 187
    {
188 188
    if( mMax[INDEX]>mNumEffects )
189 189
      {
190
      EffectNames.fillWithUnities(eln.ordinal(), mUniforms, NUM_UNIFORMS*mNumEffects);
191

  
192 190
      if( data instanceof Dynamic5D)
193 191
        {
194 192
        mInter[0][mNumEffects] = (Dynamic5D)data;
......
218 216
    {
219 217
    if( mMax[INDEX]>mNumEffects )
220 218
      {
221
      EffectNames.fillWithUnities(eln.ordinal(), mUniforms, NUM_UNIFORMS*mNumEffects);    
222

  
223 219
      if( data instanceof Dynamic3D)
224 220
        {
225 221
        mInter[0][mNumEffects] = (Dynamic3D)data;
......
247 243
    {
248 244
    if( mMax[INDEX]>mNumEffects )
249 245
      {
250
      EffectNames.fillWithUnities(eln.ordinal(), mUniforms, NUM_UNIFORMS*mNumEffects);
251

  
252 246
      if( data instanceof Dynamic1D)
253 247
        {
254 248
        mInter[0][mNumEffects] = (Dynamic1D)data;
......
272 266
    {
273 267
    if( mMax[INDEX]>mNumEffects )
274 268
      {
275
      EffectNames.fillWithUnities(eln.ordinal(), mUniforms, NUM_UNIFORMS*mNumEffects);
276

  
277 269
      if( data instanceof Dynamic1D)
278 270
        {
279 271
        mInter[0][mNumEffects] = (Dynamic1D)data;
......
297 289
    {
298 290
    if( mMax[INDEX]>mNumEffects )
299 291
      {
300
      EffectNames.fillWithUnities(eln.ordinal(), mUniforms, NUM_UNIFORMS*mNumEffects);
301

  
302 292
      if( data instanceof Dynamic2D)
303 293
        {
304 294
        mInter[0][mNumEffects] = (Dynamic2D)data;
......
323 313
    {
324 314
    if( mMax[INDEX]>mNumEffects )
325 315
      {
326
      EffectNames.fillWithUnities(eln.ordinal(), mUniforms, NUM_UNIFORMS*mNumEffects);
327

  
328 316
      if( data instanceof Dynamic2D)
329 317
        {
330 318
        mInter[0][mNumEffects] = (Dynamic2D)data;
src/main/java/org/distorted/library/effect/Effect.java
21 21

  
22 22
///////////////////////////////////////////////////////////////////////////////////////////////////
23 23

  
24
import android.content.Context;
25

  
26
import java.io.File;
27
import java.io.IOException;
28
import java.net.URL;
29
import java.util.ArrayList;
30
import java.util.Enumeration;
31
import java.util.List;
32

  
33
import dalvik.system.DexFile;
34

  
35 24
public abstract class Effect
36 25
  {
37
  long mID;
26
  private final long mID;
27
  private final int mType;
28
  private final float[] mUnity;
29
  private final int mDimension;
30
  private final boolean mSupportsR;
31
  private final boolean mSupportsC;
38 32

  
39 33
  private static long mNextID = 0;
40
  static final int NUM_TYPES;
41
  static int[] mMax;
42
  static Class[] mDescendants;
43 34

  
44
  static
45
    {
46
    try
47
      {
48
      mDescendants = getClasses("org.distorted.library.effect");
49
      }
50
    catch(ClassNotFoundException cnfe)
51
      {
52
      android.util.Log.e("Effect", "ClassNotFoundException: "+cnfe.getMessage());
53
      }
54
    catch(IOException ioe)
55
      {
56
      android.util.Log.e("Effect", "IOException: "+ioe.getMessage());
57
      }
58

  
59
    NUM_TYPES = mDescendants.length;
60
    mMax = new int[NUM_TYPES];
61

  
62
    android.util.Log.e("Effect", "Found "+NUM_TYPES+" descendant classes");
63
    }
35
  public static final int MATRIX      = 0;
36
  public static final int VERTEX      = 1;
37
  public static final int FRAGMENT    = 2;
38
  public static final int POSTPROCESS = 3;
39

  
40
  public static final int LENGTH = 4;           // The number of effect types above.
41
  public static final int MASK= (1<<LENGTH)-1;  // Needed when we do bitwise operations on Effect Types.
64 42

  
65 43
///////////////////////////////////////////////////////////////////////////////////////////////////
66 44

  
67
  public static String[] getClassesOfPackage(Context c, String packageName)
45
  public static void onDestroy()
68 46
    {
69
    ArrayList<String> classes = new ArrayList<>();
70

  
71
    try
72
      {
73
      String packageCodePath = c.getPackageCodePath();
74
      DexFile df = new DexFile(packageCodePath);
75

  
76
      for (Enumeration<String> iter = df.entries(); iter.hasMoreElements(); )
77
        {
78
        String className = iter.nextElement();
79
        if (className.contains(packageName))
80
          {
81
          classes.add(className.substring(className.lastIndexOf(".") + 1, className.length()));
82
          }
83

  
84
        android.util.Log.e("Distorted", "searching: "+className);
85
        }
86
      }
87
    catch (IOException e)
88
      {
89
      e.printStackTrace();
90
      }
91

  
92
    return classes.toArray(new String[classes.size()]);
47
    mNextID = 0;
93 48
    }
94 49

  
95 50
///////////////////////////////////////////////////////////////////////////////////////////////////
96 51

  
97
  private static Class[] getClasses(String packageName) throws ClassNotFoundException, IOException
52
  public static void reset(int[] maxtable)
98 53
    {
99
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
100
    assert classLoader != null;
101
    String path = packageName.replace('.', '/');
102
    Enumeration<URL> resources = classLoader.getResources(path);
103

  
104
    android.util.Log.e("Effect", "resources: "+resources.toString());
105

  
106
    List<File> dirs = new ArrayList<>();
107

  
108
    while (resources.hasMoreElements())
109
      {
110
      URL resource = resources.nextElement();
111
      dirs.add(new File(resource.getFile()));
112
      }
113

  
114
    android.util.Log.e("Effect", "Num of dirs: "+dirs.size());
54
    maxtable[0] = MatrixEffect.MAX;
55
    maxtable[1] = VertexEffect.MAX;
56
    maxtable[2] = FragmentEffect.MAX;
57
    maxtable[3] = PostprocessEffect.MAX;
58
    }
115 59

  
116
    ArrayList<Class> classes = new ArrayList<>();
60
///////////////////////////////////////////////////////////////////////////////////////////////////
117 61

  
118
    for (File directory : dirs)
119
      {
120
      android.util.Log.e("Effect", "Searching in "+directory.getName());
62
  public int getType()
63
    {
64
    return mType;
65
    }
121 66

  
122
      classes.addAll(findClasses(directory, packageName));
123
      }
67
///////////////////////////////////////////////////////////////////////////////////////////////////
124 68

  
125
    return classes.toArray(new Class[classes.size()]);
69
  public long getID()
70
    {
71
    return mID;
126 72
    }
127 73

  
128 74
///////////////////////////////////////////////////////////////////////////////////////////////////
129 75

  
130
  private static List<Class> findClasses(File directory, String packageName) throws ClassNotFoundException
76
  public boolean supportsCenter()
131 77
    {
132
    List<Class> classes = new ArrayList<>();
133

  
134
    if (!directory.exists())
135
      {
136
      return classes;
137
      }
138

  
139
    File[] files = directory.listFiles();
140

  
141
    for (File file : files)
142
      {
143
      if (file.isDirectory())
144
        {
145
        assert !file.getName().contains(".");
146
        classes.addAll(findClasses(file, packageName + "." + file.getName()));
147
        }
148
      else if (file.getName().endsWith(".class"))
149
        {
150
        classes.add(Class.forName(packageName + '.' + file.getName().substring(0, file.getName().length() - 6)));
151
        }
152
      }
153

  
154
    return classes;
78
    return mSupportsC;
155 79
    }
156 80

  
157

  
158 81
///////////////////////////////////////////////////////////////////////////////////////////////////
159 82

  
160
  public static void onDestroy()
83
  public boolean supportsRegion()
161 84
    {
162
    mNextID = 0;
85
    return mSupportsR;
163 86
    }
164 87

  
165 88
///////////////////////////////////////////////////////////////////////////////////////////////////
166 89

  
167
  public static void reset()
90
  public int getDimension()
168 91
    {
169
    mNextID = 1;
92
    return mDimension;
170 93
    }
171 94

  
172 95
///////////////////////////////////////////////////////////////////////////////////////////////////
173 96

  
174
  Effect()
97
  Effect(int type, float[] unity, int dimension, boolean center, boolean region)
175 98
    {
176
    mID = mNextID++;
99
    mID        = mNextID++;
100
    mType      = type;
101
    mUnity     = unity;
102
    mDimension = dimension;
103
    mSupportsC = center;
104
    mSupportsR = region;
177 105
    }
178 106
  }
src/main/java/org/distorted/library/effect/FragmentEffect.java
23 23

  
24 24
public abstract class FragmentEffect extends Effect
25 25
  {
26
  
26
  static final int MAX = 5;
27

  
28
///////////////////////////////////////////////////////////////////////////////////////////////////
29

  
30
  public FragmentEffect(float[] unity, int dimension, boolean center, boolean region)
31
    {
32
    super(FRAGMENT,unity,dimension,center,region);
33
    }
27 34
  }
src/main/java/org/distorted/library/effect/MatrixEffect.java
23 23

  
24 24
public abstract class MatrixEffect extends Effect
25 25
  {
26
  static int mMax;
26
  static final int MAX = 10;
27 27

  
28
///////////////////////////////////////////////////////////////////////////////////////////////////
28 29

  
30
  public MatrixEffect(float[] unity, int dimension, boolean center, boolean region)
31
    {
32
    super(MATRIX,unity,dimension,center,region);
33
    }
29 34
  }
src/main/java/org/distorted/library/effect/PostprocessEffect.java
23 23

  
24 24
public abstract class PostprocessEffect extends Effect
25 25
  {
26
  
26
  static final int MAX = 5;
27

  
28
///////////////////////////////////////////////////////////////////////////////////////////////////
29

  
30
  public PostprocessEffect(float[] unity, int dimension, boolean center, boolean region)
31
    {
32
    super(POSTPROCESS,unity,dimension,center,region);
33
    }
27 34
  }
src/main/java/org/distorted/library/effect/VertexEffect.java
23 23

  
24 24
public abstract class VertexEffect extends Effect
25 25
  {
26
  
26
  static final int MAX = 5;
27

  
28
///////////////////////////////////////////////////////////////////////////////////////////////////
29

  
30
  public VertexEffect(float[] unity, int dimension, boolean center, boolean region)
31
    {
32
    super(VERTEX,unity,dimension,center,region);
33
    }
27 34
  }

Also available in: Unified diff