MOHAWK: Get rid of VideoHandle

This commit is contained in:
Bastien Bouclet 2017-07-09 15:01:52 +02:00
parent 0b9bfb3d3c
commit c5496e3206
13 changed files with 138 additions and 197 deletions

View file

@ -272,20 +272,20 @@ bool MystConsole::Cmd_PlayMovie(int argc, const char **argv) {
fileName = argv[1]; fileName = argv[1];
} }
VideoHandle handle = _vm->_video->playMovie(fileName); VideoEntryPtr video = _vm->_video->playMovie(fileName);
if (!handle) { if (!video) {
debugPrintf("Failed to open movie '%s'\n", fileName.c_str()); debugPrintf("Failed to open movie '%s'\n", fileName.c_str());
return true; return true;
} }
if (argc == 4) { if (argc == 4) {
handle->setX(atoi(argv[2])); video->setX(atoi(argv[2]));
handle->setY(atoi(argv[3])); video->setY(atoi(argv[3]));
} else if (argc > 4) { } else if (argc > 4) {
handle->setX(atoi(argv[3])); video->setX(atoi(argv[3]));
handle->setY(atoi(argv[4])); video->setY(atoi(argv[4]));
} else { } else {
handle->center(); video->center();
} }
return false; return false;

View file

@ -3828,8 +3828,8 @@ LBMovieItem::~LBMovieItem() {
void LBMovieItem::update() { void LBMovieItem::update() {
if (_playing) { if (_playing) {
VideoHandle videoHandle = _vm->_video->findVideoHandle(_resourceId); VideoEntryPtr video = _vm->_video->findVideo(_resourceId);
if (!videoHandle || videoHandle->endOfVideo()) if (!video || video->endOfVideo())
done(true); done(true);
} }
@ -3840,11 +3840,11 @@ bool LBMovieItem::togglePlaying(bool playing, bool restart) {
if (playing) { if (playing) {
if ((_loaded && _enabled && _globalEnabled) || _phase == kLBPhaseNone) { if ((_loaded && _enabled && _globalEnabled) || _phase == kLBPhaseNone) {
debug("toggled video for phase %d", _phase); debug("toggled video for phase %d", _phase);
VideoHandle handle = _vm->_video->playMovie(_resourceId); VideoEntryPtr video = _vm->_video->playMovie(_resourceId);
if (!handle) if (!video)
error("Failed to open tMOV %d", _resourceId); error("Failed to open tMOV %d", _resourceId);
handle->moveTo(_rect.left, _rect.top); video->moveTo(_rect.left, _rect.top);
return true; return true;
} }
} }

View file

@ -211,9 +211,9 @@ MystAreaVideo::MystAreaVideo(MohawkEngine_Myst *vm, Common::SeekableReadStream *
debugC(kDebugResource, "\tplayRate: %d", _playRate); debugC(kDebugResource, "\tplayRate: %d", _playRate);
} }
VideoHandle MystAreaVideo::playMovie() { VideoEntryPtr MystAreaVideo::playMovie() {
// Check if the video is already running // Check if the video is already running
VideoHandle handle = _vm->_video->findVideoHandle(_videoFile); VideoEntryPtr handle = _vm->_video->findVideo(_videoFile);
// If the video is not running, play it // If the video is not running, play it
if (!handle) { if (!handle) {
@ -245,15 +245,15 @@ VideoHandle MystAreaVideo::playMovie() {
if (_playBlocking) { if (_playBlocking) {
_vm->_video->waitUntilMovieEnds(handle); _vm->_video->waitUntilMovieEnds(handle);
return VideoHandle(); return VideoEntryPtr();
} }
return handle; return handle;
} }
VideoHandle MystAreaVideo::getMovieHandle() { VideoEntryPtr MystAreaVideo::getVideo() {
// If the video is already in the manager, just return the handle // If the video is already in the manager, just return the handle
VideoHandle handle = _vm->_video->findVideoHandle(_videoFile); VideoEntryPtr handle = _vm->_video->findVideo(_videoFile);
if (!handle) { if (!handle) {
// If the video has not been loaded yet, do it but don't start playing it // If the video has not been loaded yet, do it but don't start playing it
handle = _vm->_video->playMovie(_videoFile); handle = _vm->_video->playMovie(_videoFile);
@ -271,12 +271,12 @@ void MystAreaVideo::handleCardChange() {
} }
bool MystAreaVideo::isPlaying() { bool MystAreaVideo::isPlaying() {
VideoHandle handle = _vm->_video->findVideoHandle(_videoFile); VideoEntryPtr handle = _vm->_video->findVideo(_videoFile);
return handle && !handle->endOfVideo(); return handle && !handle->endOfVideo();
} }
void MystAreaVideo::pauseMovie(bool pause) { void MystAreaVideo::pauseMovie(bool pause) {
VideoHandle handle = _vm->_video->findVideoHandle(_videoFile); VideoEntryPtr handle = _vm->_video->findVideo(_videoFile);
if (handle && !handle->endOfVideo()) if (handle && !handle->endOfVideo())
handle->pause(pause); handle->pause(pause);
} }

View file

@ -107,8 +107,8 @@ class MystAreaVideo : public MystAreaAction {
public: public:
MystAreaVideo(MohawkEngine_Myst *vm, Common::SeekableReadStream *rlstStream, MystArea *parent); MystAreaVideo(MohawkEngine_Myst *vm, Common::SeekableReadStream *rlstStream, MystArea *parent);
VideoHandle playMovie(); VideoEntryPtr playMovie();
VideoHandle getMovieHandle(); VideoEntryPtr getVideo();
void handleCardChange() override; void handleCardChange() override;
bool isPlaying(); bool isPlaying();

View file

@ -302,7 +302,7 @@ bool Channelwood::pipeChangeValve(bool open, uint16 mask) {
void Channelwood::o_bridgeToggle(uint16 op, uint16 var, uint16 argc, uint16 *argv) { void Channelwood::o_bridgeToggle(uint16 op, uint16 var, uint16 argc, uint16 *argv) {
debugC(kDebugScript, "Opcode %d: Bridge rise / skink video", op); debugC(kDebugScript, "Opcode %d: Bridge rise / skink video", op);
VideoHandle bridge = _vm->_video->playMovie(_vm->wrapMovieFilename("bridge", kChannelwoodStack)); VideoEntryPtr bridge = _vm->_video->playMovie(_vm->wrapMovieFilename("bridge", kChannelwoodStack));
if (!bridge) if (!bridge)
error("Failed to open 'bridge' movie"); error("Failed to open 'bridge' movie");
@ -324,7 +324,7 @@ void Channelwood::o_pipeExtend(uint16 op, uint16 var, uint16 argc, uint16 *argv)
debugC(kDebugScript, "\tsoundId: %d", soundId); debugC(kDebugScript, "\tsoundId: %d", soundId);
_vm->_sound->replaceSoundMyst(soundId); _vm->_sound->replaceSoundMyst(soundId);
VideoHandle pipe = _vm->_video->playMovie(_vm->wrapMovieFilename("pipebrid", kChannelwoodStack)); VideoEntryPtr pipe = _vm->_video->playMovie(_vm->wrapMovieFilename("pipebrid", kChannelwoodStack));
if (!pipe) if (!pipe)
error("Failed to open 'pipebrid' movie"); error("Failed to open 'pipebrid' movie");
@ -617,32 +617,32 @@ void Channelwood::o_hologramMonitor(uint16 op, uint16 var, uint16 argc, uint16 *
_vm->_video->stopVideos(); _vm->_video->stopVideos();
VideoHandle handle; VideoEntryPtr video;
switch (button) { switch (button) {
case 0: case 0:
handle = _vm->_video->playMovie(_vm->wrapMovieFilename("monalgh", kChannelwoodStack)); video = _vm->_video->playMovie(_vm->wrapMovieFilename("monalgh", kChannelwoodStack));
if (!handle) if (!video)
error("Failed to open monalgh movie"); error("Failed to open monalgh movie");
handle->moveTo(227, 70); video->moveTo(227, 70);
break; break;
case 1: case 1:
handle = _vm->_video->playMovie(_vm->wrapMovieFilename("monamth", kChannelwoodStack)); video = _vm->_video->playMovie(_vm->wrapMovieFilename("monamth", kChannelwoodStack));
if (!handle) if (!video)
error("Failed to open monamth movie"); error("Failed to open monamth movie");
handle->moveTo(227, 70); video->moveTo(227, 70);
break; break;
case 2: case 2:
handle = _vm->_video->playMovie(_vm->wrapMovieFilename("monasirs", kChannelwoodStack)); video = _vm->_video->playMovie(_vm->wrapMovieFilename("monasirs", kChannelwoodStack));
if (!handle) if (!video)
error("Failed to open monasirs movie"); error("Failed to open monasirs movie");
handle->moveTo(227, 70); video->moveTo(227, 70);
break; break;
case 3: case 3:
handle = _vm->_video->playMovie(_vm->wrapMovieFilename("monsmsg", kChannelwoodStack)); video = _vm->_video->playMovie(_vm->wrapMovieFilename("monsmsg", kChannelwoodStack));
if (!handle) if (!video)
error("Failed to open monsmsg movie"); error("Failed to open monsmsg movie");
handle->moveTo(226, 68); video->moveTo(226, 68);
break; break;
default: default:
warning("Opcode %d Control Variable Out of Range", op); warning("Opcode %d Control Variable Out of Range", op);

View file

@ -100,7 +100,7 @@ void Dni::o_handPage(uint16 op, uint16 var, uint16 argc, uint16 *argv) {
// Used in Card 5014 (Atrus) // Used in Card 5014 (Atrus)
// Find Atrus movie // Find Atrus movie
VideoHandle atrus = _vm->_video->findVideoHandle(_video); VideoEntryPtr atrus = _vm->_video->findVideo(_video);
// Good ending and Atrus asked to give page // Good ending and Atrus asked to give page
if (_globals.ending == 1 && atrus && atrus->getTime() > (uint)Audio::Timestamp(0, 6801, 600).msecs()) { if (_globals.ending == 1 && atrus && atrus->getTime() > (uint)Audio::Timestamp(0, 6801, 600).msecs()) {
@ -121,7 +121,7 @@ void Dni::o_handPage(uint16 op, uint16 var, uint16 argc, uint16 *argv) {
void Dni::atrusLeft_run() { void Dni::atrusLeft_run() {
if (_vm->_system->getMillis() > _atrusLeftTime + 63333) { if (_vm->_system->getMillis() > _atrusLeftTime + 63333) {
_video = _vm->wrapMovieFilename("atrus2", kDniStack); _video = _vm->wrapMovieFilename("atrus2", kDniStack);
VideoHandle atrus = _vm->_video->playMovie(_video); VideoEntryPtr atrus = _vm->_video->playMovie(_video);
if (!atrus) if (!atrus)
error("Failed to open '%s'", _video.c_str()); error("Failed to open '%s'", _video.c_str());
@ -143,7 +143,7 @@ void Dni::atrusLeft_run() {
void Dni::loopVideo_run() { void Dni::loopVideo_run() {
if (!_vm->_video->isVideoPlaying()) { if (!_vm->_video->isVideoPlaying()) {
VideoHandle atrus = _vm->_video->playMovie(_video); VideoEntryPtr atrus = _vm->_video->playMovie(_video);
if (!atrus) if (!atrus)
error("Failed to open '%s'", _video.c_str()); error("Failed to open '%s'", _video.c_str());
@ -163,7 +163,7 @@ void Dni::atrus_run() {
// Atrus asking for page // Atrus asking for page
if (!_vm->_video->isVideoPlaying()) { if (!_vm->_video->isVideoPlaying()) {
_video = _vm->wrapMovieFilename("atr1page", kDniStack); _video = _vm->wrapMovieFilename("atr1page", kDniStack);
VideoHandle atrus = _vm->_video->playMovie(_video); VideoEntryPtr atrus = _vm->_video->playMovie(_video);
if (!atrus) if (!atrus)
error("Failed to open '%s'", _video.c_str()); error("Failed to open '%s'", _video.c_str());
@ -174,7 +174,7 @@ void Dni::atrus_run() {
} else if (_globals.ending != 3 && _globals.ending != 4) { } else if (_globals.ending != 3 && _globals.ending != 4) {
if (_globals.heldPage == 13) { if (_globals.heldPage == 13) {
_video = _vm->wrapMovieFilename("atr1page", kDniStack); _video = _vm->wrapMovieFilename("atr1page", kDniStack);
VideoHandle atrus = _vm->_video->playMovie(_video); VideoEntryPtr atrus = _vm->_video->playMovie(_video);
if (!atrus) if (!atrus)
error("Failed to open '%s'", _video.c_str()); error("Failed to open '%s'", _video.c_str());
@ -190,7 +190,7 @@ void Dni::atrus_run() {
} else { } else {
_video = _vm->wrapMovieFilename("atr1nopg", kDniStack); _video = _vm->wrapMovieFilename("atr1nopg", kDniStack);
VideoHandle atrus = _vm->_video->playMovie(_video); VideoEntryPtr atrus = _vm->_video->playMovie(_video);
if (!atrus) if (!atrus)
error("Failed to open '%s'", _video.c_str()); error("Failed to open '%s'", _video.c_str());
@ -205,12 +205,12 @@ void Dni::atrus_run() {
_globals.ending = 3; _globals.ending = 3;
} }
} else if (!_vm->_video->isVideoPlaying()) { } else if (!_vm->_video->isVideoPlaying()) {
VideoHandle handle = _vm->_video->playMovie(_vm->wrapMovieFilename("atrwrite", kDniStack)); VideoEntryPtr atrus = _vm->_video->playMovie(_vm->wrapMovieFilename("atrwrite", kDniStack));
if (!handle) if (!atrus)
error("Failed to open atrwrite movie"); error("Failed to open atrwrite movie");
handle->moveTo(215, 77); atrus->moveTo(215, 77);
handle->setLooping(true); atrus->setLooping(true);
} }
} }

View file

@ -96,16 +96,16 @@ void Intro::introMovies_run() {
// Play Intro Movies // Play Intro Movies
// This is all quite messy... // This is all quite messy...
VideoHandle handle; VideoEntryPtr video;
switch (_introStep) { switch (_introStep) {
case 0: case 0:
_introStep = 1; _introStep = 1;
handle = _vm->_video->playMovie(_vm->wrapMovieFilename("broder", kIntroStack)); video = _vm->_video->playMovie(_vm->wrapMovieFilename("broder", kIntroStack));
if (!handle) if (!video)
error("Failed to open broder movie"); error("Failed to open broder movie");
handle->center(); video->center();
break; break;
case 1: case 1:
if (!_vm->_video->isVideoPlaying()) if (!_vm->_video->isVideoPlaying())
@ -113,11 +113,11 @@ void Intro::introMovies_run() {
break; break;
case 2: case 2:
_introStep = 3; _introStep = 3;
handle = _vm->_video->playMovie(_vm->wrapMovieFilename("cyanlogo", kIntroStack)); video = _vm->_video->playMovie(_vm->wrapMovieFilename("cyanlogo", kIntroStack));
if (!handle) if (!video)
error("Failed to open cyanlogo movie"); error("Failed to open cyanlogo movie");
handle->center(); video->center();
break; break;
case 3: case 3:
if (!_vm->_video->isVideoPlaying()) if (!_vm->_video->isVideoPlaying())
@ -127,11 +127,11 @@ void Intro::introMovies_run() {
_introStep = 5; _introStep = 5;
if (!(_vm->getFeatures() & GF_DEMO)) { // The demo doesn't have the intro video if (!(_vm->getFeatures() & GF_DEMO)) { // The demo doesn't have the intro video
handle = _vm->_video->playMovie(_vm->wrapMovieFilename("intro", kIntroStack)); video = _vm->_video->playMovie(_vm->wrapMovieFilename("intro", kIntroStack));
if (!handle) if (!video)
error("Failed to open intro movie"); error("Failed to open intro movie");
handle->center(); video->center();
} }
break; break;
case 5: case 5:

View file

@ -319,7 +319,7 @@ void Mechanical::o_snakeBoxTrigger(uint16 op, uint16 var, uint16 argc, uint16 *a
void Mechanical::o_fortressStaircaseMovie(uint16 op, uint16 var, uint16 argc, uint16 *argv) { void Mechanical::o_fortressStaircaseMovie(uint16 op, uint16 var, uint16 argc, uint16 *argv) {
debugC(kDebugScript, "Opcode %d: Play Stairs Movement Movie", op); debugC(kDebugScript, "Opcode %d: Play Stairs Movement Movie", op);
VideoHandle staircase = _vm->_video->playMovie(_vm->wrapMovieFilename("hhstairs", kMechanicalStack)); VideoEntryPtr staircase = _vm->_video->playMovie(_vm->wrapMovieFilename("hhstairs", kMechanicalStack));
if (!staircase) if (!staircase)
error("Failed to open hhstairs movie"); error("Failed to open hhstairs movie");
@ -578,7 +578,7 @@ void Mechanical::o_elevatorWindowMovie(uint16 op, uint16 var, uint16 argc, uint1
debugC(kDebugScript, "Opcode %d Movie Time Index %d to %d", op, startTime, endTime); debugC(kDebugScript, "Opcode %d Movie Time Index %d to %d", op, startTime, endTime);
VideoHandle window = _vm->_video->playMovie(_vm->wrapMovieFilename("ewindow", kMechanicalStack)); VideoEntryPtr window = _vm->_video->playMovie(_vm->wrapMovieFilename("ewindow", kMechanicalStack));
if (!window) if (!window)
error("Failed to open ewindow movie"); error("Failed to open ewindow movie");
@ -655,7 +655,7 @@ void Mechanical::o_elevatorTopMovie(uint16 op, uint16 var, uint16 argc, uint16 *
debugC(kDebugScript, "Opcode %d Movie Time Index %d to %d", op, startTime, endTime); debugC(kDebugScript, "Opcode %d Movie Time Index %d to %d", op, startTime, endTime);
VideoHandle window = _vm->_video->playMovie(_vm->wrapMovieFilename("hcelev", kMechanicalStack)); VideoEntryPtr window = _vm->_video->playMovie(_vm->wrapMovieFilename("hcelev", kMechanicalStack));
if (!window) if (!window)
error("Failed to open hcelev movie"); error("Failed to open hcelev movie");
@ -667,7 +667,7 @@ void Mechanical::o_elevatorTopMovie(uint16 op, uint16 var, uint16 argc, uint16 *
void Mechanical::o_fortressRotationSetPosition(uint16 op, uint16 var, uint16 argc, uint16 *argv) { void Mechanical::o_fortressRotationSetPosition(uint16 op, uint16 var, uint16 argc, uint16 *argv) {
debugC(kDebugScript, "Opcode %d: Set fortress position", op); debugC(kDebugScript, "Opcode %d: Set fortress position", op);
VideoHandle gears = _fortressRotationGears->getMovieHandle(); VideoEntryPtr gears = _fortressRotationGears->getVideo();
uint32 moviePosition = Audio::Timestamp(gears->getTime(), 600).totalNumberOfFrames(); uint32 moviePosition = Audio::Timestamp(gears->getTime(), 600).totalNumberOfFrames();
// Myst ME short movie workaround, explained in o_fortressRotation_init // Myst ME short movie workaround, explained in o_fortressRotation_init
@ -801,7 +801,7 @@ void Mechanical::o_elevatorRotation_init(uint16 op, uint16 var, uint16 argc, uin
} }
void Mechanical::fortressRotation_run() { void Mechanical::fortressRotation_run() {
VideoHandle gears = _fortressRotationGears->getMovieHandle(); VideoEntryPtr gears = _fortressRotationGears->getVideo();
double oldRate = gears->getRate().toDouble(); double oldRate = gears->getRate().toDouble();
uint32 moviePosition = Audio::Timestamp(gears->getTime(), 600).totalNumberOfFrames(); uint32 moviePosition = Audio::Timestamp(gears->getTime(), 600).totalNumberOfFrames();
@ -877,7 +877,7 @@ void Mechanical::o_fortressRotation_init(uint16 op, uint16 var, uint16 argc, uin
_fortressRotationGears = getInvokingResource<MystAreaVideo>(); _fortressRotationGears = getInvokingResource<MystAreaVideo>();
VideoHandle gears = _fortressRotationGears->playMovie(); VideoEntryPtr gears = _fortressRotationGears->playMovie();
gears->setLooping(true); gears->setLooping(true);
gears->seek(Audio::Timestamp(0, 1800 * _fortressPosition, 600)); gears->seek(Audio::Timestamp(0, 1800 * _fortressPosition, 600));
gears->setRate(0); gears->setRate(0);
@ -917,7 +917,7 @@ void Mechanical::fortressSimulation_run() {
_vm->_sound->replaceSoundMyst(_fortressSimulationStartSound2); _vm->_sound->replaceSoundMyst(_fortressSimulationStartSound2);
// Update movie while the sound is playing // Update movie while the sound is playing
VideoHandle startup = _fortressSimulationStartup->playMovie(); VideoEntryPtr startup = _fortressSimulationStartup->playMovie();
while (_vm->_sound->isPlaying(_fortressSimulationStartSound2)) { while (_vm->_sound->isPlaying(_fortressSimulationStartSound2)) {
if (_vm->_video->updateMovies()) if (_vm->_video->updateMovies())
_vm->_system->updateScreen(); _vm->_system->updateScreen();
@ -937,7 +937,7 @@ void Mechanical::fortressSimulation_run() {
_vm->_system->updateScreen(); _vm->_system->updateScreen();
_fortressSimulationStartup->pauseMovie(true); _fortressSimulationStartup->pauseMovie(true);
VideoHandle holo = _fortressSimulationHolo->playMovie(); VideoEntryPtr holo = _fortressSimulationHolo->playMovie();
holo->setLooping(true); holo->setLooping(true);
holo->setRate(0); holo->setRate(0);
@ -949,7 +949,7 @@ void Mechanical::fortressSimulation_run() {
_fortressSimulationInit = false; _fortressSimulationInit = false;
} else { } else {
VideoHandle holo = _fortressSimulationHolo->getMovieHandle(); VideoEntryPtr holo = _fortressSimulationHolo->getVideo();
double oldRate = holo->getRate().toDouble(); double oldRate = holo->getRate().toDouble();

View file

@ -1139,7 +1139,7 @@ void Myst::o_clockWheelsExecute(uint16 op, uint16 var, uint16 argc, uint16 *argv
_vm->wait(500); _vm->wait(500);
// Gears rise up // Gears rise up
VideoHandle gears = _vm->_video->playMovie(_vm->wrapMovieFilename("gears", kMystStack)); VideoEntryPtr gears = _vm->_video->playMovie(_vm->wrapMovieFilename("gears", kMystStack));
if (!gears) if (!gears)
error("Failed to open gears movie"); error("Failed to open gears movie");
@ -1154,7 +1154,7 @@ void Myst::o_clockWheelsExecute(uint16 op, uint16 var, uint16 argc, uint16 *argv
_vm->wait(500); _vm->wait(500);
// Gears sink down // Gears sink down
VideoHandle gears = _vm->_video->playMovie(_vm->wrapMovieFilename("gears", kMystStack)); VideoEntryPtr gears = _vm->_video->playMovie(_vm->wrapMovieFilename("gears", kMystStack));
if (!gears) if (!gears)
error("Failed to open gears movie"); error("Failed to open gears movie");
@ -1202,7 +1202,7 @@ void Myst::o_imagerPlayButton(uint16 op, uint16 var, uint16 argc, uint16 *argv)
if (_state.imagerActive) { if (_state.imagerActive) {
// Mountains disappearing // Mountains disappearing
Common::String file = _vm->wrapMovieFilename("vltmntn", kMystStack); Common::String file = _vm->wrapMovieFilename("vltmntn", kMystStack);
VideoHandle mountain = _vm->_video->playMovie(file); VideoEntryPtr mountain = _vm->_video->playMovie(file);
if (!mountain) if (!mountain)
error("Failed to open '%s'", file.c_str()); error("Failed to open '%s'", file.c_str());
@ -1213,7 +1213,7 @@ void Myst::o_imagerPlayButton(uint16 op, uint16 var, uint16 argc, uint16 *argv)
} else { } else {
// Mountains appearing // Mountains appearing
Common::String file = _vm->wrapMovieFilename("vltmntn", kMystStack); Common::String file = _vm->wrapMovieFilename("vltmntn", kMystStack);
VideoHandle mountain = _vm->_video->playMovie(file); VideoEntryPtr mountain = _vm->_video->playMovie(file);
if (!mountain) if (!mountain)
error("Failed to open '%s'", file.c_str()); error("Failed to open '%s'", file.c_str());
@ -1230,14 +1230,14 @@ void Myst::o_imagerPlayButton(uint16 op, uint16 var, uint16 argc, uint16 *argv)
_vm->_sound->replaceSoundMyst(argv[1]); _vm->_sound->replaceSoundMyst(argv[1]);
// Water disappearing // Water disappearing
VideoHandle water = _imagerMovie->playMovie(); VideoEntryPtr water = _imagerMovie->playMovie();
water->setBounds(Audio::Timestamp(0, 4204, 600), Audio::Timestamp(0, 6040, 600)); water->setBounds(Audio::Timestamp(0, 4204, 600), Audio::Timestamp(0, 6040, 600));
water->setLooping(false); water->setLooping(false);
_state.imagerActive = 0; _state.imagerActive = 0;
} else { } else {
// Water appearing // Water appearing
VideoHandle water = _imagerMovie->playMovie(); VideoEntryPtr water = _imagerMovie->playMovie();
water->setBounds(Audio::Timestamp(0, 0, 600), Audio::Timestamp(0, 1814, 600)); water->setBounds(Audio::Timestamp(0, 0, 600), Audio::Timestamp(0, 1814, 600));
_vm->_video->waitUntilMovieEnds(water); _vm->_video->waitUntilMovieEnds(water);
@ -2979,7 +2979,7 @@ void Myst::o_clockLeverEndMove(uint16 op, uint16 var, uint16 argc, uint16 *argv)
// Let movies stop playing // Let movies stop playing
for (uint i = 0; i < ARRAYSIZE(videos); i++) { for (uint i = 0; i < ARRAYSIZE(videos); i++) {
VideoHandle handle = _vm->_video->findVideoHandle(_vm->wrapMovieFilename(videos[i], kMystStack)); VideoEntryPtr handle = _vm->_video->findVideo(_vm->wrapMovieFilename(videos[i], kMystStack));
if (handle) if (handle)
_vm->_video->waitUntilMovieEnds(handle); _vm->_video->waitUntilMovieEnds(handle);
} }
@ -3063,7 +3063,7 @@ void Myst::clockReset() {
// Let movies stop playing // Let movies stop playing
for (uint i = 0; i < ARRAYSIZE(videos); i++) { for (uint i = 0; i < ARRAYSIZE(videos); i++) {
VideoHandle handle = _vm->_video->findVideoHandle(_vm->wrapMovieFilename(videos[i], kMystStack)); VideoEntryPtr handle = _vm->_video->findVideo(_vm->wrapMovieFilename(videos[i], kMystStack));
if (handle) if (handle)
_vm->_video->waitUntilMovieEnds(handle); _vm->_video->waitUntilMovieEnds(handle);
} }
@ -3077,7 +3077,7 @@ void Myst::clockReset() {
_vm->_sound->replaceSoundMyst(7113); _vm->_sound->replaceSoundMyst(7113);
// Gear closing movie // Gear closing movie
VideoHandle handle = _vm->_video->playMovie(_vm->wrapMovieFilename("cl1wggat", kMystStack)); VideoEntryPtr handle = _vm->_video->playMovie(_vm->wrapMovieFilename("cl1wggat", kMystStack));
if (!handle) if (!handle)
error("Failed to open cl1wggat movie"); error("Failed to open cl1wggat movie");
@ -3355,7 +3355,7 @@ void Myst::imager_run() {
_imagerRunning = false; _imagerRunning = false;
if (_state.imagerActive && _state.imagerSelection == 67) { if (_state.imagerActive && _state.imagerSelection == 67) {
VideoHandle water = _imagerMovie->playMovie(); VideoEntryPtr water = _imagerMovie->playMovie();
water->setBounds(Audio::Timestamp(0, 1814, 600), Audio::Timestamp(0, 4204, 600)); water->setBounds(Audio::Timestamp(0, 1814, 600), Audio::Timestamp(0, 4204, 600));
water->setLooping(true); water->setLooping(true);
} }
@ -3469,7 +3469,7 @@ void Myst::gullsFly1_run() {
else else
x = _vm->_rnd->getRandomNumber(160) + 260; x = _vm->_rnd->getRandomNumber(160) + 260;
VideoHandle handle = _vm->_video->playMovie(_vm->wrapMovieFilename(gulls[video], kMystStack)); VideoEntryPtr handle = _vm->_video->playMovie(_vm->wrapMovieFilename(gulls[video], kMystStack));
if (!handle) if (!handle)
error("Failed to open gulls movie"); error("Failed to open gulls movie");
@ -3614,7 +3614,7 @@ void Myst::gullsFly2_run() {
if (time > _gullsNextTime) { if (time > _gullsNextTime) {
uint16 video = _vm->_rnd->getRandomNumber(3); uint16 video = _vm->_rnd->getRandomNumber(3);
if (video != 3) { if (video != 3) {
VideoHandle handle = _vm->_video->playMovie(_vm->wrapMovieFilename(gulls[video], kMystStack)); VideoEntryPtr handle = _vm->_video->playMovie(_vm->wrapMovieFilename(gulls[video], kMystStack));
if (!handle) if (!handle)
error("Failed to open gulls movie"); error("Failed to open gulls movie");
@ -3769,7 +3769,7 @@ void Myst::greenBook_run() {
_vm->_sound->stopSound(); _vm->_sound->stopSound();
_vm->_sound->pauseBackgroundMyst(); _vm->_sound->pauseBackgroundMyst();
VideoHandle book = _vm->_video->playMovie(file); VideoEntryPtr book = _vm->_video->playMovie(file);
if (!book) if (!book)
error("Failed to open '%s'", file.c_str()); error("Failed to open '%s'", file.c_str());
@ -3783,7 +3783,7 @@ void Myst::greenBook_run() {
_tempVar = 0; _tempVar = 0;
} }
} else if (_tempVar == 2 && !_vm->_video->isVideoPlaying()) { } else if (_tempVar == 2 && !_vm->_video->isVideoPlaying()) {
VideoHandle book = _vm->_video->playMovie(file); VideoEntryPtr book = _vm->_video->playMovie(file);
if (!book) if (!book)
error("Failed to open '%s'", file.c_str()); error("Failed to open '%s'", file.c_str());
@ -3812,7 +3812,7 @@ void Myst::gullsFly3_run() {
if (video != 3) { if (video != 3) {
uint16 x = _vm->_rnd->getRandomNumber(280) + 135; uint16 x = _vm->_rnd->getRandomNumber(280) + 135;
VideoHandle handle = _vm->_video->playMovie(_vm->wrapMovieFilename(gulls[video], kMystStack)); VideoEntryPtr handle = _vm->_video->playMovie(_vm->wrapMovieFilename(gulls[video], kMystStack));
if (!handle) if (!handle)
error("Failed to open gulls movie"); error("Failed to open gulls movie");
@ -3851,8 +3851,8 @@ void Myst::o_treeEntry_exit(uint16 op, uint16 var, uint16 argc, uint16 *argv) {
void Myst::o_boiler_exit(uint16 op, uint16 var, uint16 argc, uint16 *argv) { void Myst::o_boiler_exit(uint16 op, uint16 var, uint16 argc, uint16 *argv) {
debugC(kDebugScript, "Opcode %d: Exit boiler card", op); debugC(kDebugScript, "Opcode %d: Exit boiler card", op);
_cabinGaugeMovie = VideoHandle(); _cabinGaugeMovie = VideoEntryPtr();
_cabinFireMovie = VideoHandle(); _cabinFireMovie = VideoEntryPtr();
_cabinGaugeMovieEnabled = false; _cabinGaugeMovieEnabled = false;
} }

View file

@ -199,7 +199,7 @@ protected:
MystAreaSlider *_rocketSlider5; // 264 MystAreaSlider *_rocketSlider5; // 264
uint16 _rocketSliderSound; // 294 uint16 _rocketSliderSound; // 294
uint16 _rocketLeverPosition; // 296 uint16 _rocketLeverPosition; // 296
VideoHandle _rocketLinkBook; // 268 VideoEntryPtr _rocketLinkBook; // 268
bool _libraryCombinationBookPagesTurning; bool _libraryCombinationBookPagesTurning;
int16 _libraryBookPage; // 86 int16 _libraryBookPage; // 86
@ -235,8 +235,8 @@ protected:
uint16 _clockTurningWheel; uint16 _clockTurningWheel;
VideoHandle _clockGearsVideos[3]; // 148 to 156 VideoEntryPtr _clockGearsVideos[3]; // 148 to 156
VideoHandle _clockWeightVideo; // 160 VideoEntryPtr _clockWeightVideo; // 160
uint16 _clockGearsPositions[3]; // 164 to 168 uint16 _clockGearsPositions[3]; // 164 to 168
uint16 _clockWeightPosition; // 172 uint16 _clockWeightPosition; // 172
bool _clockMiddleGearMovedAlone; // 176 bool _clockMiddleGearMovedAlone; // 176
@ -261,10 +261,10 @@ protected:
uint16 _cabinMatchState; // 60 uint16 _cabinMatchState; // 60
uint32 _matchGoOutTime; // 144 uint32 _matchGoOutTime; // 144
VideoHandle _cabinFireMovie; // 240 VideoEntryPtr _cabinFireMovie; // 240
bool _cabinGaugeMovieEnabled; bool _cabinGaugeMovieEnabled;
VideoHandle _cabinGaugeMovie; // 244 VideoEntryPtr _cabinGaugeMovie; // 244
bool _boilerPressureIncreasing; bool _boilerPressureIncreasing;
bool _boilerPressureDecreasing; bool _boilerPressureDecreasing;

View file

@ -427,7 +427,7 @@ void Stoneship::o_cabinBookMovie(uint16 op, uint16 var, uint16 argc, uint16 *arg
uint16 startTime = argv[0]; uint16 startTime = argv[0];
uint16 endTime = argv[1]; uint16 endTime = argv[1];
VideoHandle book = _vm->_video->playMovie(_vm->wrapMovieFilename("bkroom", kStoneshipStack)); VideoEntryPtr book = _vm->_video->playMovie(_vm->wrapMovieFilename("bkroom", kStoneshipStack));
if (!book) if (!book)
error("Failed to open bkroom movie"); error("Failed to open bkroom movie");
@ -598,7 +598,7 @@ void Stoneship::o_hologramPlayback(uint16 op, uint16 var, uint16 argc, uint16 *a
// uint16 direction = argv[2]; // uint16 direction = argv[2];
_hologramDisplay->setBlocking(false); _hologramDisplay->setBlocking(false);
VideoHandle displayMovie = _hologramDisplay->playMovie(); VideoEntryPtr displayMovie = _hologramDisplay->playMovie();
if (_hologramTurnedOn) { if (_hologramTurnedOn) {
if (_hologramDisplayPos) if (_hologramDisplayPos)
@ -629,7 +629,7 @@ void Stoneship::o_hologramSelectionMove(uint16 op, uint16 var, uint16 argc, uint
// Draw handle movie frame // Draw handle movie frame
uint16 selectionPos = position * 1500 / 243; uint16 selectionPos = position * 1500 / 243;
VideoHandle handleMovie = _hologramSelection->playMovie(); VideoEntryPtr handleMovie = _hologramSelection->playMovie();
_vm->_video->drawVideoFrame(handleMovie, Audio::Timestamp(0, selectionPos, 600)); _vm->_video->drawVideoFrame(handleMovie, Audio::Timestamp(0, selectionPos, 600));
_hologramDisplayPos = position * 1450 / 243 + 350; _hologramDisplayPos = position * 1450 / 243 + 350;
@ -637,7 +637,7 @@ void Stoneship::o_hologramSelectionMove(uint16 op, uint16 var, uint16 argc, uint
// Draw display movie frame // Draw display movie frame
if (_hologramTurnedOn) { if (_hologramTurnedOn) {
_hologramDisplay->setBlocking(false); _hologramDisplay->setBlocking(false);
VideoHandle displayMovie = _hologramDisplay->playMovie(); VideoEntryPtr displayMovie = _hologramDisplay->playMovie();
_vm->_video->drawVideoFrame(displayMovie, Audio::Timestamp(0, _hologramDisplayPos, 600)); _vm->_video->drawVideoFrame(displayMovie, Audio::Timestamp(0, _hologramDisplayPos, 600));
} }
} }
@ -679,7 +679,7 @@ void Stoneship::o_chestValveVideos(uint16 op, uint16 var, uint16 argc, uint16 *a
if (_state.chestValveState) { if (_state.chestValveState) {
// Valve closing // Valve closing
VideoHandle valve = _vm->_video->playMovie(movie); VideoEntryPtr valve = _vm->_video->playMovie(movie);
if (!valve) if (!valve)
error("Failed to open '%s'", movie.c_str()); error("Failed to open '%s'", movie.c_str());
@ -688,7 +688,7 @@ void Stoneship::o_chestValveVideos(uint16 op, uint16 var, uint16 argc, uint16 *a
_vm->_video->waitUntilMovieEnds(valve); _vm->_video->waitUntilMovieEnds(valve);
} else if (_state.chestWaterState) { } else if (_state.chestWaterState) {
// Valve opening, spilling water // Valve opening, spilling water
VideoHandle valve = _vm->_video->playMovie(movie); VideoEntryPtr valve = _vm->_video->playMovie(movie);
if (!valve) if (!valve)
error("Failed to open '%s'", movie.c_str()); error("Failed to open '%s'", movie.c_str());
@ -711,7 +711,7 @@ void Stoneship::o_chestValveVideos(uint16 op, uint16 var, uint16 argc, uint16 *a
_vm->_sound->resumeBackgroundMyst(); _vm->_sound->resumeBackgroundMyst();
} else { } else {
// Valve opening // Valve opening
VideoHandle valve = _vm->_video->playMovie(movie); VideoEntryPtr valve = _vm->_video->playMovie(movie);
if (!valve) if (!valve)
error("Failed to open '%s'", movie.c_str()); error("Failed to open '%s'", movie.c_str());
@ -738,7 +738,7 @@ void Stoneship::o_trapLockOpen(uint16 op, uint16 var, uint16 argc, uint16 *argv)
Common::String movie = _vm->wrapMovieFilename("openloc", kStoneshipStack); Common::String movie = _vm->wrapMovieFilename("openloc", kStoneshipStack);
VideoHandle lock = _vm->_video->playMovie(movie); VideoEntryPtr lock = _vm->_video->playMovie(movie);
if (!lock) if (!lock)
error("Failed to open '%s'", movie.c_str()); error("Failed to open '%s'", movie.c_str());

View file

@ -24,6 +24,8 @@
#include "mohawk/resource.h" #include "mohawk/resource.h"
#include "mohawk/video.h" #include "mohawk/video.h"
#include "mohawk/myst.h"
#include "common/algorithm.h" #include "common/algorithm.h"
#include "common/debug.h" #include "common/debug.h"
#include "common/events.h" #include "common/events.h"
@ -138,13 +140,7 @@ void VideoEntry::setVolume(int volume) {
_video->setVolume(CLIP(volume, 0, 255)); _video->setVolume(CLIP(volume, 0, 255));
} }
VideoHandle::VideoHandle(VideoEntryPtr ptr) : _ptr(ptr) { VideoManager::VideoManager(MohawkEngine *vm) : _vm(vm) {
}
VideoHandle::VideoHandle(const VideoHandle &handle) : _ptr(handle._ptr) {
}
VideoManager::VideoManager(MohawkEngine* vm) : _vm(vm) {
// Set dithering enabled, if required // Set dithering enabled, if required
_enableDither = (_vm->getGameType() == GType_MYST || _vm->getGameType() == GType_MAKINGOF) && !(_vm->getFeatures() & GF_ME); _enableDither = (_vm->getGameType() == GType_MYST || _vm->getGameType() == GType_MAKINGOF) && !(_vm->getFeatures() & GF_ME);
} }
@ -184,7 +180,7 @@ void VideoManager::playMovieBlocking(const Common::String &fileName, uint16 x, u
} }
ptr->start(); ptr->start();
waitUntilMovieEnds(VideoHandle(ptr)); waitUntilMovieEnds(ptr);
} }
void VideoManager::playMovieBlockingCentered(const Common::String &fileName, bool clearScreen) { void VideoManager::playMovieBlockingCentered(const Common::String &fileName, bool clearScreen) {
@ -200,20 +196,20 @@ void VideoManager::playMovieBlockingCentered(const Common::String &fileName, boo
ptr->center(); ptr->center();
ptr->start(); ptr->start();
waitUntilMovieEnds(VideoHandle(ptr)); waitUntilMovieEnds(ptr);
} }
void VideoManager::waitUntilMovieEnds(VideoHandle videoHandle) { void VideoManager::waitUntilMovieEnds(const VideoEntryPtr &video) {
if (!videoHandle) if (!video)
return; return;
// Sanity check // Sanity check
if (videoHandle._ptr->isLooping()) if (video->isLooping())
error("Called waitUntilMovieEnds() on a looping video"); error("Called waitUntilMovieEnds() on a looping video");
bool continuePlaying = true; bool continuePlaying = true;
while (!videoHandle->endOfVideo() && !_vm->shouldQuit() && continuePlaying) { while (!video->endOfVideo() && !_vm->shouldQuit() && continuePlaying) {
if (updateMovies()) if (updateMovies())
_vm->_system->updateScreen(); _vm->_system->updateScreen();
@ -245,25 +241,25 @@ void VideoManager::waitUntilMovieEnds(VideoHandle videoHandle) {
} }
// Ensure it's removed // Ensure it's removed
removeEntry(videoHandle._ptr); removeEntry(video);
} }
VideoHandle VideoManager::playMovie(const Common::String &fileName) { VideoEntryPtr VideoManager::playMovie(const Common::String &fileName) {
VideoEntryPtr ptr = open(fileName); VideoEntryPtr ptr = open(fileName);
if (!ptr) if (!ptr)
return VideoHandle(); return VideoEntryPtr();
ptr->start(); ptr->start();
return VideoHandle(ptr); return ptr;
} }
VideoHandle VideoManager::playMovie(uint16 id) { VideoEntryPtr VideoManager::playMovie(uint16 id) {
VideoEntryPtr ptr = open(id); VideoEntryPtr ptr = open(id);
if (!ptr) if (!ptr)
return VideoHandle(); return VideoEntryPtr();
ptr->start(); ptr->start();
return VideoHandle(ptr); return ptr;
} }
bool VideoManager::updateMovies() { bool VideoManager::updateMovies() {
@ -376,9 +372,9 @@ bool VideoManager::drawNextFrame(VideoEntryPtr videoEntry) {
VideoEntryPtr VideoManager::open(uint16 id) { VideoEntryPtr VideoManager::open(uint16 id) {
// If this video is already playing, return that handle // If this video is already playing, return that handle
VideoHandle oldHandle = findVideoHandle(id); VideoEntryPtr oldVideo = findVideo(id);
if (oldHandle._ptr) if (oldVideo)
return oldHandle._ptr; return oldVideo;
// Otherwise, create a new entry // Otherwise, create a new entry
Video::QuickTimeDecoder *video = new Video::QuickTimeDecoder(); Video::QuickTimeDecoder *video = new Video::QuickTimeDecoder();
@ -399,9 +395,9 @@ VideoEntryPtr VideoManager::open(uint16 id) {
VideoEntryPtr VideoManager::open(const Common::String &fileName) { VideoEntryPtr VideoManager::open(const Common::String &fileName) {
// If this video is already playing, return that entry // If this video is already playing, return that entry
VideoHandle oldHandle = findVideoHandle(fileName); VideoEntryPtr oldVideo = findVideo(fileName);
if (oldHandle._ptr) if (oldVideo)
return oldHandle._ptr; return oldVideo;
// Otherwise, create a new entry // Otherwise, create a new entry
Common::SeekableReadStream *stream = SearchMan.createReadStreamForMember(fileName); Common::SeekableReadStream *stream = SearchMan.createReadStreamForMember(fileName);
@ -427,26 +423,26 @@ VideoEntryPtr VideoManager::open(const Common::String &fileName) {
return entry; return entry;
} }
VideoHandle VideoManager::findVideoHandle(uint16 id) { VideoEntryPtr VideoManager::findVideo(uint16 id) {
if (id == 0) if (id == 0)
return VideoHandle(); return VideoEntryPtr();
for (VideoList::iterator it = _videos.begin(); it != _videos.end(); it++) for (VideoList::iterator it = _videos.begin(); it != _videos.end(); it++)
if ((*it)->getID() == id) if ((*it)->getID() == id)
return VideoHandle(*it); return *it;
return VideoHandle(); return VideoEntryPtr();
} }
VideoHandle VideoManager::findVideoHandle(const Common::String &fileName) { VideoEntryPtr VideoManager::findVideo(const Common::String &fileName) {
if (fileName.empty()) if (fileName.empty())
return VideoHandle(); return VideoEntryPtr();
for (VideoList::iterator it = _videos.begin(); it != _videos.end(); it++) for (VideoList::iterator it = _videos.begin(); it != _videos.end(); it++)
if ((*it)->getFileName().equalsIgnoreCase(fileName)) if ((*it)->getFileName().equalsIgnoreCase(fileName))
return VideoHandle(*it); return *it;
return VideoHandle(); return VideoEntryPtr();
} }
bool VideoManager::isVideoPlaying() { bool VideoManager::isVideoPlaying() {
@ -457,11 +453,11 @@ bool VideoManager::isVideoPlaying() {
return false; return false;
} }
void VideoManager::drawVideoFrame(VideoHandle handle, const Audio::Timestamp &time) { void VideoManager::drawVideoFrame(const VideoEntryPtr &video, const Audio::Timestamp &time) {
assert(handle); assert(video);
handle->seek(time); video->seek(time);
drawNextFrame(handle._ptr); drawNextFrame(video);
handle->stop(); video->stop();
} }
VideoManager::VideoList::iterator VideoManager::findEntry(VideoEntryPtr ptr) { VideoManager::VideoList::iterator VideoManager::findEntry(VideoEntryPtr ptr) {

View file

@ -234,71 +234,16 @@ private:
typedef Common::SharedPtr<VideoEntry> VideoEntryPtr; typedef Common::SharedPtr<VideoEntry> VideoEntryPtr;
/**
* A handle for manipulating a video
*/
class VideoHandle {
// The private members should be able to be manipulated by VideoManager
friend class VideoManager;
public:
/**
* Default constructor
*/
VideoHandle() {}
/**
* Copy constructor
*/
VideoHandle(const VideoHandle &handle);
/**
* Is this handle pointing to a valid video entry?
*/
bool isValid() const { return _ptr && _ptr->isOpen(); }
/**
* Convenience implicit cast to bool
*/
operator bool() const { return isValid(); }
/**
* Simple equality operator
*/
bool operator==(const VideoHandle &other) const { return _ptr.get() == other._ptr.get(); }
/**
* Simple inequality operator
*/
bool operator!=(const VideoHandle &other) const { return !(*this == other); }
/**
* Convenience operator-> override to give direct access to the VideoEntry
*/
VideoEntryPtr operator->() const { return _ptr; }
private:
/**
* Constructor for internal VideoManager use
*/
explicit VideoHandle(VideoEntryPtr ptr);
/**
* The video entry this is associated with
*/
VideoEntryPtr _ptr;
};
class VideoManager { class VideoManager {
public: public:
VideoManager(MohawkEngine *vm); VideoManager(MohawkEngine *vm);
~VideoManager(); virtual ~VideoManager();
// Generic movie functions // Generic movie functions
void playMovieBlocking(const Common::String &filename, uint16 x = 0, uint16 y = 0, bool clearScreen = false); void playMovieBlocking(const Common::String &filename, uint16 x = 0, uint16 y = 0, bool clearScreen = false);
void playMovieBlockingCentered(const Common::String &filename, bool clearScreen = true); void playMovieBlockingCentered(const Common::String &filename, bool clearScreen = true);
VideoHandle playMovie(const Common::String &filename); VideoEntryPtr playMovie(const Common::String &filename);
VideoHandle playMovie(uint16 id); VideoEntryPtr playMovie(uint16 id);
bool updateMovies(); bool updateMovies();
void pauseVideos(); void pauseVideos();
void resumeVideos(); void resumeVideos();
@ -306,12 +251,12 @@ public:
bool isVideoPlaying(); bool isVideoPlaying();
// Handle functions // Handle functions
VideoHandle findVideoHandle(uint16 id); VideoEntryPtr findVideo(uint16 id);
VideoHandle findVideoHandle(const Common::String &fileName); VideoEntryPtr findVideo(const Common::String &fileName);
void waitUntilMovieEnds(VideoHandle handle); void waitUntilMovieEnds(const VideoEntryPtr &video);
void drawVideoFrame(VideoHandle handle, const Audio::Timestamp &time); void drawVideoFrame(const VideoEntryPtr &video, const Audio::Timestamp &time);
private: protected:
MohawkEngine *_vm; MohawkEngine *_vm;
// Keep tabs on any videos playing // Keep tabs on any videos playing