Implement background video support for Riven; some VideoManager/QTPlayer cleanup.

svn-id: r48056
This commit is contained in:
Matthew Hoops 2010-02-13 23:34:18 +00:00
parent 03e8276407
commit 1cd9498dbc
6 changed files with 128 additions and 111 deletions

View file

@ -105,6 +105,7 @@ Common::Error MohawkEngine_Riven::run() {
Common::Event event; Common::Event event;
while (!_gameOver) { while (!_gameOver) {
bool needsUpdate = _gfx->runScheduledWaterEffects(); bool needsUpdate = _gfx->runScheduledWaterEffects();
needsUpdate |= _video->updateBackgroundMovies();
while (_eventMan->pollEvent(event)) { while (_eventMan->pollEvent(event)) {
switch (event.type) { switch (event.type) {
@ -215,6 +216,9 @@ void MohawkEngine_Riven::changeToStack(uint16 n) {
_curStack = n; _curStack = n;
// Stop any videos playing
_video->stopVideos();
// Clear the old stack files out // Clear the old stack files out
for (uint32 i = 0; i < _mhk.size(); i++) for (uint32 i = 0; i < _mhk.size(); i++)
delete _mhk[i]; delete _mhk[i];
@ -293,6 +297,7 @@ void MohawkEngine_Riven::changeToCard(uint16 n) {
_gfx->_updatesEnabled = true; _gfx->_updatesEnabled = true;
_gfx->clearWaterEffects(); _gfx->clearWaterEffects();
_gfx->_activatedPLSTs.clear(); _gfx->_activatedPLSTs.clear();
_video->stopVideos();
_video->_mlstRecords.clear(); _video->_mlstRecords.clear();
_gfx->drawPLST(1); _gfx->drawPLST(1);
_activatedSLST = false; _activatedSLST = false;

View file

@ -488,20 +488,17 @@ void RivenScript::enableMovie(uint16 op, uint16 argc, uint16 *argv) {
// Command 32: play foreground movie - blocking (movie_id) // Command 32: play foreground movie - blocking (movie_id)
void RivenScript::playMovie(uint16 op, uint16 argc, uint16 *argv) { void RivenScript::playMovie(uint16 op, uint16 argc, uint16 *argv) {
CursorMan.showMouse(false); // Hide the cursor before playing the video CursorMan.showMouse(false); // Hide the cursor before playing the video
_vm->_video->enableMovie(argv[0]);
_vm->_video->playMovieBlocking(argv[0]); _vm->_video->playMovieBlocking(argv[0]);
CursorMan.showMouse(true); // Show the cursor again when we're done ;) CursorMan.showMouse(true); // Show the cursor again when we're done ;)
} }
// Command 33: play background movie - nonblocking (movie_id) // Command 33: play background movie - nonblocking (movie_id)
void RivenScript::playMovieBg(uint16 op, uint16 argc, uint16 *argv) { void RivenScript::playMovieBg(uint16 op, uint16 argc, uint16 *argv) {
_vm->_video->enableMovie(argv[0]);
_vm->_video->playMovie(argv[0]); _vm->_video->playMovie(argv[0]);
} }
// Command 34: stop a movie // Command 34: stop a movie
void RivenScript::stopMovie(uint16 op, uint16 argc, uint16 *argv) { void RivenScript::stopMovie(uint16 op, uint16 argc, uint16 *argv) {
_vm->_video->disableMovie(argv[0]);
_vm->_video->stopMovie(argv[0]); _vm->_video->stopMovie(argv[0]);
} }

View file

@ -204,6 +204,7 @@ void QTPlayer::resumeAudio() {
void QTPlayer::stopAudio() { void QTPlayer::stopAudio() {
g_system->getMixer()->stopHandle(_audHandle); g_system->getMixer()->stopHandle(_audHandle);
_audStream = NULL; // the mixer automatically frees the stream
} }
Graphics::Surface *QTPlayer::getNextFrame() { Graphics::Surface *QTPlayer::getNextFrame() {
@ -1087,10 +1088,6 @@ void QTPlayer::closeFile() {
_audStream = NULL; _audStream = NULL;
} }
void QTPlayer::resetInternal() {
}
Common::SeekableReadStream *QTPlayer::getNextFramePacket() { Common::SeekableReadStream *QTPlayer::getNextFramePacket() {
if (_videoStreamIndex < 0) if (_videoStreamIndex < 0)
return NULL; return NULL;

View file

@ -243,7 +243,6 @@ protected:
Audio::AudioStream *createAudioStream(Common::SeekableReadStream *stream); Audio::AudioStream *createAudioStream(Common::SeekableReadStream *stream);
bool checkAudioCodecSupport(uint32 tag); bool checkAudioCodecSupport(uint32 tag);
Common::SeekableReadStream *getNextFramePacket(); Common::SeekableReadStream *getNextFramePacket();
void resetInternal();
uint32 getFrameDuration(); uint32 getFrameDuration();
Audio::QueuingAudioStream *_audStream; Audio::QueuingAudioStream *_audStream;

View file

@ -57,68 +57,45 @@ void VideoManager::resumeVideos() {
void VideoManager::stopVideos() { void VideoManager::stopVideos() {
for (uint16 i = 0; i < _videoStreams.size(); i++) for (uint16 i = 0; i < _videoStreams.size(); i++)
_videoStreams[i]->stop(); delete _videoStreams[i].video;
_videoStreams.clear(); _videoStreams.clear();
} }
void VideoManager::playMovie(Common::String filename, uint16 x, uint16 y, bool clearScreen) { void VideoManager::playMovie(Common::String filename, uint16 x, uint16 y, bool clearScreen) {
Common::File *file = new Common::File(); VideoHandle videoHandle = createVideoHandle(filename, x, y, false);
if (!file->open(filename)) if (videoHandle == NULL_VID_HANDLE)
return; // Return silently for now...
VideoEntry entry;
entry.video = new QTPlayer();
if (!entry.video)
return; return;
entry->loadFile(file);
// Clear screen if requested // Clear screen if requested
if (clearScreen) { if (clearScreen) {
_vm->_system->fillScreen(_vm->_system->getScreenFormat().RGBToColor(0, 0, 0)); _vm->_system->fillScreen(_vm->_system->getScreenFormat().RGBToColor(0, 0, 0));
_vm->_system->updateScreen(); _vm->_system->updateScreen();
} }
entry.x = x; waitUntilMovieEnds(videoHandle);
entry.y = y;
entry.loop = false;
playMovie(entry);
} }
void VideoManager::playMovieCentered(Common::String filename, bool clearScreen) { void VideoManager::playMovieCentered(Common::String filename, bool clearScreen) {
Common::File *file = new Common::File(); VideoHandle videoHandle = createVideoHandle(filename, 0, 0, false);
if (!file->open(filename)) if (videoHandle == NULL_VID_HANDLE)
return; // Return silently for now...
VideoEntry entry;
entry.video = new QTPlayer();
if (!entry.video)
return; return;
entry->loadFile(file);
// Clear screen if requested // Clear screen if requested
if (clearScreen) { if (clearScreen) {
_vm->_system->fillScreen(_vm->_system->getScreenFormat().RGBToColor(0, 0, 0)); _vm->_system->fillScreen(_vm->_system->getScreenFormat().RGBToColor(0, 0, 0));
_vm->_system->updateScreen(); _vm->_system->updateScreen();
} }
entry.x = (_vm->_system->getWidth() - entry->getWidth()) / 2; _videoStreams[videoHandle].x = (_vm->_system->getWidth() - _videoStreams[videoHandle]->getWidth()) / 2;
entry.y = (_vm->_system->getHeight() - entry->getHeight()) / 2; _videoStreams[videoHandle].y = (_vm->_system->getHeight() - _videoStreams[videoHandle]->getHeight()) / 2;
entry.loop = false;
playMovie(entry); waitUntilMovieEnds(videoHandle);
} }
void VideoManager::playMovie(VideoEntry videoEntry) { void VideoManager::waitUntilMovieEnds(VideoHandle videoHandle) {
// Add video to the list
_videoStreams.push_back(videoEntry);
bool continuePlaying = true; bool continuePlaying = true;
videoEntry->startAudio();
while (!videoEntry->endOfVideo() && !_vm->shouldQuit() && continuePlaying) { while (!_videoStreams[videoHandle]->endOfVideo() && !_vm->shouldQuit() && continuePlaying) {
if (updateBackgroundMovies()) if (updateBackgroundMovies())
_vm->_system->updateScreen(); _vm->_system->updateScreen();
@ -149,52 +126,40 @@ void VideoManager::playMovie(VideoEntry videoEntry) {
_vm->_system->delayMillis(10); _vm->_system->delayMillis(10);
} }
videoEntry->stop(); _videoStreams[videoHandle]->stop();
_videoStreams.clear(); _videoStreams.clear();
} }
void VideoManager::playBackgroundMovie(Common::String filename, int16 x, int16 y, bool loop) { void VideoManager::playBackgroundMovie(Common::String filename, int16 x, int16 y, bool loop) {
Common::File *file = new Common::File(); VideoHandle videoHandle = createVideoHandle(filename, x, y, loop);
if (!file->open(filename)) if (videoHandle == NULL_VID_HANDLE)
return; // Return silently for now...
VideoEntry entry;
entry.video = new QTPlayer();
if (!entry.video)
return; return;
entry->loadFile(file);
// Center x if requested // Center x if requested
if (x < 0) if (x < 0)
x = (_vm->_system->getWidth() - entry->getWidth()) / 2; _videoStreams[videoHandle].x = (_vm->_system->getWidth() - _videoStreams[videoHandle]->getWidth()) / 2;
// Center y if requested // Center y if requested
if (y < 0) if (y < 0)
y = (_vm->_system->getHeight() - entry->getHeight()) / 2; _videoStreams[videoHandle].y = (_vm->_system->getHeight() - _videoStreams[videoHandle]->getHeight()) / 2;
entry.x = x;
entry.y = y;
entry.loop = loop;
entry->startAudio();
_videoStreams.push_back(entry);
} }
bool VideoManager::updateBackgroundMovies() { bool VideoManager::updateBackgroundMovies() {
bool updateScreen = false; bool updateScreen = false;
for (uint32 i = 0; i < _videoStreams.size() && !_vm->shouldQuit(); i++) { for (uint32 i = 0; i < _videoStreams.size() && !_vm->shouldQuit(); i++) {
// Skip deleted videos
if (!_videoStreams[i].video)
continue;
// Remove any videos that are over // Remove any videos that are over
if (_videoStreams[i]->endOfVideo()) { if (_videoStreams[i]->endOfVideo()) {
if (_videoStreams[i].loop) { if (_videoStreams[i].loop) {
_videoStreams[i]->reset(); _videoStreams[i]->reset();
} else { } else {
delete _videoStreams[i].video; delete _videoStreams[i].video;
_videoStreams.remove_at(i); memset(&_videoStreams, 0, sizeof(VideoEntry));
i--; _videoStreams[i].video = NULL;
continue; continue;
} }
} }
@ -204,7 +169,7 @@ bool VideoManager::updateBackgroundMovies() {
Graphics::Surface *frame = _videoStreams[i]->getNextFrame(); Graphics::Surface *frame = _videoStreams[i]->getNextFrame();
bool deleteFrame = false; bool deleteFrame = false;
if (frame) { if (frame && _videoStreams[i].enabled) {
// Convert from 8bpp to the current screen format if necessary // Convert from 8bpp to the current screen format if necessary
if (frame->bytesPerPixel == 1) { if (frame->bytesPerPixel == 1) {
Graphics::Surface *newFrame = new Graphics::Surface(); Graphics::Surface *newFrame = new Graphics::Surface();
@ -297,9 +262,6 @@ void VideoManager::activateMLST(uint16 mlstId, uint16 card) {
if (mlstRecord.u1 != 1) if (mlstRecord.u1 != 1)
warning("mlstRecord.u1 not 1"); warning("mlstRecord.u1 not 1");
// Enable the record by default
mlstRecord.enabled = true;
if (mlstRecord.index == mlstId) { if (mlstRecord.index == mlstId) {
_mlstRecords.push_back(mlstRecord); _mlstRecords.push_back(mlstRecord);
break; break;
@ -312,19 +274,8 @@ void VideoManager::activateMLST(uint16 mlstId, uint16 card) {
void VideoManager::playMovie(uint16 id) { void VideoManager::playMovie(uint16 id) {
for (uint16 i = 0; i < _mlstRecords.size(); i++) for (uint16 i = 0; i < _mlstRecords.size(); i++)
if (_mlstRecords[i].code == id) { if (_mlstRecords[i].code == id) {
warning("STUB: Play tMOV %d (non-blocking) at (%d, %d)", _mlstRecords[i].movieID, _mlstRecords[i].left, _mlstRecords[i].top); debug(1, "Play tMOV %d (non-blocking) at (%d, %d) %s", _mlstRecords[i].movieID, _mlstRecords[i].left, _mlstRecords[i].top, _mlstRecords[i].loop != 0 ? "looping" : "non-looping");
return; // TODO: This will do a lot of things wrong if enabled right now ;) createVideoHandle(_mlstRecords[i].movieID, _mlstRecords[i].left, _mlstRecords[i].top, _mlstRecords[i].loop != 0);
QTPlayer *qtPlayer = new QTPlayer();
qtPlayer->setChunkBeginOffset(_vm->getResourceOffset(ID_TMOV, _mlstRecords[i].movieID));
qtPlayer->loadFile(_vm->getRawData(ID_TMOV, _mlstRecords[i].movieID));
VideoEntry entry;
entry.video = qtPlayer;
entry.x = _mlstRecords[i].left;
entry.y = _mlstRecords[i].top;
entry.id = _mlstRecords[i].movieID;
entry.loop = _mlstRecords[i].loop != 0;
_videoStreams.push_back(entry);
return; return;
} }
} }
@ -335,21 +286,9 @@ void VideoManager::playMovieBlocking(uint16 id) {
for (uint16 i = 0; i < _mlstRecords.size(); i++) for (uint16 i = 0; i < _mlstRecords.size(); i++)
if (_mlstRecords[i].code == id) { if (_mlstRecords[i].code == id) {
warning("STUB: Play tMOV %d (blocking) at (%d, %d)", _mlstRecords[i].movieID, _mlstRecords[i].left, _mlstRecords[i].top); debug(1, "Play tMOV %d (blocking) at (%d, %d)", _mlstRecords[i].movieID, _mlstRecords[i].left, _mlstRecords[i].top);
VideoHandle videoHandle = createVideoHandle(_mlstRecords[i].movieID, _mlstRecords[i].left, _mlstRecords[i].top, false);
// TODO: See if a non-blocking movie has been activated with the same id, waitUntilMovieEnds(videoHandle);
// and if so, block input until that movie is finished.
QTPlayer *qtPlayer = new QTPlayer();
qtPlayer->setChunkBeginOffset(_vm->getResourceOffset(ID_TMOV, _mlstRecords[i].movieID));
qtPlayer->loadFile(_vm->getRawData(ID_TMOV, _mlstRecords[i].movieID));
VideoEntry entry;
entry.video = qtPlayer;
entry.x = _mlstRecords[i].left;
entry.y = _mlstRecords[i].top;
entry.id = _mlstRecords[i].movieID;
entry.loop = false;
playMovie(entry);
return; return;
} }
} }
@ -365,8 +304,10 @@ void VideoManager::stopMovie(uint16 id) {
void VideoManager::enableMovie(uint16 id) { void VideoManager::enableMovie(uint16 id) {
debug(2, "Enabling movie %d", id); debug(2, "Enabling movie %d", id);
for (uint16 i = 0; i < _mlstRecords.size(); i++) for (uint16 i = 0; i < _mlstRecords.size(); i++)
if (_mlstRecords[i].code == id) { if (_mlstRecords[i].code == id)
_mlstRecords[i].enabled = true; for (uint16 j = 0; j < _videoStreams.size(); j++)
if (_mlstRecords[i].movieID == _videoStreams[j].id) {
_videoStreams[j].enabled = true;
return; return;
} }
} }
@ -374,16 +315,86 @@ void VideoManager::enableMovie(uint16 id) {
void VideoManager::disableMovie(uint16 id) { void VideoManager::disableMovie(uint16 id) {
debug(2, "Disabling movie %d", id); debug(2, "Disabling movie %d", id);
for (uint16 i = 0; i < _mlstRecords.size(); i++) for (uint16 i = 0; i < _mlstRecords.size(); i++)
if (_mlstRecords[i].code == id) { if (_mlstRecords[i].code == id)
_mlstRecords[i].enabled = false; for (uint16 j = 0; j < _videoStreams.size(); j++)
if (_mlstRecords[i].movieID == _videoStreams[j].id) {
_videoStreams[j].enabled = false;
return; return;
} }
} }
void VideoManager::disableAllMovies() { void VideoManager::disableAllMovies() {
debug(2, "Disabling all movies"); debug(2, "Disabling all movies");
for (uint16 i = 0; i < _mlstRecords.size(); i++) for (uint16 i = 0; i < _videoStreams.size(); i++)
_mlstRecords[i].enabled = false; _videoStreams[i].enabled = false;
}
VideoHandle VideoManager::createVideoHandle(uint16 id, uint16 x, uint16 y, bool loop) {
// First, check to see if that video is already playing
for (uint32 i = 0; i < _videoStreams.size(); i++)
if (_videoStreams[i].id == id)
return i;
// Otherwise, create a new entry
VideoEntry entry;
entry.video = new QTPlayer();
entry.x = x;
entry.y = y;
entry.filename = "";
entry.id = id;
entry.loop = loop;
entry.enabled = true;
entry->setChunkBeginOffset(_vm->getResourceOffset(ID_TMOV, id));
entry->loadFile(_vm->getRawData(ID_TMOV, id));
entry->startAudio();
// Search for any deleted videos so we can take a formerly used slot
for (uint32 i = 0; i < _videoStreams.size(); i++)
if (!_videoStreams[i].video) {
_videoStreams[i] = entry;
return i;
}
// Otherwise, just add it to the list
_videoStreams.push_back(entry);
return _videoStreams.size() - 1;
}
VideoHandle VideoManager::createVideoHandle(Common::String filename, uint16 x, uint16 y, bool loop) {
// First, check to see if that video is already playing
for (uint32 i = 0; i < _videoStreams.size(); i++)
if (_videoStreams[i].filename == filename)
return i;
// Otherwise, create a new entry
VideoEntry entry;
entry.video = new QTPlayer();
entry.x = x;
entry.y = y;
entry.filename = filename;
entry.id = 0;
entry.loop = loop;
entry.enabled = true;
Common::File *file = new Common::File();
if (!file->open(filename)) {
delete file;
return NULL_VID_HANDLE;
}
entry->loadFile(file);
entry->startAudio();
// Search for any deleted videos so we can take a formerly used slot
for (uint32 i = 0; i < _videoStreams.size(); i++)
if (!_videoStreams[i].video) {
_videoStreams[i] = entry;
return i;
}
// Otherwise, just add it to the list
_videoStreams.push_back(entry);
return _videoStreams.size() - 1;
} }
} // End of namespace Mohawk } // End of namespace Mohawk

View file

@ -42,8 +42,6 @@ struct MLSTRecord {
uint16 loop; uint16 loop;
uint16 volume; uint16 volume;
uint16 u1; uint16 u1;
bool enabled;
}; };
class QTPlayer; class QTPlayer;
@ -55,10 +53,17 @@ struct VideoEntry {
bool loop; bool loop;
Common::String filename; Common::String filename;
uint16 id; // Riven only uint16 id; // Riven only
bool enabled;
QTPlayer *operator->() const { assert(video); return video; } QTPlayer *operator->() const { assert(video); return video; }
}; };
typedef int32 VideoHandle;
enum {
NULL_VID_HANDLE = -1
};
class VideoManager { class VideoManager {
public: public:
VideoManager(MohawkEngine *vm); VideoManager(MohawkEngine *vm);
@ -88,11 +93,14 @@ public:
private: private:
MohawkEngine *_vm; MohawkEngine *_vm;
void playMovie(VideoEntry videoEntry); void waitUntilMovieEnds(VideoHandle videoHandle);
// Keep tabs on any videos playing // Keep tabs on any videos playing
Common::Array<VideoEntry> _videoStreams; Common::Array<VideoEntry> _videoStreams;
uint32 _pauseStart; uint32 _pauseStart;
VideoHandle createVideoHandle(uint16 id, uint16 x, uint16 y, bool loop);
VideoHandle createVideoHandle(Common::String filename, uint16 x, uint16 y, bool loop);
}; };
} // End of namespace Mohawk } // End of namespace Mohawk