Project

General

Profile

« Previous | Next » 

Revision 8d5a8e06

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/examples/starwars/StarWarsRenderer.java
40 40
import org.distorted.library.type.Static1D;
41 41
import org.distorted.library.type.Static3D;
42 42
import org.distorted.library.message.EffectListener;
43
import org.distorted.library.message.EffectMessage;
44 43
import org.distorted.library.main.DistortedLibrary;
45 44
import org.distorted.library.main.DistortedTexture;
46 45
import org.distorted.library.main.DistortedEffects;
......
113 112
  private DistortedScreen mScreen;
114 113
  private MeshFlat mQuad;
115 114

  
116
  private long gffaID, logoID, crawlID;
115
  private long alphaEffectID, scaleEffectID, moveEffectID;
117 116
  private Random mRnd = new Random(0);
118 117
  private int mWidth, mHeight;
119 118

  
......
245 244
    di.add(new Static1D(1.0f));
246 245
    di.add(new Static1D(1.0f));
247 246
    di.add(new Static1D(0.0f));
248
    
247

  
248
    FragmentEffectAlpha alpha = new FragmentEffectAlpha(di);
249
    alpha.notifyWhenFinished(this);
250
    alphaEffectID = alpha.getID();
251

  
249 252
    mGFFAEffects.apply( new MatrixEffectMove(new Static3D(w/5,2*h/3,0)) );
250 253
    mGFFAEffects.apply( new MatrixEffectScale(scale) );
251
    mGFFAEffects.apply( new FragmentEffectAlpha(di) );
254
    mGFFAEffects.apply( alpha );
252 255
      
253 256
    mScreen.attach(mGFFATexture, mGFFAEffects, mQuad);
254
    mGFFAEffects.registerForMessages(this);
255 257
    }
256 258
    
257 259
///////////////////////////////////////////////////////////////////////////////////////////////////
......
321 323
    ///// create Stars ///////////////////
322 324
    if( mStarTexture==null ) mStarTexture = new DistortedTexture(bitmapStar.getWidth(),bitmapStar.getHeight());
323 325
    mStarTexture.setTexture(bitmapStar);
324

  
325
    gffaID = mGFFAEffects.getID();
326
    logoID = mLogoEffects.getID();
327
    crawlID= mCrawlEffects.getID();
328 326
    }
329 327
 
330 328
///////////////////////////////////////////////////////////////////////////////////////////////////
......
370 368
    }
371 369
    
372 370
///////////////////////////////////////////////////////////////////////////////////////////////////
373
// the library sending messages to us. This is running on a library 'MessageSender' thread.
374 371

  
375
  public void effectMessage(final EffectMessage em, final long effectID, final long objectID)
372
  public void effectFinished(final long effectID)
376 373
    {
377
    if( em==EffectMessage.EFFECT_FINISHED )
374
    if( effectID == alphaEffectID )
378 375
      {
379
      if( objectID == gffaID )
380
        {
381
        mScreen.detach(mGFFAEffects);
382
        mGFFATexture.markForDeletion();
376
      mScreen.detach(mGFFAEffects);
377
      mGFFATexture.markForDeletion();
383 378

  
384
        int screenW=mScreen.getWidth();
385
        int screenH=mScreen.getHeight();
379
      int screenW=mScreen.getWidth();
380
      int screenH=mScreen.getHeight();
386 381
        
387
        int logoW = mLogoTexture.getWidth();
388
        int logoH = mLogoTexture.getHeight();
382
      int logoW = mLogoTexture.getWidth();
383
      int logoH = mLogoTexture.getHeight();
389 384
      
390
        int initSize= (int)(3.0f*screenW/logoW);
391
        int finaSize= (int)(0.1f*screenW/logoW);
385
      int initSize= (int)(3.0f*screenW/logoW);
386
      int finaSize= (int)(0.1f*screenW/logoW);
392 387
      
393
        Dynamic3D di = new Dynamic3D(10000,0.5f);
394
        di.add(new Static3D(initSize,initSize,1));
395
        di.add(new Static3D(finaSize,finaSize,1));
396

  
397
        mLogoEffects.apply( new MatrixEffectMove(new Static3D(screenW/2,screenH/2,0)) );
398
        mLogoEffects.apply( new MatrixEffectScale(di) );
399
        mLogoEffects.apply( new MatrixEffectMove(new Static3D(-logoW/2,-logoH/2,0)) );
388
      Dynamic3D di = new Dynamic3D(10000,0.5f);
389
      di.add(new Static3D(initSize,initSize,1));
390
      di.add(new Static3D(finaSize,finaSize,1));
391
      MatrixEffectScale scale = new MatrixEffectScale(di);
392
      scale.notifyWhenFinished(this);
393
      scaleEffectID = scale.getID();
394

  
395
      mLogoEffects.apply( new MatrixEffectMove(new Static3D(screenW/2,screenH/2,0)) );
396
      mLogoEffects.apply( scale );
397
      mLogoEffects.apply( new MatrixEffectMove(new Static3D(-logoW/2,-logoH/2,0)) );
400 398
      
401
        mScreen.attach(mLogoTexture, mLogoEffects,mQuad);
402
        mLogoEffects.registerForMessages(this);
403
        }
404
      else if( objectID==logoID )
405
        {
406
        mScreen.detach(mLogoEffects);
407
        mLogoTexture.markForDeletion();
399
      mScreen.attach(mLogoTexture, mLogoEffects,mQuad);
400
      }
401
    else if( effectID == scaleEffectID )
402
      {
403
      mScreen.detach(mLogoEffects);
404
      mLogoTexture.markForDeletion();
408 405
        
409
        int crawlW = mCrawlTexture.getWidth();
410
        int crawlH = mCrawlTexture.getHeight();
411
        int screenW= mScreen.getWidth();
412
        int backH  = mCrawlBackgroundTexture.getHeight();
413
        float scale= (float)screenW/crawlW;
414

  
415
        mCrawlBackgroundEffects.apply( new MatrixEffectRotate(new Static1D(CRAWL_ANGLE), new Static3D(1,0,0), new Static3D(screenW/2,0,0)) );
416

  
417
        final int transpDist = 5;
418
        Static3D center = new Static3D( screenW/2 , transpDist*backH , 0 );
419
        Static3D region = new Static3D( transpDist*backH , transpDist*backH , transpDist*backH );
420
        mCrawlBackgroundEffects.apply( new FragmentEffectAlpha(new Static1D(1-transpDist*0.6f), center, region, true) );
421

  
422
        Dynamic3D di = new Dynamic3D(70000,0.5f);
423
        di.add(new Static3D(screenW/2,-scale*crawlH/2        , 0));
424
        di.add(new Static3D(screenW/2,+scale*crawlH/2 + backH, 0));
425

  
426
        mCrawlEffects.apply( new MatrixEffectMove(di) );
427
        mCrawlEffects.apply( new MatrixEffectScale(new Static3D(scale,scale,scale)) );
428
        mCrawlEffects.apply( new MatrixEffectMove(new Static3D(-crawlW/2,-crawlH/2,0)) );
406
      int crawlW = mCrawlTexture.getWidth();
407
      int crawlH = mCrawlTexture.getHeight();
408
      int screenW= mScreen.getWidth();
409
      int backH  = mCrawlBackgroundTexture.getHeight();
410
      float scale= (float)screenW/crawlW;
411

  
412
      mCrawlBackgroundEffects.apply( new MatrixEffectRotate(new Static1D(CRAWL_ANGLE), new Static3D(1,0,0), new Static3D(screenW/2,0,0)) );
413

  
414
      final int transpDist = 5;
415
      Static3D center = new Static3D( screenW/2 , transpDist*backH , 0 );
416
      Static3D region = new Static3D( transpDist*backH , transpDist*backH , transpDist*backH );
417
      mCrawlBackgroundEffects.apply( new FragmentEffectAlpha(new Static1D(1-transpDist*0.6f), center, region, true) );
418

  
419
      Dynamic3D di = new Dynamic3D(70000,0.5f);
420
      di.add(new Static3D(screenW/2,-scale*crawlH/2        , 0));
421
      di.add(new Static3D(screenW/2,+scale*crawlH/2 + backH, 0));
422
      MatrixEffectMove move = new MatrixEffectMove(di);
423
      move.notifyWhenFinished(this);
424
      moveEffectID = move.getID();
425

  
426
      mCrawlEffects.apply( move );
427
      mCrawlEffects.apply( new MatrixEffectScale(new Static3D(scale,scale,scale)) );
428
      mCrawlEffects.apply( new MatrixEffectMove(new Static3D(-crawlW/2,-crawlH/2,0)) );
429 429
        
430
        mBackground = mScreen.attach(mCrawlBackgroundTexture, mCrawlBackgroundEffects,mQuad);
431
        mBackground.attach(mCrawlTexture, mCrawlEffects,mQuad);
432
        mBackground.glDisable(GLES31.GL_DEPTH_TEST);
433
        mBackground.glDepthMask(false);
434
        mCrawlEffects.registerForMessages(this);
435
        }
436
      else if( objectID==crawlID )
437
        {
438
        mScreen.detach(mBackground);
439
        mBackground.detach(mCrawlEffects);
440
        mCrawlTexture.markForDeletion();
441
        mCrawlBackgroundEffects.abortAllEffects();
442
        mCrawlBackgroundTexture.markForDeletion();
443
        }
430
      mBackground = mScreen.attach(mCrawlBackgroundTexture, mCrawlBackgroundEffects,mQuad);
431
      mBackground.attach(mCrawlTexture, mCrawlEffects,mQuad);
432
      mBackground.glDisable(GLES31.GL_DEPTH_TEST);
433
      mBackground.glDepthMask(false);
434
      }
435
    else if( effectID == moveEffectID )
436
      {
437
      mScreen.detach(mBackground);
438
      mBackground.detach(mCrawlEffects);
439
      mCrawlTexture.markForDeletion();
440
      mCrawlBackgroundEffects.abortAllEffects();
441
      mCrawlBackgroundTexture.markForDeletion();
444 442
      }
445 443
    }
446 444
  }

Also available in: Unified diff