From 1f0820c8e82810fb957cb1cd17fb4327debfc0e5 Mon Sep 17 00:00:00 2001 From: Bruno de Oliveira Abinader Date: Thu, 26 Nov 2015 22:38:14 +0200 Subject: [core] Added MapDebugOptions Map debug options are now cycled up to all debug options enabled, then back to none. --- src/mbgl/map/map.cpp | 10 +++++----- src/mbgl/map/map_data.hpp | 23 ++++++++++++++++------- src/mbgl/renderer/debug_bucket.cpp | 19 ++++++++++++------- src/mbgl/renderer/debug_bucket.hpp | 4 +++- src/mbgl/renderer/painter_debug.cpp | 7 ++++--- 5 files changed, 40 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp index 713222fe54..573500fd65 100644 --- a/src/mbgl/map/map.cpp +++ b/src/mbgl/map/map.cpp @@ -420,17 +420,17 @@ void Map::removeSprite(const std::string& name) { #pragma mark - Toggles -void Map::setDebug(bool value) { - data->setDebug(value); +void Map::setDebug(MapDebugOptions mode) { + data->setDebug(mode); update(Update::Repaint); } -void Map::toggleDebug() { - data->toggleDebug(); +void Map::cycleDebugOptions() { + data->cycleDebugOptions(); update(Update::Repaint); } -bool Map::getDebug() const { +MapDebugOptions Map::getDebug() const { return data->getDebug(); } diff --git a/src/mbgl/map/map_data.hpp b/src/mbgl/map/map_data.hpp index c1898fc37f..597048167c 100644 --- a/src/mbgl/map/map_data.hpp +++ b/src/mbgl/map/map_data.hpp @@ -49,14 +49,23 @@ public: std::vector getClasses() const; - inline bool getDebug() const { - return debug; + inline MapDebugOptions getDebug() const { + return debugOptions; } - inline bool toggleDebug() { - return debug ^= 1u; + + inline void cycleDebugOptions() { + if (debugOptions & MapDebugOptions::Timestamps) + debugOptions = MapDebugOptions::NoDebug; + else if (debugOptions & MapDebugOptions::ParseStatus) + debugOptions = debugOptions | MapDebugOptions::Timestamps; + else if (debugOptions & MapDebugOptions::TileBorders) + debugOptions = debugOptions | MapDebugOptions::ParseStatus; + else + debugOptions = MapDebugOptions::TileBorders; } - inline void setDebug(bool value) { - debug = value; + + inline void setDebug(MapDebugOptions debugOptions_) { + debugOptions = debugOptions_; } inline bool getCollisionDebug() const { @@ -136,7 +145,7 @@ private: mutable std::mutex mtx; std::vector classes; - std::atomic debug { false }; + std::atomic debugOptions { MapDebugOptions::NoDebug }; std::atomic collisionDebug { false }; std::atomic animationTime; std::atomic defaultFadeDuration; diff --git a/src/mbgl/renderer/debug_bucket.cpp b/src/mbgl/renderer/debug_bucket.cpp index 048ded2cda..a1a24eab73 100644 --- a/src/mbgl/renderer/debug_bucket.cpp +++ b/src/mbgl/renderer/debug_bucket.cpp @@ -10,19 +10,24 @@ using namespace mbgl; -DebugBucket::DebugBucket(const TileID id, const TileData::State state_, Seconds modified_, Seconds expires_) +DebugBucket::DebugBucket(const TileID id, const TileData::State state_, Seconds modified_, Seconds expires_, MapDebugOptions debugMode_) : state(state_), modified(modified_), - expires(expires_) { - const std::string text = std::string(id) + " - " + TileData::StateToString(state); - fontBuffer.addText(text.c_str(), 50, 200, 5); + expires(expires_), + debugMode(debugMode_) { + double baseline = 200; + if (debugMode & MapDebugOptions::ParseStatus) { + const std::string text = std::string(id) + " - " + TileData::StateToString(state); + fontBuffer.addText(text.c_str(), 50, baseline, 5); + baseline += 200; + } - if (modified > Seconds::zero() && expires > Seconds::zero()) { + if (debugMode & MapDebugOptions::Timestamps && modified > Seconds::zero() && expires > Seconds::zero()) { const std::string modifiedText = "modified: " + util::iso8601(modified.count()); - fontBuffer.addText(modifiedText.c_str(), 50, 400, 5); + fontBuffer.addText(modifiedText.c_str(), 50, baseline, 5); const std::string expiresText = "expires: " + util::iso8601(expires.count()); - fontBuffer.addText(expiresText.c_str(), 50, 600, 5); + fontBuffer.addText(expiresText.c_str(), 50, baseline + 200, 5); } } diff --git a/src/mbgl/renderer/debug_bucket.hpp b/src/mbgl/renderer/debug_bucket.hpp index fe09afc03f..7edee6beec 100644 --- a/src/mbgl/renderer/debug_bucket.hpp +++ b/src/mbgl/renderer/debug_bucket.hpp @@ -2,6 +2,7 @@ #define MBGL_RENDERER_DEBUGBUCKET #include +#include #include #include #include @@ -12,7 +13,7 @@ class PlainShader; class DebugBucket : private util::noncopyable { public: - DebugBucket(TileID id, TileData::State, Seconds modified, Seconds expires); + DebugBucket(TileID id, TileData::State, Seconds modified, Seconds expires, MapDebugOptions); void drawLines(PlainShader& shader); void drawPoints(PlainShader& shader); @@ -20,6 +21,7 @@ public: const TileData::State state; const Seconds modified; const Seconds expires; + const MapDebugOptions debugMode; private: DebugFontBuffer fontBuffer; diff --git a/src/mbgl/renderer/painter_debug.cpp b/src/mbgl/renderer/painter_debug.cpp index 88eca9ffb1..0a0900526a 100644 --- a/src/mbgl/renderer/painter_debug.cpp +++ b/src/mbgl/renderer/painter_debug.cpp @@ -12,7 +12,7 @@ using namespace mbgl; void Painter::renderTileDebug(const Tile& tile) { MBGL_DEBUG_GROUP(std::string { "debug " } + std::string(tile.id)); assert(tile.data); - if (data.getDebug()) { + if (data.getDebug() != MapDebugOptions::NoDebug) { prepareTile(tile); renderDebugText(*tile.data, tile.matrix); renderDebugFrame(tile.matrix); @@ -26,8 +26,9 @@ void Painter::renderDebugText(TileData& tileData, const mat4 &matrix) { if (!tileData.debugBucket || tileData.debugBucket->state != tileData.getState() || tileData.debugBucket->modified != tileData.modified - || tileData.debugBucket->expires != tileData.expires) { - tileData.debugBucket = std::make_unique(tileData.id, tileData.getState(), tileData.modified, tileData.expires); + || tileData.debugBucket->expires != tileData.expires + || tileData.debugBucket->debugMode != data.getDebug()) { + tileData.debugBucket = std::make_unique(tileData.id, tileData.getState(), tileData.modified, tileData.expires, data.getDebug()); } config.program = plainShader->program; -- cgit v1.2.1