[Scummvm-cvs-logs] SF.net SVN: scummvm:[48056] scummvm/trunk/engines/mohawk
mthreepwood at users.sourceforge.net
mthreepwood at users.sourceforge.net
Sun Feb 14 00:34:19 CET 2010
Revision: 48056
http://scummvm.svn.sourceforge.net/scummvm/?rev=48056&view=rev
Author: mthreepwood
Date: 2010-02-13 23:34:18 +0000 (Sat, 13 Feb 2010)
Log Message:
-----------
Implement background video support for Riven; some VideoManager/QTPlayer cleanup.
Modified Paths:
--------------
scummvm/trunk/engines/mohawk/riven.cpp
scummvm/trunk/engines/mohawk/riven_scripts.cpp
scummvm/trunk/engines/mohawk/video/qt_player.cpp
scummvm/trunk/engines/mohawk/video/qt_player.h
scummvm/trunk/engines/mohawk/video/video.cpp
scummvm/trunk/engines/mohawk/video/video.h
Modified: scummvm/trunk/engines/mohawk/riven.cpp
===================================================================
--- scummvm/trunk/engines/mohawk/riven.cpp 2010-02-13 22:26:52 UTC (rev 48055)
+++ scummvm/trunk/engines/mohawk/riven.cpp 2010-02-13 23:34:18 UTC (rev 48056)
@@ -105,6 +105,7 @@
Common::Event event;
while (!_gameOver) {
bool needsUpdate = _gfx->runScheduledWaterEffects();
+ needsUpdate |= _video->updateBackgroundMovies();
while (_eventMan->pollEvent(event)) {
switch (event.type) {
@@ -215,6 +216,9 @@
_curStack = n;
+ // Stop any videos playing
+ _video->stopVideos();
+
// Clear the old stack files out
for (uint32 i = 0; i < _mhk.size(); i++)
delete _mhk[i];
@@ -293,6 +297,7 @@
_gfx->_updatesEnabled = true;
_gfx->clearWaterEffects();
_gfx->_activatedPLSTs.clear();
+ _video->stopVideos();
_video->_mlstRecords.clear();
_gfx->drawPLST(1);
_activatedSLST = false;
Modified: scummvm/trunk/engines/mohawk/riven_scripts.cpp
===================================================================
--- scummvm/trunk/engines/mohawk/riven_scripts.cpp 2010-02-13 22:26:52 UTC (rev 48055)
+++ scummvm/trunk/engines/mohawk/riven_scripts.cpp 2010-02-13 23:34:18 UTC (rev 48056)
@@ -488,20 +488,17 @@
// Command 32: play foreground movie - blocking (movie_id)
void RivenScript::playMovie(uint16 op, uint16 argc, uint16 *argv) {
CursorMan.showMouse(false); // Hide the cursor before playing the video
- _vm->_video->enableMovie(argv[0]);
_vm->_video->playMovieBlocking(argv[0]);
CursorMan.showMouse(true); // Show the cursor again when we're done ;)
}
// Command 33: play background movie - nonblocking (movie_id)
void RivenScript::playMovieBg(uint16 op, uint16 argc, uint16 *argv) {
- _vm->_video->enableMovie(argv[0]);
_vm->_video->playMovie(argv[0]);
}
// Command 34: stop a movie
void RivenScript::stopMovie(uint16 op, uint16 argc, uint16 *argv) {
- _vm->_video->disableMovie(argv[0]);
_vm->_video->stopMovie(argv[0]);
}
Modified: scummvm/trunk/engines/mohawk/video/qt_player.cpp
===================================================================
--- scummvm/trunk/engines/mohawk/video/qt_player.cpp 2010-02-13 22:26:52 UTC (rev 48055)
+++ scummvm/trunk/engines/mohawk/video/qt_player.cpp 2010-02-13 23:34:18 UTC (rev 48056)
@@ -204,6 +204,7 @@
void QTPlayer::stopAudio() {
g_system->getMixer()->stopHandle(_audHandle);
+ _audStream = NULL; // the mixer automatically frees the stream
}
Graphics::Surface *QTPlayer::getNextFrame() {
@@ -1087,10 +1088,6 @@
_audStream = NULL;
}
-void QTPlayer::resetInternal() {
-
-}
-
Common::SeekableReadStream *QTPlayer::getNextFramePacket() {
if (_videoStreamIndex < 0)
return NULL;
Modified: scummvm/trunk/engines/mohawk/video/qt_player.h
===================================================================
--- scummvm/trunk/engines/mohawk/video/qt_player.h 2010-02-13 22:26:52 UTC (rev 48055)
+++ scummvm/trunk/engines/mohawk/video/qt_player.h 2010-02-13 23:34:18 UTC (rev 48056)
@@ -243,7 +243,6 @@
Audio::AudioStream *createAudioStream(Common::SeekableReadStream *stream);
bool checkAudioCodecSupport(uint32 tag);
Common::SeekableReadStream *getNextFramePacket();
- void resetInternal();
uint32 getFrameDuration();
Audio::QueuingAudioStream *_audStream;
Modified: scummvm/trunk/engines/mohawk/video/video.cpp
===================================================================
--- scummvm/trunk/engines/mohawk/video/video.cpp 2010-02-13 22:26:52 UTC (rev 48055)
+++ scummvm/trunk/engines/mohawk/video/video.cpp 2010-02-13 23:34:18 UTC (rev 48056)
@@ -57,68 +57,45 @@
void VideoManager::stopVideos() {
for (uint16 i = 0; i < _videoStreams.size(); i++)
- _videoStreams[i]->stop();
+ delete _videoStreams[i].video;
_videoStreams.clear();
}
void VideoManager::playMovie(Common::String filename, uint16 x, uint16 y, bool clearScreen) {
- Common::File *file = new Common::File();
- if (!file->open(filename))
- return; // Return silently for now...
-
- VideoEntry entry;
- entry.video = new QTPlayer();
-
- if (!entry.video)
+ VideoHandle videoHandle = createVideoHandle(filename, x, y, false);
+ if (videoHandle == NULL_VID_HANDLE)
return;
- entry->loadFile(file);
-
// Clear screen if requested
if (clearScreen) {
_vm->_system->fillScreen(_vm->_system->getScreenFormat().RGBToColor(0, 0, 0));
_vm->_system->updateScreen();
}
- entry.x = x;
- entry.y = y;
- entry.loop = false;
- playMovie(entry);
+ waitUntilMovieEnds(videoHandle);
}
void VideoManager::playMovieCentered(Common::String filename, bool clearScreen) {
- Common::File *file = new Common::File();
- if (!file->open(filename))
- return; // Return silently for now...
-
- VideoEntry entry;
- entry.video = new QTPlayer();
-
- if (!entry.video)
+ VideoHandle videoHandle = createVideoHandle(filename, 0, 0, false);
+ if (videoHandle == NULL_VID_HANDLE)
return;
- entry->loadFile(file);
-
// Clear screen if requested
if (clearScreen) {
_vm->_system->fillScreen(_vm->_system->getScreenFormat().RGBToColor(0, 0, 0));
_vm->_system->updateScreen();
}
- entry.x = (_vm->_system->getWidth() - entry->getWidth()) / 2;
- entry.y = (_vm->_system->getHeight() - entry->getHeight()) / 2;
- entry.loop = false;
- playMovie(entry);
+ _videoStreams[videoHandle].x = (_vm->_system->getWidth() - _videoStreams[videoHandle]->getWidth()) / 2;
+ _videoStreams[videoHandle].y = (_vm->_system->getHeight() - _videoStreams[videoHandle]->getHeight()) / 2;
+
+ waitUntilMovieEnds(videoHandle);
}
-void VideoManager::playMovie(VideoEntry videoEntry) {
- // Add video to the list
- _videoStreams.push_back(videoEntry);
-
+void VideoManager::waitUntilMovieEnds(VideoHandle videoHandle) {
bool continuePlaying = true;
- videoEntry->startAudio();
- while (!videoEntry->endOfVideo() && !_vm->shouldQuit() && continuePlaying) {
+ while (!_videoStreams[videoHandle]->endOfVideo() && !_vm->shouldQuit() && continuePlaying) {
if (updateBackgroundMovies())
_vm->_system->updateScreen();
@@ -149,52 +126,40 @@
_vm->_system->delayMillis(10);
}
- videoEntry->stop();
-
+ _videoStreams[videoHandle]->stop();
_videoStreams.clear();
}
void VideoManager::playBackgroundMovie(Common::String filename, int16 x, int16 y, bool loop) {
- Common::File *file = new Common::File();
- if (!file->open(filename))
- return; // Return silently for now...
-
- VideoEntry entry;
- entry.video = new QTPlayer();
-
- if (!entry.video)
+ VideoHandle videoHandle = createVideoHandle(filename, x, y, loop);
+ if (videoHandle == NULL_VID_HANDLE)
return;
- entry->loadFile(file);
-
// Center x if requested
if (x < 0)
- x = (_vm->_system->getWidth() - entry->getWidth()) / 2;
+ _videoStreams[videoHandle].x = (_vm->_system->getWidth() - _videoStreams[videoHandle]->getWidth()) / 2;
// Center y if requested
if (y < 0)
- y = (_vm->_system->getHeight() - entry->getHeight()) / 2;
-
- entry.x = x;
- entry.y = y;
- entry.loop = loop;
-
- entry->startAudio();
- _videoStreams.push_back(entry);
+ _videoStreams[videoHandle].y = (_vm->_system->getHeight() - _videoStreams[videoHandle]->getHeight()) / 2;
}
bool VideoManager::updateBackgroundMovies() {
bool updateScreen = false;
for (uint32 i = 0; i < _videoStreams.size() && !_vm->shouldQuit(); i++) {
+ // Skip deleted videos
+ if (!_videoStreams[i].video)
+ continue;
+
// Remove any videos that are over
if (_videoStreams[i]->endOfVideo()) {
if (_videoStreams[i].loop) {
_videoStreams[i]->reset();
} else {
delete _videoStreams[i].video;
- _videoStreams.remove_at(i);
- i--;
+ memset(&_videoStreams, 0, sizeof(VideoEntry));
+ _videoStreams[i].video = NULL;
continue;
}
}
@@ -204,7 +169,7 @@
Graphics::Surface *frame = _videoStreams[i]->getNextFrame();
bool deleteFrame = false;
- if (frame) {
+ if (frame && _videoStreams[i].enabled) {
// Convert from 8bpp to the current screen format if necessary
if (frame->bytesPerPixel == 1) {
Graphics::Surface *newFrame = new Graphics::Surface();
@@ -297,9 +262,6 @@
if (mlstRecord.u1 != 1)
warning("mlstRecord.u1 not 1");
- // Enable the record by default
- mlstRecord.enabled = true;
-
if (mlstRecord.index == mlstId) {
_mlstRecords.push_back(mlstRecord);
break;
@@ -312,19 +274,8 @@
void VideoManager::playMovie(uint16 id) {
for (uint16 i = 0; i < _mlstRecords.size(); i++)
if (_mlstRecords[i].code == id) {
- warning("STUB: Play tMOV %d (non-blocking) at (%d, %d)", _mlstRecords[i].movieID, _mlstRecords[i].left, _mlstRecords[i].top);
- return; // TODO: This will do a lot of things wrong if enabled right now ;)
- 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);
+ 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");
+ createVideoHandle(_mlstRecords[i].movieID, _mlstRecords[i].left, _mlstRecords[i].top, _mlstRecords[i].loop != 0);
return;
}
}
@@ -335,21 +286,9 @@
for (uint16 i = 0; i < _mlstRecords.size(); i++)
if (_mlstRecords[i].code == id) {
- warning("STUB: Play tMOV %d (blocking) at (%d, %d)", _mlstRecords[i].movieID, _mlstRecords[i].left, _mlstRecords[i].top);
-
- // TODO: See if a non-blocking movie has been activated with the same id,
- // 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);
+ 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);
+ waitUntilMovieEnds(videoHandle);
return;
}
}
@@ -365,25 +304,97 @@
void VideoManager::enableMovie(uint16 id) {
debug(2, "Enabling movie %d", id);
for (uint16 i = 0; i < _mlstRecords.size(); i++)
- if (_mlstRecords[i].code == id) {
- _mlstRecords[i].enabled = true;
- return;
- }
+ if (_mlstRecords[i].code == id)
+ for (uint16 j = 0; j < _videoStreams.size(); j++)
+ if (_mlstRecords[i].movieID == _videoStreams[j].id) {
+ _videoStreams[j].enabled = true;
+ return;
+ }
}
void VideoManager::disableMovie(uint16 id) {
debug(2, "Disabling movie %d", id);
for (uint16 i = 0; i < _mlstRecords.size(); i++)
- if (_mlstRecords[i].code == id) {
- _mlstRecords[i].enabled = false;
- return;
- }
+ if (_mlstRecords[i].code == id)
+ for (uint16 j = 0; j < _videoStreams.size(); j++)
+ if (_mlstRecords[i].movieID == _videoStreams[j].id) {
+ _videoStreams[j].enabled = false;
+ return;
+ }
}
void VideoManager::disableAllMovies() {
debug(2, "Disabling all movies");
- for (uint16 i = 0; i < _mlstRecords.size(); i++)
- _mlstRecords[i].enabled = false;
+ for (uint16 i = 0; i < _videoStreams.size(); i++)
+ _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
Modified: scummvm/trunk/engines/mohawk/video/video.h
===================================================================
--- scummvm/trunk/engines/mohawk/video/video.h 2010-02-13 22:26:52 UTC (rev 48055)
+++ scummvm/trunk/engines/mohawk/video/video.h 2010-02-13 23:34:18 UTC (rev 48056)
@@ -42,8 +42,6 @@
uint16 loop;
uint16 volume;
uint16 u1;
-
- bool enabled;
};
class QTPlayer;
@@ -55,10 +53,17 @@
bool loop;
Common::String filename;
uint16 id; // Riven only
+ bool enabled;
QTPlayer *operator->() const { assert(video); return video; }
};
+typedef int32 VideoHandle;
+
+enum {
+ NULL_VID_HANDLE = -1
+};
+
class VideoManager {
public:
VideoManager(MohawkEngine *vm);
@@ -88,11 +93,14 @@
private:
MohawkEngine *_vm;
- void playMovie(VideoEntry videoEntry);
+ void waitUntilMovieEnds(VideoHandle videoHandle);
// Keep tabs on any videos playing
Common::Array<VideoEntry> _videoStreams;
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
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list