[core] move TileData and dependents to new *TileID classes
This commit is contained in:
@@ -203,7 +203,11 @@ TileData::State Source::hasTile(const TileID& tileID) {
|
||||
}
|
||||
|
||||
bool Source::handlePartialTile(const TileID& tileID) {
|
||||
auto it = tileDataMap.find(tileID.normalized());
|
||||
const OverscaledTileID overscaledTileID{
|
||||
tileID.z, UnwrappedTileID{ tileID.sourceZ, tileID.x, tileID.y }.canonical
|
||||
};
|
||||
|
||||
auto it = tileDataMap.find(overscaledTileID);
|
||||
if (it == tileDataMap.end()) {
|
||||
return true;
|
||||
}
|
||||
@@ -213,7 +217,7 @@ bool Source::handlePartialTile(const TileID& tileID) {
|
||||
return true;
|
||||
}
|
||||
|
||||
auto callback = std::bind(&Source::tileLoadingCallback, this, tileID,
|
||||
auto callback = std::bind(&Source::tileLoadingCallback, this, overscaledTileID,
|
||||
std::placeholders::_1, false);
|
||||
|
||||
return tileData->parsePending(callback);
|
||||
@@ -230,9 +234,9 @@ TileData::State Source::addTile(const TileID& tileID, const StyleUpdateParameter
|
||||
|
||||
// We couldn't find the tile in the list. Create a new one.
|
||||
// Try to find the associated TileData object.
|
||||
const TileID normalizedID = tileID.normalized();
|
||||
const OverscaledTileID overscaledTileID{ tileID.z, newTile->id.canonical };
|
||||
|
||||
auto it = tileDataMap.find(normalizedID);
|
||||
auto it = tileDataMap.find(overscaledTileID);
|
||||
if (it != tileDataMap.end()) {
|
||||
// Create a shared_ptr handle. Note that this might be empty!
|
||||
newTile->data = it->second.lock();
|
||||
@@ -244,16 +248,16 @@ TileData::State Source::addTile(const TileID& tileID, const StyleUpdateParameter
|
||||
}
|
||||
|
||||
if (!newTile->data) {
|
||||
newTile->data = cache.get(normalizedID.to_uint64());
|
||||
newTile->data = cache.get(overscaledTileID);
|
||||
}
|
||||
|
||||
if (!newTile->data) {
|
||||
auto callback = std::bind(&Source::tileLoadingCallback, this, normalizedID,
|
||||
auto callback = std::bind(&Source::tileLoadingCallback, this, overscaledTileID,
|
||||
std::placeholders::_1, true);
|
||||
|
||||
// If we don't find working tile data, we're just going to load it.
|
||||
if (type == SourceType::Raster) {
|
||||
newTile->data = std::make_shared<RasterTileData>(normalizedID,
|
||||
newTile->data = std::make_shared<RasterTileData>(overscaledTileID,
|
||||
parameters.pixelRatio,
|
||||
info->tiles.at(0),
|
||||
parameters.texturePool,
|
||||
@@ -264,17 +268,17 @@ TileData::State Source::addTile(const TileID& tileID, const StyleUpdateParameter
|
||||
std::unique_ptr<GeometryTileMonitor> monitor;
|
||||
|
||||
if (type == SourceType::Vector) {
|
||||
monitor = std::make_unique<VectorTileMonitor>(normalizedID, parameters.pixelRatio, info->tiles.at(0), parameters.fileSource);
|
||||
monitor = std::make_unique<VectorTileMonitor>(overscaledTileID, parameters.pixelRatio, info->tiles.at(0), parameters.fileSource);
|
||||
} else if (type == SourceType::Annotations) {
|
||||
monitor = std::make_unique<AnnotationTileMonitor>(normalizedID, parameters.annotationManager);
|
||||
monitor = std::make_unique<AnnotationTileMonitor>(overscaledTileID, parameters.annotationManager);
|
||||
} else if (type == SourceType::GeoJSON) {
|
||||
monitor = std::make_unique<GeoJSONTileMonitor>(geojsonvt.get(), normalizedID);
|
||||
monitor = std::make_unique<GeoJSONTileMonitor>(geojsonvt.get(), overscaledTileID);
|
||||
} else {
|
||||
Log::Warning(Event::Style, "Source type '%s' is not implemented", SourceTypeClass(type).c_str());
|
||||
return TileData::State::invalid;
|
||||
}
|
||||
|
||||
newTile->data = std::make_shared<VectorTileData>(normalizedID,
|
||||
newTile->data = std::make_shared<VectorTileData>(overscaledTileID,
|
||||
std::move(monitor),
|
||||
id,
|
||||
parameters.style,
|
||||
@@ -339,7 +343,10 @@ void Source::findLoadedParent(const TileID& tileID, int32_t minCoveringZoom, std
|
||||
}
|
||||
}
|
||||
|
||||
if (cache.has(parent_id.normalized().to_uint64())) {
|
||||
const UnwrappedTileID unwrappedTileID(tileID.sourceZ, static_cast<uint32_t>(tileID.x),
|
||||
static_cast<uint32_t>(tileID.y));
|
||||
|
||||
if (cache.has(OverscaledTileID{ tileID.z, unwrappedTileID.canonical })) {
|
||||
addTile(parent_id, parameters);
|
||||
retain.emplace_back(parent_id);
|
||||
return;
|
||||
@@ -423,8 +430,8 @@ bool Source::update(const StyleUpdateParameters& parameters) {
|
||||
|
||||
// Remove tiles that we definitely don't need, i.e. tiles that are not on
|
||||
// the required list.
|
||||
std::set<TileID> retain_data;
|
||||
util::erase_if(tiles, [this, &retain, &retain_data, &tileCache](std::pair<const TileID, std::unique_ptr<Tile>> &pair) {
|
||||
std::set<OverscaledTileID> retain_data;
|
||||
util::erase_if(tiles, [this, &retain, &retain_data, &tileCache](auto &pair) {
|
||||
const auto& tileID = pair.first;
|
||||
Tile &tile = *pair.second;
|
||||
bool obsolete = std::find(retain.begin(), retain.end(), tileID) == retain.end();
|
||||
@@ -434,22 +441,22 @@ bool Source::update(const StyleUpdateParameters& parameters) {
|
||||
// Partially parsed tiles are never added to the cache because otherwise
|
||||
// they never get updated if the go out from the viewport and the pending
|
||||
// resources arrive.
|
||||
tileCache.add(tileID.normalized().to_uint64(), tile.data);
|
||||
tileCache.add(tile.data->id, tile.data);
|
||||
}
|
||||
return obsolete;
|
||||
});
|
||||
|
||||
// Remove all the expired pointers from the set.
|
||||
util::erase_if(tileDataMap, [&retain_data, &tileCache](std::pair<const TileID, std::weak_ptr<TileData>> &pair) {
|
||||
const util::ptr<TileData> tile = pair.second.lock();
|
||||
if (!tile) {
|
||||
util::erase_if(tileDataMap, [&retain_data, &tileCache](auto &pair) {
|
||||
const auto tileData = pair.second.lock();
|
||||
if (!tileData) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool obsolete = retain_data.find(tile->id) == retain_data.end();
|
||||
bool obsolete = retain_data.find(tileData->id) == retain_data.end();
|
||||
if (obsolete) {
|
||||
if (!tileCache.has(tile->id.normalized().to_uint64())) {
|
||||
tile->cancel();
|
||||
if (!tileCache.has(tileData->id)) {
|
||||
tileData->cancel();
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
@@ -479,10 +486,10 @@ void Source::updateTilePtrs() {
|
||||
}
|
||||
}
|
||||
|
||||
static Point<int16_t> coordinateToTilePoint(const TileID& tileID, const TileCoordinate& coord) {
|
||||
auto zoomedCoord = coord.zoomTo(tileID.sourceZ);
|
||||
static Point<int16_t> coordinateToTilePoint(const CanonicalTileID& tileID, const TileCoordinate& coord) {
|
||||
auto zoomedCoord = coord.zoomTo(tileID.z);
|
||||
return {
|
||||
int16_t(util::clamp<int64_t>((zoomedCoord.x - (tileID.x + tileID.w * std::pow(2, tileID.sourceZ))) * util::EXTENT,
|
||||
int16_t(util::clamp<int64_t>((zoomedCoord.x - tileID.x) * util::EXTENT,
|
||||
std::numeric_limits<int16_t>::min(),
|
||||
std::numeric_limits<int16_t>::max())),
|
||||
int16_t(util::clamp<int64_t>((zoomedCoord.y - tileID.y) * util::EXTENT,
|
||||
@@ -519,15 +526,13 @@ std::unordered_map<std::string, std::vector<Feature>> Source::queryRenderedFeatu
|
||||
maxY = util::max(maxY, c.y);
|
||||
}
|
||||
|
||||
std::unordered_map<uint64_t, TileQuery> tileQueries;
|
||||
std::map<CanonicalTileID, TileQuery> tileQueries;
|
||||
|
||||
for (auto& tilePtr : tilePtrs) {
|
||||
auto& tile = *tilePtr;
|
||||
const TileID& tileID = tile.data->id;
|
||||
const auto integerID = tileID.to_uint64();
|
||||
|
||||
auto tileSpaceBoundsMin = coordinateToTilePoint(tileID, { minX, minY, z });
|
||||
auto tileSpaceBoundsMax = coordinateToTilePoint(tileID, { maxX, maxY, z });
|
||||
auto tileSpaceBoundsMin = coordinateToTilePoint(tile.id.canonical, { minX, minY, z });
|
||||
auto tileSpaceBoundsMax = coordinateToTilePoint(tile.id.canonical, { maxX, maxY, z });
|
||||
|
||||
if (tileSpaceBoundsMin.x >= util::EXTENT || tileSpaceBoundsMin.y >= util::EXTENT ||
|
||||
tileSpaceBoundsMax.x < 0 || tileSpaceBoundsMax.y < 0) continue;
|
||||
@@ -535,18 +540,19 @@ std::unordered_map<std::string, std::vector<Feature>> Source::queryRenderedFeatu
|
||||
GeometryCoordinates tileSpaceQueryGeometry;
|
||||
|
||||
for (auto& c : queryGeometry) {
|
||||
tileSpaceQueryGeometry.push_back(coordinateToTilePoint(tileID, c));
|
||||
tileSpaceQueryGeometry.push_back(coordinateToTilePoint(tile.id.canonical, c));
|
||||
}
|
||||
|
||||
auto it = tileQueries.find(integerID);
|
||||
auto it = tileQueries.find(tile.id.canonical);
|
||||
if (it != tileQueries.end()) {
|
||||
it->second.queryGeometry.push_back(std::move(tileSpaceQueryGeometry));
|
||||
} else {
|
||||
tileQueries.emplace(integerID, TileQuery{
|
||||
(void)zoom;
|
||||
tileQueries.emplace(tile.id.canonical, TileQuery{
|
||||
tilePtr,
|
||||
{ tileSpaceQueryGeometry },
|
||||
util::tileSize * std::pow(2, tileID.z - tileID.sourceZ),
|
||||
std::pow(2, zoom - tileID.z)
|
||||
util::tileSize * tile.data->id.overscaleFactor(),
|
||||
std::pow(2, zoom - tile.data->id.overscaledZ)
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -572,9 +578,9 @@ void Source::setObserver(Observer* observer_) {
|
||||
observer = observer_;
|
||||
}
|
||||
|
||||
void Source::tileLoadingCallback(const TileID& tileID,
|
||||
std::exception_ptr error,
|
||||
bool isNewTile) {
|
||||
void Source::tileLoadingCallback(const OverscaledTileID& tileID,
|
||||
std::exception_ptr error,
|
||||
bool isNewTile) {
|
||||
auto it = tileDataMap.find(tileID);
|
||||
if (it == tileDataMap.end()) {
|
||||
return;
|
||||
|
||||
@@ -43,8 +43,8 @@ public:
|
||||
virtual void onSourceLoaded(Source&) {};
|
||||
virtual void onSourceError(Source&, std::exception_ptr) {};
|
||||
|
||||
virtual void onTileLoaded(Source&, const TileID&, bool /* isNewTile */) {};
|
||||
virtual void onTileError(Source&, const TileID&, std::exception_ptr) {};
|
||||
virtual void onTileLoaded(Source&, const OverscaledTileID&, bool /* isNewTile */) {};
|
||||
virtual void onTileError(Source&, const OverscaledTileID&, std::exception_ptr) {};
|
||||
virtual void onPlacementRedone() {};
|
||||
};
|
||||
|
||||
@@ -94,7 +94,7 @@ public:
|
||||
bool enabled = false;
|
||||
|
||||
private:
|
||||
void tileLoadingCallback(const TileID&,
|
||||
void tileLoadingCallback(const OverscaledTileID&,
|
||||
std::exception_ptr,
|
||||
bool isNewTile);
|
||||
bool handlePartialTile(const TileID&);
|
||||
@@ -115,7 +115,7 @@ private:
|
||||
|
||||
std::map<TileID, std::unique_ptr<Tile>> tiles;
|
||||
std::vector<Tile*> tilePtrs;
|
||||
std::map<TileID, std::weak_ptr<TileData>> tileDataMap;
|
||||
std::map<OverscaledTileID, std::weak_ptr<TileData>> tileDataMap;
|
||||
TileCache cache;
|
||||
|
||||
std::unique_ptr<AsyncRequest> req;
|
||||
|
||||
Reference in New Issue
Block a user