From 2e0fdda51ff9ff48bb8cbfcc770f9fd99cccd43e Mon Sep 17 00:00:00 2001 From: Matthew Hoops Date: Thu, 20 May 2010 18:38:06 +0000 Subject: Add a pause level system to VideoDecoder (blatantly ripped off from Engine) and adapt Mohawk to it. svn-id: r49120 --- graphics/video/video_decoder.cpp | 18 ++++++++++++++++++ graphics/video/video_decoder.h | 38 +++++++++++++++++++++++++++++++++----- 2 files changed, 51 insertions(+), 5 deletions(-) (limited to 'graphics/video') diff --git a/graphics/video/video_decoder.cpp b/graphics/video/video_decoder.cpp index a3f63921a8..fe4a5848f3 100644 --- a/graphics/video/video_decoder.cpp +++ b/graphics/video/video_decoder.cpp @@ -71,12 +71,30 @@ bool VideoDecoder::needsUpdate() const { void VideoDecoder::reset() { _curFrame = -1; _startTime = 0; + _pauseLevel = 0; } bool VideoDecoder::endOfVideo() const { return !isVideoLoaded() || (getCurFrame() >= (int32)getFrameCount() - 1); } +void VideoDecoder::pauseVideo(bool pause) { + if (pause) { + _pauseLevel++; + } else { + assert(_pauseLevel); // We can't go negative + _pauseLevel--; + } + + if (_pauseLevel == 1 && pause) { + _pauseStartTime = g_system->getMillis(); // Store the starting time from pausing to keep it for later + pauseVideoIntern(true); + } else if (_pauseLevel == 0) { + pauseVideoIntern(false); + addPauseTime(g_system->getMillis() - _pauseStartTime); + } +} + uint32 FixedRateVideoDecoder::getTimeToNextFrame() const { if (endOfVideo() || _curFrame < 0) return 0; diff --git a/graphics/video/video_decoder.h b/graphics/video/video_decoder.h index 2ab8306d76..d96545d2c1 100644 --- a/graphics/video/video_decoder.h +++ b/graphics/video/video_decoder.h @@ -127,11 +127,6 @@ public: */ virtual bool hasDirtyPalette() const { return false; } - /** - * Add the time the video has been paused to maintain sync - */ - virtual void addPauseTime(uint32 ms) { _startTime += ms; } - /** * Returns if the video is finished or not */ @@ -147,14 +142,47 @@ public: */ virtual uint32 getTimeToNextFrame() const = 0; + /** + * Pause or resume the video. This should stop/resume any audio playback + * and other stuff. The initial pause time is kept so that any timing + * variables can be updated appropriately. + * + * This is a convenience tracker which automatically keeps track on how + * often the video has been paused, ensuring that after pausing an video + * e.g. twice, it has to be unpaused twice before actuallying resuming. + * + * @param pause true to pause the video, false to resume it + */ + void pauseVideo(bool pause); + + /** + * Return whether the video is currently paused or not. + */ + bool isPaused() const { return _pauseLevel != 0; } + protected: /** * Resets _curFrame and _startTime. Should be called from every close() function. */ void reset(); + /** + * Actual implementation of pause by subclasses. See pause() + * for details. + */ + virtual void pauseVideoIntern(bool pause) {} + + /** + * Add the time the video has been paused to maintain sync + */ + virtual void addPauseTime(uint32 ms) { _startTime += ms; } + int32 _curFrame; uint32 _startTime; + +private: + uint32 _pauseLevel; + uint32 _pauseStartTime; }; /** -- cgit v1.2.3