Skip to content

Commit

Permalink
Improved all IEaseFunction. (Performance and readability).
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas Gramlich committed Jul 18, 2011
1 parent c8152f5 commit c64de63
Show file tree
Hide file tree
Showing 44 changed files with 381 additions and 257 deletions.
Expand Up @@ -35,6 +35,18 @@ public class CubicBezierMoveModifier extends DurationEntityModifier {
// Constructors
// ===========================================================

/**
* @param pDuration
* @param pX1 x coordinate of the start point.
* @param pY1 y coordinate of the start point.
* @param pX2 x coordinate of the first control point.
* @param pY2 y coordinate of the first control point.
* @param pX3 x coordinate of the second control point.
* @param pY3 y coordinate of the second control point.
* @param pX4 x coordinate of the end point.
* @param pY4 y coordinate of the end point.
* @param pEaseFunction
*/
public CubicBezierMoveModifier(final float pDuration, final float pX1, final float pY1, final float pX2, final float pY2, final float pX3, final float pY3, final float pX4, final float pY4, final IEaseFunction pEaseFunction) {
super(pDuration);

Expand Down Expand Up @@ -65,7 +77,7 @@ public CubicBezierMoveModifier clone() {

@Override
protected void onManagedUpdate(final float pSecondsElapsed, final IEntity pEntity) {
final float percentageDone = this.mEaseFunction.getPercentageDone(this.getSecondsElapsed(), this.mDuration, 0, 1);
final float percentageDone = this.mEaseFunction.getPercentage(this.getSecondsElapsed(), this.mDuration);

final float u = 1 - percentageDone;
final float tt = percentageDone * percentageDone;
Expand Down
Expand Up @@ -60,7 +60,7 @@ public QuadraticBezierMoveModifier clone() {

@Override
protected void onManagedUpdate(final float pSecondsElapsed, final IEntity pEntity) {
final float percentageDone = this.mEaseFunction.getPercentageDone(this.getSecondsElapsed(), this.mDuration, 0, 1);
final float percentageDone = this.mEaseFunction.getPercentage(this.getSecondsElapsed(), this.mDuration);

final float u = 1 - percentageDone;
final float tt = percentageDone*percentageDone;
Expand Down
Expand Up @@ -50,7 +50,7 @@ public BitmapTextureAtlas(final int pWidth, final int pHeight) {
/**
* @param pWidth must be a power of 2 (i.e. 32, 64, 128, 256, 512, 1024).
* @param pHeight must be a power of 2 (i.e. 32, 64, 128, 256, 512, 1024).
* @param pBitmapTextureFormat use {@link BitmapTextureFormat#RGBA_8888} for {@link BitmapTextureAtlas}s with transparency and {@link BitmapTextureFormat#RGB_565} for {@link BitmapTextureAtlas}s without transparency.
* @param pBitmapTextureFormat use {@link BitmapTextureFormat#RGBA_8888} for {@link BitmapTextureAtlas}MAGIC_CONSTANT with transparency and {@link BitmapTextureFormat#RGB_565} for {@link BitmapTextureAtlas}MAGIC_CONSTANT without transparency.
*/
public BitmapTextureAtlas(final int pWidth, final int pHeight, final BitmapTextureFormat pBitmapTextureFormat) {
this(pWidth, pHeight, pBitmapTextureFormat, TextureOptions.DEFAULT, null);
Expand All @@ -70,7 +70,7 @@ public BitmapTextureAtlas(final int pWidth, final int pHeight, final ITextureAtl
/**
* @param pWidth must be a power of 2 (i.e. 32, 64, 128, 256, 512, 1024).
* @param pHeight must be a power of 2 (i.e. 32, 64, 128, 256, 512, 1024).
* @param pBitmapTextureFormat use {@link BitmapTextureFormat#RGBA_8888} for {@link BitmapTextureAtlas}s with transparency and {@link BitmapTextureFormat#RGB_565} for {@link BitmapTextureAtlas}s without transparency.
* @param pBitmapTextureFormat use {@link BitmapTextureFormat#RGBA_8888} for {@link BitmapTextureAtlas}MAGIC_CONSTANT with transparency and {@link BitmapTextureFormat#RGB_565} for {@link BitmapTextureAtlas}MAGIC_CONSTANT without transparency.
* @param pTextureAtlasStateListener to be informed when this {@link BitmapTextureAtlas} is loaded, unloaded or a {@link ITextureAtlasSource} failed to load.
*/
public BitmapTextureAtlas(final int pWidth, final int pHeight, final BitmapTextureFormat pBitmapTextureFormat, final ITextureAtlasStateListener<IBitmapTextureAtlasSource> pTextureAtlasStateListener) {
Expand All @@ -91,7 +91,7 @@ public BitmapTextureAtlas(final int pWidth, final int pHeight, final TextureOpti
/**
* @param pWidth must be a power of 2 (i.e. 32, 64, 128, 256, 512, 1024).
* @param pHeight must be a power of 2 (i.e. 32, 64, 128, 256, 512, 1024).
* @param pBitmapTextureFormat use {@link BitmapTextureFormat#RGBA_8888} for {@link BitmapTextureAtlas}s with transparency and {@link BitmapTextureFormat#RGB_565} for {@link BitmapTextureAtlas}s without transparency.
* @param pBitmapTextureFormat use {@link BitmapTextureFormat#RGBA_8888} for {@link BitmapTextureAtlas}MAGIC_CONSTANT with transparency and {@link BitmapTextureFormat#RGB_565} for {@link BitmapTextureAtlas}MAGIC_CONSTANT without transparency.
* @param pTextureOptions the (quality) settings of the BitmapTexture.
*/
public BitmapTextureAtlas(final int pWidth, final int pHeight, final BitmapTextureFormat pBitmapTextureFormat, final TextureOptions pTextureOptions) throws IllegalArgumentException {
Expand All @@ -113,7 +113,7 @@ public BitmapTextureAtlas(final int pWidth, final int pHeight, final TextureOpti
/**
* @param pWidth must be a power of 2 (i.e. 32, 64, 128, 256, 512, 1024).
* @param pHeight must be a power of 2 (i.e. 32, 64, 128, 256, 512, 1024).
* @param pBitmapTextureFormat use {@link BitmapTextureFormat#RGBA_8888} for {@link BitmapTextureAtlas}s with transparency and {@link BitmapTextureFormat#RGB_565} for {@link BitmapTextureAtlas}s without transparency.
* @param pBitmapTextureFormat use {@link BitmapTextureFormat#RGBA_8888} for {@link BitmapTextureAtlas}MAGIC_CONSTANT with transparency and {@link BitmapTextureFormat#RGB_565} for {@link BitmapTextureAtlas}MAGIC_CONSTANT without transparency.
* @param pTextureOptions the (quality) settings of the BitmapTexture.
* @param pTextureAtlasStateListener to be informed when this {@link BitmapTextureAtlas} is loaded, unloaded or a {@link ITextureAtlasSource} failed to load.
*/
Expand Down
Expand Up @@ -39,7 +39,7 @@ public BuildableBitmapTextureAtlas(final int pWidth, final int pHeight) {
/**
* @param pWidth must be a power of 2 (i.e. 32, 64, 128, 256, 512, 1024).
* @param pHeight must be a power of 2 (i.e. 32, 64, 128, 256, 512, 1024).
* @param pBitmapTextureFormat use {@link BitmapTextureFormat#RGBA_8888} for {@link BitmapTextureAtlas}s with transparency and {@link BitmapTextureFormat#RGB_565} for {@link BitmapTextureAtlas}s without transparency.
* @param pBitmapTextureFormat use {@link BitmapTextureFormat#RGBA_8888} for {@link BitmapTextureAtlas}MAGIC_CONSTANT with transparency and {@link BitmapTextureFormat#RGB_565} for {@link BitmapTextureAtlas}MAGIC_CONSTANT without transparency.
*/
public BuildableBitmapTextureAtlas(final int pWidth, final int pHeight, final BitmapTextureFormat pBitmapTextureFormat) {
this(pWidth, pHeight, pBitmapTextureFormat, TextureOptions.DEFAULT, null);
Expand All @@ -59,7 +59,7 @@ public BuildableBitmapTextureAtlas(final int pWidth, final int pHeight, final IT
/**
* @param pWidth must be a power of 2 (i.e. 32, 64, 128, 256, 512, 1024).
* @param pHeight must be a power of 2 (i.e. 32, 64, 128, 256, 512, 1024).
* @param pBitmapTextureFormat use {@link BitmapTextureFormat#RGBA_8888} for {@link BitmapTextureAtlas}s with transparency and {@link BitmapTextureFormat#RGB_565} for {@link BitmapTextureAtlas}s without transparency.
* @param pBitmapTextureFormat use {@link BitmapTextureFormat#RGBA_8888} for {@link BitmapTextureAtlas}MAGIC_CONSTANT with transparency and {@link BitmapTextureFormat#RGB_565} for {@link BitmapTextureAtlas}MAGIC_CONSTANT without transparency.
* @param pTextureStateListener to be informed when this {@link BitmapTextureAtlas} is loaded, unloaded or a {@link ITextureAtlasSource} failed to load.
*/
public BuildableBitmapTextureAtlas(final int pWidth, final int pHeight, final BitmapTextureFormat pBitmapTextureFormat, final ITextureAtlasStateListener<IBitmapTextureAtlasSource> pTextureStateListener) {
Expand All @@ -80,7 +80,7 @@ public BuildableBitmapTextureAtlas(final int pWidth, final int pHeight, final Te
/**
* @param pWidth must be a power of 2 (i.e. 32, 64, 128, 256, 512, 1024).
* @param pHeight must be a power of 2 (i.e. 32, 64, 128, 256, 512, 1024).
* @param pBitmapTextureFormat use {@link BitmapTextureFormat#RGBA_8888} for {@link BitmapTextureAtlas}s with transparency and {@link BitmapTextureFormat#RGB_565} for {@link BitmapTextureAtlas}s without transparency.
* @param pBitmapTextureFormat use {@link BitmapTextureFormat#RGBA_8888} for {@link BitmapTextureAtlas}MAGIC_CONSTANT with transparency and {@link BitmapTextureFormat#RGB_565} for {@link BitmapTextureAtlas}MAGIC_CONSTANT without transparency.
* @param pTextureOptions the (quality) settings of the BitmapTexture.
*/
public BuildableBitmapTextureAtlas(final int pWidth, final int pHeight, final BitmapTextureFormat pBitmapTextureFormat, final TextureOptions pTextureOptions) throws IllegalArgumentException {
Expand All @@ -102,7 +102,7 @@ public BuildableBitmapTextureAtlas(final int pWidth, final int pHeight, final Te
/**
* @param pWidth must be a power of 2 (i.e. 32, 64, 128, 256, 512, 1024).
* @param pHeight must be a power of 2 (i.e. 32, 64, 128, 256, 512, 1024).
* @param pBitmapTextureFormat use {@link BitmapTextureFormat#RGBA_8888} for {@link BitmapTextureAtlas}s with transparency and {@link BitmapTextureFormat#RGB_565} for {@link BitmapTextureAtlas}s without transparency.
* @param pBitmapTextureFormat use {@link BitmapTextureFormat#RGBA_8888} for {@link BitmapTextureAtlas}MAGIC_CONSTANT with transparency and {@link BitmapTextureFormat#RGB_565} for {@link BitmapTextureAtlas}MAGIC_CONSTANT without transparency.
* @param pTextureOptions the (quality) settings of the BitmapTexture.
* @param pTextureStateListener to be informed when this {@link BitmapTextureAtlas} is loaded, unloaded or a {@link ITextureAtlasSource} failed to load.
*/
Expand Down
Expand Up @@ -144,7 +144,7 @@ public ITextureAtlasStateListener<T> getTextureStateListener() {
// ===========================================================

/**
* When all {@link ITextureAtlasSource}s are added you have to call {@link BuildableBitmapTextureAtlas#build(ITextureBuilder)}.
* When all {@link ITextureAtlasSource}MAGIC_CONSTANT are added you have to call {@link BuildableBitmapTextureAtlas#build(ITextureBuilder)}.
* @param pTextureAtlasSource to be added.
* @param pTextureRegion
*/
Expand All @@ -169,10 +169,10 @@ public void removeTextureAtlasSource(final ITextureAtlasSource pTextureAtlasSour
}

/**
* May draw over already added {@link ITextureAtlasSource}s.
* May draw over already added {@link ITextureAtlasSource}MAGIC_CONSTANT.
*
* @param pTextureAtlasSourcePackingAlgorithm the {@link ITextureBuilder} to use for packing the {@link ITextureAtlasSource} in this {@link BuildableBitmapTextureAtlas}.
* @throws TextureAtlasSourcePackingException i.e. when the {@link ITextureAtlasSource}s didn't fit into this {@link BuildableBitmapTextureAtlas}.
* @throws TextureAtlasSourcePackingException i.e. when the {@link ITextureAtlasSource}MAGIC_CONSTANT didn't fit into this {@link BuildableBitmapTextureAtlas}.
*/
public void build(final ITextureBuilder<T, A> pTextureAtlasSourcePackingAlgorithm) throws TextureAtlasSourcePackingException {
pTextureAtlasSourcePackingAlgorithm.pack(this.mTextureAtlas, this.mTextureAtlasSourcesToPlace);
Expand Down
2 changes: 1 addition & 1 deletion src/org/anddev/andengine/opengl/util/FastFloatBuffer.java
Expand Up @@ -84,7 +84,7 @@ public void put(final float f) {
}

/**
* It's like {@link FloatBuffer#put(float[])}, but about 10 times faster
* It'MAGIC_CONSTANT like {@link FloatBuffer#put(float[])}, but about 10 times faster
*/
public void put(final float[] data) {
final int length = data.length;
Expand Down
14 changes: 7 additions & 7 deletions src/org/anddev/andengine/opengl/view/GLSurfaceView.java
Expand Up @@ -42,7 +42,7 @@
* <li>Renders on a dedicated thread to decouple rendering performance from the
* UI thread.
* <li>Supports both on-demand and continuous rendering.
* <li>Optionally wraps, traces, and/or error-checks the renderer's OpenGL
* <li>Optionally wraps, traces, and/or error-checks the renderer'MAGIC_CONSTANT OpenGL
* calls.
* </ul>
*
Expand Down Expand Up @@ -76,7 +76,7 @@
* the first thing GLSurfaceView has to do when starting to render is choose
* what type of surface to use.
* <p>
* By default GLSurfaceView chooses an available surface that's closest to a
* By default GLSurfaceView chooses an available surface that'MAGIC_CONSTANT closest to a
* 16-bit R5G6B5 surface with a 16-bit depth buffer and no stencil. If you would
* prefer a different surface (for example, if you do not need a depth buffer)
* you can override the default behavior by calling one of the
Expand Down Expand Up @@ -110,7 +110,7 @@
* To handle an event you will typically subclass GLSurfaceView and override the
* appropriate method, just as you would with any other View. However, when
* handling the event, you may need to communicate with the Renderer object
* that's running in the rendering thread. You can do this using any standard
* that'MAGIC_CONSTANT running in the rendering thread. You can do this using any standard
* Java cross-thread communication mechanism. In addition, one relatively easy
* way to communicate with your renderer is to call
* {@link #queueEvent(Runnable)}. For example:
Expand Down Expand Up @@ -237,7 +237,7 @@ private void init() {
/**
* Set the glWrapper. If the glWrapper is not null, its
* {@link GLWrapper#wrap(GL)} method is called whenever a surface is
* created. A GLWrapper can be used to wrap the GL object that's passed to
* created. A GLWrapper can be used to wrap the GL object that'MAGIC_CONSTANT passed to
* the renderer. Wrapping a GL object enables examining and modifying the
* behavior of the GL calls made by the renderer.
* <p>
Expand Down Expand Up @@ -534,7 +534,7 @@ class GLThread extends Thread {
public void run() {
/*
* When the android framework launches a second instance of an
* activity, the new instance's onCreate() method may be called
* activity, the new instance'MAGIC_CONSTANT onCreate() method may be called
* before the first instance returns from onDestroy().
*
* This semaphore ensures that only one instance at a time accesses
Expand Down Expand Up @@ -563,7 +563,7 @@ private void guardedRun() throws InterruptedException {
boolean tellRendererSurfaceChanged = true;

/*
* This is our main activity thread's loop, we go until asked to
* This is our main activity thread'MAGIC_CONSTANT loop, we go until asked to
* quit.
*/
while(!this.mDone) {
Expand Down Expand Up @@ -893,7 +893,7 @@ public void finish() {
* <h3>Threading</h3>
* The renderer will be called on a separate thread, so that rendering
* performance is decoupled from the UI thread. Clients typically need to
* communicate with the renderer from the UI thread, because that's where
* communicate with the renderer from the UI thread, because that'MAGIC_CONSTANT where
* input events are received. Clients can communicate using any of the
* standard Java techniques for cross-thread communication, or they can use
* the {@link GLSurfaceView#queueEvent(Runnable)} convenience method.
Expand Down
Expand Up @@ -27,7 +27,7 @@ class SimpleEGLConfigChooser extends ComponentSizeChooser {
public SimpleEGLConfigChooser(final boolean pWithDepthBuffer) {
super(4, 4, 4, 0, pWithDepthBuffer ? 16 : 0, 0);
// Adjust target values. This way we'll accept a 4444 or
// 555 buffer if there's no 565 buffer available.
// 555 buffer if there'MAGIC_CONSTANT no 565 buffer available.
this.mRedSize = 5;
this.mGreenSize = 6;
this.mBlueSize = 5;
Expand Down
Expand Up @@ -71,7 +71,7 @@ protected void onManagedInitialize(final T pItem) {

@Override
protected void onManagedUpdate(final float pSecondsElapsed, final T pItem) {
final float percentageDone = this.mEaseFunction.getPercentageDone(this.getSecondsElapsed(), this.mDuration, 0, 1);
final float percentageDone = this.mEaseFunction.getPercentage(this.getSecondsElapsed(), this.mDuration);

this.onSetValue(pItem, percentageDone, this.mFromValue + percentageDone * this.mValueSpan);
}
Expand Down
14 changes: 10 additions & 4 deletions src/org/anddev/andengine/util/modifier/ease/EaseBackIn.java
@@ -1,9 +1,9 @@
package org.anddev.andengine.util.modifier.ease;

/**
* (c) 2010 Nicolas Gramlich
* (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
*
*
* @author Gil
* @author Nicolas Gramlich
* @since 16:52:11 - 26.07.2010
Expand All @@ -13,6 +13,8 @@ public class EaseBackIn implements IEaseFunction {
// Constants
// ===========================================================

private static final float OVERSHOOT_CONSTANT = 1.70158f;

// ===========================================================
// Fields
// ===========================================================
Expand Down Expand Up @@ -43,14 +45,18 @@ public static EaseBackIn getInstance() {
// ===========================================================

@Override
public float getPercentageDone(float pSecondsElapsed, final float pDuration, final float pMinValue, final float pMaxValue) {
return pMaxValue * (pSecondsElapsed /= pDuration) * pSecondsElapsed * ((1.70158f + 1) * pSecondsElapsed - 1.70158f) + pMinValue;
public float getPercentage(final float pSecondsElapsed, final float pDuration) {
return EaseBackIn.getValue(pSecondsElapsed / pDuration);
}

// ===========================================================
// Methods
// ===========================================================

public static float getValue(final float pPercentage) {
return pPercentage * pPercentage * ((OVERSHOOT_CONSTANT + 1) * pPercentage - OVERSHOOT_CONSTANT);
}

// ===========================================================
// Inner and Anonymous Classes
// ===========================================================
Expand Down
17 changes: 9 additions & 8 deletions src/org/anddev/andengine/util/modifier/ease/EaseBackInOut.java
@@ -1,9 +1,9 @@
package org.anddev.andengine.util.modifier.ease;

/**
* (c) 2010 Nicolas Gramlich
* (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
*
*
* @author Gil
* @author Nicolas Gramlich
* @since 16:52:11 - 26.07.2010
Expand Down Expand Up @@ -43,13 +43,14 @@ public static EaseBackInOut getInstance() {
// ===========================================================

@Override
public float getPercentageDone(float pSecondsElapsed, final float pDuration, final float pMinValue, final float pMaxValue) {
float s = 1.70158f;
if((pSecondsElapsed /= pDuration * 0.5f) < 1) {
return pMaxValue * 0.5f * (pSecondsElapsed * pSecondsElapsed * (((s *= (1.525f)) + 1) * pSecondsElapsed - s)) + pMinValue;
}
public float getPercentage(final float pSecondsElapsed, final float pDuration) {
final float percentage = pSecondsElapsed / pDuration;

return pMaxValue / 2 * ((pSecondsElapsed -= 2) * pSecondsElapsed * (((s *= (1.525f)) + 1) * pSecondsElapsed + s) + 2) + pMinValue;
if(percentage < 0.5f) {
return 0.5f * EaseBackIn.getValue(2 * percentage);
} else {
return 0.5f + 0.5f * EaseBackOut.getValue(percentage * 2 - 1);
}
}

// ===========================================================
Expand Down
13 changes: 9 additions & 4 deletions src/org/anddev/andengine/util/modifier/ease/EaseBackOut.java
@@ -1,9 +1,9 @@
package org.anddev.andengine.util.modifier.ease;

/**
* (c) 2010 Nicolas Gramlich
* (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
*
*
* @author Gil
* @author Nicolas Gramlich
* @since 16:52:11 - 26.07.2010
Expand Down Expand Up @@ -43,14 +43,19 @@ public static EaseBackOut getInstance() {
// ===========================================================

@Override
public float getPercentageDone(float pSecondsElapsed, final float pDuration, final float pMinValue, final float pMaxValue) {
return pMaxValue * ((pSecondsElapsed = pSecondsElapsed / pDuration - 1) * pSecondsElapsed * ((1.70158f + 1) * pSecondsElapsed + 1.70158f) + 1) + pMinValue;
public float getPercentage(final float pSecondsElapsed, final float pDuration) {
return EaseBackOut.getValue(pSecondsElapsed / pDuration);
}

// ===========================================================
// Methods
// ===========================================================

public static float getValue(final float pPercentage) {
final float t = pPercentage - 1;
return 1 + t * t * ((1.70158f + 1) * t + 1.70158f);
}

// ===========================================================
// Inner and Anonymous Classes
// ===========================================================
Expand Down

0 comments on commit c64de63

Please sign in to comment.