Unify time point for Mapcontext::update

- Let style classes cascade use the same time point as the one used to
  recalculate style.
- Cleaned up MapContext::update to return early whenever possible.
- Cleaned up MapContext::loadStyleJSON to avoid redundant calls to style
  classes cascade.
This commit is contained in:
Bruno de Oliveira Abinader
2015-07-12 22:00:32 +03:00
parent 77a91f64d8
commit 7023ea061c
4 changed files with 25 additions and 32 deletions

View File

@@ -131,10 +131,10 @@ void MapContext::loadStyleJSON(const std::string& json, const std::string& base)
assert(util::ThreadContext::currentlyOn(util::ThreadType::Map));
style->setJSON(json, base);
style->cascade(data.getClasses());
style->setDefaultTransitionDuration(data.getDefaultTransitionDuration());
style->setObserver(this);
updated |= static_cast<UpdateType>(Update::DefaultTransitionDuration);
updated |= static_cast<UpdateType>(Update::Classes);
updated |= static_cast<UpdateType>(Update::Zoom);
asyncUpdate->send();
@@ -240,45 +240,43 @@ void MapContext::updateAnnotationTiles(const std::unordered_set<TileID, TileID::
}
}
cascadeClasses();
updated |= static_cast<UpdateType>(Update::Classes);
asyncUpdate->send();
annotationManager->resetStaleTiles();
}
void MapContext::cascadeClasses() {
style->cascade(data.getClasses());
}
void MapContext::update() {
assert(util::ThreadContext::currentlyOn(util::ThreadType::Map));
const auto now = Clock::now();
if (!style) {
updated = static_cast<UpdateType>(Update::Nothing);
return;
}
TimePoint now = Clock::now();
data.setAnimationTime(now);
if (style) {
if (updated & static_cast<UpdateType>(Update::DefaultTransitionDuration)) {
style->setDefaultTransitionDuration(data.getDefaultTransitionDuration());
}
if (updated & static_cast<UpdateType>(Update::DefaultTransitionDuration)) {
style->setDefaultTransitionDuration(data.getDefaultTransitionDuration());
}
if (updated & static_cast<UpdateType>(Update::Classes)) {
cascadeClasses();
}
if (updated & static_cast<UpdateType>(Update::Classes)) {
style->cascade(data.getClasses(), now);
}
if (updated & static_cast<UpdateType>(Update::Classes) ||
if (updated & static_cast<UpdateType>(Update::Classes) ||
updated & static_cast<UpdateType>(Update::Zoom)) {
style->recalculate(transformState.getNormalizedZoom(), now);
}
style->recalculate(transformState.getNormalizedZoom(), now);
}
style->update(transformState, *texturePool);
style->update(transformState, *texturePool);
if (data.mode == MapMode::Continuous) {
view.invalidate();
} else if (callback && style->isLoaded()) {
renderSync(transformState, frameData);
}
if (data.mode == MapMode::Continuous) {
view.invalidate();
} else if (callback && style->isLoaded()) {
renderSync(transformState, frameData);
}
updated = static_cast<UpdateType>(Update::Nothing);

View File

@@ -72,9 +72,6 @@ public:
void onResourceLoadingFailed(std::exception_ptr error) override;
private:
// Style-related updates.
void cascadeClasses();
// Update the state indicated by the accumulated Update flags, then render.
void update();

View File

@@ -86,9 +86,7 @@ void Style::update(const TransformState& transform,
}
}
void Style::cascade(const std::vector<std::string>& classes) {
TimePoint now = Clock::now();
void Style::cascade(const std::vector<std::string>& classes, TimePoint now) {
for (const auto& layer : layers) {
layer->setClasses(classes, now, defaultTransition);
}

View File

@@ -54,7 +54,7 @@ public:
// a tile is ready so observers can render the tile.
void update(const TransformState&, TexturePool&);
void cascade(const std::vector<std::string>&);
void cascade(const std::vector<std::string>&, TimePoint now);
void recalculate(float z, TimePoint now);
void setDefaultTransitionDuration(Duration);