Project

General

Profile

« Previous | Next » 

Revision 9becf30e

Added by Leszek Koltunski about 4 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/effect/VertexEffect.java
19 19

  
20 20
package org.distorted.library.effect;
21 21

  
22
import org.distorted.library.main.DistortedEffects;
22 23
import org.distorted.library.type.Static4D;
23 24

  
24 25
import java.lang.reflect.Method;
......
212 213
    {
213 214
    mAndAssociation = andAssociation;
214 215
    mEquAssociation = equAssociation;
216

  
217
    DistortedEffects.setAssociation(getID());
215 218
    }
216 219
  }
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
                         }
src/main/java/org/distorted/library/effectqueue/EffectQueueVertex.java
67 67
    mUniformsH[variant]  = GLES30.glGetUniformLocation( mProgramH, "vUniforms");
68 68
    }
69 69

  
70
///////////////////////////////////////////////////////////////////////////////////////////////////
71
/**
72
 * Not part of public API, do not document (public only because has to be called from DistortedEffects)
73
 *
74
 * @y.exclude
75
 */
76
  public void setAssociation(long effectID)
77
    {
78
    for(int j=0; j<mNumEffects; j++)
79
      {
80
      if (mEffects[j].getID() == effectID)
81
        {
82
        mEffects[j].writeAssociations(mIntUniforms, NUM_INT_UNIFORMS*j+1, NUM_INT_UNIFORMS*j+3);
83
        }
84
      }
85
    }
86

  
70 87
///////////////////////////////////////////////////////////////////////////////////////////////////
71 88
/**
72 89
 * Not part of public API, do not document (public only because has to be used in Meshes)
......
81 98

  
82 99
    for(int i=0; i<mNumEffects; i++)
83 100
      {
84
      mEffects[i].writeAssociations(mIntUniforms, NUM_INT_UNIFORMS*i+1, NUM_INT_UNIFORMS*i+3);
85

  
86 101
      if( mEffects[i].compute(mFloatUniforms, NUM_FLOAT_UNIFORMS*i, currTime, step) )
87 102
        {
88 103
        EffectMessageSender.newMessage(mEffects[i]);
src/main/java/org/distorted/library/main/DistortedEffects.java
23 23
import org.distorted.library.effect.EffectName;
24 24
import org.distorted.library.effectqueue.EffectQueue;
25 25
import org.distorted.library.effect.EffectType;
26
import org.distorted.library.effectqueue.EffectQueueVertex;
27

  
28
import java.util.ArrayList;
26 29

  
27 30
///////////////////////////////////////////////////////////////////////////////////////////////////
28 31
/**
......
32 35
 */
33 36
public class DistortedEffects
34 37
  {
38
  private static ArrayList<DistortedEffects> mAllEffectQueues = new ArrayList<>();
35 39
  private static long mNextID =0;
36 40
  private long mID;
37 41
  private EffectQueue[] mQueues;
......
50 54
  static void onDestroy()
51 55
    {
52 56
    mNextID =  0;
57
    mAllEffectQueues.clear();
58
    }
59

  
60
///////////////////////////////////////////////////////////////////////////////////////////////////
61
/**
62
 * @y.exclude
63
 */
64
  public static void setAssociation(long effectID)
65
    {
66
    EffectQueue[] queues;
67
    int numQueues = mAllEffectQueues.size();
68

  
69
    for(int i=0; i<numQueues; i++)
70
      {
71
      queues = mAllEffectQueues.get(i).getQueues();
72
      ((EffectQueueVertex)queues[1]).setAssociation(effectID);
73
      }
53 74
    }
54 75

  
55 76
///////////////////////////////////////////////////////////////////////////////////////////////////
......
63 84
    mID = ++mNextID;
64 85
    mQueues = new EffectQueue[EffectType.LENGTH];
65 86
    EffectQueue.allocateQueues(mQueues,null,0);
87
    mAllEffectQueues.add(this);
66 88
    }
67 89

  
68 90
///////////////////////////////////////////////////////////////////////////////////////////////////
......
80 102
    mID = ++mNextID;
81 103
    mQueues = new EffectQueue[EffectType.LENGTH];
82 104
    EffectQueue.allocateQueues(mQueues,dc.getQueues(),flags);
105
    mAllEffectQueues.add(this);
83 106
    }
84 107

  
85 108
///////////////////////////////////////////////////////////////////////////////////////////////////

Also available in: Unified diff