make sure we're not calling functions that aren't threadsafe
This commit is contained in:
@@ -173,32 +173,21 @@ void Map::loadStyle(const uint8_t *const data, uint32_t bytes) {
|
||||
|
||||
#pragma mark - Size
|
||||
|
||||
// Note: This function is called from another thread. Make sure you only call threadsafe functions!
|
||||
void Map::resize(uint16_t width, uint16_t height, float ratio) {
|
||||
resize(width, height, ratio, width * ratio, height * ratio);
|
||||
}
|
||||
|
||||
// Note: This function is called from another thread. Make sure you only call threadsafe functions!
|
||||
void Map::resize(uint16_t width, uint16_t height, float ratio, uint16_t fb_width, uint16_t fb_height) {
|
||||
bool changed = false;
|
||||
|
||||
if (transform.resize(width, height, ratio, fb_width, fb_height)) {
|
||||
changed = true;
|
||||
}
|
||||
|
||||
// TODO: Make sure we're not currently rendering anything
|
||||
if (spriteAtlas.resize(ratio)) {
|
||||
changed = true;
|
||||
}
|
||||
|
||||
// TODO: Make sure we're not currently rendering anything
|
||||
painter.clearFramebuffers();
|
||||
|
||||
if (changed) {
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - Transitions
|
||||
|
||||
// Note: This function is called from another thread. Make sure you only call threadsafe functions!
|
||||
void Map::cancelTransitions() {
|
||||
transform.cancelTransitions();
|
||||
|
||||
@@ -208,30 +197,36 @@ void Map::cancelTransitions() {
|
||||
|
||||
#pragma mark - Position
|
||||
|
||||
// Note: This function is called from another thread. Make sure you only call threadsafe functions!
|
||||
void Map::moveBy(double dx, double dy, double duration) {
|
||||
transform.moveBy(dx, dy, duration * 1_second);
|
||||
update();
|
||||
}
|
||||
|
||||
// Note: This function is called from another thread. Make sure you only call threadsafe functions!
|
||||
void Map::setLonLat(double lon, double lat, double duration) {
|
||||
transform.setLonLat(lon, lat, duration * 1_second);
|
||||
update();
|
||||
}
|
||||
|
||||
// Note: This function is called from another thread. Make sure you only call threadsafe functions!
|
||||
void Map::getLonLat(double& lon, double& lat) const {
|
||||
transform.getLonLat(lon, lat);
|
||||
}
|
||||
|
||||
// Note: This function is called from another thread. Make sure you only call threadsafe functions!
|
||||
void Map::startPanning() {
|
||||
transform.startPanning();
|
||||
update();
|
||||
}
|
||||
|
||||
// Note: This function is called from another thread. Make sure you only call threadsafe functions!
|
||||
void Map::stopPanning() {
|
||||
transform.stopPanning();
|
||||
update();
|
||||
}
|
||||
|
||||
// Note: This function is called from another thread. Make sure you only call threadsafe functions!
|
||||
void Map::resetPosition() {
|
||||
transform.setAngle(0);
|
||||
transform.setLonLat(0, 0);
|
||||
@@ -242,47 +237,57 @@ void Map::resetPosition() {
|
||||
|
||||
#pragma mark - Scale
|
||||
|
||||
// Note: This function is called from another thread. Make sure you only call threadsafe functions!
|
||||
void Map::scaleBy(double ds, double cx, double cy, double duration) {
|
||||
transform.scaleBy(ds, cx, cy, duration * 1_second);
|
||||
update();
|
||||
}
|
||||
|
||||
// Note: This function is called from another thread. Make sure you only call threadsafe functions!
|
||||
void Map::setScale(double scale, double cx, double cy, double duration) {
|
||||
transform.setScale(scale, cx, cy, duration * 1_second);
|
||||
update();
|
||||
}
|
||||
|
||||
// Note: This function is called from another thread. Make sure you only call threadsafe functions!
|
||||
double Map::getScale() const {
|
||||
return transform.getScale();
|
||||
}
|
||||
|
||||
// Note: This function is called from another thread. Make sure you only call threadsafe functions!
|
||||
void Map::setZoom(double zoom, double duration) {
|
||||
transform.setZoom(zoom, duration * 1_second);
|
||||
update();
|
||||
}
|
||||
|
||||
// Note: This function is called from another thread. Make sure you only call threadsafe functions!
|
||||
double Map::getZoom() const {
|
||||
return transform.getZoom();
|
||||
}
|
||||
|
||||
// Note: This function is called from another thread. Make sure you only call threadsafe functions!
|
||||
void Map::setLonLatZoom(double lon, double lat, double zoom, double duration) {
|
||||
transform.setLonLatZoom(lon, lat, zoom, duration * 1_second);
|
||||
update();
|
||||
}
|
||||
|
||||
// Note: This function is called from another thread. Make sure you only call threadsafe functions!
|
||||
void Map::getLonLatZoom(double& lon, double& lat, double& zoom) const {
|
||||
transform.getLonLatZoom(lon, lat, zoom);
|
||||
}
|
||||
|
||||
// Note: This function is called from another thread. Make sure you only call threadsafe functions!
|
||||
void Map::resetZoom() {
|
||||
setZoom(0);
|
||||
}
|
||||
|
||||
// Note: This function is called from another thread. Make sure you only call threadsafe functions!
|
||||
void Map::startScaling() {
|
||||
transform.startScaling();
|
||||
update();
|
||||
}
|
||||
|
||||
// Note: This function is called from another thread. Make sure you only call threadsafe functions!
|
||||
void Map::stopScaling() {
|
||||
transform.stopScaling();
|
||||
update();
|
||||
@@ -291,35 +296,42 @@ void Map::stopScaling() {
|
||||
|
||||
#pragma mark - Rotation
|
||||
|
||||
// Note: This function is called from another thread. Make sure you only call threadsafe functions!
|
||||
void Map::rotateBy(double sx, double sy, double ex, double ey, double duration) {
|
||||
transform.rotateBy(sx, sy, ex, ey, duration * 1_second);
|
||||
update();
|
||||
}
|
||||
|
||||
// Note: This function is called from another thread. Make sure you only call threadsafe functions!
|
||||
void Map::setAngle(double angle, double duration) {
|
||||
transform.setAngle(angle, duration * 1_second);
|
||||
update();
|
||||
}
|
||||
|
||||
// Note: This function is called from another thread. Make sure you only call threadsafe functions!
|
||||
void Map::setAngle(double angle, double cx, double cy) {
|
||||
transform.setAngle(angle, cx, cy);
|
||||
update();
|
||||
}
|
||||
|
||||
// Note: This function is called from another thread. Make sure you only call threadsafe functions!
|
||||
double Map::getAngle() const {
|
||||
return transform.getAngle();
|
||||
}
|
||||
|
||||
// Note: This function is called from another thread. Make sure you only call threadsafe functions!
|
||||
void Map::resetNorth() {
|
||||
transform.setAngle(0, 500_milliseconds);
|
||||
update();
|
||||
}
|
||||
|
||||
// Note: This function is called from another thread. Make sure you only call threadsafe functions!
|
||||
void Map::startRotating() {
|
||||
transform.startRotating();
|
||||
update();
|
||||
}
|
||||
|
||||
// Note: This function is called from another thread. Make sure you only call threadsafe functions!
|
||||
void Map::stopRotating() {
|
||||
transform.stopRotating();
|
||||
update();
|
||||
@@ -402,11 +414,29 @@ void Map::prepare() {
|
||||
transform.updateTransitions(animationTime);
|
||||
}
|
||||
|
||||
|
||||
const TransformState oldState = state;
|
||||
state = transform.currentState();
|
||||
style.cascade(state.getNormalizedZoom());
|
||||
if (!style.sprite || style.sprite->pixelRatio != state.getPixelRatio()) {
|
||||
|
||||
bool pixelRatioChanged = oldState.getPixelRatio() != state.getPixelRatio();
|
||||
bool dimensionsChanged = oldState.getFramebufferWidth() != state.getFramebufferWidth() ||
|
||||
oldState.getFramebufferHeight() != state.getFramebufferHeight();
|
||||
bool zoomChanged = oldState.getNormalizedZoom() != state.getNormalizedZoom();
|
||||
|
||||
if (pixelRatioChanged) {
|
||||
// We have a pixelratio change
|
||||
style.sprite = std::make_shared<Sprite>(*this, state.getPixelRatio());
|
||||
style.sprite->load(kSpriteURL);
|
||||
|
||||
spriteAtlas.resize(state.getPixelRatio());
|
||||
}
|
||||
|
||||
if (pixelRatioChanged || dimensionsChanged) {
|
||||
painter.clearFramebuffers();
|
||||
}
|
||||
|
||||
if (zoomChanged) {
|
||||
style.cascade(state.getNormalizedZoom());
|
||||
}
|
||||
|
||||
// Allow the sprite atlas to potentially pull new sprite images if needed.
|
||||
|
||||
Reference in New Issue
Block a user