diff options
Diffstat (limited to 'src/renderer/frame_history.cpp')
-rw-r--r-- | src/renderer/frame_history.cpp | 31 |
1 files changed, 31 insertions, 0 deletions
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 |