cmake + tile loading

This commit is contained in:
Konstantin Käfer
2014-01-13 18:07:13 +01:00
parent 16d0c83df2
commit 654972bb3f
18 changed files with 392 additions and 87 deletions

View File

@@ -1,18 +1,43 @@
#include <llmr/map/tile.hpp>
#include <stdint.h>
#include <cassert>
// #include <iostream>
#include <thread>
#include "pbf.hpp"
#include <llmr/util/vec2.hpp>
#include <cmath>
using namespace llmr;
uint64_t tile::toID(int32_t z, int32_t x, int32_t y, int32_t w) {
w *= 2;
if (w < 0) w = w * -1 -1;
int32_t dim = 1 << z;
return ((dim * dim * w + dim * y + x) * 32) + z;
}
vec4<int32_t> tile::fromID(uint64_t id) {
vec4<int32_t> coord;
coord.z = id % 32;
int32_t dim = 1 << coord.z;
int32_t xy = ((id - coord.z) / 32);
coord.x = xy % dim;
coord.y = ((xy - coord.x) / dim) % dim;
coord.w = floor(xy / (dim * dim));
if (coord.w % 2 != 0) coord.w = coord.w * -1 -1;
coord.w /= 2;
return coord;
};
tile::tile(int32_t z, int32_t x, int32_t y)
: z(z),
x(x),
y(y),
loaded(false),
cancelled(false),
data(0),
bytes(0) {
}
@@ -23,8 +48,26 @@ void tile::setData(uint8_t *data, uint32_t bytes) {
memcpy(this->data, data, bytes);
}
void tile::cancel()
{
// TODO: thread safety
if (!cancelled) {
cancelled = true;
if (loaded) {
delete this;
}
} else {
assert((!"logic error? multiple cancelleations"));
}
}
bool tile::parse()
{
if (cancelled) {
delete this;
return false;
}
fprintf(stderr, "[%p] parsing tile...\n", this);
pbf tile(data, bytes);
@@ -40,6 +83,11 @@ bool tile::parse()
fprintf(stderr, "[%p] parsing tile...done\n", this);
if (cancelled) {
delete this;
return false;
}
loaded = true;
return true;
}
@@ -84,7 +132,7 @@ void tile::parseFeature(const uint8_t *data, uint32_t bytes) {
}
void tile::loadGeometry(const uint8_t *data, uint32_t bytes) {
pbf geometry(data, bytes);
pbf geometry(data, bytes);
uint32_t cmd = 1;
uint32_t length = 0;