Project

General

Profile

« Previous | Next » 

Revision 20dbec0e

Added by Leszek Koltunski about 5 years ago

Simplify the way applications can get notifications when an effect finishes.

Now, instead of the 'DistortedEffects.(de)registerForNotifications()' 2 APIs, we call a single 'Effect.notifyWhenFinished()'.

View differences:

src/main/java/org/distorted/library/effectqueue/EffectQueue.java
24 24
import org.distorted.library.effect.EffectType;
25 25
import org.distorted.library.main.DistortedLibrary;
26 26
import org.distorted.library.main.InternalMaster;
27
import org.distorted.library.message.EffectListener;
28
import org.distorted.library.message.EffectMessage;
29
import org.distorted.library.message.EffectMessageSender;
30 27

  
31 28
import java.util.ArrayList;
32 29
import java.util.HashMap;
......
53 50
  Effect[] mEffects;
54 51
  int[] mName;
55 52
  long mTime=0;
56
  ArrayList<EffectListener> mListeners =null;
57
  int mNumListeners=0;  // ==mListeners.length(), but we only create mListeners if the first one gets added
58
  long mDistortedEffectsID;
59 53

  
60 54
  private static int[] mMax = new int[EffectType.LENGTH];
61 55
  private static long mNextID;
......
90 84
  
91 85
///////////////////////////////////////////////////////////////////////////////////////////////////
92 86
   
93
  EffectQueue(long id, int numUniforms, int index)
87
  EffectQueue(int numUniforms, int index)
94 88
    {
95 89
    mCreated            = false;
96 90
    mID                 = 0;
97 91
    mNumEffects         = 0;
98 92
    mNumEffectsToBe     = 0;
99
    mDistortedEffectsID = id;
100 93
    mIndex              = index;
101 94

  
102 95
    mJobs.add(new Job(CREATE,numUniforms,false,null));  // create the stuff that depends on max number
......
105 98

  
106 99
///////////////////////////////////////////////////////////////////////////////////////////////////
107 100

  
108
  public static void allocateQueues(EffectQueue[] queues, EffectQueue[] from, int flags, long id)
101
  public static void allocateQueues(EffectQueue[] queues, EffectQueue[] from, int flags)
109 102
    {
110
    queues[0] = (flags & DistortedLibrary.CLONE_MATRIX     ) != 0 ? from[0] : new EffectQueueMatrix(id);
111
    queues[1] = (flags & DistortedLibrary.CLONE_VERTEX     ) != 0 ? from[1] : new EffectQueueVertex(id);
112
    queues[2] = (flags & DistortedLibrary.CLONE_FRAGMENT   ) != 0 ? from[2] : new EffectQueueFragment(id);
113
    queues[3] = (flags & DistortedLibrary.CLONE_POSTPROCESS) != 0 ? from[3] : new EffectQueuePostprocess(id);
103
    queues[0] = (flags & DistortedLibrary.CLONE_MATRIX     ) != 0 ? from[0] : new EffectQueueMatrix();
104
    queues[1] = (flags & DistortedLibrary.CLONE_VERTEX     ) != 0 ? from[1] : new EffectQueueVertex();
105
    queues[2] = (flags & DistortedLibrary.CLONE_FRAGMENT   ) != 0 ? from[2] : new EffectQueueFragment();
106
    queues[3] = (flags & DistortedLibrary.CLONE_POSTPROCESS) != 0 ? from[3] : new EffectQueuePostprocess();
114 107
    }
115 108

  
116 109
///////////////////////////////////////////////////////////////////////////////////////////////////
......
205 198
    return mMax[index];
206 199
    }
207 200

  
208
///////////////////////////////////////////////////////////////////////////////////////////////////
209

  
210
  public void registerForMessages(EffectListener el)
211
    {
212
    if( mListeners==null ) mListeners = new ArrayList<>();
213

  
214
    if( !mListeners.contains(el) )
215
      {
216
      mListeners.add(el);
217
      mNumListeners++;
218
      }
219
    }
220
 
221
///////////////////////////////////////////////////////////////////////////////////////////////////
222

  
223
  public void deregisterForMessages(EffectListener el)
224
    {
225
    if( mListeners.remove(el) )
226
      {
227
      mNumListeners--;
228
      }
229
    }
230

  
231 201
///////////////////////////////////////////////////////////////////////////////////////////////////
232 202

  
233 203
  public static void onDestroy()
......
244 214
    {
245 215
    mNumEffects--;
246 216

  
247
    long removedID = mEffects[effect].getID();
248

  
249 217
    for(int j=effect; j<mNumEffects; j++ )
250 218
      {
251 219
      mEffects[j]         = mEffects[j+1];
......
254 222
      }
255 223

  
256 224
    mEffects[mNumEffects] = null;
257

  
258
    for(int i=0; i<mNumListeners; i++)
259
      EffectMessageSender.newMessage( mListeners.get(i), EffectMessage.EFFECT_REMOVED, removedID, mDistortedEffectsID);
260 225
    }
261 226

  
262 227
///////////////////////////////////////////////////////////////////////////////////////////////////
......
441 406
        case DETALL: for(int j=0; j<mNumEffects; j++ )
442 407
                       {
443 408
                       changed = true;
444

  
445
                       if( job.notify )
446
                         {
447
                         for(int k=0; k<mNumListeners; k++)
448
                           EffectMessageSender.newMessage( mListeners.get(k), EffectMessage.EFFECT_REMOVED, mEffects[j].getID(), mDistortedEffectsID);
449
                         }
450

  
451 409
                       mEffects[j] = null;
452 410
                       }
453 411

  

Also available in: Unified diff