fix tile loading
This commit is contained in:
@@ -381,10 +381,13 @@ bool Map::updateTiles() {
|
||||
|
||||
// Remove tiles that we definitely don't need, i.e. tiles that are not on
|
||||
// the required list.
|
||||
tiles.remove_if([&retain, &changed](const Tile & tile) {
|
||||
std::forward_list<Tile::ID> retain_data;
|
||||
tiles.remove_if([&retain, &retain_data, &changed](const Tile & tile) {
|
||||
bool obsolete = std::find(retain.begin(), retain.end(), tile.id) == retain.end();
|
||||
if (obsolete) {
|
||||
changed = true;
|
||||
} else {
|
||||
retain_data.push_front(tile.data->id);
|
||||
}
|
||||
return obsolete;
|
||||
});
|
||||
@@ -397,8 +400,18 @@ bool Map::updateTiles() {
|
||||
});
|
||||
|
||||
// Remove all the expired pointers from the list.
|
||||
tile_data.remove_if([](const std::weak_ptr<TileData>& tile_data) {
|
||||
return tile_data.expired();
|
||||
tile_data.remove_if([&retain_data](const std::weak_ptr<TileData>& tile_data) {
|
||||
const std::shared_ptr<TileData> tile = tile_data.lock();
|
||||
if (!tile) {
|
||||
return true;
|
||||
}
|
||||
bool obsolete = std::find(retain_data.begin(), retain_data.end(), tile->id) == retain_data.end();
|
||||
if (obsolete) {
|
||||
tile->cancel();
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
return changed;
|
||||
|
||||
@@ -34,6 +34,7 @@ TileData::TileData(Tile::ID id, const Style& style)
|
||||
}
|
||||
|
||||
TileData::~TileData() {
|
||||
cancel();
|
||||
}
|
||||
|
||||
const std::string TileData::toString() const {
|
||||
@@ -48,13 +49,17 @@ void TileData::request() {
|
||||
id.z, id.x, id.y);
|
||||
|
||||
// Note: Somehow this feels slower than the change to request_http()
|
||||
std::shared_ptr<TileData> tile = shared_from_this();
|
||||
std::weak_ptr<TileData> weak_tile = shared_from_this();
|
||||
platform::Request *request = platform::request_http(url, [=](platform::Response& res) {
|
||||
if (res.code == 200 && tile->state != State::obsolete) {
|
||||
std::shared_ptr<TileData> tile = weak_tile.lock();
|
||||
if (!tile || tile->state == State::obsolete) {
|
||||
// noop. Tile is obsolete and we're now just waiting for the refcount
|
||||
// to drop to zero for destruction.
|
||||
} else if (res.code == 200) {
|
||||
tile->state = State::loaded;
|
||||
tile->data.swap(res.body);
|
||||
tile->parse();
|
||||
} else if (tile->state != State::obsolete) {
|
||||
} else {
|
||||
fprintf(stderr, "tile loading failed\n");
|
||||
}
|
||||
}, []() {
|
||||
@@ -67,8 +72,6 @@ void TileData::cancel() {
|
||||
if (state != State::obsolete) {
|
||||
state = State::obsolete;
|
||||
platform::cancel_request_http(req);
|
||||
} else {
|
||||
assert((!"logic error? multiple cancelleations"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ void Painter::setup() {
|
||||
|
||||
// Blending
|
||||
// We are blending the new pixels *behind* the existing pixels. That way we can
|
||||
// draw front-to-back and use then stencil buffer to cull opaque pixels early.
|
||||
// draw front-to-back and use the depth buffer to cull opaque pixels early.
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_ONE_MINUS_DST_ALPHA, GL_ONE);
|
||||
|
||||
@@ -126,7 +126,7 @@ void Painter::finishClippingMask() {
|
||||
void Painter::clear() {
|
||||
glStencilMask(0xFF);
|
||||
depthMask(true);
|
||||
// glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
||||
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user