From fcaea3d937a16a8d975989710f14320629c951d4 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Thu, 3 May 2018 13:25:07 +0200 Subject: Optimize gif rendering --- src/Gif.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/Gif.cpp') diff --git a/src/Gif.cpp b/src/Gif.cpp index 5b83158..f87b0ab 100644 --- a/src/Gif.cpp +++ b/src/Gif.cpp @@ -134,7 +134,12 @@ namespace dchat void Gif::draw(sf::RenderTarget &target) { - double frameDeltaCs = (double)frameTimer.getElapsedTime().asMilliseconds() * 0.1; // Centisecond + double timeElapsedMilli = (double)frameTimer.getElapsedTime().asMilliseconds(); + // If gif is not redrawn for a while, then we want to reset it; otherwise the decoding loop will take too long time. + // This means that if gif is not visible for a while and then it becomes visible, the gif will reset instead of trying to process several seconds of frames + if(timeElapsedMilli > 3000) + timeElapsedMilli = 0; + double frameDeltaCs = timeElapsedMilli * 0.1; // Centisecond frameTimer.restart(); timeElapsedCs += frameDeltaCs; -- cgit v1.2.3