* fix typedef's
* fix virtual dtor's
* make ctor's with one argument explicit
* util::noncopyable utility class  ( class my_object : private noncopyable {} )
* update kTileURL
This commit is contained in:
artemp
2014-02-06 10:25:36 +00:00
parent 61c69f5872
commit d6654ccaed
18 changed files with 78 additions and 97 deletions

View File

@@ -1,6 +1,7 @@
#ifndef LLMR_GEOMETRY_BINPACK
#define LLMR_GEOMETRY_BINPACK
#include <llmr/util/noncopyable.hpp>
#include <cstdint>
#include <list>
@@ -14,23 +15,15 @@ struct Rect {
};
template <typename T>
class BinPack {
class BinPack : private noncopyable {
public:
BinPack(T width, T height)
: free(1, { 0, 0, width, height }) {}
private:
// Make noncopyable
BinPack(const BinPack&) = delete;
BinPack(const BinPack&&) = delete;
BinPack& operator=(const BinPack&) = delete;
BinPack& operator=(const BinPack && ) = delete;
public:
Rect<T> allocate(T width, T height) {
// Find the smallest free rect angle
auto smallest = free.end();
for (auto it = free.begin(); it != free.end(); it++) {
for (auto it = free.begin(); it != free.end(); ++it) {
const Rect<T>& ref = *it;
const Rect<T>& rect = *smallest;
if (width <= ref.w && height <= ref.h) {

View File

@@ -9,6 +9,7 @@ namespace llmr {
class FillBuffer {
public:
typedef int16_t vertex_type;
typedef uint16_t element_type;
const uint8_t components = 2;
FillBuffer();
@@ -19,13 +20,13 @@ public:
void addDegenerate();
void addCoordinate(vertex_type x, vertex_type y);
void addElements(uint16_t a, uint16_t b, uint16_t c);
void addElements(element_type a, element_type b, element_type c);
void bind();
private:
std::vector<vertex_type> vertices;
std::vector<uint16_t> elements;
std::vector<element_type> elements;
uint32_t vertex_buffer;
uint32_t element_buffer;
bool dirty;

View File

@@ -2,15 +2,17 @@
#define LLMR_GEOMETRY_GEOMETRY
#include <llmr/util/pbf.hpp>
#include <llmr/util/noncopyable.hpp>
#include <cstdlib>
namespace llmr {
class Geometry {
public:
inline Geometry(pbf& data);
class Geometry : private util::noncopyable {
public:
inline explicit Geometry(pbf& data);
enum command {
end = 0,
move_to = 1,
@@ -37,13 +39,13 @@ Geometry::Geometry(pbf& data)
Geometry::command Geometry::next(int32_t &rx, int32_t &ry) {
if (data.data < data.end) {
if (!length) {
uint32_t cmd_length = (uint32_t)data.varint();
if (length == 0) {
uint32_t cmd_length = static_cast<uint32_t>(data.varint());
cmd = cmd_length & 0x7;
length = cmd_length >> 3;
}
length--;
--length;
if (cmd == move_to || cmd == line_to) {
rx = (x += data.svarint());

View File

@@ -9,6 +9,8 @@ namespace llmr {
class LineBuffer {
public:
typedef int16_t vertex_type;
~LineBuffer();
/*
@@ -30,7 +32,7 @@ public:
* @param {number} tx texture normal
* @param {number} ty texture normal
*/
void add(int16_t x, int16_t y, float ex, float ey, int8_t tx, int8_t ty, int32_t linesofar = 0);
void add(vertex_type x, vertex_type y, float ex, float ey, int8_t tx, int8_t ty, int32_t linesofar = 0);
/*
* Add a degenerate triangle to the buffer
@@ -56,7 +58,7 @@ public:
private:
bool dirty = true;
std::vector<int16_t> array;
std::vector<vertex_type> array;
uint32_t buffer = 0;
};

View File

@@ -9,7 +9,8 @@ namespace llmr {
class VertexBuffer {
public:
VertexBuffer(std::initializer_list<int16_t> init);
typedef int16_t vertex_type;
VertexBuffer(std::initializer_list<vertex_type> init);
~VertexBuffer();
/*
@@ -24,7 +25,7 @@ public:
void bind();
private:
const std::vector<int16_t> array;
const std::vector<vertex_type> array;
uint32_t buffer = 0;
};

View File

@@ -5,6 +5,7 @@
#include <llmr/map/transform.hpp>
#include <llmr/style/style.hpp>
#include <llmr/renderer/painter.hpp>
#include <llmr/util/noncopyable.hpp>
#include <cstdint>
#include <string>
@@ -13,18 +14,11 @@ namespace llmr {
class Settings;
class Map {
class Map : private util::noncopyable {
public:
Map(Settings& settings);
explicit Map(Settings& settings);
~Map();
// Make noncopyable
Map(const Map&) = delete;
Map(const Map&&) = delete;
Map &operator=(const Map&) = delete;
Map &operator=(const Map&&) = delete;
/* setup */
void setup();
void loadStyle(const uint8_t *const data, uint32_t bytes);

View File

@@ -1,19 +1,14 @@
#ifndef LLMR_MAP_SETTINGS
#define LLMR_MAP_SETTINGS
#include <llmr/util/noncopyable.hpp>
namespace llmr {
class Settings {
class Settings : private util::noncopyable {
public:
virtual void save() = 0;
// Make noncopyable
Settings() = default;
Settings(const Settings&) = delete;
Settings(const Settings&&) = delete;
Settings &operator=(const Settings&) = delete;
Settings &operator=(const Settings&&) = delete;
virtual ~Settings() {}
public:
// position
double longitude = 0;

View File

@@ -2,6 +2,7 @@
#define LLMR_MAP_TILE
#include <llmr/util/vec.hpp>
#include <llmr/util/noncopyable.hpp>
#include <llmr/geometry/debug_font_buffer.hpp>
#include <llmr/geometry/vao.hpp>
@@ -24,7 +25,8 @@ class FillBuffer;
class LineBuffer;
class PlainShader;
class Tile : public std::enable_shared_from_this<Tile> {
class Tile : public std::enable_shared_from_this<Tile>,
private util::noncopyable {
public:
struct exception : std::exception {};
struct geometry_too_long_exception : exception {};
@@ -45,12 +47,6 @@ public:
Tile(ID id, const Style& style);
~Tile();
// Make noncopyable
Tile(const Tile&) = delete;
Tile(const Tile&&) = delete;
Tile& operator=(const Tile&) = delete;
Tile& operator=(const Tile && ) = delete;
// Start loading the tile.
void request();

View File

@@ -4,6 +4,7 @@
#include <llmr/util/vec.hpp>
#include <llmr/util/mat4.hpp>
#include <llmr/util/animation.hpp>
#include <llmr/util/noncopyable.hpp>
#include <forward_list>
@@ -11,16 +12,10 @@ namespace llmr {
struct box;
class Transform {
class Transform : private util::noncopyable {
public:
Transform();
// Make noncopyable
Transform(const Transform&) = delete;
Transform(const Transform&&) = delete;
Transform &operator=(const Transform&) = delete;
Transform &operator=(const Transform&&) = delete;
// Animations
bool needsAnimation() const;
void updateAnimations();

View File

@@ -5,7 +5,7 @@
#include <functional>
#include <string>
#define kTileURL "http://mapbox:magic@kkaefer.net/gl/tiles/plain/%d-%d-%d.vector.pbf"
#define kTileURL "http://a.gl-api-us-east-1.tilestream.net/v3/mapbox.mapbox-streets-v4/%d/%d/%d.gl.pbf"
#define kSpriteURL "http://mapbox:magic@kkaefer.net/gl/debug/img/sprite"
namespace llmr {

View File

@@ -3,22 +3,16 @@
#include <string>
#include <llmr/map/tile.hpp>
#include <llmr/util/noncopyable.hpp>
namespace llmr {
class Painter;
class Bucket {
class Bucket : private util::noncopyable {
public:
Bucket() = default;
virtual void render(Painter& painter, const std::string& layer_name, const Tile::ID& id) = 0;
private:
// Make noncopyable
Bucket(const Bucket&) = delete;
Bucket(const Bucket&&) = delete;
Bucket& operator=(const Bucket&) = delete;
Bucket& operator=(const Bucket && ) = delete;
virtual ~Bucket() {}
};
}

View File

@@ -5,6 +5,7 @@
#include <llmr/geometry/vao.hpp>
#include <llmr/geometry/vertex_buffer.hpp>
#include <llmr/util/mat4.hpp>
#include <llmr/util/noncopyable.hpp>
#include <llmr/renderer/shader-plain.hpp>
#include <llmr/renderer/shader-outline.hpp>
@@ -22,18 +23,11 @@ class Tile;
class FillBucket;
class LineBucket;
class Painter {
class Painter : private util::noncopyable {
public:
Painter(Transform& transform, Settings& settings, Style& style);
// Make noncopyable
Painter(const Painter&) = delete;
Painter(const Painter&&) = delete;
Painter& operator=(const Painter&) = delete;
Painter& operator=(const Painter && ) = delete;
void setup();
void clear();
void changeMatrix(const Tile::ID& id);
void render(const std::shared_ptr<Tile>& tile);

View File

@@ -2,20 +2,14 @@
#define LLMR_RENDERER_SHADER
#include <cstdint>
#include <llmr/util/noncopyable.hpp>
namespace llmr {
class Shader {
class Shader : private util::noncopyable {
public:
Shader(const char *vertex, const char *fragment);
virtual ~Shader();
// Make noncopyable
Shader(const Shader&) = delete;
Shader(const Shader&&) = delete;
Shader &operator=(const Shader&) = delete;
Shader &operator=(const Shader&&) = delete;
~Shader();
bool valid;
uint32_t program;

View File

@@ -1,10 +1,12 @@
#ifndef LLMR_UTIL_ANIMATION
#define LLMR_UTIL_ANIMATION
#include <llmr/util/noncopyable.hpp>
namespace llmr {
namespace util {
class animation {
class animation : private noncopyable {
public:
enum state {
running,
@@ -12,13 +14,6 @@ public:
};
animation(double from, double to, double &value, double duration);
// Make noncopyable
animation(const animation&) = delete;
animation(const animation&&) = delete;
animation &operator=(const animation&) = delete;
animation &operator=(const animation&&) = delete;
state update() const;
private:

View File

@@ -0,0 +1,23 @@
#ifndef LLMR_UTIL_NONCOPYABLE
#define LLMR_UTIL_NONCOPYABLE
namespace llmr { namespace util {
namespace non_copyable_
{
class noncopyable
{
protected:
constexpr noncopyable() = default;
~noncopyable() = default;
noncopyable( noncopyable const& ) = delete;
noncopyable& operator=(noncopyable const& ) = delete;
};
}
typedef non_copyable_::noncopyable noncopyable;
}}
#endif //LLMR_UTIL_NONCOPYABLE

View File

@@ -1,6 +1,8 @@
#include <llmr/geometry/fill_buffer.hpp>
#include <llmr/platform/gl.hpp>
#include <climits>
using namespace llmr;
FillBuffer::FillBuffer()
@@ -32,16 +34,16 @@ uint32_t FillBuffer::elements_length() const {
}
void FillBuffer::addDegenerate() {
vertices.push_back(32767);
vertices.push_back(std::numeric_limits<vertex_type>::max());
vertices.push_back(0);
}
void FillBuffer::addCoordinate(int16_t x, int16_t y) {
void FillBuffer::addCoordinate(vertex_type x, vertex_type y) {
vertices.push_back(x);
vertices.push_back(y);
}
void FillBuffer::addElements(uint16_t a, uint16_t b, uint16_t c) {
void FillBuffer::addElements(element_type a, element_type b, element_type c) {
elements.push_back(a);
elements.push_back(b);
elements.push_back(c);
@@ -60,8 +62,8 @@ void FillBuffer::bind() {
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, element_buffer);
if (dirty) {
glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(uint16_t), vertices.data(), GL_STATIC_DRAW);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, elements.size() * sizeof(uint16_t), elements.data(), GL_STATIC_DRAW);
glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(vertex_type), vertices.data(), GL_STATIC_DRAW);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, elements.size() * sizeof(element_type), elements.data(), GL_STATIC_DRAW);
dirty = false;
}
}

View File

@@ -15,7 +15,7 @@ uint32_t LineBuffer::length() const {
return array.size() / 4;
}
void LineBuffer::add(int16_t x, int16_t y, float ex, float ey, int8_t tx, int8_t ty, int32_t linesofar) {
void LineBuffer::add(vertex_type x, vertex_type y, float ex, float ey, int8_t tx, int8_t ty, int32_t linesofar) {
array.push_back((x * 2) | tx);
array.push_back((y * 2) | ty);
array.push_back(linesofar);
@@ -40,7 +40,7 @@ void LineBuffer::bind() {
glBindBuffer(GL_ARRAY_BUFFER, buffer);
if (dirty) {
glBufferData(GL_ARRAY_BUFFER, array.size() * sizeof(int16_t), array.data(), GL_STATIC_DRAW);
glBufferData(GL_ARRAY_BUFFER, array.size() * sizeof(vertex_type), array.data(), GL_STATIC_DRAW);
dirty = false;
}
}

View File

@@ -21,7 +21,7 @@ void VertexBuffer::bind() {
if (buffer == 0) {
glGenBuffers(1, &buffer);
glBindBuffer(GL_ARRAY_BUFFER, buffer);
glBufferData(GL_ARRAY_BUFFER, array.size() * sizeof(int16_t), array.data(), GL_STATIC_DRAW);
glBufferData(GL_ARRAY_BUFFER, array.size() * sizeof(vertex_type), array.data(), GL_STATIC_DRAW);
} else {
glBindBuffer(GL_ARRAY_BUFFER, buffer);
}