Project

General

Profile

« Previous | Next » 

Revision 1418a5eb

Added by Leszek Koltunski almost 6 years ago

Relax requirements on when we can call DistortedEffects.setMax().

Before this change one had to call it before creation of shaders and before any of the DistortedEffects classes got created.
This commit removes the second requirement so now with setMax it's just like with enabling effects: it's best done in onSurfaceCreated.

View differences:

src/main/java/org/distorted/library/main/EffectQueue.java
33 33

  
34 34
abstract class EffectQueue implements DistortedMaster.Slave
35 35
  {
36
  private static final int ATTACH = 0;
37
  private static final int DETACH = 1;
38
  private static final int DETALL = 2;
36
  private static final int CREATE = 0;
37
  private static final int ATTACH = 1;
38
  private static final int DETACH = 2;
39
  private static final int DETALL = 3;
39 40

  
40 41
  int mNumEffects;      // 'ToBe' will be more than mNumEffects if doWork() hasn't
41 42
  int mNumEffectsToBe;  // added them yet (or less if it hasn't removed some yet)
......
54 55
                                                                         // single long - the queue ID.
55 56
  private ArrayList<DistortedNode> mNodes = null;
56 57
  private long mID;
57
  private static boolean mCreated;
58 58
  private int mIndex;
59 59

  
60 60
  private class Job
61 61
    {
62 62
    int type;
63
    int num;
63 64
    boolean notify;
64 65
    Effect effect;
65 66

  
66
    Job(int t, boolean n, Effect e)
67
    Job(int t, int m, boolean n, Effect e)
67 68
      {
68 69
      type  = t;
70
      num   = m;
69 71
      notify= n;
70 72
      effect= e;
71 73
      }
......
88 90
    mDistortedEffectsID = id;
89 91
    mIndex              = index;
90 92

  
91
    int max = mMax[mIndex];
92

  
93
    if( max>0 )
94
      {
95
      mUniforms        = new float[numUniforms*max];
96
      mCurrentDuration = new long[max];
97
      mEffects         = new Effect[max];
98
      mName            = new int[max];
99
      }
100
   
101
    mCreated = true;  
93
    mJobs.add(new Job(CREATE,numUniforms,false,null));  // create the stuff that depends on max number
94
    DistortedMaster.newSlave(this);                     // of uniforms later, on first render.
102 95
    }
103 96

  
104 97
///////////////////////////////////////////////////////////////////////////////////////////////////
......
172 165

  
173 166
  static boolean setMax(int index, int m)
174 167
    {
175
    if( (!mCreated && !Distorted.isInitialized()) || m<=mMax[index] )
168
    if( !Distorted.isInitialized() || m<=mMax[index] )
176 169
      {
177 170
      mMax[index] = m<0 ? 0:m;
178 171
      return true;
......
218 211
    mNextID = 1;
219 212
    mMapID.clear();
220 213
    EffectType.reset(mMax);
221
    mCreated = false;  
222 214
    }
223 215

  
224 216
///////////////////////////////////////////////////////////////////////////////////////////////////
......
253 245
      {
254 246
      if( mEffects[i].getName() == name )
255 247
        {
256
        mJobs.add(new Job(DETACH,true,mEffects[i]));
248
        mJobs.add(new Job(DETACH,0,true,mEffects[i]));
257 249
        ret++;
258 250
        }
259 251
      }
......
275 267
      {
276 268
      if( mEffects[i].getID() == id )
277 269
        {
278
        mJobs.add(new Job(DETACH,true,mEffects[i]));
270
        mJobs.add(new Job(DETACH,0,true,mEffects[i]));
279 271
        DistortedMaster.newSlave(this);
280 272
        mNumEffectsToBe--;
281 273
        return 1;
......
293 285
      {
294 286
      if( mEffects[i]==effect )
295 287
        {
296
        mJobs.add(new Job(DETACH,true,mEffects[i]));
288
        mJobs.add(new Job(DETACH,0,true,mEffects[i]));
297 289
        DistortedMaster.newSlave(this);
298 290
        mNumEffectsToBe--;
299 291
        return 1;
......
309 301

  
310 302
  synchronized int abortAll(boolean notify)
311 303
    {
312
    mJobs.add(new Job(DETALL,notify,null));
304
    mJobs.add(new Job(DETALL,0,notify,null));
313 305
    DistortedMaster.newSlave(this);
314 306
    mNumEffectsToBe = 0;
315 307
    return mNumEffects;
......
324 316
      //android.util.Log.e("queue", "scheduling future add of "+effect.getName().name()+" to "+mNumEffectsToBe+" id="+effect.getID());
325 317
      //android.util.Log.e("queue", "queue id="+mDistortedEffectsID);
326 318

  
327
      mJobs.add(new Job(ATTACH,false,effect));
319
      mJobs.add(new Job(ATTACH,0,false,effect));
328 320
      DistortedMaster.newSlave(this);
329 321
      mNumEffectsToBe++;
330 322
      return true;
......
352 344

  
353 345
      switch(job.type)
354 346
        {
355
        case ATTACH: //android.util.Log.e("queue", "DisEffects ID: "+mDistortedEffectsID+" bank:"+mNumEffects+
356
                     //                   " attaching effectID="+job.effect.getID()+" ("+job.effect.getName().name()+")");
357

  
358
                     mCurrentDuration[mNumEffects] = 0;
359
                     mEffects[mNumEffects] = job.effect;
360
                     mName[mNumEffects] = job.effect.getName().ordinal();
361
                     mNumEffects++;
362
                     //android.util.Log.d("queue", "DisEffects ID: "+mDistortedEffectsID+
363
                     //        " success attaching, num to be:"+mNumEffectsToBe+" num:"+mNumEffects);
347
        case CREATE: int max = mMax[mIndex];
364 348

  
349
                     if( max>0 )
350
                       {
351
                       mUniforms        = new float[max*job.num];
352
                       mCurrentDuration = new long[max];
353
                       mEffects         = new Effect[max];
354
                       mName            = new int[max];
355
                       }
356
                     break;
357
        case ATTACH: if( mMax[mIndex]>mNumEffects ) // it is possible that we have first
358
                       {                            // added effects and then lowered mMax
359
                       mCurrentDuration[mNumEffects] = 0;
360
                       mEffects[mNumEffects] = job.effect;
361
                       mName[mNumEffects] = job.effect.getName().ordinal();
362
                       mNumEffects++;
363
                       }
364
                     else
365
                       {
366
                       android.util.Log.e("queue", "failed to add effect "+job.effect.getName());
367
                       }
365 368
                     break;
366
        case DETACH: //android.util.Log.e("queue", "DisEffects ID: "+mDistortedEffectsID+" detaching effect "+
367
                     //                             job.effect.getID());
368
                     for(int j=0; j<mNumEffects; j++)
369
        case DETACH: for(int j=0; j<mNumEffects; j++)
369 370
                       {
370 371
                       if (mEffects[j] == job.effect)
371 372
                         {
372 373
                         remove(j);
373
                         //android.util.Log.d("queue", "DisEffects ID: "+mDistortedEffectsID+
374
                         //    " success detaching, num to be:"+mNumEffectsToBe+" num:"+mNumEffects);
375

  
376 374
                         break;
377 375
                         }
378 376
                       }

Also available in: Unified diff