aboutsummaryrefslogtreecommitdiff
path: root/graphics
diff options
context:
space:
mode:
authorMatthew Hoops2010-05-20 18:38:06 +0000
committerMatthew Hoops2010-05-20 18:38:06 +0000
commit2e0fdda51ff9ff48bb8cbfcc770f9fd99cccd43e (patch)
tree415ceedd9e1e46b743edc1155549252ef1773b61 /graphics
parentf76f64774aa5c7d9669196c0258767d1e9f43cfb (diff)
downloadscummvm-rg350-2e0fdda51ff9ff48bb8cbfcc770f9fd99cccd43e.tar.gz
scummvm-rg350-2e0fdda51ff9ff48bb8cbfcc770f9fd99cccd43e.tar.bz2
scummvm-rg350-2e0fdda51ff9ff48bb8cbfcc770f9fd99cccd43e.zip
Add a pause level system to VideoDecoder (blatantly ripped off from Engine) and adapt Mohawk to it.
svn-id: r49120
Diffstat (limited to 'graphics')
-rw-r--r--graphics/video/video_decoder.cpp18
-rw-r--r--graphics/video/video_decoder.h38
2 files changed, 51 insertions, 5 deletions
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
@@ -128,11 +128,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
*/
virtual bool endOfVideo() const;
@@ -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;
};
/**