fix: make updateAnimation synchronized

This commit is contained in:
Hannes Janetzek 2013-09-20 18:36:39 +02:00
parent 4aae6c0a09
commit 8cc115a108

View File

@ -21,9 +21,9 @@ public class MapAnimator {
} }
private final int ANIM_NONE = 0; private final int ANIM_NONE = 0;
private final int ANIM_MOVE = 1 << 1; private final int ANIM_MOVE = 1 << 0;
private final int ANIM_SCALE = 1 << 2; private final int ANIM_SCALE = 1 << 1;
private final int ANIM_FLING = 1 << 3; private final int ANIM_FLING = 1 << 2;
private final Map mMap; private final Map mMap;
private final Viewport mViewport; private final Viewport mViewport;
@ -48,10 +48,10 @@ public class MapAnimator {
// calculate the maximum scale at which the bbox is completely visible // calculate the maximum scale at which the bbox is completely visible
double dx = Math.abs(MercatorProjection.longitudeToX(bbox.getMaxLongitude()) double dx = Math.abs(MercatorProjection.longitudeToX(bbox.getMaxLongitude())
- MercatorProjection.longitudeToX(bbox.getMinLongitude())); - MercatorProjection.longitudeToX(bbox.getMinLongitude()));
double dy = Math.abs(MercatorProjection.latitudeToY(bbox.getMinLatitude()) double dy = Math.abs(MercatorProjection.latitudeToY(bbox.getMinLatitude())
- MercatorProjection.latitudeToY(bbox.getMaxLatitude())); - MercatorProjection.latitudeToY(bbox.getMaxLatitude()));
double zx = mMap.getWidth() / (dx * Tile.SIZE); double zx = mMap.getWidth() / (dx * Tile.SIZE);
double zy = mMap.getHeight() / (dy * Tile.SIZE); double zy = mMap.getHeight() / (dy * Tile.SIZE);
@ -166,12 +166,14 @@ public class MapAnimator {
/** /**
* called by MapRenderer at begin of each frame. * called by MapRenderer at begin of each frame.
*/ */
public void updateAnimation() { public synchronized void updateAnimation() {
if (mState == ANIM_NONE) if (mState == ANIM_NONE)
return; return;
long millisLeft = mAnimEnd - MapRenderer.frametime; long millisLeft = mAnimEnd - MapRenderer.frametime;
boolean changed = false;
synchronized (mViewport) { synchronized (mViewport) {
// cancel animation when position was changed since last // cancel animation when position was changed since last
@ -200,8 +202,6 @@ public class MapAnimator {
} }
float adv = FastMath.clamp(1.0f - millisLeft / mDuration, 0, 1); float adv = FastMath.clamp(1.0f - millisLeft / mDuration, 0, 1);
boolean changed = false;
if ((mState & ANIM_SCALE) != 0) { if ((mState & ANIM_SCALE) != 0) {
if (mScaleBy > 0) if (mScaleBy > 0)
@ -218,11 +218,6 @@ public class MapAnimator {
changed = true; changed = true;
} }
//if (mAnimMove && mAnimScale) {
// mPos.angle = mStartPos.angle * (1 - adv);
// updateMatrix();
//}
if ((mState & ANIM_FLING) != 0) { if ((mState & ANIM_FLING) != 0) {
adv = (float) Math.sqrt(adv); adv = (float) Math.sqrt(adv);
double dx = mVelocity.x * adv; double dx = mVelocity.x * adv;
@ -236,18 +231,20 @@ public class MapAnimator {
changed = true; changed = true;
} }
} }
// continue animation
if (changed) {
// render and inform layers that position has changed
mMap.updateMap(true);
} else {
// just render next frame
mMap.render();
}
// remember current map position // remember current map position
mViewport.getMapPosition(mPos); mViewport.getMapPosition(mPos);
} }
// continue animation
if (changed) {
// render and inform layers that position has changed
mMap.updateMap(true);
} else {
// just render next frame
mMap.render();
}
} }
private void doScale(double newScale) { private void doScale(double newScale) {