diff --git a/emscripten/main.cpp b/emscripten/main.cpp index 4565a67d5..ffdef046b 100644 --- a/emscripten/main.cpp +++ b/emscripten/main.cpp @@ -28,7 +28,7 @@ public: } int width, height; - emscripten_get_canvas_size(&width, &height, NULL); + emscripten_get_canvas_size(&width, &height, nullptr); glfwSetMousePosCallback(mousemove); glfwSetMouseButtonCallback(mouseclick); diff --git a/include/llmr/geometry/binpack.hpp b/include/llmr/geometry/binpack.hpp index 03b34c63d..53b9e6c1a 100644 --- a/include/llmr/geometry/binpack.hpp +++ b/include/llmr/geometry/binpack.hpp @@ -1,6 +1,7 @@ #ifndef LLMR_GEOMETRY_BINPACK #define LLMR_GEOMETRY_BINPACK +#include #include #include @@ -14,23 +15,15 @@ struct Rect { }; template -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 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& ref = *it; const Rect& rect = *smallest; if (width <= ref.w && height <= ref.h) { @@ -76,7 +69,7 @@ public: // Simple algorithm to recursively merge the newly released cell with its // neighbor. This doesn't merge more than two cells at a time, and fails // for complicated merges. - for (auto it = free.begin(); it != free.end(); it++) { + for (auto it = free.begin(); it != free.end(); ++it) { Rect ref = *it; if (ref.y == rect.y && ref.h == rect.h && ref.x + ref.w == rect.x) { ref.w += rect.w; diff --git a/include/llmr/geometry/fill_buffer.hpp b/include/llmr/geometry/fill_buffer.hpp index 626d66179..b141825fc 100644 --- a/include/llmr/geometry/fill_buffer.hpp +++ b/include/llmr/geometry/fill_buffer.hpp @@ -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 vertices; - std::vector elements; + std::vector elements; uint32_t vertex_buffer; uint32_t element_buffer; bool dirty; diff --git a/include/llmr/geometry/geometry.hpp b/include/llmr/geometry/geometry.hpp index 680832429..2f321934a 100644 --- a/include/llmr/geometry/geometry.hpp +++ b/include/llmr/geometry/geometry.hpp @@ -2,16 +2,18 @@ #define LLMR_GEOMETRY_GEOMETRY #include +#include #include namespace llmr { -class Geometry { -public: - inline Geometry(pbf& data); +class Geometry : private util::noncopyable { - enum command { +public: + inline explicit Geometry(pbf& data); + + enum command : uint8_t { end = 0, move_to = 1, line_to = 2, @@ -22,7 +24,7 @@ public: private: pbf& data; - uint32_t cmd; + uint8_t cmd; uint32_t length; int32_t x, y; int32_t ox, oy; @@ -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(data.varint()); cmd = cmd_length & 0x7; length = cmd_length >> 3; } - length--; + --length; if (cmd == move_to || cmd == line_to) { rx = (x += data.svarint()); diff --git a/include/llmr/geometry/line_buffer.hpp b/include/llmr/geometry/line_buffer.hpp index 4965a919a..412ba860c 100644 --- a/include/llmr/geometry/line_buffer.hpp +++ b/include/llmr/geometry/line_buffer.hpp @@ -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 array; + std::vector array; uint32_t buffer = 0; }; diff --git a/include/llmr/geometry/vao.hpp b/include/llmr/geometry/vao.hpp index 6d710d831..49401e01d 100644 --- a/include/llmr/geometry/vao.hpp +++ b/include/llmr/geometry/vao.hpp @@ -42,7 +42,7 @@ private: // For debug reasons, we're storing the bind information so that we can // detect errors and report - void *buffer_ptr = NULL; + void *buffer_ptr = nullptr; char *offset_ptr = 0; }; diff --git a/include/llmr/geometry/vertex_buffer.hpp b/include/llmr/geometry/vertex_buffer.hpp index 667e3fc8a..5dd5ec719 100644 --- a/include/llmr/geometry/vertex_buffer.hpp +++ b/include/llmr/geometry/vertex_buffer.hpp @@ -9,7 +9,8 @@ namespace llmr { class VertexBuffer { public: - VertexBuffer(std::initializer_list init); + typedef int16_t vertex_type; + VertexBuffer(std::initializer_list init); ~VertexBuffer(); /* @@ -24,7 +25,7 @@ public: void bind(); private: - const std::vector array; + const std::vector array; uint32_t buffer = 0; }; diff --git a/include/llmr/map/map.hpp b/include/llmr/map/map.hpp index 46b7dfb3c..189327c52 100644 --- a/include/llmr/map/map.hpp +++ b/include/llmr/map/map.hpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -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); diff --git a/include/llmr/map/settings.hpp b/include/llmr/map/settings.hpp index 8f2e12810..3e5395b80 100644 --- a/include/llmr/map/settings.hpp +++ b/include/llmr/map/settings.hpp @@ -1,19 +1,14 @@ #ifndef LLMR_MAP_SETTINGS #define LLMR_MAP_SETTINGS +#include + 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; diff --git a/include/llmr/map/tile.hpp b/include/llmr/map/tile.hpp index 2569764cc..7896d91eb 100644 --- a/include/llmr/map/tile.hpp +++ b/include/llmr/map/tile.hpp @@ -2,6 +2,7 @@ #define LLMR_MAP_TILE #include +#include #include #include @@ -24,7 +25,8 @@ class FillBuffer; class LineBuffer; class PlainShader; -class Tile : public std::enable_shared_from_this { +class Tile : public std::enable_shared_from_this, + 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(); diff --git a/include/llmr/map/transform.hpp b/include/llmr/map/transform.hpp index 9b39aa149..521bcd75a 100644 --- a/include/llmr/map/transform.hpp +++ b/include/llmr/map/transform.hpp @@ -4,6 +4,7 @@ #include #include #include +#include #include @@ -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(); diff --git a/include/llmr/platform/platform.hpp b/include/llmr/platform/platform.hpp index b31a112b8..ff6330241 100644 --- a/include/llmr/platform/platform.hpp +++ b/include/llmr/platform/platform.hpp @@ -5,7 +5,7 @@ #include #include -#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 { diff --git a/include/llmr/renderer/bucket.hpp b/include/llmr/renderer/bucket.hpp index 7ae0d2d00..9326aaed1 100644 --- a/include/llmr/renderer/bucket.hpp +++ b/include/llmr/renderer/bucket.hpp @@ -3,22 +3,16 @@ #include #include +#include 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() {} }; } diff --git a/include/llmr/renderer/fill_bucket.hpp b/include/llmr/renderer/fill_bucket.hpp index e980125b1..209e164e8 100644 --- a/include/llmr/renderer/fill_bucket.hpp +++ b/include/llmr/renderer/fill_bucket.hpp @@ -10,7 +10,7 @@ #include #ifndef BUFFER_OFFSET -#define BUFFER_OFFSET(i) ((char *)NULL + (i)) +#define BUFFER_OFFSET(i) ((char *)nullptr + (i)) #endif namespace llmr { diff --git a/include/llmr/renderer/painter.hpp b/include/llmr/renderer/painter.hpp index b991c9592..925defd03 100644 --- a/include/llmr/renderer/painter.hpp +++ b/include/llmr/renderer/painter.hpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -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); diff --git a/include/llmr/renderer/shader.hpp b/include/llmr/renderer/shader.hpp index 26674d2d6..77fd7a6f6 100644 --- a/include/llmr/renderer/shader.hpp +++ b/include/llmr/renderer/shader.hpp @@ -2,20 +2,14 @@ #define LLMR_RENDERER_SHADER #include +#include 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; diff --git a/include/llmr/util/animation.hpp b/include/llmr/util/animation.hpp index c31f1ff9d..4095fcba1 100644 --- a/include/llmr/util/animation.hpp +++ b/include/llmr/util/animation.hpp @@ -1,10 +1,12 @@ #ifndef LLMR_UTIL_ANIMATION #define LLMR_UTIL_ANIMATION +#include + 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: diff --git a/include/llmr/util/noncopyable.hpp b/include/llmr/util/noncopyable.hpp new file mode 100644 index 000000000..7891e529e --- /dev/null +++ b/include/llmr/util/noncopyable.hpp @@ -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 diff --git a/include/llmr/util/pbf.hpp b/include/llmr/util/pbf.hpp index 5585d5c15..b685d158c 100644 --- a/include/llmr/util/pbf.hpp +++ b/include/llmr/util/pbf.hpp @@ -8,12 +8,8 @@ * Author: Josh Haberman */ -#include -#include -#include #include - namespace llmr { struct pbf { @@ -46,8 +42,8 @@ struct pbf { inline void skipValue(uint32_t val); inline void skipBytes(uint32_t bytes); - const uint8_t *data = NULL; - const uint8_t *end = NULL; + const uint8_t *data = nullptr; + const uint8_t *end = nullptr; uint32_t value = 0; uint32_t tag = 0; }; @@ -60,8 +56,8 @@ pbf::pbf(const unsigned char *data, uint32_t length) } pbf::pbf() - : data(NULL), - end(NULL), + : data(nullptr), + end(nullptr), value(0), tag(0) { } @@ -73,7 +69,7 @@ pbf::operator bool() const { bool pbf::next() { if (data < end) { - value = (uint32_t)varint(); + value = static_cast(varint()); tag = value >> 3; return true; } @@ -134,8 +130,8 @@ double pbf::float64() { } std::string pbf::string() { - uint32_t bytes = (uint32_t)varint(); - const char *string = (const char *)data; + uint32_t bytes = static_cast(varint()); + const char *string = reinterpret_cast(data); skipBytes(bytes); return std::string(string, bytes); } @@ -146,7 +142,7 @@ bool pbf::boolean() { } pbf pbf::message() { - uint32_t bytes = (uint32_t)varint(); + uint32_t bytes = static_cast(varint()); const uint8_t *pos = data; skipBytes(bytes); return pbf(pos, bytes); @@ -165,7 +161,7 @@ void pbf::skipValue(uint32_t val) { skipBytes(8); break; case 2: // string/message - skipBytes((uint32_t)varint()); + skipBytes(static_cast(varint())); break; case 5: // 32 bit skipBytes(4); @@ -185,4 +181,3 @@ void pbf::skipBytes(uint32_t bytes) { } // end namespace llmr #endif - diff --git a/include/llmr/util/unitbezier.hpp b/include/llmr/util/unitbezier.hpp index e64f7abd4..6acae7a3d 100644 --- a/include/llmr/util/unitbezier.hpp +++ b/include/llmr/util/unitbezier.hpp @@ -66,7 +66,7 @@ struct UnitBezier { int i; // First try a few iterations of Newton's method -- normally very fast. - for (t2 = x, i = 0; i < 8; i++) { + for (t2 = x, i = 0; i < 8; ++i) { x2 = sampleCurveX(t2) - x; if (fabs (x2) < epsilon) return t2; diff --git a/src/geometry/debug_font.cpp b/src/geometry/debug_font.cpp index 8e7999189..2da0c6784 100644 --- a/src/geometry/debug_font.cpp +++ b/src/geometry/debug_font.cpp @@ -97,7 +97,7 @@ const int8_t simplex_93[] = { 5, 25, 7, 24, 8, 23, 9, 21, 9, 19, 8, 17, 7, 16, 6 const int8_t simplex_94[] = { 3, 6, 3, 8, 4, 11, 6, 12, 8, 12, 10, 11, 14, 8, 16, 7, 18, 7, 20, 8, 21, 10, -1, -1, 3, 8, 4, 10, 6, 11, 8, 11, 10, 10, 14, 7, 16, 6, 18, 6, 20, 7, 21, 10, 21, 12 }; struct glyph { - glyph() : width(0), length(0), data(NULL) { } + glyph() : width(0), length(0), data(nullptr) { } glyph(uint8_t width, uint8_t length, const int8_t *data) : width(width), length(length), @@ -110,7 +110,7 @@ struct glyph { // Font data From Hershey Simplex Font // http://paulbourke.net/dataformats/hershey/ const std::map simplex = { - { ' ', { 16, 0, NULL } }, + { ' ', { 16, 0, nullptr } }, { '!', { 10, sizeof(simplex_1), simplex_1 } }, { '"', { 16, sizeof(simplex_2), simplex_2 } }, { '#', { 21, sizeof(simplex_3), simplex_3 } }, diff --git a/src/geometry/debug_font_buffer.cpp b/src/geometry/debug_font_buffer.cpp index de0394c11..7316ca21c 100644 --- a/src/geometry/debug_font_buffer.cpp +++ b/src/geometry/debug_font_buffer.cpp @@ -22,7 +22,7 @@ DebugFontBuffer::~DebugFontBuffer() { void DebugFontBuffer::addText(const char *text, double left, double baseline, double scale) { int32_t length = strlen(text); - for (int32_t i = 0; i < length; i++) { + for (int32_t i = 0; i < length; ++i) { if (text[i] < 32 || text[i] > 127) { continue; } diff --git a/src/geometry/fill_buffer.cpp b/src/geometry/fill_buffer.cpp index 36d276538..ba6cfcb40 100644 --- a/src/geometry/fill_buffer.cpp +++ b/src/geometry/fill_buffer.cpp @@ -1,6 +1,8 @@ #include #include +#include + 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::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; } } diff --git a/src/geometry/line_buffer.cpp b/src/geometry/line_buffer.cpp index ff95a5079..4e1200d2f 100644 --- a/src/geometry/line_buffer.cpp +++ b/src/geometry/line_buffer.cpp @@ -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; } } diff --git a/src/geometry/vertex_buffer.cpp b/src/geometry/vertex_buffer.cpp index 591b0c13d..2d209f6be 100644 --- a/src/geometry/vertex_buffer.cpp +++ b/src/geometry/vertex_buffer.cpp @@ -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); } diff --git a/src/map/map.cpp b/src/map/map.cpp index 2828b9d9b..cc028496b 100644 --- a/src/map/map.cpp +++ b/src/map/map.cpp @@ -222,7 +222,7 @@ bool Map::findLoadedChildren(const Tile::ID& id, int32_t maxCoveringZoom, std::f * @return boolean Whether a parent was found. */ bool Map::findLoadedParent(const Tile::ID& id, int32_t minCoveringZoom, std::forward_list& retain) { - for (int32_t z = id.z - 1; z >= minCoveringZoom; z--) { + for (int32_t z = id.z - 1; z >= minCoveringZoom; --z) { const Tile::ID parent_id = Tile::parent(id, z); const Tile::Ptr tile = hasTile(parent_id); if (tile && tile->state == Tile::ready) { @@ -263,8 +263,8 @@ void Map::updateTiles() { // TODO: Discard tiles that are outside the viewport std::forward_list required; - for (int32_t y = tl.y; y < br.y; y++) { - for (int32_t x = tl.x; x < br.x; x++) { + for (int32_t y = tl.y; y < br.y; ++y) { + for (int32_t x = tl.x; x < br.x; ++x) { required.emplace_front(x, y, zoom); } } diff --git a/src/map/tile.cpp b/src/map/tile.cpp index b7cf468d0..da0ad0006 100644 --- a/src/map/tile.cpp +++ b/src/map/tile.cpp @@ -17,7 +17,7 @@ Tile::ID Tile::parent(const ID& id, int32_t z) { assert(z < id.z); ID pos(id); while (pos.z > z) { - pos.z--; + --pos.z; pos.x = floor(pos.x / 2); pos.y = floor(pos.y / 2); } @@ -30,8 +30,8 @@ std::forward_list Tile::children(const ID& id, int32_t z) { int32_t factor = pow(2, z - id.z); std::forward_list children; - for (int32_t y = id.y * factor, y_max = (id.y + 1) * factor; y < y_max; y++) { - for (int32_t x = id.x * factor, x_max = (id.x + 1) * factor; x < x_max; x++) { + for (int32_t y = id.y * factor, y_max = (id.y + 1) * factor; y < y_max; ++y) { + for (int32_t x = id.x * factor, x_max = (id.x + 1) * factor; x < x_max; ++x) { children.emplace_front(x, y, z); } } @@ -77,7 +77,7 @@ void Tile::request() { } }, []() { // TODO: Make sure this gets passed the correct map ID/pointer. - platform::restart(NULL); + platform::restart(nullptr); }); } @@ -162,7 +162,7 @@ std::shared_ptr Tile::createBucket(const VectorTile& tile, const BucketD // The layer specified in the bucket does not exist. Do nothing. } - return NULL; + return nullptr; } std::shared_ptr Tile::createFillBucket(const VectorTileLayer& layer, const BucketDescription& bucket_desc) { diff --git a/src/renderer/fill_bucket.cpp b/src/renderer/fill_bucket.cpp index 6815efb6f..bfa50b007 100644 --- a/src/renderer/fill_bucket.cpp +++ b/src/renderer/fill_bucket.cpp @@ -44,17 +44,13 @@ void FillBucket::addGeometry(pbf& geom) { } void FillBucket::addGeometry(const std::vector& line) { - // Alias this. - FillBuffer& buffer = *this->buffer; - - uint32_t vertex_start = buffer.vertex_length(); - - buffer.addDegenerate(); + uint32_t vertex_start = buffer->vertex_length(); + buffer->addDegenerate(); for (const Coordinate& coord : line) { - buffer.addCoordinate(coord.x, coord.y); + buffer->addCoordinate(coord.x, coord.y); } - uint32_t vertex_end = buffer.vertex_length(); + uint32_t vertex_end = buffer->vertex_length(); if (vertex_end - vertex_start > 65535) { throw geometry_too_long_exception(); @@ -82,13 +78,13 @@ void FillBucket::addGeometry(const std::vector& line) { assert(firstIndex + vertex_count - 1 < 65536); - uint32_t elements_start = buffer.elements_length(); + uint32_t elements_start = buffer->elements_length(); - for (uint32_t i = 2; i < vertex_count; i++) { - buffer.addElements(firstIndex, firstIndex + i - 1, firstIndex + i); + for (uint32_t i = 2; i < vertex_count; ++i) { + buffer->addElements(firstIndex, firstIndex + i - 1, firstIndex + i); } - uint32_t elements_end = buffer.elements_length(); + uint32_t elements_end = buffer->elements_length(); uint32_t elements_count = elements_end - elements_start; group.vertex_length += vertex_count; group.elements_length += elements_count; @@ -122,5 +118,3 @@ void FillBucket::drawVertices(OutlineShader& shader) { array.bind(shader, *buffer, vertex_index); glDrawArrays(GL_LINE_STRIP, 0, length); } - - diff --git a/src/renderer/line_bucket.cpp b/src/renderer/line_bucket.cpp index 6e95a7bc6..5cad0ddd4 100644 --- a/src/renderer/line_bucket.cpp +++ b/src/renderer/line_bucket.cpp @@ -10,7 +10,7 @@ #include #include -#define BUFFER_OFFSET(i) ((char *)NULL + (i)) +#define BUFFER_OFFSET(i) ((char *)nullptr + (i)) #include @@ -34,7 +34,7 @@ void LineBucket::addGeometry(pbf& geom) { int32_t x, y; while ((cmd = geometry.next(x, y)) != Geometry::end) { if (cmd == Geometry::move_to) { - if (line.size()) { + if (!line.empty()) { addGeometry(line); line.clear(); } @@ -93,7 +93,7 @@ void LineBucket::addGeometry(const std::vector& vertices) { // Start all lines with a degenerate vertex buffer->addDegenerate(); - for (size_t i = 0; i < vertices.size(); i++) { + for (size_t i = 0; i < vertices.size(); ++i) { if (nextNormal) prevNormal = { -nextNormal.x, -nextNormal.y }; if (currentVertex) prevVertex = currentVertex; diff --git a/src/renderer/painter.cpp b/src/renderer/painter.cpp index 8ec633d9b..31f8a8333 100644 --- a/src/renderer/painter.cpp +++ b/src/renderer/painter.cpp @@ -17,7 +17,7 @@ using namespace llmr; -#define BUFFER_OFFSET(i) ((char *)NULL + (i)) +#define BUFFER_OFFSET(i) ((char *)nullptr + (i)) Painter::Painter(Transform& transform, Settings& settings, Style& style) : transform(transform), @@ -131,7 +131,7 @@ void Painter::render(const Tile::Ptr& tile) { void Painter::renderLayers(const std::shared_ptr& tile, const std::vector& layers) { // Render everything top-to-bottom by using reverse iterators typedef std::vector::const_reverse_iterator iterator; - for (iterator it = layers.rbegin(), end = layers.rend(); it != end; it++) { + for (iterator it = layers.rbegin(), end = layers.rend(); it != end; ++it) { const LayerDescription& layer_desc = *it; if (layer_desc.child_layer.size()) { diff --git a/src/style/sprite.cpp b/src/style/sprite.cpp index 3a481a5d7..a37b31f93 100644 --- a/src/style/sprite.cpp +++ b/src/style/sprite.cpp @@ -129,7 +129,7 @@ void Sprite::loadImage(const std::string& data) { return; } - png_structp png = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, errorHandler, warningHandler); + png_structp png = png_create_read_struct(PNG_LIBPNG_VER_STRING, nullptr, errorHandler, warningHandler); assert(png); png_infop info = png_create_info_struct(png); @@ -140,7 +140,7 @@ void Sprite::loadImage(const std::string& data) { try { png_set_read_fn(png, (png_voidp)&buffer, readCallback); png_read_info(png, info); - png_get_IHDR(png, info, (png_uint_32*)&width, (png_uint_32*)&height, &depth, &color, &interlace, NULL, NULL); + png_get_IHDR(png, info, (png_uint_32*)&width, (png_uint_32*)&height, &depth, &color, &interlace, nullptr, nullptr); bool alpha = (color & PNG_COLOR_MASK_ALPHA) || png_get_valid(png, info, PNG_INFO_tRNS); // From http://trac.mapnik.org/browser/trunk/src/png_reader.cpp @@ -180,17 +180,17 @@ void Sprite::loadImage(const std::string& data) { assert(surface); png_bytep row_pointers[height]; - for (unsigned i = 0; i < height; i++) { + for (unsigned i = 0; i < height; ++i) { row_pointers[i] = (png_bytep)(surface + (i * rowbytes)); } // Read image data png_read_image(png, row_pointers); - png_read_end(png, NULL); + png_read_end(png, nullptr); } catch (std::exception& e) { fprintf(stderr, "loading PNG failed: %s\n", e.what()); - png_destroy_read_struct(&png, &info, NULL); + png_destroy_read_struct(&png, &info, nullptr); img.clear(); width = 0; height = 0; diff --git a/src/style/style.cpp b/src/style/style.cpp index 85c85b979..0e8e9f3b6 100644 --- a/src/style/style.cpp +++ b/src/style/style.cpp @@ -322,7 +322,7 @@ BucketDescription loadBucketJSON(const rapidjson::Value& value) { } } else if (name == "value") { if (value.IsArray()) { - for (rapidjson::SizeType i = 0; i < value.Size(); i++) { + for (rapidjson::SizeType i = 0; i < value.Size(); ++i) { bucket.source_value.push_back(loadValueJSON(value[i])); } } else { @@ -361,7 +361,7 @@ BucketDescription loadBucketJSON(const rapidjson::Value& value) { void loadLayersJSON(const rapidjson::Value& value, std::vector& layers) { if (value.IsArray()) { - for (rapidjson::SizeType i = 0; i < value.Size(); i++) { + for (rapidjson::SizeType i = 0; i < value.Size(); ++i) { layers.push_back(loadLayerJSON(value[i])); } } else { @@ -407,7 +407,7 @@ LayerDescription loadLayerJSON(const rapidjson::Value& value) { void loadClassesJSON(const rapidjson::Value& value, std::map& classes) { if (value.IsArray()) { - for (rapidjson::SizeType i = 0; i < value.Size(); i++) { + for (rapidjson::SizeType i = 0; i < value.Size(); ++i) { classes.insert(loadClassDescriptionJSON(value[i])); } } else {