Merge branch 'master' into tessellation
Conflicts: include/llmr/renderer/fill_bucket.hpp src/renderer/fill_bucket.cpp src/renderer/painter.cpp
This commit is contained in:
@@ -15,19 +15,20 @@ Map::Map(Settings& settings)
|
||||
painter(transform, settings, style),
|
||||
min_zoom(0),
|
||||
max_zoom(14) {
|
||||
|
||||
// TODO: Extract that information from the stylesheet instead of hard coding
|
||||
style.sprite = std::make_shared<Sprite>();
|
||||
style.sprite->load(kSpriteURL);
|
||||
}
|
||||
|
||||
Map::~Map() {
|
||||
settings.sync();
|
||||
}
|
||||
|
||||
void Map::setup() {
|
||||
void Map::setup(float pixelRatio) {
|
||||
painter.setup();
|
||||
|
||||
pixel_ratio = pixelRatio;
|
||||
|
||||
style.sprite = std::make_shared<Sprite>();
|
||||
style.sprite->load(kSpriteURL, pixel_ratio);
|
||||
|
||||
style.load(resources::style, resources::style_size);
|
||||
// style.loadJSON((const char *)resources::style, resources::style_size);
|
||||
}
|
||||
@@ -54,7 +55,7 @@ void Map::resize(uint32_t width, uint32_t height, uint32_t fb_width, uint32_t fb
|
||||
transform.height = height;
|
||||
transform.fb_width = fb_width;
|
||||
transform.fb_height = fb_height;
|
||||
transform.pixelRatio = (double)fb_width / (double)width;
|
||||
transform.pixelRatio = pixel_ratio;
|
||||
update();
|
||||
}
|
||||
|
||||
@@ -66,6 +67,16 @@ void Map::moveBy(double dx, double dy, double duration) {
|
||||
settings.persist();
|
||||
}
|
||||
|
||||
void Map::startPanning() {
|
||||
transform.startPanning();
|
||||
platform::restart();
|
||||
}
|
||||
|
||||
void Map::stopPanning() {
|
||||
transform.stopPanning();
|
||||
platform::restart();
|
||||
}
|
||||
|
||||
void Map::scaleBy(double ds, double cx, double cy, double duration) {
|
||||
transform.scaleBy(ds, cx, cy, duration);
|
||||
style.cascade(transform.getZoom());
|
||||
@@ -76,6 +87,16 @@ void Map::scaleBy(double ds, double cx, double cy, double duration) {
|
||||
settings.persist();
|
||||
}
|
||||
|
||||
void Map::startScaling() {
|
||||
transform.startScaling();
|
||||
platform::restart();
|
||||
}
|
||||
|
||||
void Map::stopScaling() {
|
||||
transform.stopScaling();
|
||||
platform::restart();
|
||||
}
|
||||
|
||||
void Map::rotateBy(double cx, double cy, double sx, double sy, double ex, double ey, double duration) {
|
||||
transform.rotateBy(cx, cy, sx, sy, ex, ey, duration);
|
||||
update();
|
||||
@@ -84,6 +105,16 @@ void Map::rotateBy(double cx, double cy, double sx, double sy, double ex, double
|
||||
settings.persist();
|
||||
}
|
||||
|
||||
void Map::startRotating() {
|
||||
transform.startRotating();
|
||||
platform::restart();
|
||||
}
|
||||
|
||||
void Map::stopRotating() {
|
||||
transform.stopRotating();
|
||||
platform::restart();
|
||||
}
|
||||
|
||||
void Map::setLonLat(double lon, double lat, double duration) {
|
||||
transform.setLonLat(lon, lat, duration);
|
||||
update();
|
||||
@@ -92,7 +123,7 @@ void Map::setLonLat(double lon, double lat, double duration) {
|
||||
settings.persist();
|
||||
}
|
||||
|
||||
void Map::getLonLat(double &lon, double &lat) const {
|
||||
void Map::getLonLat(double& lon, double& lat) const {
|
||||
transform.getLonLat(lon, lat);
|
||||
}
|
||||
|
||||
@@ -106,7 +137,7 @@ void Map::setLonLatZoom(double lon, double lat, double zoom, double duration) {
|
||||
settings.persist();
|
||||
}
|
||||
|
||||
void Map::getLonLatZoom(double &lon, double &lat, double &zoom) const {
|
||||
void Map::getLonLatZoom(double& lon, double& lat, double& zoom) const {
|
||||
transform.getLonLatZoom(lon, lat, zoom);
|
||||
}
|
||||
|
||||
@@ -202,7 +233,7 @@ void Map::cancelAnimations() {
|
||||
|
||||
void Map::update() {
|
||||
updateTiles();
|
||||
platform::restart(this);
|
||||
platform::restart();
|
||||
}
|
||||
|
||||
|
||||
@@ -375,12 +406,12 @@ bool Map::updateTiles() {
|
||||
}
|
||||
|
||||
bool Map::render() {
|
||||
bool changed = false;
|
||||
if (transform.needsAnimation()) {
|
||||
transform.updateAnimations();
|
||||
changed = updateTiles();
|
||||
}
|
||||
|
||||
bool changed = updateTiles();
|
||||
|
||||
painter.clear();
|
||||
|
||||
for (Tile::Ptr& tile : tiles) {
|
||||
@@ -395,14 +426,3 @@ bool Map::render() {
|
||||
|
||||
return changed || transform.needsAnimation();
|
||||
}
|
||||
|
||||
void Map::tileLoaded(Tile::Ptr tile) {
|
||||
// std::cerr << "loaded " << tile->toString() << std::endl;
|
||||
update();
|
||||
}
|
||||
|
||||
void Map::tileFailed(Tile::Ptr tile) {
|
||||
// fprintf(stderr, "[%8zx] tile failed to load %d/%d/%d\n",
|
||||
// std::hash<std::thread::id>()(std::this_thread::get_id()),
|
||||
// tile->z, tile->x, tile->y);
|
||||
}
|
||||
|
||||
@@ -4,9 +4,11 @@
|
||||
#include <llmr/map/vector_tile.hpp>
|
||||
#include <llmr/geometry/fill_buffer.hpp>
|
||||
#include <llmr/geometry/line_buffer.hpp>
|
||||
#include <llmr/geometry/point_buffer.hpp>
|
||||
#include <llmr/geometry/elements_buffer.hpp>
|
||||
#include <llmr/renderer/fill_bucket.hpp>
|
||||
#include <llmr/renderer/line_bucket.hpp>
|
||||
#include <llmr/renderer/point_bucket.hpp>
|
||||
#include <llmr/platform/platform.hpp>
|
||||
#include <llmr/util/pbf.hpp>
|
||||
#include <llmr/util/string.hpp>
|
||||
@@ -46,6 +48,7 @@ Tile::Tile(ID id, const Style& style)
|
||||
state(initial),
|
||||
fillVertexBuffer(std::make_shared<FillVertexBuffer>()),
|
||||
lineVertexBuffer(std::make_shared<LineVertexBuffer>()),
|
||||
pointVertexBuffer(std::make_shared<PointVertexBuffer>()),
|
||||
triangleElementsBuffer(std::make_shared<TriangleElementsBuffer>()),
|
||||
lineElementsBuffer(std::make_shared<LineElementsBuffer>()),
|
||||
pointElementsBuffer(std::make_shared<PointElementsBuffer>()),
|
||||
@@ -81,8 +84,7 @@ void Tile::request() {
|
||||
fprintf(stderr, "tile loading failed\n");
|
||||
}
|
||||
}, []() {
|
||||
// TODO: Make sure this gets passed the correct map ID/pointer.
|
||||
platform::restart(nullptr);
|
||||
platform::restart();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -160,6 +162,8 @@ std::shared_ptr<Bucket> Tile::createBucket(const VectorTile& tile, const BucketD
|
||||
return createFillBucket(layer, bucket_desc);
|
||||
} else if (bucket_desc.type == BucketType::Line) {
|
||||
return createLineBucket(layer, bucket_desc);
|
||||
} else if (bucket_desc.type == BucketType::Point) {
|
||||
return createPointBucket(layer, bucket_desc);
|
||||
} else {
|
||||
// TODO: create other bucket types.
|
||||
}
|
||||
@@ -214,3 +218,19 @@ std::shared_ptr<Bucket> Tile::createLineBucket(const VectorTileLayer& layer, con
|
||||
|
||||
return bucket;
|
||||
}
|
||||
|
||||
std::shared_ptr<Bucket> Tile::createPointBucket(const VectorTileLayer& layer, const BucketDescription& bucket_desc) {
|
||||
std::shared_ptr<PointBucket> bucket = std::make_shared<PointBucket>(pointVertexBuffer, bucket_desc);
|
||||
|
||||
FilteredVectorTileLayer filtered_layer(layer, bucket_desc);
|
||||
for (pbf feature : filtered_layer) {
|
||||
while (feature.next(4)) { // geometry
|
||||
pbf geometry_pbf = feature.message();
|
||||
if (geometry_pbf) {
|
||||
bucket->addGeometry(geometry_pbf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return bucket;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <llmr/map/transform.hpp>
|
||||
#include <llmr/util/constants.hpp>
|
||||
#include <llmr/util/mat4.hpp>
|
||||
#include <llmr/util/std.hpp>
|
||||
#include <llmr/util/math.hpp>
|
||||
#include <cstdio>
|
||||
|
||||
@@ -24,8 +25,8 @@ bool Transform::needsAnimation() const {
|
||||
}
|
||||
|
||||
void Transform::updateAnimations() {
|
||||
animations.remove_if([](const util::animation& animation) {
|
||||
return animation.update() == util::animation::complete;
|
||||
animations.remove_if([](const std::shared_ptr<util::animation>& animation) {
|
||||
return animation->update() == util::animation::complete;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -40,8 +41,25 @@ void Transform::moveBy(double dx, double dy, double duration) {
|
||||
x = xn;
|
||||
y = yn;
|
||||
} else {
|
||||
animations.emplace_front(x, xn, x, duration);
|
||||
animations.emplace_front(y, yn, y, duration);
|
||||
animations.emplace_front(std::make_shared<util::ease_animation>(x, xn, x, duration));
|
||||
animations.emplace_front(std::make_shared<util::ease_animation>(y, yn, y, duration));
|
||||
}
|
||||
}
|
||||
|
||||
void Transform::startPanning() {
|
||||
stopPanning();
|
||||
|
||||
// Add a 200ms timeout for resetting this to false
|
||||
panning = true;
|
||||
pan_timeout = std::make_shared<util::timeout<bool>>(false, panning, 0.2);
|
||||
animations.emplace_front(pan_timeout);
|
||||
}
|
||||
|
||||
void Transform::stopPanning() {
|
||||
panning = false;
|
||||
if (pan_timeout) {
|
||||
animations.remove(pan_timeout);
|
||||
pan_timeout.reset();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,6 +77,22 @@ void Transform::scaleBy(double ds, double cx, double cy, double duration) {
|
||||
setScale(new_scale, cx, cy, duration);
|
||||
}
|
||||
|
||||
void Transform::startScaling() {
|
||||
stopScaling();
|
||||
|
||||
// Add a 200ms timeout for resetting this to false
|
||||
scaling = true;
|
||||
scale_timeout = std::make_shared<util::timeout<bool>>(false, scaling, 0.2);
|
||||
animations.emplace_front(scale_timeout);
|
||||
}
|
||||
|
||||
void Transform::stopScaling() {
|
||||
scaling = false;
|
||||
if (scale_timeout) {
|
||||
animations.remove(scale_timeout);
|
||||
scale_timeout.reset();
|
||||
}
|
||||
}
|
||||
|
||||
void Transform::rotateBy(double anchor_x, double anchor_y, double start_x, double start_y, double end_x, double end_y, double duration) {
|
||||
double center_x = width / 2, center_y = height / 2;
|
||||
@@ -94,7 +128,24 @@ void Transform::setAngle(double new_angle, double duration) {
|
||||
if (duration == 0) {
|
||||
angle = new_angle;
|
||||
} else {
|
||||
animations.emplace_front(angle, new_angle, angle, duration);
|
||||
animations.emplace_front(std::make_shared<util::ease_animation>(angle, new_angle, angle, duration));
|
||||
}
|
||||
}
|
||||
|
||||
void Transform::startRotating() {
|
||||
stopRotating();
|
||||
|
||||
// Add a 200ms timeout for resetting this to false
|
||||
rotating = true;
|
||||
rotate_timeout = std::make_shared<util::timeout<bool>>(false, rotating, 0.2);
|
||||
animations.emplace_front(rotate_timeout);
|
||||
}
|
||||
|
||||
void Transform::stopRotating() {
|
||||
rotating = false;
|
||||
if (rotate_timeout) {
|
||||
animations.remove(rotate_timeout);
|
||||
rotate_timeout.reset();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,9 +155,9 @@ void Transform::setScaleXY(double new_scale, double xn, double yn, double durati
|
||||
x = xn;
|
||||
y = yn;
|
||||
} else {
|
||||
animations.emplace_front(scale, new_scale, scale, duration);
|
||||
animations.emplace_front(x, xn, x, duration);
|
||||
animations.emplace_front(y, yn, y, duration);
|
||||
animations.emplace_front(std::make_shared<util::ease_animation>(scale, new_scale, scale, duration));
|
||||
animations.emplace_front(std::make_shared<util::ease_animation>(x, xn, x, duration));
|
||||
animations.emplace_front(std::make_shared<util::ease_animation>(y, yn, y, duration));
|
||||
}
|
||||
|
||||
const double s = scale * util::tileSize;
|
||||
|
||||
@@ -52,13 +52,13 @@ FilteredVectorTileLayer::FilteredVectorTileLayer(const VectorTileLayer& layer, c
|
||||
// Find out what key/value IDs we need.
|
||||
auto key_it = std::find(layer.keys.begin(), layer.keys.end(), bucket_desc.source_field);
|
||||
if (key_it != layer.keys.end()) {
|
||||
key = key_it - layer.keys.begin();
|
||||
key = (int32_t)(key_it - layer.keys.begin());
|
||||
}
|
||||
|
||||
for (const Value& source_value : bucket_desc.source_value) {
|
||||
auto value_it = std::find(layer.values.begin(), layer.values.end(), source_value);
|
||||
if (value_it != layer.values.end()) {
|
||||
values.insert(value_it - layer.values.begin());
|
||||
values.insert((uint32_t)(value_it - layer.values.begin()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user