diff options
-rw-r--r-- | include/llmr/renderer/frame_history.hpp | 2 | ||||
-rw-r--r-- | include/llmr/renderer/painter.hpp | 2 | ||||
-rw-r--r-- | src/map/map.cpp | 2 | ||||
-rw-r--r-- | src/renderer/frame_history.cpp | 31 | ||||
-rw-r--r-- | src/renderer/painter.cpp | 4 |
5 files changed, 40 insertions, 1 deletions
diff --git a/include/llmr/renderer/frame_history.hpp b/include/llmr/renderer/frame_history.hpp index 7326f627b1..d26dbbcf64 100644 --- a/include/llmr/renderer/frame_history.hpp +++ b/include/llmr/renderer/frame_history.hpp @@ -20,6 +20,8 @@ public: // Record frame history that will be used to calculate fading params void record(float zoom); + bool needsAnimation(float duration) const; + public: std::deque<FrameSnapshot> history; }; diff --git a/include/llmr/renderer/painter.hpp b/include/llmr/renderer/painter.hpp index 027c7e215a..c5cf22c5e5 100644 --- a/include/llmr/renderer/painter.hpp +++ b/include/llmr/renderer/painter.hpp @@ -48,6 +48,8 @@ public: void prepareClippingMask(); void drawClippingMask(const mat4& matrix, uint8_t clip_id, bool opaque = true); void finishClippingMask(); + + bool needsAnimation() const; private: void setupShaders(); void renderRaster(const std::shared_ptr<TileData>& tile); diff --git a/src/map/map.cpp b/src/map/map.cpp index 078fe01b92..75bfdb2c9e 100644 --- a/src/map/map.cpp +++ b/src/map/map.cpp @@ -483,5 +483,5 @@ bool Map::render() { painter.renderMatte(); - return changed || transform.needsAnimation(); + return changed || transform.needsAnimation() || painter.needsAnimation(); } diff --git a/src/renderer/frame_history.cpp b/src/renderer/frame_history.cpp index de65c1ad4a..ba0cf56c70 100644 --- a/src/renderer/frame_history.cpp +++ b/src/renderer/frame_history.cpp @@ -14,3 +14,34 @@ void FrameHistory::record(float zoom) { history.emplace_back(FrameSnapshot{static_cast<float>(platform::time() * 1000), zoom}); } } + +bool FrameHistory::needsAnimation(const float duration) const { + if (!history.size()) return true; + + // If we have a value that is older than duration and whose z value is the + // same as the most current z value, and if all values inbetween have the + // same z value, we don't need animation, otherwise we probably do. + const FrameSnapshot &pivot = history.back(); + + int i = -1; + while (history.size() > i + 1 && + history[i + 1].time + duration < pivot.time) { + i++; + } + + if (i < 0) { + // There is no frame that is older than the duration time, so we need to + // check all frames. + i = 0; + } + + // Make sure that all subsequent snapshots have the same zoom as the last + // pivot element. + for (; history.size() > i; i++) { + if (history[i].z != pivot.z) { + return true; + } + } + + return false; +}
\ No newline at end of file diff --git a/src/renderer/painter.cpp b/src/renderer/painter.cpp index 95017465c3..9a52cb36d3 100644 --- a/src/renderer/painter.cpp +++ b/src/renderer/painter.cpp @@ -29,6 +29,10 @@ Painter::Painter(Transform& transform, Settings& settings, Style& style, GlyphAt glyphAtlas(glyphAtlas) { } +bool Painter::needsAnimation() const { + return frameHistory.needsAnimation(300); +} + void Painter::setup() { setupShaders(); |