From 03e400e00224e8012d4272ad9ebcba0bc11ed3f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20K=C3=A4fer?= Date: Fri, 20 Mar 2015 18:53:44 +0100 Subject: [PATCH] make the debug flag atomic and move to MapData --- include/mbgl/map/map.hpp | 2 +- src/mbgl/map/map.cpp | 15 +++++++++------ src/mbgl/map/map_data.hpp | 6 ++++++ 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/include/mbgl/map/map.hpp b/include/mbgl/map/map.hpp index 9ea5c72f6..71e81d077 100644 --- a/include/mbgl/map/map.hpp +++ b/include/mbgl/map/map.hpp @@ -80,6 +80,7 @@ public: enum class Update : UpdateType { Nothing = 0, StyleInfo = 1 << 0, + Debug = 1 << 1, }; void triggerUpdate(Update = Update::Nothing); @@ -254,7 +255,6 @@ private: std::chrono::steady_clock::duration defaultTransitionDuration; - bool debug = false; std::chrono::steady_clock::time_point animationTime = std::chrono::steady_clock::time_point::min(); std::set> activeSources; diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp index 57000e040..e00cf6e0a 100644 --- a/src/mbgl/map/map.cpp +++ b/src/mbgl/map/map.cpp @@ -591,18 +591,17 @@ void Map::updateAnnotationTiles(std::vector& ids) { #pragma mark - Toggles void Map::setDebug(bool value) { - debug = value; - assert(painter); - painter->setDebug(debug); - triggerUpdate(); + data->setDebug(value); + triggerUpdate(Update::Debug); } void Map::toggleDebug() { - setDebug(!debug); + data->toggleDebug(); + triggerUpdate(Update::Debug); } bool Map::getDebug() const { - return debug; + return data->getDebug(); } void Map::addClass(const std::string& klass) { @@ -765,6 +764,10 @@ void Map::prepare() { if (u & static_cast(Update::StyleInfo)) { reloadStyle(); } + if (u & static_cast(Update::Debug)) { + assert(painter); + painter->setDebug(data->getDebug()); + } // Update transform transitions. animationTime = std::chrono::steady_clock::now(); diff --git a/src/mbgl/map/map_data.hpp b/src/mbgl/map/map_data.hpp index 98d2518a2..55bf5f7f6 100644 --- a/src/mbgl/map/map_data.hpp +++ b/src/mbgl/map/map_data.hpp @@ -3,6 +3,7 @@ #include #include +#include namespace mbgl { @@ -25,10 +26,15 @@ public: styleInfo = info; } + inline bool getDebug() const { return debug; } + inline bool toggleDebug() { return debug ^= 1u; } + inline void setDebug(bool value) { debug = value; } + private: mutable std::mutex mtx; StyleInfo styleInfo; + std::atomic debug; }; }