Project

General

Profile

« Previous | Next » 

Revision 9becf30e

Added by Leszek Koltunski over 3 years ago

Speedup: remember the mesh associations of VertexEffects only once, when they actually change, and not every time we compute() a VertexQueue.

View differences:

src/main/java/org/distorted/library/effectqueue/EffectQueue.java
267 267
///////////////////////////////////////////////////////////////////////////////////////////////////
268 268
// this assumes 0<=effect
269 269

  
270
  protected void remove(int effect)
270
  private void removeNow(int pos)
271 271
    {
272
    if( mNumEffects>effect )
272
    if( mNumEffects>pos )
273 273
      {
274 274
      mNumEffects--;
275
      System.arraycopy(mEffects, effect+1, mEffects, effect, mNumEffects-effect);
276
      System.arraycopy(mIntUniforms, mNumIntUniforms*(effect+1), mIntUniforms, mNumIntUniforms*effect, mNumIntUniforms*(mNumEffects-effect) );
275
      System.arraycopy(mEffects, pos+1, mEffects, pos, mNumEffects-pos);
276
      System.arraycopy(mIntUniforms, mNumIntUniforms*(pos+1), mIntUniforms, mNumIntUniforms*pos, mNumIntUniforms*(mNumEffects-pos) );
277 277
      mEffects[mNumEffects] = null;
278 278
      }
279 279
    }
280 280

  
281
///////////////////////////////////////////////////////////////////////////////////////////////////
282

  
283
  private void addNow(int pos, Effect effect)
284
    {
285
    mEffects[pos]                     = effect;
286
    mIntUniforms[mNumIntUniforms*pos] = effect.getName().ordinal();
287

  
288
    if( mIndex==EffectType.VERTEX.ordinal() )
289
      {
290
      effect.writeAssociations(mIntUniforms, mNumIntUniforms*pos+1, mNumIntUniforms*pos+3);
291
      }
292
    }
293

  
281 294
///////////////////////////////////////////////////////////////////////////////////////////////////
282 295

  
283 296
  public synchronized int removeByName(EffectName name)
......
437 450
                       {                            // added effects and then lowered mMax
438 451
                       int position = job.num1;
439 452

  
440
                       if( position==-1 )
453
                       if( position<0 )
441 454
                         {
442
                         mEffects[mNumEffects]                     = job.effect;
443
                         mIntUniforms[mNumIntUniforms*mNumEffects] = job.effect.getName().ordinal();
444

  
455
                         addNow(mNumEffects,job.effect);
445 456
                         mNumEffects++;
446 457
                         changed = true;
447 458
                         }
448
                       else if( position>=0 && position<=mNumEffects )
459
                       else if( position<=mNumEffects )
449 460
                         {
450 461
                         System.arraycopy(mEffects    , position, mEffects    , position+1, mNumEffects-position);
451 462
                         System.arraycopy(mIntUniforms, mNumIntUniforms*position, mIntUniforms, mNumIntUniforms*(position+1), mNumIntUniforms*(mNumEffects-position) );
452

  
453
                         mEffects[position]                     = job.effect;
454
                         mIntUniforms[mNumIntUniforms*position] = job.effect.getName().ordinal();
455

  
463
                         addNow(position,job.effect);
456 464
                         mNumEffects++;
457 465
                         changed = true;
458 466
                         }
......
466 474
                       {
467 475
                       if (mEffects[j] == job.effect)
468 476
                         {
469
                         remove(j);
477
                         removeNow(j);
470 478
                         changed = true;
471 479
                         break;
472 480
                         }

Also available in: Unified diff