Use std::chrono
This commit is contained in:
@@ -380,19 +380,19 @@ jobject JNICALL nativeGetClasses(JNIEnv *env, jobject obj, jlong nativeMapViewPt
|
||||
}
|
||||
|
||||
void JNICALL nativeSetDefaultTransitionDuration(JNIEnv *env, jobject obj, jlong nativeMapViewPtr,
|
||||
jlong milliseconds) {
|
||||
jlong duration) {
|
||||
mbgl::Log::Debug(mbgl::Event::JNI, "nativeSetDefaultTransitionDuration");
|
||||
assert(nativeMapViewPtr != 0);
|
||||
assert(milliseconds >= 0);
|
||||
assert(duration >= 0);
|
||||
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
|
||||
nativeMapView->getMap().setDefaultTransitionDuration(milliseconds);
|
||||
nativeMapView->getMap().setDefaultTransitionDuration(std::chrono::milliseconds(duration));
|
||||
}
|
||||
|
||||
jlong JNICALL nativeGetDefaultTransitionDuration(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) {
|
||||
mbgl::Log::Debug(mbgl::Event::JNI, "nativeGetDefaultTransitionDuration");
|
||||
assert(nativeMapViewPtr != 0);
|
||||
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
|
||||
return nativeMapView->getMap().getDefaultTransitionDuration();
|
||||
return std::chrono::duration_cast<std::chrono::milliseconds>(nativeMapView->getMap().getDefaultTransitionDuration()).count();
|
||||
}
|
||||
|
||||
void JNICALL nativeSetStyleURL(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jstring url) {
|
||||
@@ -441,15 +441,15 @@ void JNICALL nativeCancelTransitions(JNIEnv *env, jobject obj, jlong nativeMapVi
|
||||
}
|
||||
|
||||
void JNICALL nativeMoveBy(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jdouble dx, jdouble dy,
|
||||
jdouble duration) {
|
||||
jlong duration) {
|
||||
mbgl::Log::Debug(mbgl::Event::JNI, "nativeMoveBy");
|
||||
assert(nativeMapViewPtr != 0);
|
||||
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
|
||||
nativeMapView->getMap().moveBy(dx, dy, duration);
|
||||
nativeMapView->getMap().moveBy(dx, dy, std::chrono::milliseconds(duration));
|
||||
}
|
||||
|
||||
void JNICALL nativeSetLonLat(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jobject lonLat,
|
||||
jdouble duration) {
|
||||
jlong duration) {
|
||||
mbgl::Log::Debug(mbgl::Event::JNI, "nativeSetLonLat");
|
||||
assert(nativeMapViewPtr != 0);
|
||||
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
|
||||
@@ -466,7 +466,7 @@ void JNICALL nativeSetLonLat(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, j
|
||||
return;
|
||||
}
|
||||
|
||||
nativeMapView->getMap().setLonLat(lon, lat, duration);
|
||||
nativeMapView->getMap().setLonLat(lon, lat, std::chrono::milliseconds(duration));
|
||||
}
|
||||
|
||||
jobject JNICALL nativeGetLonLat(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) {
|
||||
@@ -507,19 +507,19 @@ void JNICALL nativeResetPosition(JNIEnv *env, jobject obj, jlong nativeMapViewPt
|
||||
}
|
||||
|
||||
void JNICALL nativeScaleBy(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jdouble ds, jdouble cx,
|
||||
jdouble cy, jdouble duration) {
|
||||
jdouble cy, jlong duration) {
|
||||
mbgl::Log::Debug(mbgl::Event::JNI, "nativeScaleBy");
|
||||
assert(nativeMapViewPtr != 0);
|
||||
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
|
||||
nativeMapView->getMap().scaleBy(ds, cx, cy, duration);
|
||||
nativeMapView->getMap().scaleBy(ds, cx, cy, std::chrono::milliseconds(duration));
|
||||
}
|
||||
|
||||
void JNICALL nativeSetScale(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jdouble scale,
|
||||
jdouble cx, jdouble cy, jdouble duration) {
|
||||
jdouble cx, jdouble cy, jlong duration) {
|
||||
mbgl::Log::Debug(mbgl::Event::JNI, "nativeSetScale");
|
||||
assert(nativeMapViewPtr != 0);
|
||||
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
|
||||
nativeMapView->getMap().setScale(scale, cx, cy, duration);
|
||||
nativeMapView->getMap().setScale(scale, cx, cy, std::chrono::milliseconds(duration));
|
||||
}
|
||||
|
||||
jdouble JNICALL nativeGetScale(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) {
|
||||
@@ -530,11 +530,11 @@ jdouble JNICALL nativeGetScale(JNIEnv *env, jobject obj, jlong nativeMapViewPtr)
|
||||
}
|
||||
|
||||
void JNICALL
|
||||
nativeSetZoom(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jdouble zoom, jdouble duration) {
|
||||
nativeSetZoom(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jdouble zoom, jlong duration) {
|
||||
mbgl::Log::Debug(mbgl::Event::JNI, "nativeSetZoom");
|
||||
assert(nativeMapViewPtr != 0);
|
||||
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
|
||||
nativeMapView->getMap().setZoom(zoom, duration);
|
||||
nativeMapView->getMap().setZoom(zoom, std::chrono::milliseconds(duration));
|
||||
}
|
||||
|
||||
jdouble JNICALL nativeGetZoom(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) {
|
||||
@@ -545,7 +545,7 @@ jdouble JNICALL nativeGetZoom(JNIEnv *env, jobject obj, jlong nativeMapViewPtr)
|
||||
}
|
||||
|
||||
void JNICALL nativeSetLonLatZoom(JNIEnv *env, jobject obj, jlong nativeMapViewPtr,
|
||||
jobject lonLatZoom, jdouble duration) {
|
||||
jobject lonLatZoom, jlong duration) {
|
||||
mbgl::Log::Debug(mbgl::Event::JNI, "nativeSetLonLatZoom");
|
||||
assert(nativeMapViewPtr != 0);
|
||||
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
|
||||
@@ -568,7 +568,7 @@ void JNICALL nativeSetLonLatZoom(JNIEnv *env, jobject obj, jlong nativeMapViewPt
|
||||
return;
|
||||
}
|
||||
|
||||
nativeMapView->getMap().setLonLatZoom(lon, lat, zoom, duration);
|
||||
nativeMapView->getMap().setLonLatZoom(lon, lat, zoom, std::chrono::milliseconds(duration));
|
||||
}
|
||||
|
||||
jobject JNICALL nativeGetLonLatZoom(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) {
|
||||
@@ -623,19 +623,19 @@ jdouble JNICALL nativeGetMaxZoom(JNIEnv *env, jobject obj, jlong nativeMapViewPt
|
||||
}
|
||||
|
||||
void JNICALL nativeRotateBy(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jdouble sx,
|
||||
jdouble sy, jdouble ex, jdouble ey, jdouble duration) {
|
||||
jdouble sy, jdouble ex, jdouble ey, jlong duration) {
|
||||
mbgl::Log::Debug(mbgl::Event::JNI, "nativeRotateBy");
|
||||
assert(nativeMapViewPtr != 0);
|
||||
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
|
||||
nativeMapView->getMap().rotateBy(sx, sy, ex, ey, duration);
|
||||
nativeMapView->getMap().rotateBy(sx, sy, ex, ey, std::chrono::milliseconds(duration));
|
||||
}
|
||||
|
||||
void JNICALL nativeSetBearing(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jdouble degrees,
|
||||
jdouble duration) {
|
||||
jlong duration) {
|
||||
mbgl::Log::Debug(mbgl::Event::JNI, "nativeSetBearing");
|
||||
assert(nativeMapViewPtr != 0);
|
||||
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
|
||||
nativeMapView->getMap().setBearing(degrees, duration);
|
||||
nativeMapView->getMap().setBearing(degrees, std::chrono::milliseconds(duration));
|
||||
}
|
||||
|
||||
void JNICALL nativeSetBearing(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jdouble degrees,
|
||||
@@ -889,20 +889,20 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
|
||||
{"nativeGetAccessToken", "(J)Ljava/lang/String;",
|
||||
reinterpret_cast<void *>(&nativeGetAccessToken)},
|
||||
{"nativeCancelTransitions", "(J)V", reinterpret_cast<void *>(&nativeCancelTransitions)},
|
||||
{"nativeMoveBy", "(JDDD)V", reinterpret_cast<void *>(&nativeMoveBy)},
|
||||
{"nativeSetLonLat", "(JLcom/mapbox/mapboxgl/lib/LonLat;D)V",
|
||||
{"nativeMoveBy", "(JDDJ)V", reinterpret_cast<void *>(&nativeMoveBy)},
|
||||
{"nativeSetLonLat", "(JLcom/mapbox/mapboxgl/lib/LonLat;J)V",
|
||||
reinterpret_cast<void *>(&nativeSetLonLat)},
|
||||
{"nativeGetLonLat", "(J)Lcom/mapbox/mapboxgl/lib/LonLat;",
|
||||
reinterpret_cast<void *>(&nativeGetLonLat)},
|
||||
{"nativeStartPanning", "(J)V", reinterpret_cast<void *>(&nativeStartPanning)},
|
||||
{"nativeStopPanning", "(J)V", reinterpret_cast<void *>(&nativeStopPanning)},
|
||||
{"nativeResetPosition", "(J)V", reinterpret_cast<void *>(&nativeResetPosition)},
|
||||
{"nativeScaleBy", "(JDDDD)V", reinterpret_cast<void *>(&nativeScaleBy)},
|
||||
{"nativeSetScale", "(JDDDD)V", reinterpret_cast<void *>(&nativeSetScale)},
|
||||
{"nativeScaleBy", "(JDDDJ)V", reinterpret_cast<void *>(&nativeScaleBy)},
|
||||
{"nativeSetScale", "(JDDDJ)V", reinterpret_cast<void *>(&nativeSetScale)},
|
||||
{"nativeGetScale", "(J)D", reinterpret_cast<void *>(&nativeGetScale)},
|
||||
{"nativeSetZoom", "(JDD)V", reinterpret_cast<void *>(&nativeSetZoom)},
|
||||
{"nativeSetZoom", "(JDJ)V", reinterpret_cast<void *>(&nativeSetZoom)},
|
||||
{"nativeGetZoom", "(J)D", reinterpret_cast<void *>(&nativeGetZoom)},
|
||||
{"nativeSetLonLatZoom", "(JLcom/mapbox/mapboxgl/lib/LonLatZoom;D)V",
|
||||
{"nativeSetLonLatZoom", "(JLcom/mapbox/mapboxgl/lib/LonLatZoom;J)V",
|
||||
reinterpret_cast<void *>(&nativeSetLonLatZoom)},
|
||||
{"nativeGetLonLatZoom", "(J)Lcom/mapbox/mapboxgl/lib/LonLatZoom;",
|
||||
reinterpret_cast<void *>(&nativeGetLonLatZoom)},
|
||||
@@ -911,10 +911,10 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
|
||||
{"nativeStopPanning", "(J)V", reinterpret_cast<void *>(&nativeStopScaling)},
|
||||
{"nativeGetMinZoom", "(J)D", reinterpret_cast<void *>(&nativeGetMinZoom)},
|
||||
{"nativeGetMaxZoom", "(J)D", reinterpret_cast<void *>(&nativeGetMaxZoom)},
|
||||
{"nativeRotateBy", "(JDDDDD)V", reinterpret_cast<void *>(&nativeRotateBy)},
|
||||
{"nativeSetBearing", "(JDD)V",
|
||||
{"nativeRotateBy", "(JDDDDJ)V", reinterpret_cast<void *>(&nativeRotateBy)},
|
||||
{"nativeSetBearing", "(JDJ)V",
|
||||
reinterpret_cast<void *>(
|
||||
static_cast<void JNICALL (*)(JNIEnv *, jobject, jlong, jdouble, jdouble)>(
|
||||
static_cast<void JNICALL (*)(JNIEnv *, jobject, jlong, jdouble, jlong)>(
|
||||
&nativeSetBearing))},
|
||||
{"nativeSetBearing", "(JDDD)V",
|
||||
reinterpret_cast<void *>(
|
||||
|
||||
@@ -718,7 +718,7 @@ void NativeMapView::resume() {
|
||||
}
|
||||
}
|
||||
|
||||
void NativeMapView::notifyMapChange(mbgl::MapChange, mbgl::timestamp) {
|
||||
void NativeMapView::notifyMapChange(mbgl::MapChange, std::chrono::steady_clock::duration) {
|
||||
mbgl::Log::Debug(mbgl::Event::Android, "NativeMapView::notifyMapChange()");
|
||||
|
||||
assert(vm != nullptr);
|
||||
|
||||
@@ -46,6 +46,9 @@ public class MapView extends SurfaceView {
|
||||
// Tag used for logging
|
||||
private static final String TAG = "MapView";
|
||||
|
||||
// Used for animation
|
||||
private static final long ANIMATION_DURATION = 300;
|
||||
|
||||
// Used for saving instance state
|
||||
private static final String STATE_CENTER_COORDINATE = "centerCoordinate";
|
||||
private static final String STATE_CENTER_DIRECTION = "centerDirection";
|
||||
@@ -188,7 +191,7 @@ public class MapView extends SurfaceView {
|
||||
if (!isInEditMode()) {
|
||||
if (!context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH)) {
|
||||
mZoomButtonsController = new ZoomButtonsController(this);
|
||||
mZoomButtonsController.setZoomSpeed(300);
|
||||
mZoomButtonsController.setZoomSpeed(ANIMATION_DURATION);
|
||||
mZoomButtonsController.setOnZoomListener(new OnZoomListener());
|
||||
}
|
||||
|
||||
@@ -213,7 +216,7 @@ public class MapView extends SurfaceView {
|
||||
}
|
||||
|
||||
public void setCenterCoordinate(LonLat centerCoordinate, boolean animated) {
|
||||
double duration = animated ? 0.3 : 0.0;
|
||||
long duration = animated ? ANIMATION_DURATION : 0;
|
||||
mNativeMapView.setLonLat(centerCoordinate, duration);
|
||||
}
|
||||
|
||||
@@ -223,7 +226,7 @@ public class MapView extends SurfaceView {
|
||||
|
||||
public void setCenterCoordinate(LonLatZoom centerCoordinate,
|
||||
boolean animated) {
|
||||
double duration = animated ? 0.3 : 0.0;
|
||||
long duration = animated ? ANIMATION_DURATION : 0;
|
||||
mNativeMapView.setLonLatZoom(centerCoordinate, duration);
|
||||
}
|
||||
|
||||
@@ -243,8 +246,7 @@ public class MapView extends SurfaceView {
|
||||
}
|
||||
|
||||
public void setDirection(double direction, boolean animated) {
|
||||
double duration = animated ? 0.3 : 0.0;
|
||||
|
||||
long duration = animated ? ANIMATION_DURATION : 0;
|
||||
mNativeMapView.setBearing(-direction, duration);
|
||||
}
|
||||
|
||||
@@ -265,7 +267,7 @@ public class MapView extends SurfaceView {
|
||||
}
|
||||
|
||||
public void setZoomLevel(double zoomLevel, boolean animated) {
|
||||
double duration = animated ? 0.3 : 0.0;
|
||||
long duration = animated ? ANIMATION_DURATION : 0;
|
||||
mNativeMapView.setZoom(zoomLevel, duration);
|
||||
}
|
||||
|
||||
@@ -565,10 +567,10 @@ public class MapView extends SurfaceView {
|
||||
mNativeMapView.cancelTransitions();
|
||||
|
||||
if (zoomIn) {
|
||||
mNativeMapView.scaleBy(2.0, x / mScreenDensity, y / mScreenDensity, 0.3);
|
||||
mNativeMapView.scaleBy(2.0, x / mScreenDensity, y / mScreenDensity, ANIMATION_DURATION);
|
||||
} else {
|
||||
// TODO two finger tap zoom out
|
||||
mNativeMapView.scaleBy(0.5, x / mScreenDensity, y / mScreenDensity, 0.3);
|
||||
mNativeMapView.scaleBy(0.5, x / mScreenDensity, y / mScreenDensity, ANIMATION_DURATION);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -695,7 +697,7 @@ public class MapView extends SurfaceView {
|
||||
// Cancel any animation
|
||||
mNativeMapView.cancelTransitions();
|
||||
|
||||
mNativeMapView.moveBy(velocityX * duration / 2.0 / mScreenDensity, velocityY * duration / 2.0 / mScreenDensity, duration);
|
||||
mNativeMapView.moveBy(velocityX * duration / 2.0 / mScreenDensity, velocityY * duration / 2.0 / mScreenDensity, (long)(duration * 1000.0f));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -234,18 +234,18 @@ class NativeMapView {
|
||||
}
|
||||
|
||||
public void moveBy(double dx, double dy) {
|
||||
moveBy(dx, dy, 0.0);
|
||||
moveBy(dx, dy, 0);
|
||||
}
|
||||
|
||||
public void moveBy(double dx, double dy, double duration) {
|
||||
public void moveBy(double dx, double dy, long duration) {
|
||||
nativeMoveBy(mNativeMapViewPtr, dx, dy, duration);
|
||||
}
|
||||
|
||||
public void setLonLat(LonLat lonLat) {
|
||||
setLonLat(lonLat, 0.0);
|
||||
setLonLat(lonLat, 0);
|
||||
}
|
||||
|
||||
public void setLonLat(LonLat lonLat, double duration) {
|
||||
public void setLonLat(LonLat lonLat, long duration) {
|
||||
nativeSetLonLat(mNativeMapViewPtr, lonLat, duration);
|
||||
}
|
||||
|
||||
@@ -270,10 +270,10 @@ class NativeMapView {
|
||||
}
|
||||
|
||||
public void scaleBy(double ds, double cx, double cy) {
|
||||
scaleBy(ds, cx, cy, 0.0);
|
||||
scaleBy(ds, cx, cy, 0);
|
||||
}
|
||||
|
||||
public void scaleBy(double ds, double cx, double cy, double duration) {
|
||||
public void scaleBy(double ds, double cx, double cy, long duration) {
|
||||
nativeScaleBy(mNativeMapViewPtr, ds, cx, cy, duration);
|
||||
}
|
||||
|
||||
@@ -282,10 +282,10 @@ class NativeMapView {
|
||||
}
|
||||
|
||||
public void setScale(double scale, double cx, double cy) {
|
||||
setScale(scale, cx, cy, 0.0);
|
||||
setScale(scale, cx, cy, 0);
|
||||
}
|
||||
|
||||
public void setScale(double scale, double cx, double cy, double duration) {
|
||||
public void setScale(double scale, double cx, double cy, long duration) {
|
||||
nativeSetScale(mNativeMapViewPtr, scale, cx, cy, duration);
|
||||
}
|
||||
|
||||
@@ -294,10 +294,10 @@ class NativeMapView {
|
||||
}
|
||||
|
||||
public void setZoom(double zoom) {
|
||||
setZoom(zoom, 0.0);
|
||||
setZoom(zoom, 0);
|
||||
}
|
||||
|
||||
public void setZoom(double zoom, double duration) {
|
||||
public void setZoom(double zoom, long duration) {
|
||||
nativeSetZoom(mNativeMapViewPtr, zoom, duration);
|
||||
}
|
||||
|
||||
@@ -306,10 +306,10 @@ class NativeMapView {
|
||||
}
|
||||
|
||||
public void setLonLatZoom(LonLatZoom lonLatZoom) {
|
||||
setLonLatZoom(lonLatZoom, 0.0);
|
||||
setLonLatZoom(lonLatZoom, 0);
|
||||
}
|
||||
|
||||
public void setLonLatZoom(LonLatZoom lonLatZoom, double duration) {
|
||||
public void setLonLatZoom(LonLatZoom lonLatZoom, long duration) {
|
||||
nativeSetLonLatZoom(mNativeMapViewPtr, lonLatZoom, duration);
|
||||
}
|
||||
|
||||
@@ -338,19 +338,19 @@ class NativeMapView {
|
||||
}
|
||||
|
||||
public void rotateBy(double sx, double sy, double ex, double ey) {
|
||||
rotateBy(sx, sy, ex, ey, 0.0);
|
||||
rotateBy(sx, sy, ex, ey, 0);
|
||||
}
|
||||
|
||||
public void rotateBy(double sx, double sy, double ex, double ey,
|
||||
double duration) {
|
||||
long duration) {
|
||||
nativeRotateBy(mNativeMapViewPtr, sx, sy, ex, ey, duration);
|
||||
}
|
||||
|
||||
public void setBearing(double degrees) {
|
||||
setBearing(degrees, 0.0);
|
||||
setBearing(degrees, 0);
|
||||
}
|
||||
|
||||
public void setBearing(double degrees, double duration) {
|
||||
public void setBearing(double degrees, long duration) {
|
||||
nativeSetBearing(mNativeMapViewPtr, degrees, duration);
|
||||
}
|
||||
|
||||
@@ -468,7 +468,7 @@ class NativeMapView {
|
||||
private native List<String> nativeGetClasses(long nativeMapViewPtr);
|
||||
|
||||
private native void nativeSetDefaultTransitionDuration(
|
||||
long nativeMapViewPtr, long milliseconds);
|
||||
long nativeMapViewPtr, long duration);
|
||||
|
||||
private native long nativeGetDefaultTransitionDuration(long nativeMapViewPtr);
|
||||
|
||||
@@ -486,10 +486,10 @@ class NativeMapView {
|
||||
private native void nativeCancelTransitions(long nativeMapViewPtr);
|
||||
|
||||
private native void nativeMoveBy(long nativeMapViewPtr, double dx,
|
||||
double dy, double duration);
|
||||
double dy, long duration);
|
||||
|
||||
private native void nativeSetLonLat(long nativeMapViewPtr, LonLat lonLat,
|
||||
double duration);
|
||||
long duration);
|
||||
|
||||
private native LonLat nativeGetLonLat(long nativeMapViewPtr);
|
||||
|
||||
@@ -500,20 +500,20 @@ class NativeMapView {
|
||||
private native void nativeResetPosition(long nativeMapViewPtr);
|
||||
|
||||
private native void nativeScaleBy(long nativeMapViewPtr, double ds,
|
||||
double cx, double cy, double duration);
|
||||
double cx, double cy, long duration);
|
||||
|
||||
private native void nativeSetScale(long nativeMapViewPtr, double scale,
|
||||
double cx, double cy, double duration);
|
||||
double cx, double cy, long duration);
|
||||
|
||||
private native double nativeGetScale(long nativeMapViewPtr);
|
||||
|
||||
private native void nativeSetZoom(long nativeMapViewPtr, double zoom,
|
||||
double duration);
|
||||
long duration);
|
||||
|
||||
private native double nativeGetZoom(long nativeMapViewPtr);
|
||||
|
||||
private native void nativeSetLonLatZoom(long nativeMapViewPtr,
|
||||
LonLatZoom lonLatZoom, double duration);
|
||||
LonLatZoom lonLatZoom, long duration);
|
||||
|
||||
private native LonLatZoom nativeGetLonLatZoom(long nativeMapViewPtr);
|
||||
|
||||
@@ -528,10 +528,10 @@ class NativeMapView {
|
||||
private native double nativeGetMaxZoom(long nativeMapViewPtr);
|
||||
|
||||
private native void nativeRotateBy(long nativeMapViewPtr, double sx,
|
||||
double sy, double ex, double ey, double duration);
|
||||
double sy, double ex, double ey, long duration);
|
||||
|
||||
private native void nativeSetBearing(long nativeMapViewPtr, double degrees,
|
||||
double duration);
|
||||
long duration);
|
||||
|
||||
private native void nativeSetBearing(long nativeMapViewPtr, double degrees,
|
||||
double cx, double cy);
|
||||
|
||||
@@ -7,8 +7,6 @@ NAME=$1
|
||||
export JOBS=2
|
||||
|
||||
export CC=clang CXX=clang++
|
||||
export CXXFLAGS="-Wno-unknown-warning-option -Wno-unused-local-typedefs -Wno-unknown-pragmas ${CXXFLAGS}";
|
||||
|
||||
export MASON_PLATFORM=android
|
||||
|
||||
mkdir ./android/java/app/src/main/res/raw/
|
||||
|
||||
@@ -22,18 +22,13 @@
|
||||
'-Wno-variadic-macros',
|
||||
'-frtti',
|
||||
'-fexceptions',
|
||||
'-Wno-error=unused-parameter',
|
||||
],
|
||||
'GCC_WARN_PEDANTIC': 'YES',
|
||||
'GCC_WARN_UNINITIALIZED_AUTOS': 'YES_AGGRESSIVE',
|
||||
},
|
||||
}],
|
||||
['OS=="linux"', {
|
||||
'cflags_cc': [
|
||||
'-Wno-unknown-pragmas', # We are using '#pragma mark', but it is only available on Darwin.
|
||||
'-Wno-literal-suffix', # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61653
|
||||
'-Wno-unknown-warning-option',
|
||||
'-Wno-error=unused-parameter',
|
||||
'cflags_cc': ['-Wno-unknown-pragmas', # We are using '#pragma mark', but it is only available on Darwin.
|
||||
],
|
||||
}],
|
||||
],
|
||||
|
||||
@@ -25,7 +25,7 @@ public:
|
||||
void swap() override;
|
||||
|
||||
void notify() override;
|
||||
void notifyMapChange(mbgl::MapChange change, mbgl::timestamp delay) override;
|
||||
void notifyMapChange(mbgl::MapChange change, std::chrono::steady_clock::duration delay = std::chrono::steady_clock::duration::zero()) override;
|
||||
|
||||
mbgl::Map &getMap();
|
||||
mbgl::CachingHTTPFileSource &getFileSource();
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
|
||||
#include <mbgl/map/transform.hpp>
|
||||
#include <mbgl/util/noncopyable.hpp>
|
||||
#include <mbgl/util/time.hpp>
|
||||
#include <mbgl/util/uv.hpp>
|
||||
#include <mbgl/util/ptr.hpp>
|
||||
|
||||
@@ -16,6 +15,7 @@
|
||||
#include <mutex>
|
||||
#include <condition_variable>
|
||||
#include <functional>
|
||||
#include <chrono>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
@@ -83,8 +83,8 @@ public:
|
||||
void setClasses(const std::vector<std::string>&);
|
||||
std::vector<std::string> getClasses() const;
|
||||
|
||||
void setDefaultTransitionDuration(uint64_t milliseconds = 0);
|
||||
uint64_t getDefaultTransitionDuration();
|
||||
void setDefaultTransitionDuration(std::chrono::steady_clock::duration duration = std::chrono::steady_clock::duration::zero());
|
||||
std::chrono::steady_clock::duration getDefaultTransitionDuration();
|
||||
void setStyleURL(const std::string &url);
|
||||
void setStyleJSON(std::string newStyleJSON, const std::string &base = "");
|
||||
std::string getStyleJSON() const;
|
||||
@@ -93,20 +93,20 @@ public:
|
||||
void cancelTransitions();
|
||||
|
||||
// Position
|
||||
void moveBy(double dx, double dy, double duration = 0);
|
||||
void setLonLat(double lon, double lat, double duration = 0);
|
||||
void moveBy(double dx, double dy, std::chrono::steady_clock::duration duration = std::chrono::steady_clock::duration::zero());
|
||||
void setLonLat(double lon, double lat, std::chrono::steady_clock::duration duration = std::chrono::steady_clock::duration::zero());
|
||||
void getLonLat(double &lon, double &lat) const;
|
||||
void startPanning();
|
||||
void stopPanning();
|
||||
void resetPosition();
|
||||
|
||||
// Scale
|
||||
void scaleBy(double ds, double cx = -1, double cy = -1, double duration = 0);
|
||||
void setScale(double scale, double cx = -1, double cy = -1, double duration = 0);
|
||||
void scaleBy(double ds, double cx = -1, double cy = -1, std::chrono::steady_clock::duration duration = std::chrono::steady_clock::duration::zero());
|
||||
void setScale(double scale, double cx = -1, double cy = -1, std::chrono::steady_clock::duration duration = std::chrono::steady_clock::duration::zero());
|
||||
double getScale() const;
|
||||
void setZoom(double zoom, double duration = 0);
|
||||
void setZoom(double zoom, std::chrono::steady_clock::duration duration = std::chrono::steady_clock::duration::zero());
|
||||
double getZoom() const;
|
||||
void setLonLatZoom(double lon, double lat, double zoom, double duration = 0);
|
||||
void setLonLatZoom(double lon, double lat, double zoom, std::chrono::steady_clock::duration duration = std::chrono::steady_clock::duration::zero());
|
||||
void getLonLatZoom(double &lon, double &lat, double &zoom) const;
|
||||
void resetZoom();
|
||||
void startScaling();
|
||||
@@ -115,8 +115,8 @@ public:
|
||||
double getMaxZoom() const;
|
||||
|
||||
// Rotation
|
||||
void rotateBy(double sx, double sy, double ex, double ey, double duration = 0);
|
||||
void setBearing(double degrees, double duration = 0);
|
||||
void rotateBy(double sx, double sy, double ex, double ey, std::chrono::steady_clock::duration duration = std::chrono::steady_clock::duration::zero());
|
||||
void setBearing(double degrees, std::chrono::steady_clock::duration duration = std::chrono::steady_clock::duration::zero());
|
||||
void setBearing(double degrees, double cx, double cy);
|
||||
double getBearing() const;
|
||||
void resetNorth();
|
||||
@@ -129,7 +129,7 @@ public:
|
||||
bool getDebug() const;
|
||||
|
||||
inline const TransformState &getState() const { return state; }
|
||||
inline timestamp getTime() const { return animationTime; }
|
||||
inline std::chrono::steady_clock::time_point getTime() const { return animationTime; }
|
||||
|
||||
private:
|
||||
util::ptr<Sprite> getSprite();
|
||||
@@ -215,10 +215,10 @@ private:
|
||||
std::string styleJSON = "";
|
||||
std::vector<std::string> classes;
|
||||
|
||||
std::atomic_uint_fast64_t defaultTransitionDuration;
|
||||
std::chrono::steady_clock::duration defaultTransitionDuration;
|
||||
|
||||
bool debug = false;
|
||||
timestamp animationTime = 0;
|
||||
std::chrono::steady_clock::time_point animationTime = std::chrono::steady_clock::time_point::min();
|
||||
|
||||
std::set<util::ptr<StyleSource>> activeSources;
|
||||
};
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#ifndef MBGL_MAP_TRANSFORM
|
||||
#define MBGL_MAP_TRANSFORM
|
||||
|
||||
#include <mbgl/util/time.hpp>
|
||||
#include <mbgl/map/transform_state.hpp>
|
||||
#include <mbgl/util/noncopyable.hpp>
|
||||
|
||||
@@ -9,6 +8,7 @@
|
||||
#include <cmath>
|
||||
#include <forward_list>
|
||||
#include <mutex>
|
||||
#include <chrono>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
@@ -25,18 +25,18 @@ public:
|
||||
uint16_t fb_width, uint16_t fb_height);
|
||||
|
||||
// Position
|
||||
void moveBy(double dx, double dy, timestamp duration = 0);
|
||||
void setLonLat(double lon, double lat, timestamp duration = 0);
|
||||
void setLonLatZoom(double lon, double lat, double zoom, timestamp duration = 0);
|
||||
void moveBy(double dx, double dy, std::chrono::steady_clock::duration duration = std::chrono::steady_clock::duration::zero());
|
||||
void setLonLat(double lon, double lat, std::chrono::steady_clock::duration duration = std::chrono::steady_clock::duration::zero());
|
||||
void setLonLatZoom(double lon, double lat, double zoom, std::chrono::steady_clock::duration duration = std::chrono::steady_clock::duration::zero());
|
||||
void getLonLat(double& lon, double& lat) const;
|
||||
void getLonLatZoom(double& lon, double& lat, double& zoom) const;
|
||||
void startPanning();
|
||||
void stopPanning();
|
||||
|
||||
// Zoom
|
||||
void scaleBy(double ds, double cx = -1, double cy = -1, timestamp duration = 0);
|
||||
void setScale(double scale, double cx = -1, double cy = -1, timestamp duration = 0);
|
||||
void setZoom(double zoom, timestamp duration = 0);
|
||||
void scaleBy(double ds, double cx = -1, double cy = -1, std::chrono::steady_clock::duration duration = std::chrono::steady_clock::duration::zero());
|
||||
void setScale(double scale, double cx = -1, double cy = -1, std::chrono::steady_clock::duration duration = std::chrono::steady_clock::duration::zero());
|
||||
void setZoom(double zoom, std::chrono::steady_clock::duration duration = std::chrono::steady_clock::duration::zero());
|
||||
double getZoom() const;
|
||||
double getScale() const;
|
||||
void startScaling();
|
||||
@@ -45,8 +45,8 @@ public:
|
||||
double getMaxZoom() const;
|
||||
|
||||
// Angle
|
||||
void rotateBy(double sx, double sy, double ex, double ey, timestamp duration = 0);
|
||||
void setAngle(double angle, timestamp duration = 0);
|
||||
void rotateBy(double sx, double sy, double ex, double ey, std::chrono::steady_clock::duration duration = std::chrono::steady_clock::duration::zero());
|
||||
void setAngle(double angle, std::chrono::steady_clock::duration duration = std::chrono::steady_clock::duration::zero());
|
||||
void setAngle(double angle, double cx, double cy);
|
||||
double getAngle() const;
|
||||
void startRotating();
|
||||
@@ -54,7 +54,7 @@ public:
|
||||
|
||||
// Transitions
|
||||
bool needsTransition() const;
|
||||
void updateTransitions(timestamp now);
|
||||
void updateTransitions(std::chrono::steady_clock::time_point now);
|
||||
void cancelTransitions();
|
||||
|
||||
// Transform state
|
||||
@@ -64,10 +64,10 @@ public:
|
||||
private:
|
||||
// Functions prefixed with underscores will *not* perform any locks. It is the caller's
|
||||
// responsibility to lock this object.
|
||||
void _moveBy(double dx, double dy, timestamp duration = 0);
|
||||
void _setScale(double scale, double cx, double cy, timestamp duration = 0);
|
||||
void _setScaleXY(double new_scale, double xn, double yn, timestamp duration = 0);
|
||||
void _setAngle(double angle, timestamp duration = 0);
|
||||
void _moveBy(double dx, double dy, std::chrono::steady_clock::duration duration = std::chrono::steady_clock::duration::zero());
|
||||
void _setScale(double scale, double cx, double cy, std::chrono::steady_clock::duration duration = std::chrono::steady_clock::duration::zero());
|
||||
void _setScaleXY(double new_scale, double xn, double yn, std::chrono::steady_clock::duration duration = std::chrono::steady_clock::duration::zero());
|
||||
void _setAngle(double angle, std::chrono::steady_clock::duration duration = std::chrono::steady_clock::duration::zero());
|
||||
void _clearPanning();
|
||||
void _clearRotating();
|
||||
void _clearScaling();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef MBGL_MAP_VIEW
|
||||
#define MBGL_MAP_VIEW
|
||||
|
||||
#include <mbgl/util/time.hpp>
|
||||
#include <chrono>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
@@ -44,7 +44,7 @@ public:
|
||||
// Notifies a watcher of map x/y/scale/rotation changes.
|
||||
// Must only be called from the same thread that caused the change.
|
||||
// Must not be called from the render thread.
|
||||
virtual void notifyMapChange(MapChange change, timestamp delay = 0) = 0;
|
||||
virtual void notifyMapChange(MapChange change, std::chrono::steady_clock::duration delay = std::chrono::steady_clock::duration::zero()) = 0;
|
||||
|
||||
protected:
|
||||
mbgl::Map *map = nullptr;
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
#define MBGL_COMMON_GLFW_VIEW
|
||||
|
||||
#include <mbgl/mbgl.hpp>
|
||||
#include <mbgl/util/time.hpp>
|
||||
|
||||
#ifdef NVIDIA
|
||||
#define GLFW_INCLUDE_ES2
|
||||
@@ -19,7 +18,7 @@ public:
|
||||
void activate();
|
||||
void deactivate();
|
||||
void notify();
|
||||
void notifyMapChange(mbgl::MapChange change, mbgl::timestamp delay = 0);
|
||||
void notifyMapChange(mbgl::MapChange change, std::chrono::steady_clock::duration delay = std::chrono::steady_clock::duration::zero());
|
||||
|
||||
static void key(GLFWwindow *window, int key, int scancode, int action, int mods);
|
||||
static void scroll(GLFWwindow *window, double xoffset, double yoffset);
|
||||
|
||||
@@ -31,7 +31,7 @@ public:
|
||||
std::unique_ptr<uint32_t[]> readPixels();
|
||||
|
||||
void notify();
|
||||
void notifyMapChange(MapChange change, timestamp delay = 0);
|
||||
void notifyMapChange(MapChange change, std::chrono::steady_clock::duration delay = std::chrono::steady_clock::duration::zero());
|
||||
void activate();
|
||||
void deactivate();
|
||||
void swap();
|
||||
|
||||
@@ -9,7 +9,13 @@ extern "C"
|
||||
#include <jpeglib.h>
|
||||
}
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#ifndef __clang__
|
||||
#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
|
||||
#pragma GCC diagnostic ignored "-Wshadow"
|
||||
#endif
|
||||
#include <boost/iostreams/stream.hpp>
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
namespace mbgl { namespace util {
|
||||
|
||||
|
||||
@@ -11,7 +11,13 @@ extern "C"
|
||||
#include <cstring>
|
||||
#include <memory>
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#ifndef __clang__
|
||||
#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
|
||||
#pragma GCC diagnostic ignored "-Wshadow"
|
||||
#endif
|
||||
#include <boost/iostreams/stream.hpp>
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
namespace mbgl { namespace util {
|
||||
|
||||
|
||||
@@ -7,41 +7,13 @@
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
typedef uint64_t timestamp;
|
||||
|
||||
namespace util {
|
||||
|
||||
|
||||
// Returns time in nanoseconds since an arbitrary point in the past. This has
|
||||
// no relation to the current time, but is continuously increasing, so
|
||||
// comparisons between different timestamps produce meaningful values.
|
||||
timestamp now();
|
||||
|
||||
|
||||
// Returns the RFC1123 formatted date. E.g. "Tue, 04 Nov 2014 02:13:24 GMT"
|
||||
std::string rfc1123(std::time_t time);
|
||||
|
||||
}
|
||||
|
||||
// used for time conversions
|
||||
constexpr timestamp operator"" _nanoseconds (long double ns) { return ns; }
|
||||
constexpr timestamp operator"" _nanosecond (long double ns) { return ns; }
|
||||
constexpr timestamp operator"" _microseconds (long double us) { return us * 1e3; }
|
||||
constexpr timestamp operator"" _microsecond (long double us) { return us * 1e3; }
|
||||
constexpr timestamp operator"" _milliseconds (long double ms) { return ms * 1e6; }
|
||||
constexpr timestamp operator"" _millisecond (long double ms) { return ms * 1e6; }
|
||||
constexpr timestamp operator"" _seconds (long double s) { return s * 1e9; }
|
||||
constexpr timestamp operator"" _second (long double s) { return s * 1e9; }
|
||||
|
||||
constexpr timestamp operator"" _nanoseconds (unsigned long long ns) { return ns; }
|
||||
constexpr timestamp operator"" _nanosecond (unsigned long long ns) { return ns; }
|
||||
constexpr timestamp operator"" _microseconds (unsigned long long us) { return us * 1e3; }
|
||||
constexpr timestamp operator"" _microsecond (unsigned long long us) { return us * 1e3; }
|
||||
constexpr timestamp operator"" _milliseconds (unsigned long long ms) { return ms * 1e6; }
|
||||
constexpr timestamp operator"" _millisecond (unsigned long long ms) { return ms * 1e6; }
|
||||
constexpr timestamp operator"" _seconds (unsigned long long s) { return s * 1e9; }
|
||||
constexpr timestamp operator"" _second (unsigned long long s) { return s * 1e9; }
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Submodule ios/mapbox-gl-cocoa updated: 2e5bfbdcd5...08c15cac9d
@@ -174,7 +174,7 @@ void GLFWView::key(GLFWwindow *window, int key, int /*scancode*/, int action, in
|
||||
break;
|
||||
case GLFW_KEY_R:
|
||||
if (!mods) {
|
||||
view->map->setDefaultTransitionDuration(300);
|
||||
view->map->setDefaultTransitionDuration(std::chrono::milliseconds(300));
|
||||
if (view->map->hasClass("night")) {
|
||||
view->map->removeClass("night");
|
||||
} else {
|
||||
@@ -239,9 +239,9 @@ void GLFWView::mouseClick(GLFWwindow *window, int button, int action, int modifi
|
||||
double now = glfwGetTime();
|
||||
if (now - view->lastClick < 0.4 /* ms */) {
|
||||
if (modifiers & GLFW_MOD_SHIFT) {
|
||||
view->map->scaleBy(0.5, view->lastX, view->lastY, 0.5);
|
||||
view->map->scaleBy(0.5, view->lastX, view->lastY, std::chrono::milliseconds(500));
|
||||
} else {
|
||||
view->map->scaleBy(2.0, view->lastX, view->lastY, 0.5);
|
||||
view->map->scaleBy(2.0, view->lastX, view->lastY, std::chrono::milliseconds(500));
|
||||
}
|
||||
}
|
||||
view->lastClick = now;
|
||||
@@ -301,7 +301,7 @@ void GLFWView::swap() {
|
||||
fps();
|
||||
}
|
||||
|
||||
void GLFWView::notifyMapChange(mbgl::MapChange /*change*/, mbgl::timestamp /*delay*/) {
|
||||
void GLFWView::notifyMapChange(mbgl::MapChange /*change*/, std::chrono::steady_clock::duration /*delay*/) {
|
||||
// no-op
|
||||
}
|
||||
|
||||
|
||||
@@ -244,7 +244,7 @@ void HeadlessView::notify() {
|
||||
// no-op
|
||||
}
|
||||
|
||||
void HeadlessView::notifyMapChange(mbgl::MapChange /*change*/, mbgl::timestamp /*delay*/) {
|
||||
void HeadlessView::notifyMapChange(mbgl::MapChange /*change*/, std::chrono::steady_clock::duration /*delay*/) {
|
||||
// no-op
|
||||
}
|
||||
|
||||
|
||||
@@ -30,6 +30,3 @@ if [[ ${TRAVIS_OS_NAME} == "linux" ]]; then
|
||||
# fi
|
||||
# fi
|
||||
fi
|
||||
|
||||
# turn off a few warnings
|
||||
export CXXFLAGS="-Wno-unknown-warning-option -Wno-unused-local-typedefs -Wno-unknown-pragmas ${CXXFLAGS}";
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
#include <mbgl/renderer/painter.hpp>
|
||||
#include <mbgl/map/sprite.hpp>
|
||||
#include <mbgl/util/transition.hpp>
|
||||
#include <mbgl/util/time.hpp>
|
||||
#include <mbgl/util/math.hpp>
|
||||
#include <mbgl/util/clip_ids.hpp>
|
||||
#include <mbgl/util/string.hpp>
|
||||
@@ -435,13 +434,13 @@ void Map::cancelTransitions() {
|
||||
|
||||
#pragma mark - Position
|
||||
|
||||
void Map::moveBy(double dx, double dy, double duration) {
|
||||
transform.moveBy(dx, dy, duration * 1_second);
|
||||
void Map::moveBy(double dx, double dy, std::chrono::steady_clock::duration duration) {
|
||||
transform.moveBy(dx, dy, duration);
|
||||
update();
|
||||
}
|
||||
|
||||
void Map::setLonLat(double lon, double lat, double duration) {
|
||||
transform.setLonLat(lon, lat, duration * 1_second);
|
||||
void Map::setLonLat(double lon, double lat, std::chrono::steady_clock::duration duration) {
|
||||
transform.setLonLat(lon, lat, duration);
|
||||
update();
|
||||
}
|
||||
|
||||
@@ -469,13 +468,13 @@ void Map::resetPosition() {
|
||||
|
||||
#pragma mark - Scale
|
||||
|
||||
void Map::scaleBy(double ds, double cx, double cy, double duration) {
|
||||
transform.scaleBy(ds, cx, cy, duration * 1_second);
|
||||
void Map::scaleBy(double ds, double cx, double cy, std::chrono::steady_clock::duration duration) {
|
||||
transform.scaleBy(ds, cx, cy, duration);
|
||||
update();
|
||||
}
|
||||
|
||||
void Map::setScale(double scale, double cx, double cy, double duration) {
|
||||
transform.setScale(scale, cx, cy, duration * 1_second);
|
||||
void Map::setScale(double scale, double cx, double cy, std::chrono::steady_clock::duration duration) {
|
||||
transform.setScale(scale, cx, cy, duration);
|
||||
update();
|
||||
}
|
||||
|
||||
@@ -483,8 +482,8 @@ double Map::getScale() const {
|
||||
return transform.getScale();
|
||||
}
|
||||
|
||||
void Map::setZoom(double zoom, double duration) {
|
||||
transform.setZoom(zoom, duration * 1_second);
|
||||
void Map::setZoom(double zoom, std::chrono::steady_clock::duration duration) {
|
||||
transform.setZoom(zoom, duration);
|
||||
update();
|
||||
}
|
||||
|
||||
@@ -492,8 +491,8 @@ double Map::getZoom() const {
|
||||
return transform.getZoom();
|
||||
}
|
||||
|
||||
void Map::setLonLatZoom(double lon, double lat, double zoom, double duration) {
|
||||
transform.setLonLatZoom(lon, lat, zoom, duration * 1_second);
|
||||
void Map::setLonLatZoom(double lon, double lat, double zoom, std::chrono::steady_clock::duration duration) {
|
||||
transform.setLonLatZoom(lon, lat, zoom, duration);
|
||||
update();
|
||||
}
|
||||
|
||||
@@ -526,13 +525,13 @@ double Map::getMaxZoom() const {
|
||||
|
||||
#pragma mark - Rotation
|
||||
|
||||
void Map::rotateBy(double sx, double sy, double ex, double ey, double duration) {
|
||||
transform.rotateBy(sx, sy, ex, ey, duration * 1_second);
|
||||
void Map::rotateBy(double sx, double sy, double ex, double ey, std::chrono::steady_clock::duration duration) {
|
||||
transform.rotateBy(sx, sy, ex, ey, duration);
|
||||
update();
|
||||
}
|
||||
|
||||
void Map::setBearing(double degrees, double duration) {
|
||||
transform.setAngle(-degrees * M_PI / 180, duration * 1_second);
|
||||
void Map::setBearing(double degrees, std::chrono::steady_clock::duration duration) {
|
||||
transform.setAngle(-degrees * M_PI / 180, duration);
|
||||
update();
|
||||
}
|
||||
|
||||
@@ -546,7 +545,7 @@ double Map::getBearing() const {
|
||||
}
|
||||
|
||||
void Map::resetNorth() {
|
||||
transform.setAngle(0, 500_milliseconds);
|
||||
transform.setAngle(0, std::chrono::milliseconds(500));
|
||||
update();
|
||||
}
|
||||
|
||||
@@ -618,14 +617,14 @@ std::vector<std::string> Map::getClasses() const {
|
||||
return classes;
|
||||
}
|
||||
|
||||
void Map::setDefaultTransitionDuration(uint64_t milliseconds) {
|
||||
defaultTransitionDuration = milliseconds;
|
||||
void Map::setDefaultTransitionDuration(std::chrono::steady_clock::duration duration) {
|
||||
defaultTransitionDuration = duration;
|
||||
if (style) {
|
||||
style->setDefaultTransitionDuration(milliseconds);
|
||||
style->setDefaultTransitionDuration(duration);
|
||||
}
|
||||
}
|
||||
|
||||
uint64_t Map::getDefaultTransitionDuration() {
|
||||
std::chrono::steady_clock::duration Map::getDefaultTransitionDuration() {
|
||||
return defaultTransitionDuration;
|
||||
}
|
||||
|
||||
@@ -704,14 +703,14 @@ void Map::prepare() {
|
||||
}
|
||||
|
||||
// Update transform transitions.
|
||||
animationTime = util::now();
|
||||
animationTime = std::chrono::steady_clock::now();
|
||||
if (transform.needsTransition()) {
|
||||
transform.updateTransitions(animationTime);
|
||||
}
|
||||
|
||||
state = transform.currentState();
|
||||
|
||||
animationTime = util::now();
|
||||
animationTime = std::chrono::steady_clock::now();
|
||||
updateSources();
|
||||
style->updateProperties(state.getNormalizedZoom(), animationTime);
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
#include <mbgl/style/style_source.hpp>
|
||||
|
||||
#include <mbgl/util/noncopyable.hpp>
|
||||
#include <mbgl/util/time.hpp>
|
||||
#include <mbgl/util/mat4.hpp>
|
||||
#include <mbgl/util/ptr.hpp>
|
||||
|
||||
@@ -14,6 +13,7 @@
|
||||
#include <forward_list>
|
||||
#include <iosfwd>
|
||||
#include <map>
|
||||
#include <chrono>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
@@ -75,7 +75,7 @@ private:
|
||||
bool loaded = false;
|
||||
|
||||
// Stores the time when this source was most recently updated.
|
||||
timestamp updated = 0;
|
||||
std::chrono::steady_clock::time_point updated = std::chrono::steady_clock::time_point::min();
|
||||
|
||||
std::map<Tile::ID, std::unique_ptr<Tile>> tiles;
|
||||
std::map<Tile::ID, std::weak_ptr<TileData>> tile_data;
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
#include <mbgl/util/mat4.hpp>
|
||||
#include <mbgl/util/std.hpp>
|
||||
#include <mbgl/util/math.hpp>
|
||||
#include <mbgl/util/time.hpp>
|
||||
#include <mbgl/util/transition.hpp>
|
||||
#include <mbgl/platform/platform.hpp>
|
||||
|
||||
@@ -48,16 +47,16 @@ bool Transform::resize(const uint16_t w, const uint16_t h, const float ratio,
|
||||
|
||||
#pragma mark - Position
|
||||
|
||||
void Transform::moveBy(const double dx, const double dy, const timestamp duration) {
|
||||
void Transform::moveBy(const double dx, const double dy, const std::chrono::steady_clock::duration duration) {
|
||||
std::lock_guard<std::recursive_mutex> lock(mtx);
|
||||
|
||||
_moveBy(dx, dy, duration);
|
||||
}
|
||||
|
||||
void Transform::_moveBy(const double dx, const double dy, const timestamp duration) {
|
||||
void Transform::_moveBy(const double dx, const double dy, const std::chrono::steady_clock::duration duration) {
|
||||
// This is only called internally, so we don't need a lock here.
|
||||
|
||||
view.notifyMapChange(duration ?
|
||||
view.notifyMapChange(duration != std::chrono::steady_clock::duration::zero() ?
|
||||
MapChangeRegionWillChangeAnimated :
|
||||
MapChangeRegionWillChange);
|
||||
|
||||
@@ -66,25 +65,25 @@ void Transform::_moveBy(const double dx, const double dy, const timestamp durati
|
||||
|
||||
constrain(final.scale, final.y);
|
||||
|
||||
if (duration == 0) {
|
||||
if (duration == std::chrono::steady_clock::duration::zero()) {
|
||||
current.x = final.x;
|
||||
current.y = final.y;
|
||||
} else {
|
||||
// Use a common start time for all of the transitions to avoid divergent transitions.
|
||||
timestamp start = util::now();
|
||||
std::chrono::steady_clock::time_point start = std::chrono::steady_clock::now();
|
||||
transitions.emplace_front(
|
||||
std::make_shared<util::ease_transition<double>>(current.x, final.x, current.x, start, duration));
|
||||
transitions.emplace_front(
|
||||
std::make_shared<util::ease_transition<double>>(current.y, final.y, current.y, start, duration));
|
||||
}
|
||||
|
||||
view.notifyMapChange(duration ?
|
||||
view.notifyMapChange(duration != std::chrono::steady_clock::duration::zero() ?
|
||||
MapChangeRegionDidChangeAnimated :
|
||||
MapChangeRegionDidChange,
|
||||
duration);
|
||||
}
|
||||
|
||||
void Transform::setLonLat(const double lon, const double lat, const timestamp duration) {
|
||||
void Transform::setLonLat(const double lon, const double lat, const std::chrono::steady_clock::duration duration) {
|
||||
std::lock_guard<std::recursive_mutex> lock(mtx);
|
||||
|
||||
const double f = std::fmin(std::fmax(std::sin(D2R * lat), -0.9999), 0.9999);
|
||||
@@ -95,7 +94,7 @@ void Transform::setLonLat(const double lon, const double lat, const timestamp du
|
||||
}
|
||||
|
||||
void Transform::setLonLatZoom(const double lon, const double lat, const double zoom,
|
||||
const timestamp duration) {
|
||||
const std::chrono::steady_clock::duration duration) {
|
||||
std::lock_guard<std::recursive_mutex> lock(mtx);
|
||||
|
||||
double new_scale = std::pow(2.0, zoom);
|
||||
@@ -131,8 +130,8 @@ void Transform::startPanning() {
|
||||
|
||||
// Add a 200ms timeout for resetting this to false
|
||||
current.panning = true;
|
||||
timestamp start = util::now();
|
||||
pan_timeout = std::make_shared<util::timeout<bool>>(false, current.panning, start, 200_milliseconds);
|
||||
std::chrono::steady_clock::time_point start = std::chrono::steady_clock::now();
|
||||
pan_timeout = std::make_shared<util::timeout<bool>>(false, current.panning, start, std::chrono::steady_clock::duration(200));
|
||||
transitions.emplace_front(pan_timeout);
|
||||
}
|
||||
|
||||
@@ -152,7 +151,7 @@ void Transform::_clearPanning() {
|
||||
|
||||
#pragma mark - Zoom
|
||||
|
||||
void Transform::scaleBy(const double ds, const double cx, const double cy, const timestamp duration) {
|
||||
void Transform::scaleBy(const double ds, const double cx, const double cy, const std::chrono::steady_clock::duration duration) {
|
||||
std::lock_guard<std::recursive_mutex> lock(mtx);
|
||||
|
||||
// clamp scale to min/max values
|
||||
@@ -167,13 +166,13 @@ void Transform::scaleBy(const double ds, const double cx, const double cy, const
|
||||
}
|
||||
|
||||
void Transform::setScale(const double scale, const double cx, const double cy,
|
||||
const timestamp duration) {
|
||||
const std::chrono::steady_clock::duration duration) {
|
||||
std::lock_guard<std::recursive_mutex> lock(mtx);
|
||||
|
||||
_setScale(scale, cx, cy, duration);
|
||||
}
|
||||
|
||||
void Transform::setZoom(const double zoom, const timestamp duration) {
|
||||
void Transform::setZoom(const double zoom, const std::chrono::steady_clock::duration duration) {
|
||||
std::lock_guard<std::recursive_mutex> lock(mtx);
|
||||
|
||||
_setScale(std::pow(2.0, zoom), -1, -1, duration);
|
||||
@@ -198,8 +197,8 @@ void Transform::startScaling() {
|
||||
|
||||
// Add a 200ms timeout for resetting this to false
|
||||
current.scaling = true;
|
||||
timestamp start = util::now();
|
||||
scale_timeout = std::make_shared<util::timeout<bool>>(false, current.scaling, start, 200_milliseconds);
|
||||
std::chrono::steady_clock::time_point start = std::chrono::steady_clock::now();
|
||||
scale_timeout = std::make_shared<util::timeout<bool>>(false, current.scaling, start, std::chrono::milliseconds(200));
|
||||
transitions.emplace_front(scale_timeout);
|
||||
}
|
||||
|
||||
@@ -231,7 +230,7 @@ void Transform::_clearScaling() {
|
||||
}
|
||||
}
|
||||
|
||||
void Transform::_setScale(double new_scale, double cx, double cy, const timestamp duration) {
|
||||
void Transform::_setScale(double new_scale, double cx, double cy, const std::chrono::steady_clock::duration duration) {
|
||||
// This is only called internally, so we don't need a lock here.
|
||||
|
||||
// Ensure that we don't zoom in further than the maximum allowed.
|
||||
@@ -265,10 +264,10 @@ void Transform::_setScale(double new_scale, double cx, double cy, const timestam
|
||||
}
|
||||
|
||||
void Transform::_setScaleXY(const double new_scale, const double xn, const double yn,
|
||||
const timestamp duration) {
|
||||
const std::chrono::steady_clock::duration duration) {
|
||||
// This is only called internally, so we don't need a lock here.
|
||||
|
||||
view.notifyMapChange(duration ?
|
||||
view.notifyMapChange(duration != std::chrono::steady_clock::duration::zero() ?
|
||||
MapChangeRegionWillChangeAnimated :
|
||||
MapChangeRegionWillChange);
|
||||
|
||||
@@ -278,13 +277,13 @@ void Transform::_setScaleXY(const double new_scale, const double xn, const doubl
|
||||
|
||||
constrain(final.scale, final.y);
|
||||
|
||||
if (duration == 0) {
|
||||
if (duration == std::chrono::steady_clock::duration::zero()) {
|
||||
current.scale = final.scale;
|
||||
current.x = final.x;
|
||||
current.y = final.y;
|
||||
} else {
|
||||
// Use a common start time for all of the transitions to avoid divergent transitions.
|
||||
timestamp start = util::now();
|
||||
std::chrono::steady_clock::time_point start = std::chrono::steady_clock::now();
|
||||
transitions.emplace_front(std::make_shared<util::ease_transition<double>>(
|
||||
current.scale, final.scale, current.scale, start, duration));
|
||||
transitions.emplace_front(
|
||||
@@ -297,7 +296,7 @@ void Transform::_setScaleXY(const double new_scale, const double xn, const doubl
|
||||
Bc = s / 360;
|
||||
Cc = s / (2 * M_PI);
|
||||
|
||||
view.notifyMapChange(duration ?
|
||||
view.notifyMapChange(duration != std::chrono::steady_clock::duration::zero() ?
|
||||
MapChangeRegionDidChangeAnimated :
|
||||
MapChangeRegionDidChange,
|
||||
duration);
|
||||
@@ -319,7 +318,7 @@ void Transform::constrain(double& scale, double& y) const {
|
||||
#pragma mark - Angle
|
||||
|
||||
void Transform::rotateBy(const double start_x, const double start_y, const double end_x,
|
||||
const double end_y, const timestamp duration) {
|
||||
const double end_y, const std::chrono::steady_clock::duration duration) {
|
||||
std::lock_guard<std::recursive_mutex> lock(mtx);
|
||||
|
||||
double center_x = current.width / 2, center_y = current.height / 2;
|
||||
@@ -349,7 +348,7 @@ void Transform::rotateBy(const double start_x, const double start_y, const doubl
|
||||
_setAngle(ang, duration);
|
||||
}
|
||||
|
||||
void Transform::setAngle(const double new_angle, const timestamp duration) {
|
||||
void Transform::setAngle(const double new_angle, const std::chrono::steady_clock::duration duration) {
|
||||
std::lock_guard<std::recursive_mutex> lock(mtx);
|
||||
|
||||
_setAngle(new_angle, duration);
|
||||
@@ -363,20 +362,20 @@ void Transform::setAngle(const double new_angle, const double cx, const double c
|
||||
if (cx >= 0 && cy >= 0) {
|
||||
dx = (final.width / 2) - cx;
|
||||
dy = (final.height / 2) - cy;
|
||||
_moveBy(dx, dy, 0);
|
||||
_moveBy(dx, dy, std::chrono::steady_clock::duration::zero());
|
||||
}
|
||||
|
||||
_setAngle(new_angle, 0);
|
||||
_setAngle(new_angle, std::chrono::steady_clock::duration::zero());
|
||||
|
||||
if (cx >= 0 && cy >= 0) {
|
||||
_moveBy(-dx, -dy, 0);
|
||||
_moveBy(-dx, -dy, std::chrono::steady_clock::duration::zero());
|
||||
}
|
||||
}
|
||||
|
||||
void Transform::_setAngle(double new_angle, const timestamp duration) {
|
||||
void Transform::_setAngle(double new_angle, const std::chrono::steady_clock::duration duration) {
|
||||
// This is only called internally, so we don't need a lock here.
|
||||
|
||||
view.notifyMapChange(duration ?
|
||||
view.notifyMapChange(duration != std::chrono::steady_clock::duration::zero() ?
|
||||
MapChangeRegionWillChangeAnimated :
|
||||
MapChangeRegionWillChange);
|
||||
|
||||
@@ -387,15 +386,15 @@ void Transform::_setAngle(double new_angle, const timestamp duration) {
|
||||
|
||||
final.angle = new_angle;
|
||||
|
||||
if (duration == 0) {
|
||||
if (duration == std::chrono::steady_clock::duration::zero()) {
|
||||
current.angle = final.angle;
|
||||
} else {
|
||||
timestamp start = util::now();
|
||||
std::chrono::steady_clock::time_point start = std::chrono::steady_clock::now();
|
||||
transitions.emplace_front(std::make_shared<util::ease_transition<double>>(
|
||||
current.angle, final.angle, current.angle, start, duration));
|
||||
}
|
||||
|
||||
view.notifyMapChange(duration ?
|
||||
view.notifyMapChange(duration != std::chrono::steady_clock::duration::zero() ?
|
||||
MapChangeRegionDidChangeAnimated :
|
||||
MapChangeRegionDidChange,
|
||||
duration);
|
||||
@@ -414,8 +413,8 @@ void Transform::startRotating() {
|
||||
|
||||
// Add a 200ms timeout for resetting this to false
|
||||
current.rotating = true;
|
||||
timestamp start = util::now();
|
||||
rotate_timeout = std::make_shared<util::timeout<bool>>(false, current.rotating, start, 200_milliseconds);
|
||||
std::chrono::steady_clock::time_point start = std::chrono::steady_clock::now();
|
||||
rotate_timeout = std::make_shared<util::timeout<bool>>(false, current.rotating, start, std::chrono::milliseconds(200));
|
||||
transitions.emplace_front(rotate_timeout);
|
||||
}
|
||||
|
||||
@@ -443,7 +442,7 @@ bool Transform::needsTransition() const {
|
||||
return !transitions.empty();
|
||||
}
|
||||
|
||||
void Transform::updateTransitions(const timestamp now) {
|
||||
void Transform::updateTransitions(const std::chrono::steady_clock::time_point now) {
|
||||
std::lock_guard<std::recursive_mutex> lock(mtx);
|
||||
|
||||
transitions.remove_if([now](const util::ptr<util::transition> &transition) {
|
||||
|
||||
@@ -3,11 +3,11 @@
|
||||
using namespace mbgl;
|
||||
|
||||
// Record frame history that will be used to calculate fading params
|
||||
void FrameHistory::record(timestamp now, float zoom) {
|
||||
void FrameHistory::record(std::chrono::steady_clock::time_point now, float zoom) {
|
||||
// first frame ever
|
||||
if (!history.size()) {
|
||||
history.emplace_back(FrameSnapshot{0, zoom});
|
||||
history.emplace_back(FrameSnapshot{0, zoom});
|
||||
history.emplace_back(FrameSnapshot{std::chrono::steady_clock::time_point::min(), zoom});
|
||||
history.emplace_back(FrameSnapshot{std::chrono::steady_clock::time_point::min(), zoom});
|
||||
}
|
||||
|
||||
if (history.size() > 0 || history.back().z != zoom) {
|
||||
@@ -15,7 +15,7 @@ void FrameHistory::record(timestamp now, float zoom) {
|
||||
}
|
||||
}
|
||||
|
||||
bool FrameHistory::needsAnimation(const timestamp duration) const {
|
||||
bool FrameHistory::needsAnimation(const std::chrono::steady_clock::duration duration) const {
|
||||
if (!history.size()) {
|
||||
return false;
|
||||
}
|
||||
@@ -26,7 +26,7 @@ bool FrameHistory::needsAnimation(const timestamp duration) const {
|
||||
const FrameSnapshot &pivot = history.back();
|
||||
|
||||
int i = -1;
|
||||
while ((int)history.size() > i + 1 && history[i + 1].t + duration < pivot.t) {
|
||||
while ((int)history.size() > i + 1 && history[i + 1].now + duration < pivot.now) {
|
||||
i++;
|
||||
}
|
||||
|
||||
@@ -47,16 +47,16 @@ bool FrameHistory::needsAnimation(const timestamp duration) const {
|
||||
return false;
|
||||
}
|
||||
|
||||
FadeProperties FrameHistory::getFadeProperties(timestamp duration)
|
||||
FadeProperties FrameHistory::getFadeProperties(std::chrono::steady_clock::duration duration)
|
||||
{
|
||||
const timestamp currentTime = util::now();
|
||||
const std::chrono::steady_clock::time_point currentTime = std::chrono::steady_clock::now();
|
||||
|
||||
// Remove frames until only one is outside the duration, or until there are only three
|
||||
while (history.size() > 3 && history[1].t + duration < currentTime) {
|
||||
while (history.size() > 3 && history[1].now + duration < currentTime) {
|
||||
history.pop_front();
|
||||
}
|
||||
|
||||
if (history[1].t + duration < currentTime) {
|
||||
if (history[1].now + duration < currentTime) {
|
||||
history[0].z = history[1].z;
|
||||
}
|
||||
|
||||
@@ -69,12 +69,13 @@ FadeProperties FrameHistory::getFadeProperties(timestamp duration)
|
||||
|
||||
// Calculate the speed of zooming, and how far it would zoom in terms of zoom levels in one
|
||||
// duration
|
||||
float zoomDiff = endingZ - history[1].z, timeDiff = lastFrame.t - history[1].t;
|
||||
float zoomDiff = endingZ - history[1].z;
|
||||
std::chrono::duration<float> timeDiff = lastFrame.now - history[1].now;
|
||||
float fadedist = zoomDiff / (timeDiff / duration);
|
||||
|
||||
// At end of a zoom when the zoom stops changing continue pretending to zoom at that speed
|
||||
// bump is how much farther it would have been if it had continued zooming at the same rate
|
||||
float bump = (currentTime - lastFrame.t) / duration * fadedist;
|
||||
float bump = std::chrono::duration<float>(currentTime - lastFrame.now) / duration * fadedist;
|
||||
|
||||
return FadeProperties {
|
||||
fadedist,
|
||||
|
||||
@@ -4,15 +4,15 @@
|
||||
#include <deque>
|
||||
#include <cassert>
|
||||
#include <cmath>
|
||||
#include <chrono>
|
||||
|
||||
#include <mbgl/platform/platform.hpp>
|
||||
#include <mbgl/util/time.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
struct FrameSnapshot {
|
||||
explicit inline FrameSnapshot(timestamp t_, float z_) : t(t_), z(z_) {}
|
||||
float t;
|
||||
explicit inline FrameSnapshot(std::chrono::steady_clock::time_point now_, float z_) : now(now_), z(z_) {}
|
||||
std::chrono::steady_clock::time_point now;
|
||||
float z;
|
||||
};
|
||||
|
||||
@@ -26,10 +26,10 @@ struct FadeProperties {
|
||||
class FrameHistory {
|
||||
public:
|
||||
// Record frame history that will be used to calculate fading params
|
||||
void record(timestamp now, float zoom);
|
||||
void record(std::chrono::steady_clock::time_point now, float zoom);
|
||||
|
||||
bool needsAnimation(timestamp duration) const;
|
||||
FadeProperties getFadeProperties(timestamp duration);
|
||||
bool needsAnimation(std::chrono::steady_clock::duration duration) const;
|
||||
FadeProperties getFadeProperties(std::chrono::steady_clock::duration duration);
|
||||
|
||||
public:
|
||||
std::deque<FrameSnapshot> history;
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
#include <mbgl/style/style_bucket.hpp>
|
||||
#include <mbgl/util/std.hpp>
|
||||
#include <mbgl/util/string.hpp>
|
||||
#include <mbgl/util/time.hpp>
|
||||
#include <mbgl/util/clip_ids.hpp>
|
||||
#include <mbgl/util/constants.hpp>
|
||||
#include <mbgl/util/mat3.hpp>
|
||||
@@ -35,7 +34,7 @@ Painter::~Painter() {
|
||||
}
|
||||
|
||||
bool Painter::needsAnimation() const {
|
||||
return frameHistory.needsAnimation(300);
|
||||
return frameHistory.needsAnimation(std::chrono::milliseconds(300));
|
||||
}
|
||||
|
||||
void Painter::setup() {
|
||||
@@ -216,7 +215,7 @@ void Painter::prepareTile(const Tile& tile) {
|
||||
}
|
||||
|
||||
void Painter::render(const Style& style, const std::set<util::ptr<StyleSource>>& sources,
|
||||
TransformState state_, timestamp time) {
|
||||
TransformState state_, std::chrono::steady_clock::time_point time) {
|
||||
state = state_;
|
||||
|
||||
clear();
|
||||
@@ -461,7 +460,7 @@ mat4 Painter::translatedMatrix(const mat4& matrix, const std::array<float, 2> &t
|
||||
}
|
||||
}
|
||||
|
||||
void Painter::recordZoom(const timestamp time, const float zoom) {
|
||||
void Painter::recordZoom(const std::chrono::steady_clock::time_point time, const float zoom) {
|
||||
frameHistory.record(time, zoom);
|
||||
|
||||
if (lastZoom < 0) {
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#include <map>
|
||||
#include <unordered_map>
|
||||
#include <set>
|
||||
#include <chrono>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
@@ -78,7 +79,7 @@ public:
|
||||
void render(const Style& style,
|
||||
const std::set<util::ptr<StyleSource>>& sources,
|
||||
TransformState state,
|
||||
timestamp time);
|
||||
std::chrono::steady_clock::time_point time);
|
||||
|
||||
void renderLayers(util::ptr<StyleLayerGroup> group);
|
||||
void renderLayer(util::ptr<StyleLayer> layer_desc, const Tile::ID* id = nullptr, const mat4* matrix = nullptr);
|
||||
@@ -139,7 +140,7 @@ private:
|
||||
mat4 translatedMatrix(const mat4& matrix, const std::array<float, 2> &translation, const Tile::ID &id, TranslateAnchorType anchor);
|
||||
|
||||
void prepareTile(const Tile& tile);
|
||||
void recordZoom(const timestamp time, const float zoom);
|
||||
void recordZoom(const std::chrono::steady_clock::time_point time, const float zoom);
|
||||
|
||||
template <typename BucketProperties, typename StyleProperties>
|
||||
void renderSDF(SymbolBucket &bucket,
|
||||
@@ -193,7 +194,7 @@ private:
|
||||
const float strata_epsilon = 1.0f / (1 << 16);
|
||||
|
||||
int lastIntegerZoom;
|
||||
timestamp lastIntegerZoomTime = 0;
|
||||
std::chrono::steady_clock::time_point lastIntegerZoomTime = std::chrono::steady_clock::time_point::min();
|
||||
float lastZoom = -1;
|
||||
|
||||
public:
|
||||
|
||||
@@ -63,9 +63,9 @@ void Painter::renderFill(FillBucket& bucket, util::ptr<StyleLayer> layer_desc, c
|
||||
float factor = 8.0 / std::pow(2, state.getIntegerZoom() - id.z);
|
||||
|
||||
float mix;
|
||||
float duration = 300 * 1_millisecond;
|
||||
std::chrono::steady_clock::duration duration = std::chrono::milliseconds(300);
|
||||
const float fraction = std::fmod(float(state.getZoom()), 1.0f);
|
||||
float t = std::min((util::now() - lastIntegerZoomTime) / duration, 1.0f);
|
||||
float t = std::min(static_cast<float>((std::chrono::steady_clock::now() - lastIntegerZoomTime) / duration), 1.0f);
|
||||
if (state.getZoom() > lastIntegerZoom) {
|
||||
// zooming in
|
||||
mix = fraction + (1.0f - fraction) * t;
|
||||
|
||||
@@ -70,9 +70,9 @@ void Painter::renderLine(LineBucket& bucket, util::ptr<StyleLayer> layer_desc, c
|
||||
bucket.drawPoints(*linejoinShader);
|
||||
}
|
||||
|
||||
float duration = 300 * 1_millisecond;
|
||||
std::chrono::steady_clock::duration duration = std::chrono::milliseconds(300);
|
||||
const float fraction = std::fmod(float(state.getZoom()), 1.0f);
|
||||
float t = std::min((util::now() - lastIntegerZoomTime) / duration, 1.0f);
|
||||
float t = std::min(static_cast<float>(std::chrono::duration<float>(std::chrono::steady_clock::now() - lastIntegerZoomTime) / duration), 1.0f);
|
||||
|
||||
if (properties.dash_array.size()) {
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <mbgl/geometry/sprite_atlas.hpp>
|
||||
#include <mbgl/map/map.hpp>
|
||||
#include <mbgl/util/math.hpp>
|
||||
|
||||
#include <cmath>
|
||||
|
||||
using namespace mbgl;
|
||||
@@ -52,7 +53,7 @@ void Painter::renderSDF(SymbolBucket &bucket,
|
||||
sdfShader.u_angle = (int32_t)(angle + 256) % 256;
|
||||
sdfShader.u_zoom = (state.getNormalizedZoom() - zoomAdjust) * 10; // current zoom level
|
||||
|
||||
FadeProperties f = frameHistory.getFadeProperties(300_milliseconds);
|
||||
FadeProperties f = frameHistory.getFadeProperties(std::chrono::milliseconds(300));
|
||||
sdfShader.u_fadedist = f.fadedist * 10;
|
||||
sdfShader.u_minfadezoom = std::floor(f.minfadezoom * 10);
|
||||
sdfShader.u_maxfadezoom = std::floor(f.maxfadezoom * 10);
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
AppliedClassProperty::AppliedClassProperty(ClassID class_id, timestamp begin_, timestamp end_, const PropertyValue &value_)
|
||||
AppliedClassProperty::AppliedClassProperty(ClassID class_id, std::chrono::steady_clock::time_point begin_, std::chrono::steady_clock::time_point end_, const PropertyValue &value_)
|
||||
: name(class_id),
|
||||
begin(begin_),
|
||||
end(end_),
|
||||
@@ -13,7 +13,7 @@ ClassID AppliedClassProperties::mostRecent() const {
|
||||
return properties.size() ? properties.back().name : ClassID::Fallback;
|
||||
}
|
||||
|
||||
void AppliedClassProperties::add(ClassID class_id, timestamp begin, timestamp end, const PropertyValue &value) {
|
||||
void AppliedClassProperties::add(ClassID class_id, std::chrono::steady_clock::time_point begin, std::chrono::steady_clock::time_point end, const PropertyValue &value) {
|
||||
properties.emplace_back(class_id, begin, end, value);
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ bool AppliedClassProperties::hasTransitions() const {
|
||||
|
||||
// Erase all items in the property list that are before a completed transition.
|
||||
// Then, if the only remaining property is a Fallback value, remove it too.
|
||||
void AppliedClassProperties::cleanup(timestamp now) {
|
||||
void AppliedClassProperties::cleanup(std::chrono::steady_clock::time_point now) {
|
||||
// Iterate backwards, but without using the rbegin/rend interface since we need forward
|
||||
// iterators to use .erase().
|
||||
for (auto it = properties.end(), begin = properties.begin(); it != begin;) {
|
||||
@@ -49,4 +49,4 @@ bool AppliedClassProperties::empty() const {
|
||||
return properties.empty();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,20 +3,20 @@
|
||||
|
||||
#include <mbgl/style/property_value.hpp>
|
||||
#include <mbgl/style/class_dictionary.hpp>
|
||||
#include <mbgl/util/time.hpp>
|
||||
|
||||
#include <list>
|
||||
#include <chrono>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
class AppliedClassProperty {
|
||||
public:
|
||||
AppliedClassProperty(ClassID class_id, timestamp begin, timestamp end, const PropertyValue &value);
|
||||
AppliedClassProperty(ClassID class_id, std::chrono::steady_clock::time_point begin, std::chrono::steady_clock::time_point end, const PropertyValue &value);
|
||||
|
||||
public:
|
||||
const ClassID name;
|
||||
const timestamp begin;
|
||||
const timestamp end;
|
||||
const std::chrono::steady_clock::time_point begin;
|
||||
const std::chrono::steady_clock::time_point end;
|
||||
const PropertyValue value;
|
||||
};
|
||||
|
||||
@@ -28,9 +28,9 @@ public:
|
||||
public:
|
||||
// Returns thie ID of the most recent
|
||||
ClassID mostRecent() const;
|
||||
void add(ClassID class_id, timestamp begin, timestamp end, const PropertyValue &value);
|
||||
void add(ClassID class_id, std::chrono::steady_clock::time_point begin, std::chrono::steady_clock::time_point end, const PropertyValue &value);
|
||||
bool hasTransitions() const;
|
||||
void cleanup(timestamp now);
|
||||
void cleanup(std::chrono::steady_clock::time_point now);
|
||||
bool empty() const;
|
||||
};
|
||||
|
||||
|
||||
@@ -2,14 +2,15 @@
|
||||
#define MBGL_STYLE_PROPERTY_TRANSITION
|
||||
|
||||
#include <cstdint>
|
||||
#include <chrono>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
struct PropertyTransition {
|
||||
uint16_t duration = 0;
|
||||
uint16_t delay = 0;
|
||||
std::chrono::steady_clock::duration duration = std::chrono::steady_clock::duration::zero();
|
||||
std::chrono::steady_clock::duration delay = std::chrono::steady_clock::duration::zero();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
#include <mbgl/style/style_parser.hpp>
|
||||
#include <mbgl/style/style_bucket.hpp>
|
||||
#include <mbgl/util/constants.hpp>
|
||||
#include <mbgl/util/time.hpp>
|
||||
#include <mbgl/util/error.hpp>
|
||||
#include <mbgl/util/std.hpp>
|
||||
#include <mbgl/util/uv_detail.hpp>
|
||||
@@ -26,7 +25,7 @@ Style::Style()
|
||||
// for deleting the std::unique_ptr<uv::rwlock>.
|
||||
Style::~Style() {}
|
||||
|
||||
void Style::updateProperties(float z, timestamp now) {
|
||||
void Style::updateProperties(float z, std::chrono::steady_clock::time_point now) {
|
||||
uv::writelock lock(mtx);
|
||||
|
||||
if (layers) {
|
||||
@@ -44,13 +43,13 @@ const std::string &Style::getSpriteURL() const {
|
||||
return sprite_url;
|
||||
}
|
||||
|
||||
void Style::setDefaultTransitionDuration(uint16_t duration_milliseconds) {
|
||||
defaultTransition.duration = duration_milliseconds;
|
||||
void Style::setDefaultTransitionDuration(std::chrono::steady_clock::duration duration) {
|
||||
defaultTransition.duration = duration;
|
||||
}
|
||||
|
||||
void Style::cascadeClasses(const std::vector<std::string>& classes) {
|
||||
if (layers) {
|
||||
layers->setClasses(classes, util::now(), defaultTransition);
|
||||
layers->setClasses(classes, std::chrono::steady_clock::now(), defaultTransition);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
#include <mbgl/style/property_transition.hpp>
|
||||
#include <mbgl/style/style_source.hpp>
|
||||
|
||||
#include <mbgl/util/time.hpp>
|
||||
#include <mbgl/util/uv.hpp>
|
||||
#include <mbgl/util/ptr.hpp>
|
||||
|
||||
@@ -14,6 +13,7 @@
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
#include <set>
|
||||
#include <chrono>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
@@ -31,9 +31,9 @@ public:
|
||||
void loadJSON(const uint8_t *const data);
|
||||
|
||||
size_t layerCount() const;
|
||||
void updateProperties(float z, timestamp t);
|
||||
void updateProperties(float z, std::chrono::steady_clock::time_point now);
|
||||
|
||||
void setDefaultTransitionDuration(uint16_t duration_milliseconds = 0);
|
||||
void setDefaultTransitionDuration(std::chrono::steady_clock::duration duration = std::chrono::steady_clock::duration::zero());
|
||||
void cascadeClasses(const std::vector<std::string>&);
|
||||
|
||||
bool hasTransitions() const;
|
||||
|
||||
@@ -14,7 +14,7 @@ bool StyleLayer::isBackground() const {
|
||||
return type == StyleLayerType::Background;
|
||||
}
|
||||
|
||||
void StyleLayer::setClasses(const std::vector<std::string> &class_names, const timestamp now,
|
||||
void StyleLayer::setClasses(const std::vector<std::string> &class_names, const std::chrono::steady_clock::time_point now,
|
||||
const PropertyTransition &defaultTransition) {
|
||||
// Stores all keys that we have already added transitions for.
|
||||
std::set<PropertyKey> already_applied;
|
||||
@@ -45,8 +45,8 @@ void StyleLayer::setClasses(const std::vector<std::string> &class_names, const t
|
||||
if (appliedProperties.mostRecent() != ClassID::Fallback) {
|
||||
// This property key hasn't been set by a previous class, so we need to add a transition
|
||||
// to the fallback value for that key.
|
||||
const timestamp begin = now + defaultTransition.delay * 1_millisecond;
|
||||
const timestamp end = begin + defaultTransition.duration * 1_millisecond;
|
||||
const std::chrono::steady_clock::time_point begin = now + defaultTransition.delay;
|
||||
const std::chrono::steady_clock::time_point end = begin + defaultTransition.duration;
|
||||
const PropertyValue &value = PropertyFallbackValue::Get(key);
|
||||
appliedProperties.add(ClassID::Fallback, begin, end, value);
|
||||
}
|
||||
@@ -55,7 +55,7 @@ void StyleLayer::setClasses(const std::vector<std::string> &class_names, const t
|
||||
|
||||
// Helper function for applying all properties of a a single class that haven't been applied yet.
|
||||
void StyleLayer::applyClassProperties(const ClassID class_id,
|
||||
std::set<PropertyKey> &already_applied, timestamp now,
|
||||
std::set<PropertyKey> &already_applied, std::chrono::steady_clock::time_point now,
|
||||
const PropertyTransition &defaultTransition) {
|
||||
auto style_it = styles.find(class_id);
|
||||
if (style_it == styles.end()) {
|
||||
@@ -83,8 +83,8 @@ void StyleLayer::applyClassProperties(const ClassID class_id,
|
||||
if (appliedProperties.mostRecent() != class_id) {
|
||||
const PropertyTransition &transition =
|
||||
class_properties.getTransition(key, defaultTransition);
|
||||
const timestamp begin = now + transition.delay * 1_millisecond;
|
||||
const timestamp end = begin + transition.duration * 1_millisecond;
|
||||
const std::chrono::steady_clock::time_point begin = now + transition.delay;
|
||||
const std::chrono::steady_clock::time_point end = begin + transition.duration;
|
||||
const PropertyValue &value = property_pair.second;
|
||||
appliedProperties.add(class_id, begin, end, value);
|
||||
}
|
||||
@@ -115,7 +115,7 @@ private:
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
void StyleLayer::applyStyleProperty(PropertyKey key, T &target, const float z, const timestamp now) {
|
||||
void StyleLayer::applyStyleProperty(PropertyKey key, T &target, const float z, const std::chrono::steady_clock::time_point now) {
|
||||
auto it = appliedStyle.find(key);
|
||||
if (it != appliedStyle.end()) {
|
||||
AppliedClassProperties &applied = it->second;
|
||||
@@ -133,7 +133,7 @@ void StyleLayer::applyStyleProperty(PropertyKey key, T &target, const float z, c
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void StyleLayer::applyTransitionedStyleProperty(PropertyKey key, T &target, const float z, const timestamp now) {
|
||||
void StyleLayer::applyTransitionedStyleProperty(PropertyKey key, T &target, const float z, const std::chrono::steady_clock::time_point now) {
|
||||
auto it = appliedStyle.find(key);
|
||||
if (it != appliedStyle.end()) {
|
||||
AppliedClassProperties &applied = it->second;
|
||||
@@ -145,7 +145,7 @@ void StyleLayer::applyTransitionedStyleProperty(PropertyKey key, T &target, cons
|
||||
target = mapbox::util::apply_visitor(evaluator, property.value);
|
||||
} else if (now >= property.begin) {
|
||||
// We overwrite the current property partially with the new value.
|
||||
float progress = float(now - property.begin) / float(property.end - property.begin);
|
||||
float progress = std::chrono::duration<float>(now - property.begin) / (property.end - property.begin);
|
||||
target = util::interpolate(target, mapbox::util::apply_visitor(evaluator, property.value), progress);
|
||||
} else {
|
||||
// Do not apply this property because its transition hasn't begun yet.
|
||||
@@ -155,7 +155,7 @@ void StyleLayer::applyTransitionedStyleProperty(PropertyKey key, T &target, cons
|
||||
}
|
||||
|
||||
template <>
|
||||
void StyleLayer::applyStyleProperties<FillProperties>(const float z, const timestamp now) {
|
||||
void StyleLayer::applyStyleProperties<FillProperties>(const float z, const std::chrono::steady_clock::time_point now) {
|
||||
properties.set<FillProperties>();
|
||||
FillProperties &fill = properties.get<FillProperties>();
|
||||
applyStyleProperty(PropertyKey::FillAntialias, fill.antialias, z, now);
|
||||
@@ -169,7 +169,7 @@ void StyleLayer::applyStyleProperties<FillProperties>(const float z, const times
|
||||
}
|
||||
|
||||
template <>
|
||||
void StyleLayer::applyStyleProperties<LineProperties>(const float z, const timestamp now) {
|
||||
void StyleLayer::applyStyleProperties<LineProperties>(const float z, const std::chrono::steady_clock::time_point now) {
|
||||
properties.set<LineProperties>();
|
||||
LineProperties &line = properties.get<LineProperties>();
|
||||
applyTransitionedStyleProperty(PropertyKey::LineOpacity, line.opacity, z, now);
|
||||
@@ -184,11 +184,11 @@ void StyleLayer::applyStyleProperties<LineProperties>(const float z, const times
|
||||
applyStyleProperty(PropertyKey::LineImage, line.image, z, now);
|
||||
|
||||
// for scaling dasharrays
|
||||
applyStyleProperty(PropertyKey::LineWidth, line.dash_line_width, std::floor(z), now + 10000);
|
||||
applyStyleProperty(PropertyKey::LineWidth, line.dash_line_width, std::floor(z), std::chrono::steady_clock::time_point::max());
|
||||
}
|
||||
|
||||
template <>
|
||||
void StyleLayer::applyStyleProperties<SymbolProperties>(const float z, const timestamp now) {
|
||||
void StyleLayer::applyStyleProperties<SymbolProperties>(const float z, const std::chrono::steady_clock::time_point now) {
|
||||
properties.set<SymbolProperties>();
|
||||
SymbolProperties &symbol = properties.get<SymbolProperties>();
|
||||
applyTransitionedStyleProperty(PropertyKey::IconOpacity, symbol.icon.opacity, z, now);
|
||||
@@ -214,7 +214,7 @@ void StyleLayer::applyStyleProperties<SymbolProperties>(const float z, const tim
|
||||
}
|
||||
|
||||
template <>
|
||||
void StyleLayer::applyStyleProperties<RasterProperties>(const float z, const timestamp now) {
|
||||
void StyleLayer::applyStyleProperties<RasterProperties>(const float z, const std::chrono::steady_clock::time_point now) {
|
||||
properties.set<RasterProperties>();
|
||||
RasterProperties &raster = properties.get<RasterProperties>();
|
||||
applyTransitionedStyleProperty(PropertyKey::RasterOpacity, raster.opacity, z, now);
|
||||
@@ -227,7 +227,7 @@ void StyleLayer::applyStyleProperties<RasterProperties>(const float z, const tim
|
||||
}
|
||||
|
||||
template <>
|
||||
void StyleLayer::applyStyleProperties<BackgroundProperties>(const float z, const timestamp now) {
|
||||
void StyleLayer::applyStyleProperties<BackgroundProperties>(const float z, const std::chrono::steady_clock::time_point now) {
|
||||
properties.set<BackgroundProperties>();
|
||||
BackgroundProperties &background = properties.get<BackgroundProperties>();
|
||||
applyTransitionedStyleProperty(PropertyKey::BackgroundOpacity, background.opacity, z, now);
|
||||
@@ -235,7 +235,7 @@ void StyleLayer::applyStyleProperties<BackgroundProperties>(const float z, const
|
||||
applyStyleProperty(PropertyKey::BackgroundImage, background.image, z, now);
|
||||
}
|
||||
|
||||
void StyleLayer::updateProperties(float z, const timestamp now) {
|
||||
void StyleLayer::updateProperties(float z, const std::chrono::steady_clock::time_point now) {
|
||||
cleanupAppliedStyleProperties(now);
|
||||
|
||||
switch (type) {
|
||||
@@ -258,7 +258,7 @@ bool StyleLayer::hasTransitions() const {
|
||||
}
|
||||
|
||||
|
||||
void StyleLayer::cleanupAppliedStyleProperties(timestamp now) {
|
||||
void StyleLayer::cleanupAppliedStyleProperties(std::chrono::steady_clock::time_point now) {
|
||||
auto it = appliedStyle.begin();
|
||||
const auto end = appliedStyle.end();
|
||||
while (it != end) {
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <chrono>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
@@ -35,10 +36,10 @@ public:
|
||||
|
||||
// Updates the StyleProperties information in this layer by evaluating all
|
||||
// pending transitions and applied classes in order.
|
||||
void updateProperties(float z, timestamp now);
|
||||
void updateProperties(float z, std::chrono::steady_clock::time_point now);
|
||||
|
||||
// Sets the list of classes and creates transitions to the currently applied values.
|
||||
void setClasses(const std::vector<std::string> &class_names, timestamp now,
|
||||
void setClasses(const std::vector<std::string> &class_names, std::chrono::steady_clock::time_point now,
|
||||
const PropertyTransition &defaultTransition);
|
||||
|
||||
bool hasTransitions() const;
|
||||
@@ -46,16 +47,16 @@ public:
|
||||
private:
|
||||
// Applies all properties from a class, if they haven't been applied already.
|
||||
void applyClassProperties(ClassID class_id, std::set<PropertyKey> &already_applied,
|
||||
timestamp now, const PropertyTransition &defaultTransition);
|
||||
std::chrono::steady_clock::time_point now, const PropertyTransition &defaultTransition);
|
||||
|
||||
// Sets the properties of this object by evaluating all pending transitions and
|
||||
// aplied classes in order.
|
||||
template <typename T> void applyStyleProperties(float z, timestamp now);
|
||||
template <typename T> void applyStyleProperty(PropertyKey key, T &, float z, timestamp now);
|
||||
template <typename T> void applyTransitionedStyleProperty(PropertyKey key, T &, float z, timestamp now);
|
||||
template <typename T> void applyStyleProperties(float z, std::chrono::steady_clock::time_point now);
|
||||
template <typename T> void applyStyleProperty(PropertyKey key, T &, float z, std::chrono::steady_clock::time_point now);
|
||||
template <typename T> void applyTransitionedStyleProperty(PropertyKey key, T &, float z, std::chrono::steady_clock::time_point now);
|
||||
|
||||
// Removes all expired style transitions.
|
||||
void cleanupAppliedStyleProperties(timestamp now);
|
||||
void cleanupAppliedStyleProperties(std::chrono::steady_clock::time_point now);
|
||||
|
||||
public:
|
||||
// The name of this layer.
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
void StyleLayerGroup::setClasses(const std::vector<std::string> &class_names, timestamp now,
|
||||
void StyleLayerGroup::setClasses(const std::vector<std::string> &class_names, std::chrono::steady_clock::time_point now,
|
||||
const PropertyTransition &defaultTransition) {
|
||||
for (const util::ptr<StyleLayer> &layer : layers) {
|
||||
if (layer) {
|
||||
@@ -11,10 +11,10 @@ void StyleLayerGroup::setClasses(const std::vector<std::string> &class_names, ti
|
||||
}
|
||||
}
|
||||
|
||||
void StyleLayerGroup::updateProperties(float z, timestamp t) {
|
||||
void StyleLayerGroup::updateProperties(float z, std::chrono::steady_clock::time_point now) {
|
||||
for (const util::ptr<StyleLayer> &layer: layers) {
|
||||
if (layer) {
|
||||
layer->updateProperties(z, t);
|
||||
layer->updateProperties(z, now);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,14 +4,15 @@
|
||||
#include <mbgl/style/style_layer.hpp>
|
||||
|
||||
#include <vector>
|
||||
#include <chrono>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
class StyleLayerGroup {
|
||||
public:
|
||||
void setClasses(const std::vector<std::string> &class_names, timestamp now,
|
||||
void setClasses(const std::vector<std::string> &class_names, std::chrono::steady_clock::time_point now,
|
||||
const PropertyTransition &defaultTransition);
|
||||
void updateProperties(float z, timestamp t);
|
||||
void updateProperties(float z, std::chrono::steady_clock::time_point now);
|
||||
|
||||
bool hasTransitions() const;
|
||||
public:
|
||||
|
||||
@@ -367,14 +367,14 @@ template<> std::tuple<bool, PropertyTransition> StyleParser::parseProperty(JSVal
|
||||
PropertyTransition transition;
|
||||
if (value.IsObject()) {
|
||||
if (value.HasMember("duration") && value["duration"].IsNumber()) {
|
||||
transition.duration = value["duration"].GetUint();
|
||||
transition.duration = std::chrono::milliseconds(value["duration"].GetUint());
|
||||
}
|
||||
if (value.HasMember("delay") && value["delay"].IsNumber()) {
|
||||
transition.delay = value["delay"].GetUint();
|
||||
transition.delay = std::chrono::milliseconds(value["delay"].GetUint());
|
||||
}
|
||||
}
|
||||
|
||||
if (transition.duration == 0 && transition.delay == 0) {
|
||||
if (transition.duration == std::chrono::steady_clock::duration::zero() && transition.delay == std::chrono::steady_clock::duration::zero()) {
|
||||
return std::tuple<bool, PropertyTransition> { false, std::move(transition) };
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
#include <mbgl/platform/gl.hpp>
|
||||
|
||||
#include <mbgl/util/raster.hpp>
|
||||
#include <mbgl/util/time.hpp>
|
||||
#include <mbgl/util/uv_detail.hpp>
|
||||
#include <mbgl/util/std.hpp>
|
||||
|
||||
@@ -91,15 +90,15 @@ void Raster::bind(const GLuint custom_texture) {
|
||||
}
|
||||
|
||||
void Raster::beginFadeInTransition() {
|
||||
timestamp start = util::now();
|
||||
fade_transition = std::make_shared<util::ease_transition<double>>(opacity, 1.0, opacity, start, 250_milliseconds);
|
||||
std::chrono::steady_clock::time_point start = std::chrono::steady_clock::now();
|
||||
fade_transition = std::make_shared<util::ease_transition<double>>(opacity, 1.0, opacity, start, std::chrono::milliseconds(250));
|
||||
}
|
||||
|
||||
bool Raster::needsTransition() const {
|
||||
return fade_transition != nullptr;
|
||||
}
|
||||
|
||||
void Raster::updateTransitions(timestamp now) {
|
||||
void Raster::updateTransitions(std::chrono::steady_clock::time_point now) {
|
||||
if (fade_transition->update(now) == util::transition::complete) {
|
||||
fade_transition = nullptr;
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
#include <string>
|
||||
#include <mutex>
|
||||
#include <chrono>
|
||||
|
||||
typedef struct uv_loop_s uv_loop_t;
|
||||
|
||||
@@ -34,7 +35,7 @@ public:
|
||||
// transitions
|
||||
void beginFadeInTransition();
|
||||
bool needsTransition() const;
|
||||
void updateTransitions(timestamp now);
|
||||
void updateTransitions(std::chrono::steady_clock::time_point now);
|
||||
|
||||
public:
|
||||
// loaded image dimensions
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#ifndef DISABLE_STOPWATCH
|
||||
#include <mbgl/util/stopwatch.hpp>
|
||||
#include <mbgl/util/time.hpp>
|
||||
#include <mbgl/util/string.hpp>
|
||||
#include <mbgl/platform/log.hpp>
|
||||
|
||||
@@ -10,21 +9,21 @@
|
||||
using namespace mbgl::util;
|
||||
|
||||
stopwatch::stopwatch(Event event_)
|
||||
: event(event_), start(now()) {}
|
||||
: event(event_), start(std::chrono::steady_clock::now()) {}
|
||||
|
||||
stopwatch::stopwatch(EventSeverity severity_, Event event_)
|
||||
: severity(severity_), event(event_), start(now()) {}
|
||||
: severity(severity_), event(event_), start(std::chrono::steady_clock::now()) {}
|
||||
|
||||
stopwatch::stopwatch(const std::string &name_, Event event_)
|
||||
: name(name_), event(event_), start(now()) {}
|
||||
: name(name_), event(event_), start(std::chrono::steady_clock::now()) {}
|
||||
|
||||
stopwatch::stopwatch(const std::string &name_, EventSeverity severity_, Event event_)
|
||||
: name(name_), severity(severity_), event(event_), start(now()) {}
|
||||
: name(name_), severity(severity_), event(event_), start(std::chrono::steady_clock::now()) {}
|
||||
|
||||
void stopwatch::report(const std::string &name_) {
|
||||
timestamp duration = now() - start;
|
||||
std::chrono::steady_clock::duration duration = std::chrono::steady_clock::now() - start;
|
||||
|
||||
Log::Record(severity, event, name_ + ": " + util::toString(double(duration) / 1_millisecond) + "ms");
|
||||
Log::Record(severity, event, name_ + ": " + util::toString(std::chrono::duration_cast<std::chrono::milliseconds>(duration).count()) + "ms");
|
||||
start += duration;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <mbgl/platform/event.hpp>
|
||||
|
||||
#include <string>
|
||||
#include <chrono>
|
||||
|
||||
namespace mbgl {
|
||||
namespace util {
|
||||
@@ -22,7 +23,7 @@ private:
|
||||
const std::string name;
|
||||
EventSeverity severity = EventSeverity::Debug;
|
||||
Event event = Event::General;
|
||||
uint64_t start;
|
||||
std::chrono::steady_clock::time_point start;
|
||||
};
|
||||
#else
|
||||
class stopwatch {
|
||||
|
||||
@@ -4,10 +4,6 @@
|
||||
namespace mbgl {
|
||||
namespace util {
|
||||
|
||||
timestamp now() {
|
||||
return uv_hrtime();
|
||||
}
|
||||
|
||||
static const char *week[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
|
||||
static const char *months[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
|
||||
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
|
||||
|
||||
@@ -10,7 +10,7 @@ UnitBezier ease(0, 0, 0.25, 1);
|
||||
transition::~transition() {}
|
||||
|
||||
template <typename T>
|
||||
transition::state ease_transition<T>::update(timestamp now) const {
|
||||
transition::state ease_transition<T>::update(std::chrono::steady_clock::time_point now) const {
|
||||
float t = progress(now);
|
||||
if (t >= 1) {
|
||||
value = to;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#define MBGL_UTIL_TRANSITION
|
||||
|
||||
#include <mbgl/util/noncopyable.hpp>
|
||||
#include <mbgl/util/time.hpp>
|
||||
#include <chrono>
|
||||
|
||||
namespace mbgl {
|
||||
namespace util {
|
||||
@@ -14,34 +14,35 @@ public:
|
||||
complete
|
||||
};
|
||||
|
||||
inline transition(timestamp start_, timestamp duration_)
|
||||
inline transition(std::chrono::steady_clock::time_point start_, std::chrono::steady_clock::duration duration_)
|
||||
: start(start_),
|
||||
duration(duration_) {}
|
||||
|
||||
inline float progress(timestamp now) const {
|
||||
if (duration == 0) return 1;
|
||||
inline float progress(std::chrono::steady_clock::time_point now) const {
|
||||
if (duration == std::chrono::steady_clock::duration::zero()) return 1;
|
||||
if (start > now) return 0;
|
||||
|
||||
return (float)(now - start) / duration;
|
||||
return std::chrono::duration<float>(now - start) / duration;
|
||||
}
|
||||
|
||||
virtual state update(timestamp now) const = 0;
|
||||
virtual state update(std::chrono::steady_clock::time_point now) const = 0;
|
||||
virtual ~transition();
|
||||
|
||||
protected:
|
||||
const timestamp start, duration;
|
||||
const std::chrono::steady_clock::time_point start;
|
||||
const std::chrono::steady_clock::duration duration;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class ease_transition : public transition {
|
||||
public:
|
||||
ease_transition(T from_, T to_, T& value_, timestamp start_, timestamp duration_)
|
||||
ease_transition(T from_, T to_, T& value_, std::chrono::steady_clock::time_point start_, std::chrono::steady_clock::duration duration_)
|
||||
: transition(start_, duration_),
|
||||
from(from_),
|
||||
to(to_),
|
||||
value(value_) {}
|
||||
|
||||
state update(timestamp now) const;
|
||||
state update(std::chrono::steady_clock::time_point now) const;
|
||||
|
||||
private:
|
||||
const T from, to;
|
||||
@@ -52,12 +53,12 @@ private:
|
||||
template <typename T>
|
||||
class timeout : public transition {
|
||||
public:
|
||||
timeout(T final_value_, T& value_, timestamp start_, timestamp duration_)
|
||||
timeout(T final_value_, T& value_, std::chrono::steady_clock::time_point start_, std::chrono::steady_clock::duration duration_)
|
||||
: transition(start_, duration_),
|
||||
final_value(final_value_),
|
||||
value(value_) {}
|
||||
|
||||
state update(timestamp now) const {
|
||||
state update(std::chrono::steady_clock::time_point now) const {
|
||||
if (progress(now) >= 1) {
|
||||
value = final_value;
|
||||
return complete;
|
||||
|
||||
Reference in New Issue
Block a user