Skip to content
Browse files

Removed usage of FloatMath since it's slower than plain Math since AP…

…I level 8.
  • Loading branch information...
1 parent 6a08408 commit 95d4ccc45440d9de6b526ba4f5101503f0769d19 Nicolas Gramlich committed Feb 10, 2013
View
2 project.properties
@@ -11,4 +11,4 @@ android.library=true
# Indicates whether an apk should be generated for each density.
split.density=false
# Project target.
-target=android-15
+target=android-17
View
4 src/org/andengine/engine/camera/hud/controls/AnalogOnScreenControl.java
@@ -8,8 +8,6 @@
import org.andengine.opengl.vbo.VertexBufferObjectManager;
import org.andengine.util.math.MathUtils;
-import android.util.FloatMath;
-
/**
* (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
@@ -82,7 +80,7 @@ protected void onUpdateControlKnob(final float pRelativeX, final float pRelative
super.onUpdateControlKnob(pRelativeX, pRelativeY);
} else {
final float angleRad = MathUtils.atan2(pRelativeY, pRelativeX);
- super.onUpdateControlKnob(FloatMath.cos(angleRad) * 0.5f, FloatMath.sin(angleRad) * 0.5f);
+ super.onUpdateControlKnob((float)Math.cos(angleRad) * 0.5f, (float)Math.sin(angleRad) * 0.5f);
}
}
View
4 src/org/andengine/entity/modifier/PathModifier.java
@@ -7,8 +7,6 @@
import org.andengine.util.modifier.ease.EaseLinear;
import org.andengine.util.modifier.ease.IEaseFunction;
-import android.util.FloatMath;
-
/**
* (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
@@ -316,7 +314,7 @@ public float getSegmentLength(final int pSegmentIndex) {
final float dx = coordinatesX[pSegmentIndex] - coordinatesX[nextSegmentIndex];
final float dy = coordinatesY[pSegmentIndex] - coordinatesY[nextSegmentIndex];
- return FloatMath.sqrt(dx * dx + dy * dy);
+ return (float)Math.sqrt(dx * dx + dy * dy);
}
// ===========================================================
View
4 src/org/andengine/entity/particle/ParticleSystem.java
@@ -13,8 +13,6 @@
import org.andengine.util.Constants;
import org.andengine.util.math.MathUtils;
-import android.util.FloatMath;
-
/**
* (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
@@ -178,7 +176,7 @@ private void spawnParticles(final float pSecondsElapsed) {
this.mParticlesDueToSpawn += newParticlesThisFrame;
- final int particlesToSpawnThisFrame = Math.min(this.mParticlesMaximum - this.mParticlesAlive, (int)FloatMath.floor(this.mParticlesDueToSpawn));
+ final int particlesToSpawnThisFrame = Math.min(this.mParticlesMaximum - this.mParticlesAlive, (int)Math.floor(this.mParticlesDueToSpawn));
this.mParticlesDueToSpawn -= particlesToSpawnThisFrame;
for (int i = 0; i < particlesToSpawnThisFrame; i++) {
View
6 src/org/andengine/entity/particle/emitter/CircleOutlineParticleEmitter.java
@@ -6,8 +6,6 @@
import org.andengine.util.math.MathConstants;
import org.andengine.util.math.MathUtils;
-import android.util.FloatMath;
-
/**
* (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
@@ -47,8 +45,8 @@ public CircleOutlineParticleEmitter(final float pCenterX, final float pCenterY,
@Override
public void getPositionOffset(final float[] pOffset) {
final float random = MathUtils.RANDOM.nextFloat() * MathConstants.PI * 2;
- pOffset[VERTEX_INDEX_X] = this.mCenterX + FloatMath.cos(random) * this.mRadiusX;
- pOffset[VERTEX_INDEX_Y] = this.mCenterY + FloatMath.sin(random) * this.mRadiusY;
+ pOffset[VERTEX_INDEX_X] = this.mCenterX + (float)Math.cos(random) * this.mRadiusX;
+ pOffset[VERTEX_INDEX_Y] = this.mCenterY + (float)Math.sin(random) * this.mRadiusY;
}
// ===========================================================
View
6 src/org/andengine/entity/particle/emitter/CircleParticleEmitter.java
@@ -6,8 +6,6 @@
import org.andengine.util.math.MathConstants;
import org.andengine.util.math.MathUtils;
-import android.util.FloatMath;
-
/**
* (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
@@ -47,8 +45,8 @@ public CircleParticleEmitter(final float pCenterX, final float pCenterY, final f
@Override
public void getPositionOffset(final float[] pOffset) {
final float random = MathUtils.RANDOM.nextFloat() * MathConstants.PI * 2;
- pOffset[VERTEX_INDEX_X] = this.mCenterX + FloatMath.cos(random) * this.mRadiusX * MathUtils.RANDOM.nextFloat();
- pOffset[VERTEX_INDEX_Y] = this.mCenterY + FloatMath.sin(random) * this.mRadiusY * MathUtils.RANDOM.nextFloat();
+ pOffset[VERTEX_INDEX_X] = this.mCenterX + (float)Math.cos(random) * this.mRadiusX * MathUtils.RANDOM.nextFloat();
+ pOffset[VERTEX_INDEX_Y] = this.mCenterY + (float)Math.sin(random) * this.mRadiusY * MathUtils.RANDOM.nextFloat();
}
// ===========================================================
View
3 src/org/andengine/entity/primitive/Gradient.java
@@ -16,7 +16,6 @@
import org.andengine.util.math.MathUtils;
import android.opengl.GLES20;
-import android.util.FloatMath;
/**
* (c) Zynga 2012
@@ -375,7 +374,7 @@ public void setGradientVector(final float pGradientVectorX, final float pGradien
public void setGradientAngle(final float pGradientAngle) {
final float angleInRad = MathUtils.degToRad(pGradientAngle);
- this.setGradientVector(FloatMath.cos(angleInRad), FloatMath.sin(angleInRad));
+ this.setGradientVector((float)Math.cos(angleInRad), (float)Math.sin(angleInRad));
}
public void setGradientColor(final float pFromRed, final float pToRed, final float pFromGreen, final float pToGreen, final float pFromBlue, final float pToBlue) {
View
3 src/org/andengine/opengl/font/StrokeFont.java
@@ -6,7 +6,6 @@
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Typeface;
-import android.util.FloatMath;
/**
* TODO Re-implement with Font changes.
@@ -73,7 +72,7 @@ public StrokeFont(final FontManager pFontManager, final ITexture pTexture, final
@Override
protected void updateTextBounds(final String pCharacterAsString) {
this.mStrokePaint.getTextBounds(pCharacterAsString, 0, 1, this.mTextBounds);
- final int inset = -(int)FloatMath.floor(this.mStrokeWidth * 0.5f);
+ final int inset = -(int)Math.floor(this.mStrokeWidth * 0.5f);
this.mTextBounds.inset(inset, inset);
}
View
2 src/org/andengine/opengl/texture/TextureManager.java
@@ -231,7 +231,7 @@ public synchronized void updateTextures(final GLState pGLState) {
final ArrayList<ITexture> texturesToBeLoaded = this.mTexturesToBeLoaded;
final ArrayList<ITexture> texturesToBeUnloaded = this.mTexturesToBeUnloaded;
- /* First reload Textures that need to be updated. */
+ /* First reCreate Textures that need to be updated. */
for (int i = texturesLoaded.size() - 1; i >= 0; i--) {
final ITexture textureToBeReloaded = texturesLoaded.get(i);
if (textureToBeReloaded.isUpdateOnHardwareNeeded()) {
View
14 src/org/andengine/util/adt/transformation/Transformation.java
@@ -2,8 +2,6 @@
import org.andengine.util.math.MathConstants;
-import android.util.FloatMath;
-
/**
* <p>This class is basically a java-space replacement for the native {@link android.graphics.Matrix} class.</p>
@@ -119,8 +117,8 @@ public final Transformation setToTranslate(final float pX, final float pY) {
public final void preRotate(final float pAngle) {
final float angleRad = MathConstants.DEG_TO_RAD * pAngle;
- final float sin = FloatMath.sin(angleRad);
- final float cos = FloatMath.cos(angleRad);
+ final float sin = (float)Math.sin(angleRad);
+ final float cos = (float)Math.cos(angleRad);
final float a = this.a;
final float b = this.b;
@@ -136,8 +134,8 @@ public final void preRotate(final float pAngle) {
public final void postRotate(final float pAngle) {
final float angleRad = MathConstants.DEG_TO_RAD * pAngle;
- final float sin = FloatMath.sin(angleRad);
- final float cos = FloatMath.cos(angleRad);
+ final float sin = (float)Math.sin(angleRad);
+ final float cos = (float)Math.cos(angleRad);
final float a = this.a;
final float b = this.b;
@@ -157,8 +155,8 @@ public final void postRotate(final float pAngle) {
public final Transformation setToRotate(final float pAngle) {
final float angleRad = MathConstants.DEG_TO_RAD * pAngle;
- final float sin = FloatMath.sin(angleRad);
- final float cos = FloatMath.cos(angleRad);
+ final float sin = (float)Math.sin(angleRad);
+ final float cos = (float)Math.cos(angleRad);
this.a = cos;
this.b = sin;
View
4 src/org/andengine/util/algorithm/path/astar/EuclideanHeuristic.java
@@ -2,8 +2,6 @@
import org.andengine.util.algorithm.path.IPathFinderMap;
-import android.util.FloatMath;
-
/**
* (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
@@ -37,7 +35,7 @@ public float getExpectedRestCost(final IPathFinderMap<T> pPathFinderMap, final T
final float dX = pToX - pFromX;
final float dY = pToY - pFromY;
- return FloatMath.sqrt(dX * dX + dY * dY);
+ return (float)Math.sqrt(dX * dX + dY * dY);
}
// ===========================================================
View
3 src/org/andengine/util/math/MathConstants.java
@@ -1,6 +1,5 @@
package org.andengine.util.math;
-import android.util.FloatMath;
/**
* (c) 2010 Nicolas Gramlich
@@ -22,7 +21,7 @@
public static final float DEG_TO_RAD = PI / 180.0f;
public static final float RAD_TO_DEG = 180.0f / PI;
- public static final float SQRT_2 = FloatMath.sqrt(2);
+ public static final float SQRT_2 = (float)Math.sqrt(2);
// ===========================================================
// Methods
View
12 src/org/andengine/util/math/MathUtils.java
@@ -2,8 +2,6 @@
import java.util.Random;
-import android.util.FloatMath;
-
/**
* (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
@@ -230,7 +228,7 @@ public static final boolean isPowerOfTwo(final int n) {
}
public static final int nextPowerOfTwo(final float f) {
- return MathUtils.nextPowerOfTwo((int)(FloatMath.ceil(f)));
+ return MathUtils.nextPowerOfTwo((int)(Math.ceil(f)));
}
public static final int nextPowerOfTwo(final int n) {
@@ -261,8 +259,8 @@ public static final int sum(final int[] pValues) {
public static float[] rotateAroundCenter(final float[] pVertices, final float pRotation, final float pRotationCenterX, final float pRotationCenterY) {
if (pRotation != 0) {
final float rotationRad = MathUtils.degToRad(pRotation);
- final float sinRotationRad = FloatMath.sin(rotationRad);
- final float cosRotationInRad = FloatMath.cos(rotationRad);
+ final float sinRotationRad = (float)Math.sin(rotationRad);
+ final float cosRotationInRad = (float)Math.cos(rotationRad);
for (int i = pVertices.length - 2; i >= 0; i -= 2) {
final float pX = pVertices[i];
@@ -337,14 +335,14 @@ public static final float bringToBounds(final float pMinValue, final float pMaxV
public static final float distance(final float pX1, final float pY1, final float pX2, final float pY2) {
final float dX = pX2 - pX1;
final float dY = pY2 - pY1;
- return FloatMath.sqrt((dX * dX) + (dY * dY));
+ return (float)Math.sqrt((dX * dX) + (dY * dY));
}
/**
* @return the euclidean distance between the origin (0, 0) and (pX, pY).
*/
public static final float length(final float pX, final float pY) {
- return FloatMath.sqrt((pX * pX) + (pY * pY));
+ return (float)Math.sqrt((pX * pX) + (pY * pY));
}
/**
View
3 src/org/andengine/util/modifier/ease/EaseCircularIn.java
@@ -1,6 +1,5 @@
package org.andengine.util.modifier.ease;
-import android.util.FloatMath;
/**
* (c) 2010 Nicolas Gramlich
@@ -54,7 +53,7 @@ public float getPercentage(final float pSecondsElapsed, final float pDuration) {
// ===========================================================
public static float getValue(final float pPercentage) {
- return -(FloatMath.sqrt(1 - pPercentage * pPercentage) - 1.0f);
+ return -((float)Math.sqrt(1 - pPercentage * pPercentage) - 1.0f);
}
// ===========================================================
View
3 src/org/andengine/util/modifier/ease/EaseCircularOut.java
@@ -1,6 +1,5 @@
package org.andengine.util.modifier.ease;
-import android.util.FloatMath;
/**
* (c) 2010 Nicolas Gramlich
@@ -55,7 +54,7 @@ public float getPercentage(final float pSecondsElapsed, final float pDuration) {
public static float getValue(final float pPercentage) {
final float t = pPercentage - 1;
- return FloatMath.sqrt(1 - t * t);
+ return (float)Math.sqrt(1 - t * t);
}
// ===========================================================
View
4 src/org/andengine/util/modifier/ease/EaseElasticIn.java
@@ -2,8 +2,6 @@
import org.andengine.util.math.MathConstants;
-import android.util.FloatMath;
-
/**
* (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
@@ -67,7 +65,7 @@ public static float getValue(final float pSecondsElapsed, final float pDuration,
final float s = p / 4;
final float t = pPercentage - 1;
- return -(float)Math.pow(2, 10 * t) * FloatMath.sin((t * pDuration - s) * MathConstants.PI_TWICE / p);
+ return -(float)Math.pow(2, 10 * t) * (float)Math.sin((t * pDuration - s) * MathConstants.PI_TWICE / p);
}
// ===========================================================
View
4 src/org/andengine/util/modifier/ease/EaseElasticOut.java
@@ -2,8 +2,6 @@
import org.andengine.util.math.MathConstants;
-import android.util.FloatMath;
-
/**
* (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
@@ -66,7 +64,7 @@ public static float getValue(final float pSecondsElapsed, final float pDuration,
final float p = pDuration * 0.3f;
final float s = p / 4;
- return 1 + (float)Math.pow(2, -10 * pPercentageDone) * FloatMath.sin((pPercentageDone * pDuration - s) * MathConstants.PI_TWICE / p);
+ return 1 + (float)Math.pow(2, -10 * pPercentageDone) * (float)Math.sin((pPercentageDone * pDuration - s) * MathConstants.PI_TWICE / p);
}
// ===========================================================
View
4 src/org/andengine/util/modifier/ease/EaseSineIn.java
@@ -2,8 +2,6 @@
import org.andengine.util.math.MathConstants;
-import android.util.FloatMath;
-
/**
* (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
@@ -56,7 +54,7 @@ public float getPercentage(final float pSecondsElapsed, final float pDuration) {
// ===========================================================
public static float getValue(final float pPercentage) {
- return -FloatMath.cos(pPercentage * MathConstants.PI_HALF) + 1;
+ return -(float)Math.cos(pPercentage * MathConstants.PI_HALF) + 1;
}
// ===========================================================
View
3 src/org/andengine/util/modifier/ease/EaseSineInOut.java
@@ -1,7 +1,6 @@
package org.andengine.util.modifier.ease;
import static org.andengine.util.math.MathConstants.PI;
-import android.util.FloatMath;
/**
* (c) 2010 Nicolas Gramlich
@@ -49,7 +48,7 @@ public static EaseSineInOut getInstance() {
public float getPercentage(final float pSecondsElapsed, final float pDuration) {
final float percentage = pSecondsElapsed / pDuration;
- return -0.5f * (FloatMath.cos(percentage * PI) - 1);
+ return -0.5f * ((float)Math.cos(percentage * PI) - 1);
}
// ===========================================================
View
4 src/org/andengine/util/modifier/ease/EaseSineOut.java
@@ -2,8 +2,6 @@
import org.andengine.util.math.MathConstants;
-import android.util.FloatMath;
-
/**
* (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
@@ -56,7 +54,7 @@ public float getPercentage(final float pSecondsElapsed, final float pDuration) {
// ===========================================================
public static float getValue(final float pPercentage) {
- return FloatMath.sin(pPercentage * MathConstants.PI_HALF);
+ return (float)Math.sin(pPercentage * MathConstants.PI_HALF);
}
// ===========================================================

0 comments on commit 95d4ccc

Please sign in to comment.
Something went wrong with that request. Please try again.