Eliminate MapData::get/setFullyLoaded

This commit is contained in:
John Firebaugh
2015-06-26 14:42:32 -07:00
parent ccc631886f
commit 37117dae00
4 changed files with 25 additions and 33 deletions

View File

@@ -46,11 +46,12 @@ void Map::renderStill(StillImageCallback callback) {
}
void Map::renderSync() {
bool rerender = context->invokeSync<bool>(&MapContext::renderSync, transform->getState());
MapContext::RenderResult result =
context->invokeSync<MapContext::RenderResult>(&MapContext::renderSync, transform->getState());
if (transform->needsTransition()) {
update(Update(transform->updateTransitions(Clock::now())));
} else if (rerender) {
} else if (result.needsRerender) {
update();
}
}
@@ -361,7 +362,7 @@ bool Map::getCollisionDebug() const {
}
bool Map::isFullyLoaded() const {
return data->getFullyLoaded();
return context->invokeSync<bool>(&MapContext::isLoaded);
}
void Map::addClass(const std::string& klass) {

View File

@@ -249,20 +249,10 @@ void MapContext::update() {
style->update(data, transformState, *texturePool);
if (style->isLoaded()) {
if (!data.getFullyLoaded()) {
data.setFullyLoaded(true);
}
} else {
if (data.getFullyLoaded()) {
data.setFullyLoaded(false);
}
}
if (callback) {
renderSync(transformState);
} else {
if (data.mode == MapMode::Continuous) {
view.invalidate();
} else if (callback && style->isLoaded()) {
renderSync(transformState);
}
}
@@ -302,12 +292,12 @@ void MapContext::renderStill(const TransformState& state, StillImageCallback fn)
asyncUpdate->send();
}
bool MapContext::renderSync(const TransformState& state) {
MapContext::RenderResult MapContext::renderSync(const TransformState& state) {
assert(util::ThreadContext::currentlyOn(util::ThreadType::Map));
// Style was not loaded yet.
if (!style) {
return false;
return { false, false };
}
transformState = state;
@@ -315,11 +305,6 @@ bool MapContext::renderSync(const TransformState& state) {
// Cleanup OpenGL objects that we abandoned since the last render call.
glObjectStore.performCleanup();
if (data.mode == MapMode::Still && (!callback || !data.getFullyLoaded())) {
// We are either not waiting for a map to be rendered, or we don't have all resources yet.
return false;
}
if (!painter) {
painter = std::make_unique<Painter>();
painter->setup();
@@ -335,7 +320,14 @@ bool MapContext::renderSync(const TransformState& state) {
view.swap();
return style->hasTransitions();
return RenderResult {
style->isLoaded(),
style->hasTransitions()
};
}
bool MapContext::isLoaded() const {
return style->isLoaded();
}
double MapContext::getTopOffsetPixelsForAnnotationSymbol(const std::string& symbol) {

View File

@@ -33,6 +33,11 @@ public:
MapContext(uv_loop_t*, View&, FileSource&, MapData&);
~MapContext();
struct RenderResult {
bool fullyLoaded;
bool needsRerender;
};
void pause();
void resize(uint16_t width, uint16_t height, float ratio);
@@ -41,13 +46,15 @@ public:
void triggerUpdate(const TransformState&, Update = Update::Nothing);
void renderStill(const TransformState&, StillImageCallback callback);
bool renderSync(const TransformState&);
RenderResult renderSync(const TransformState&);
void setStyleURL(const std::string&);
void setStyleJSON(const std::string& json, const std::string& base);
std::string getStyleURL() const { return styleURL; }
std::string getStyleJSON() const { return styleJSON; }
bool isLoaded() const;
double getTopOffsetPixelsForAnnotationSymbol(const std::string& symbol);
void updateAnnotationTiles(const std::unordered_set<TileID, TileID::Hash>&);

View File

@@ -62,13 +62,6 @@ public:
collisionDebug = value;
}
inline bool getFullyLoaded() const {
return loaded;
}
inline void setFullyLoaded(bool value) {
loaded = value;
}
inline TimePoint getAnimationTime() const {
// We're casting the TimePoint to and from a Duration because libstdc++
// has a bug that doesn't allow TimePoints to be atomic.
@@ -95,7 +88,6 @@ private:
std::vector<std::string> classes;
std::atomic<uint8_t> debug { false };
std::atomic<uint8_t> collisionDebug { false };
std::atomic<bool> loaded { false };
std::atomic<Duration> animationTime;
std::atomic<Duration> defaultTransitionDuration;