diff --git a/include/mbgl/map/map.hpp b/include/mbgl/map/map.hpp index 71e81d077..7473a0694 100644 --- a/include/mbgl/map/map.hpp +++ b/include/mbgl/map/map.hpp @@ -164,7 +164,7 @@ public: bool getDebug() const; inline const TransformState &getState() const { return state; } - inline std::chrono::steady_clock::time_point getTime() const { return animationTime; } + std::chrono::steady_clock::time_point getTime() const; inline AnnotationManager& getAnnotationManager() const { return *annotationManager; } private: @@ -255,8 +255,6 @@ private: std::chrono::steady_clock::duration defaultTransitionDuration; - std::chrono::steady_clock::time_point animationTime = std::chrono::steady_clock::time_point::min(); - std::set> activeSources; std::atomic updated; diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp index e00cf6e0a..8d4dd1461 100644 --- a/src/mbgl/map/map.cpp +++ b/src/mbgl/map/map.cpp @@ -604,6 +604,10 @@ bool Map::getDebug() const { return data->getDebug(); } +std::chrono::steady_clock::time_point Map::getTime() const { + return data->getAnimationTime(); +} + void Map::addClass(const std::string& klass) { if (hasClass(klass)) return; classes.push_back(klass); @@ -770,15 +774,15 @@ void Map::prepare() { } // Update transform transitions. - animationTime = std::chrono::steady_clock::now(); + + const auto animationTime = std::chrono::steady_clock::now(); + data->setAnimationTime(animationTime); if (transform.needsTransition()) { transform.updateTransitions(animationTime); } state = transform.currentState(); - animationTime = std::chrono::steady_clock::now(); - if (style) { updateSources(); style->updateProperties(state.getNormalizedZoom(), animationTime); @@ -803,7 +807,7 @@ void Map::render() { assert(painter); painter->render(*style, activeSources, - state, animationTime); + state, data->getAnimationTime()); // Schedule another rerender when we definitely need a next frame. if (transform.needsTransition() || style->hasTransitions()) { triggerUpdate(); diff --git a/src/mbgl/map/map_data.hpp b/src/mbgl/map/map_data.hpp index 55bf5f7f6..8efa43911 100644 --- a/src/mbgl/map/map_data.hpp +++ b/src/mbgl/map/map_data.hpp @@ -4,6 +4,7 @@ #include #include #include +#include namespace mbgl { @@ -17,6 +18,10 @@ class MapData { using Lock = std::lock_guard; public: + inline MapData() { + setAnimationTime(std::chrono::steady_clock::time_point::min()); + } + inline StyleInfo getStyleInfo() const { Lock lock(mtx); return styleInfo; @@ -26,15 +31,31 @@ public: styleInfo = info; } - inline bool getDebug() const { return debug; } - inline bool toggleDebug() { return debug ^= 1u; } - inline void setDebug(bool value) { debug = value; } + inline bool getDebug() const { + return debug; + } + inline bool toggleDebug() { + return debug ^= 1u; + } + inline void setDebug(bool value) { + debug = value; + } + + inline std::chrono::steady_clock::time_point getAnimationTime() const { + // We're casting the time_point to and from a duration because libstdc++ + // has a bug that doesn't allow time_points to be atomic. + return std::chrono::steady_clock::time_point(animationTime); + } + inline void setAnimationTime(std::chrono::steady_clock::time_point timePoint) { + animationTime = timePoint.time_since_epoch(); + }; private: mutable std::mutex mtx; StyleInfo styleInfo; - std::atomic debug; + std::atomic debug { false }; + std::atomic animationTime; }; }