Revision 476bbc81
Added by Leszek Koltunski over 8 years ago
src/main/java/org/distorted/library/DistortedObject.java | ||
---|---|---|
386 | 386 |
* Aborts a single Effect. |
387 | 387 |
* |
388 | 388 |
* @param id ID of the Effect we want to abort. |
389 |
* @return <code>true</code> if the Effect was found and successfully aborted.
|
|
389 |
* @return number of Effects aborted. Always either 0 or 1.
|
|
390 | 390 |
*/ |
391 |
public boolean abortEffect(long id)
|
|
391 |
public int abortEffect(long id)
|
|
392 | 392 |
{ |
393 | 393 |
int type = (int)(id&EffectTypes.MASK); |
394 | 394 |
|
395 |
if( type==EffectTypes.MATRIX.type ) return mM.removeByID(id>>EffectTypes.LENGTH);
|
|
396 |
if( type==EffectTypes.VERTEX.type ) return mV.removeByID(id>>EffectTypes.LENGTH);
|
|
397 |
if( type==EffectTypes.FRAGMENT.type ) return mF.removeByID(id>>EffectTypes.LENGTH);
|
|
398 |
if( type==EffectTypes.OTHER.type ) return mO.removeByID(id>>EffectTypes.LENGTH);
|
|
395 |
if( type==EffectTypes.MATRIX.type ) return mM.removeByID(id>>EffectTypes.LENGTH); |
|
396 |
if( type==EffectTypes.VERTEX.type ) return mV.removeByID(id>>EffectTypes.LENGTH); |
|
397 |
if( type==EffectTypes.FRAGMENT.type ) return mF.removeByID(id>>EffectTypes.LENGTH); |
|
398 |
if( type==EffectTypes.OTHER.type ) return mO.removeByID(id>>EffectTypes.LENGTH); |
|
399 | 399 |
|
400 |
return false;
|
|
400 |
return 0;
|
|
401 | 401 |
} |
402 | 402 |
|
403 | 403 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
405 | 405 |
* Abort all Effects of a given type, for example all rotations. |
406 | 406 |
* |
407 | 407 |
* @param name one of the constants defined in {@link EffectNames} |
408 |
* @return <code>true</code> if a single Effect of type effectType has been found and aborted.
|
|
408 |
* @return number of Effects aborted.
|
|
409 | 409 |
*/ |
410 |
public boolean abortEffects(EffectNames name)
|
|
410 |
public int abortEffects(EffectNames name)
|
|
411 | 411 |
{ |
412 | 412 |
switch(name.getType()) |
413 | 413 |
{ |
... | ... | |
415 | 415 |
case VERTEX : return mV.removeByType(name); |
416 | 416 |
case FRAGMENT: return mF.removeByType(name); |
417 | 417 |
case OTHER : return mO.removeByType(name); |
418 |
default : return false;
|
|
418 |
default : return 0;
|
|
419 | 419 |
} |
420 | 420 |
} |
421 | 421 |
|
src/main/java/org/distorted/library/EffectNames.java | ||
---|---|---|
1 | 1 |
package org.distorted.library; |
2 | 2 |
|
3 | 3 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
4 |
|
|
5 |
enum EffectNames |
|
4 |
/** |
|
5 |
* Names of Effects one can apply to DistortedObjects. |
|
6 |
*/ |
|
7 |
public enum EffectNames |
|
6 | 8 |
{ |
7 | 9 |
// EFFECT NAME /////// EFFECT TYPE ////////////// UNITY ///////////////////////// |
8 | 10 |
|
... | ... | |
83 | 85 |
} |
84 | 86 |
|
85 | 87 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
86 |
|
|
87 |
public EffectTypes getType() |
|
88 |
{ |
|
89 |
return type; |
|
90 |
} |
|
91 |
|
|
92 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
93 |
// yes, I know we could have used values(i) |
|
88 |
// yes, I know we could have used values(i) but that allocates a new copy each time! |
|
94 | 89 |
|
95 | 90 |
static EffectTypes getType(int ordinal) |
96 | 91 |
{ |
... | ... | |
146 | 141 |
|
147 | 142 |
return false; |
148 | 143 |
} |
149 |
} |
|
150 | 144 |
|
151 | 145 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
152 |
|
|
146 |
// PUBLIC API |
|
147 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
148 |
/** |
|
149 |
* Returns the Type of an individual Effect. For example, EffectNames.ROTATION.getType() will |
|
150 |
* return EffectTypes.MATRIX. |
|
151 |
* @return type of the effect. |
|
152 |
*/ |
|
153 |
public EffectTypes getType() |
|
154 |
{ |
|
155 |
return type; |
|
156 |
} |
|
157 |
} |
src/main/java/org/distorted/library/EffectQueue.java | ||
---|---|---|
132 | 132 |
|
133 | 133 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
134 | 134 |
|
135 |
synchronized boolean removeByID(long id)
|
|
135 |
synchronized int removeByID(long id)
|
|
136 | 136 |
{ |
137 | 137 |
int i = getEffectIndex(id); |
138 | 138 |
|
139 | 139 |
if( i>=0 ) |
140 | 140 |
{ |
141 | 141 |
remove(i); |
142 |
return true;
|
|
142 |
return 1;
|
|
143 | 143 |
} |
144 | 144 |
|
145 |
return false;
|
|
145 |
return 0;
|
|
146 | 146 |
} |
147 | 147 |
|
148 | 148 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
149 | 149 |
|
150 |
synchronized boolean removeByType(EffectNames effect)
|
|
150 |
synchronized int removeByType(EffectNames effect)
|
|
151 | 151 |
{ |
152 |
boolean ret = false;
|
|
152 |
int ret = 0;
|
|
153 | 153 |
int ord = effect.ordinal(); |
154 | 154 |
|
155 | 155 |
for(int i=0; i<mNumEffects; i++) |
... | ... | |
157 | 157 |
if( mType[i]==ord ) |
158 | 158 |
{ |
159 | 159 |
remove(i); |
160 |
// TODO: don't we have to do a 'i--' here? Check this.
|
|
161 |
ret = true;
|
|
160 |
i--;
|
|
161 |
ret++;
|
|
162 | 162 |
} |
163 | 163 |
} |
164 | 164 |
|
Also available in: Unified diff
Bugfix for removeByType