aboutsummaryrefslogtreecommitdiff
path: root/engines/mohawk/myst.cpp
diff options
context:
space:
mode:
authorBastien Bouclet2017-07-09 17:47:56 +0200
committerBastien Bouclet2017-07-22 20:38:56 +0200
commit49fa0bdd689514fda992bffb39e06ccd37df85c4 (patch)
tree4300a47b3bfd75da0fd6683e936830fc596cb968 /engines/mohawk/myst.cpp
parenta106dc8dd4a055821743ed5bf01a27171e093cd0 (diff)
downloadscummvm-rg350-49fa0bdd689514fda992bffb39e06ccd37df85c4.tar.gz
scummvm-rg350-49fa0bdd689514fda992bffb39e06ccd37df85c4.tar.bz2
scummvm-rg350-49fa0bdd689514fda992bffb39e06ccd37df85c4.zip
MOHAWK: Myst: Change blocking movies and waits to use the main loop
Diffstat (limited to 'engines/mohawk/myst.cpp')
-rw-r--r--engines/mohawk/myst.cpp98
1 files changed, 70 insertions, 28 deletions
diff --git a/engines/mohawk/myst.cpp b/engines/mohawk/myst.cpp
index 7804fb52bd..f965756fca 100644
--- a/engines/mohawk/myst.cpp
+++ b/engines/mohawk/myst.cpp
@@ -84,6 +84,8 @@ MohawkEngine_Myst::MohawkEngine_Myst(OSystem *syst, const MohawkGameDescription
_optionsDialog = nullptr;
_prevStack = nullptr;
+
+ _escapePressed = false;
}
MohawkEngine_Myst::~MohawkEngine_Myst() {
@@ -220,6 +222,52 @@ Common::String MohawkEngine_Myst::wrapMovieFilename(const Common::String &movieN
return Common::String("qtw/") + prefix + movieName + ".mov";
}
+
+void MohawkEngine_Myst::playMovieBlocking(const Common::String &fileName, uint16 x, uint16 y) {
+ VideoEntryPtr video = _video->playMovie(fileName);
+ if (!video) {
+ error("Failed to open the '%s' movie", fileName.c_str());
+ }
+
+ video->moveTo(x, y);
+
+ waitUntilMovieEnds(video);
+}
+
+void MohawkEngine_Myst::playMovieBlockingCentered(const Common::String &fileName) {
+ VideoEntryPtr video = _video->playMovie(fileName);
+ if (!video) {
+ error("Failed to open the '%s' movie", fileName.c_str());
+ }
+
+ // Clear screen
+ _system->fillScreen(_system->getScreenFormat().RGBToColor(0, 0, 0));
+
+ video->center();
+ waitUntilMovieEnds(video);
+}
+
+void MohawkEngine_Myst::waitUntilMovieEnds(const VideoEntryPtr &video) {
+ assert(video);
+
+ // Sanity check
+ if (video->isLooping())
+ error("Called waitUntilMovieEnds() on a looping video");
+
+ while (!video->endOfVideo() && !shouldQuit()) {
+ doFrame();
+
+ // Allow skipping
+ if (_escapePressed) {
+ _escapePressed = false;
+ break;
+ }
+ }
+
+ // Ensure it's removed
+ _video->removeEntry(video);
+}
+
Common::Error MohawkEngine_Myst::run() {
MohawkEngine::run();
@@ -336,6 +384,18 @@ void MohawkEngine_Myst::doFrame() {
_needsShowCredits = false;
}
break;
+ case Common::KEYCODE_ESCAPE:
+ _escapePressed = true;
+ break;
+ default:
+ break;
+ }
+ break;
+ case Common::EVENT_KEYUP:
+ switch (event.kbd.keycode) {
+ case Common::KEYCODE_ESCAPE:
+ _escapePressed = false;
+ break;
default:
break;
}
@@ -355,36 +415,17 @@ void MohawkEngine_Myst::doFrame() {
bool MohawkEngine_Myst::wait(uint32 duration, bool skippable) {
uint32 end = getTotalPlayTime() + duration;
- bool skipped = false;
- while (getTotalPlayTime() < end && !skipped && !shouldQuit()) {
- Common::Event event;
- while (_system->getEventManager()->pollEvent(event)) {
- switch (event.type) {
- case Common::EVENT_LBUTTONUP:
- skipped = skippable;
- break;
- case Common::EVENT_KEYDOWN:
- switch (event.kbd.keycode) {
- case Common::KEYCODE_SPACE:
- pauseGame();
- break;
- case Common::KEYCODE_ESCAPE:
- skipped = skippable;
- break;
- default:
- break;
- }
- default:
- break;
- }
- }
+ while (getTotalPlayTime() < end && !shouldQuit()) {
+ doFrame();
- // Cut down on CPU usage
- _system->delayMillis(10);
+ if (_escapePressed && skippable) {
+ _escapePressed = false;
+ return true; // Return true if skipped
+ }
}
- return skipped;
+ return false;
}
void MohawkEngine_Myst::pollAndDiscardEvents() {
@@ -539,8 +580,9 @@ void MohawkEngine_Myst::changeToStack(uint16 stack, uint16 card, uint16 linkSrcS
break;
}
- if (flyby)
- _video->playMovieBlockingCentered(wrapMovieFilename(flyby, kMasterpieceOnly));
+ if (flyby) {
+ playMovieBlockingCentered(wrapMovieFilename(flyby, kMasterpieceOnly));
+ }
}
changeToCard(card, kTransitionCopy);