aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
Diffstat (limited to 'engines')
-rw-r--r--engines/agos/animation.cpp117
-rw-r--r--engines/agos/animation.h10
-rw-r--r--engines/mohawk/jpeg.h1
-rw-r--r--engines/mohawk/video/cinepak.h1
-rw-r--r--engines/mohawk/video/qtrle.h1
-rw-r--r--engines/mohawk/video/rpza.h1
-rw-r--r--engines/mohawk/video/smc.h1
-rw-r--r--engines/saga/introproc_saga2.cpp59
-rw-r--r--engines/saga/scene.h1
-rw-r--r--engines/sci/console.cpp66
-rw-r--r--engines/sci/engine/kgraphics.cpp66
-rw-r--r--engines/sci/video/seq_decoder.cpp80
-rw-r--r--engines/sci/video/seq_decoder.h50
-rw-r--r--engines/sci/video/vmd_decoder.cpp74
-rw-r--r--engines/sci/video/vmd_decoder.h31
-rw-r--r--engines/scumm/he/animation_he.cpp27
-rw-r--r--engines/scumm/he/animation_he.h3
-rw-r--r--engines/scumm/he/script_v100he.cpp2
-rw-r--r--engines/scumm/he/script_v90he.cpp2
-rw-r--r--engines/sword1/animation.cpp78
-rw-r--r--engines/sword1/animation.h13
-rw-r--r--engines/sword2/animation.cpp78
-rw-r--r--engines/sword2/animation.h11
-rw-r--r--engines/tucker/sequences.cpp73
24 files changed, 477 insertions, 369 deletions
diff --git a/engines/agos/animation.cpp b/engines/agos/animation.cpp
index eccb51c732..1b3ac9fd65 100644
--- a/engines/agos/animation.cpp
+++ b/engines/agos/animation.cpp
@@ -241,29 +241,46 @@ MoviePlayerDXA::MoviePlayerDXA(AGOSEngine_Feeble *vm, const char *name)
}
bool MoviePlayerDXA::load() {
- char videoName[20];
- uint i;
-
if ((_vm->getPlatform() == Common::kPlatformAmiga || _vm->getPlatform() == Common::kPlatformMacintosh) &&
_vm->_language != Common::EN_ANY) {
_sequenceNum = 0;
- for (i = 0; i < 90; i++) {
+ for (uint i = 0; i < 90; i++) {
if (!scumm_stricmp(baseName, _sequenceList[i]))
_sequenceNum = i;
}
}
- sprintf(videoName, "%s.dxa", baseName);
+ Common::String videoName = Common::String::printf("%s.dxa", baseName);
if (!loadFile(videoName))
- error("Failed to load video file %s", videoName);
+ error("Failed to load video file %s", videoName.c_str());
- debug(0, "Playing video %s", videoName);
+ debug(0, "Playing video %s", videoName.c_str());
CursorMan.showMouse(false);
+ _firstFrameOffset = _fileStream->pos();
+
return true;
}
+void MoviePlayerDXA::copyFrameToBuffer(byte *dst, uint x, uint y, uint pitch) {
+ uint h = getHeight();
+ uint w = getWidth();
+
+ Graphics::Surface *surface = decodeNextFrame();
+ byte *src = (byte *)surface->pixels;
+ dst += y * pitch + x;
+
+ do {
+ memcpy(dst, src, w);
+ dst += pitch;
+ src += w;
+ } while (--h);
+
+ if (hasDirtyPalette())
+ setSystemPalette();
+}
+
void MoviePlayerDXA::playVideo() {
// Most of the videos included in the Amiga version, reduced the
// resoluton to 384 x 280, so require the screen to be cleared,
@@ -277,7 +294,7 @@ void MoviePlayerDXA::playVideo() {
}
void MoviePlayerDXA::stopVideo() {
- closeFile();
+ close();
_mixer->stopHandle(_bgSound);
}
@@ -318,70 +335,56 @@ void MoviePlayerDXA::startSound() {
}
void MoviePlayerDXA::nextFrame() {
- if (_bgSoundStream && _vm->_mixer->isSoundHandleActive(_bgSound) && (_vm->_mixer->getSoundElapsedTime(_bgSound) * getFrameRate()) / 1000 <= (uint32)getCurFrame()) {
+ if (_bgSoundStream && _vm->_mixer->isSoundHandleActive(_bgSound) && needsUpdate()) {
copyFrameToBuffer(_vm->getBackBuf(), 465, 222, _vm->_screenWidth);
return;
}
if (_vm->_interactiveVideo == TYPE_LOOPING && endOfVideo()) {
- _fileStream->seek(_videoInfo.firstframeOffset);
- _videoInfo.currentFrame = -1;
+ _fileStream->seek(_firstFrameOffset);
+ _curFrame = -1;
startSound();
}
if (!endOfVideo()) {
- decodeNextFrame();
if (_vm->_interactiveVideo == TYPE_OMNITV) {
copyFrameToBuffer(_vm->getBackBuf(), 465, 222, _vm->_screenWidth);
} else if (_vm->_interactiveVideo == TYPE_LOOPING) {
copyFrameToBuffer(_vm->getBackBuf(), (_vm->_screenWidth - getWidth()) / 2, (_vm->_screenHeight - getHeight()) / 2, _vm->_screenWidth);
}
} else if (_vm->_interactiveVideo == TYPE_OMNITV) {
- closeFile();
+ close();
_vm->_interactiveVideo = 0;
_vm->_variableArray[254] = 6747;
}
}
void MoviePlayerDXA::handleNextFrame() {
- decodeNextFrame();
if (processFrame())
_vm->_system->updateScreen();
MoviePlayer::handleNextFrame();
}
-void MoviePlayerDXA::setPalette(byte *pal) {
- byte palette[1024];
- byte *p = palette;
-
- for (int i = 0; i < 256; i++) {
- *p++ = *pal++;
- *p++ = *pal++;
- *p++ = *pal++;
- *p++ = 0;
- }
-
- _vm->_system->setPalette(palette, 0, 256);
-}
-
bool MoviePlayerDXA::processFrame() {
Graphics::Surface *screen = _vm->_system->lockScreen();
copyFrameToBuffer((byte *)screen->pixels, (_vm->_screenWidth - getWidth()) / 2, (_vm->_screenHeight - getHeight()) / 2, _vm->_screenWidth);
_vm->_system->unlockScreen();
- if ((_bgSoundStream == NULL) || ((int)(_mixer->getSoundElapsedTime(_bgSound) * getFrameRate()) / 1000 <= getCurFrame())) {
+ Common::Rational soundTime(_mixer->getSoundElapsedTime(_bgSound), 1000);
+ if ((_bgSoundStream == NULL) || ((int)(soundTime * getFrameRate()) / 1000 < getCurFrame() + 1)) {
if (_bgSoundStream && _mixer->isSoundHandleActive(_bgSound)) {
- while (_mixer->isSoundHandleActive(_bgSound) && (_mixer->getSoundElapsedTime(_bgSound) * getFrameRate()) / 1000 <= (uint32)getCurFrame()) {
+ while (_mixer->isSoundHandleActive(_bgSound) && ((int) (soundTime * getFrameRate())) < getCurFrame()) {
_vm->_system->delayMillis(10);
+ soundTime = Common::Rational(_mixer->getSoundElapsedTime(_bgSound), 1000);
}
// In case the background sound ends prematurely, update
// _ticks so that we can still fall back on the no-sound
// sync case for the subsequent frames.
_ticks = _vm->_system->getMillis();
} else {
- _ticks += getFrameWaitTime();
+ _ticks += getTimeToNextFrame();
while (_vm->_system->getMillis() < _ticks)
_vm->_system->delayMillis(10);
}
@@ -407,33 +410,51 @@ MoviePlayerSMK::MoviePlayerSMK(AGOSEngine_Feeble *vm, const char *name)
}
bool MoviePlayerSMK::load() {
- char videoName[20];
+ Common::String videoName = Common::String::printf("%s.smk", baseName);
- sprintf(videoName, "%s.smk", baseName);
if (!loadFile(videoName))
- error("Failed to load video file %s", videoName);
+ error("Failed to load video file %s", videoName.c_str());
- debug(0, "Playing video %s", videoName);
+ debug(0, "Playing video %s", videoName.c_str());
CursorMan.showMouse(false);
+ _firstFrameOffset = _fileStream->pos();
+
return true;
}
+void MoviePlayerSMK::copyFrameToBuffer(byte *dst, uint x, uint y, uint pitch) {
+ uint h = getHeight();
+ uint w = getWidth();
+
+ Graphics::Surface *surface = decodeNextFrame();
+ byte *src = (byte *)surface->pixels;
+ dst += y * pitch + x;
+
+ do {
+ memcpy(dst, src, w);
+ dst += pitch;
+ src += w;
+ } while (--h);
+
+ if (hasDirtyPalette())
+ setSystemPalette();
+}
+
void MoviePlayerSMK::playVideo() {
while (!endOfVideo() && !_skipMovie && !_vm->shouldQuit())
handleNextFrame();
}
void MoviePlayerSMK::stopVideo() {
- closeFile();
+ close();
}
void MoviePlayerSMK::startSound() {
}
void MoviePlayerSMK::handleNextFrame() {
- decodeNextFrame();
processFrame();
MoviePlayer::handleNextFrame();
@@ -441,8 +462,8 @@ void MoviePlayerSMK::handleNextFrame() {
void MoviePlayerSMK::nextFrame() {
if (_vm->_interactiveVideo == TYPE_LOOPING && endOfVideo()) {
- _fileStream->seek(_videoInfo.firstframeOffset);
- _videoInfo.currentFrame = -1;
+ _fileStream->seek(_firstFrameOffset);
+ _curFrame = -1;
}
if (!endOfVideo()) {
@@ -453,32 +474,18 @@ void MoviePlayerSMK::nextFrame() {
copyFrameToBuffer(_vm->getBackBuf(), (_vm->_screenWidth - getWidth()) / 2, (_vm->_screenHeight - getHeight()) / 2, _vm->_screenWidth);
}
} else if (_vm->_interactiveVideo == TYPE_OMNITV) {
- closeFile();
+ close();
_vm->_interactiveVideo = 0;
_vm->_variableArray[254] = 6747;
}
}
-void MoviePlayerSMK::setPalette(byte *pal) {
- byte palette[1024];
- byte *p = palette;
-
- for (int i = 0; i < 256; i++) {
- *p++ = *pal++;
- *p++ = *pal++;
- *p++ = *pal++;
- *p++ = 0;
- }
-
- _vm->_system->setPalette(palette, 0, 256);
-}
-
bool MoviePlayerSMK::processFrame() {
Graphics::Surface *screen = _vm->_system->lockScreen();
copyFrameToBuffer((byte *)screen->pixels, (_vm->_screenWidth - getWidth()) / 2, (_vm->_screenHeight - getHeight()) / 2, _vm->_screenWidth);
_vm->_system->unlockScreen();
- uint32 waitTime = getFrameWaitTime();
+ uint32 waitTime = getTimeToNextFrame();
if (!waitTime) {
warning("dropped frame %i", getCurFrame());
diff --git a/engines/agos/animation.h b/engines/agos/animation.h
index 6a1bdccadf..68a76e1f88 100644
--- a/engines/agos/animation.h
+++ b/engines/agos/animation.h
@@ -72,6 +72,9 @@ private:
virtual void handleNextFrame();
virtual bool processFrame() = 0;
virtual void startSound() {}
+
+protected:
+ uint32 _firstFrameOffset;
};
class MoviePlayerDXA : public MoviePlayer, ::Graphics::DXADecoder {
@@ -84,13 +87,12 @@ public:
void playVideo();
void nextFrame();
virtual void stopVideo();
-protected:
- void setPalette(byte *pal);
private:
void handleNextFrame();
bool processFrame();
void startSound();
+ void copyFrameToBuffer(byte *dst, uint x, uint y, uint pitch);
};
class MoviePlayerSMK : public MoviePlayer, ::Graphics::SmackerDecoder {
@@ -101,12 +103,12 @@ public:
void playVideo();
void nextFrame();
virtual void stopVideo();
-protected:
- void setPalette(byte *pal);
+
private:
void handleNextFrame();
bool processFrame();
void startSound();
+ void copyFrameToBuffer(byte *dst, uint x, uint y, uint pitch);
};
MoviePlayer *makeMoviePlayer(AGOSEngine_Feeble *vm, const char *name);
diff --git a/engines/mohawk/jpeg.h b/engines/mohawk/jpeg.h
index 086e78332f..ec87b1e7af 100644
--- a/engines/mohawk/jpeg.h
+++ b/engines/mohawk/jpeg.h
@@ -45,6 +45,7 @@ public:
~JPEGDecoder();
Graphics::Surface *decodeImage(Common::SeekableReadStream *stream);
+ Graphics::PixelFormat getPixelFormat() const { return _pixelFormat; }
private:
Graphics::PixelFormat _pixelFormat;
diff --git a/engines/mohawk/video/cinepak.h b/engines/mohawk/video/cinepak.h
index 43cc22bfc9..3f4cbba17c 100644
--- a/engines/mohawk/video/cinepak.h
+++ b/engines/mohawk/video/cinepak.h
@@ -65,6 +65,7 @@ public:
~CinepakDecoder();
Graphics::Surface *decodeImage(Common::SeekableReadStream *stream);
+ Graphics::PixelFormat getPixelFormat() const { return _pixelFormat; }
private:
CinepakFrame _curFrame;
diff --git a/engines/mohawk/video/qtrle.h b/engines/mohawk/video/qtrle.h
index fdccf626a6..2832bd6b24 100644
--- a/engines/mohawk/video/qtrle.h
+++ b/engines/mohawk/video/qtrle.h
@@ -37,6 +37,7 @@ public:
~QTRLEDecoder();
Graphics::Surface *decodeImage(Common::SeekableReadStream *stream);
+ Graphics::PixelFormat getPixelFormat() const { return _pixelFormat; }
private:
byte _bitsPerPixel;
diff --git a/engines/mohawk/video/rpza.h b/engines/mohawk/video/rpza.h
index b9522ec2e3..c6d0ada6f5 100644
--- a/engines/mohawk/video/rpza.h
+++ b/engines/mohawk/video/rpza.h
@@ -37,6 +37,7 @@ public:
~RPZADecoder() { delete _surface; }
Graphics::Surface *decodeImage(Common::SeekableReadStream *stream);
+ Graphics::PixelFormat getPixelFormat() const { return _pixelFormat; }
private:
Graphics::Surface *_surface;
diff --git a/engines/mohawk/video/smc.h b/engines/mohawk/video/smc.h
index 331fddb9a5..c52226100e 100644
--- a/engines/mohawk/video/smc.h
+++ b/engines/mohawk/video/smc.h
@@ -43,6 +43,7 @@ public:
~SMCDecoder() { delete _surface; }
Graphics::Surface *decodeImage(Common::SeekableReadStream *stream);
+ Graphics::PixelFormat getPixelFormat() const { return Graphics::PixelFormat::createFormatCLUT8(); }
private:
Graphics::Surface *_surface;
diff --git a/engines/saga/introproc_saga2.cpp b/engines/saga/introproc_saga2.cpp
index 0af31dae61..7491815303 100644
--- a/engines/saga/introproc_saga2.cpp
+++ b/engines/saga/introproc_saga2.cpp
@@ -40,13 +40,7 @@ namespace Saga {
int Scene::DinoStartProc() {
_vm->_gfx->showCursor(false);
- Graphics::SmackerDecoder *smkDecoder = new Graphics::SmackerDecoder(_vm->_mixer);
- Graphics::VideoPlayer *player = new Graphics::VideoPlayer(smkDecoder);
- if (smkDecoder->loadFile("testvid.smk"))
- player->playVideo(); // Play introduction
- smkDecoder->closeFile();
- delete player;
- delete smkDecoder;
+ playMovie("testvid.smk");
// HACK: Forcibly quit here
_vm->quitGame();
@@ -57,16 +51,8 @@ int Scene::DinoStartProc() {
int Scene::FTA2StartProc() {
_vm->_gfx->showCursor(false);
- Graphics::SmackerDecoder *smkDecoder = new Graphics::SmackerDecoder(_vm->_mixer);
- Graphics::VideoPlayer *player = new Graphics::VideoPlayer(smkDecoder);
- if (smkDecoder->loadFile("trimark.smk"))
- player->playVideo(); // Show Ignite logo
- smkDecoder->closeFile();
- if (smkDecoder->loadFile("intro.smk"))
- player->playVideo(); // Play introduction
- smkDecoder->closeFile();
- delete player;
- delete smkDecoder;
+ playMovie("trimark.smk");
+ playMovie("intro.smk");
// HACK: Forcibly quit here
_vm->quitGame();
@@ -100,18 +86,41 @@ int Scene::FTA2EndProc(FTA2Endings whichEnding) {
_vm->_gfx->showCursor(false);
// Play ending
- Graphics::SmackerDecoder *smkDecoder = new Graphics::SmackerDecoder(_vm->_mixer);
- Graphics::VideoPlayer *player = new Graphics::VideoPlayer(smkDecoder);
- if (smkDecoder->loadFile(videoName)) {
- player->playVideo();
- smkDecoder->closeFile();
- }
- delete player;
- delete smkDecoder;
+ playMovie(videoName);
return SUCCESS;
}
+void Scene::playMovie(const char *filename) {
+ Graphics::SmackerDecoder *smkDecoder = new Graphics::SmackerDecoder(_vm->_mixer);
+
+ if (!smkDecoder->loadFile(filename))
+ return;
+
+ uint16 x = (g_system->getWidth() - smkDecoder->getWidth()) / 2;
+ uint16 y = (g_system->getHeight() - smkDecoder->getHeight()) / 2;
+
+ while (!_vm->shouldQuit() && !smkDecoder->endOfVideo()) {
+ if (smkDecoder->needsUpdate()) {
+ Graphics::Surface *frame = smkDecoder->decodeNextFrame();
+ if (frame) {
+ _vm->_system->copyRectToScreen((byte *)frame->pixels, frame->pitch, x, y, frame->w, frame->h);
+
+ if (smkDecoder->hasDirtyPalette())
+ smkDecoder->setSystemPalette();
+
+ _vm->_system->updateScreen();
+ }
+ }
+
+ Common::Event event;
+ while (_vm->_system->getEventManager()->pollEvent(event))
+ ;
+
+ _vm->_system->delayMillis(10);
+ }
+}
+
} // End of namespace Saga
#endif
diff --git a/engines/saga/scene.h b/engines/saga/scene.h
index 4fbde560b5..0131e01abb 100644
--- a/engines/saga/scene.h
+++ b/engines/saga/scene.h
@@ -424,6 +424,7 @@ class Scene {
int DinoStartProc();
int FTA2StartProc();
int FTA2EndProc(FTA2Endings whichEnding);
+ void playMovie(const char *filename);
void IHNMLoadCutaways();
bool checkKey();
diff --git a/engines/sci/console.cpp b/engines/sci/console.cpp
index 73b9788ca0..f2e5601c9e 100644
--- a/engines/sci/console.cpp
+++ b/engines/sci/console.cpp
@@ -222,42 +222,48 @@ void Console::postEnter() {
if (!_videoFile.empty()) {
_engine->_gfxCursor->kernelHide();
+ Graphics::VideoDecoder *videoDecoder = 0;
+
if (_videoFile.hasSuffix(".seq")) {
- SeqDecoder *seqDecoder = new SeqDecoder();
- Graphics::VideoPlayer *player = new Graphics::VideoPlayer(seqDecoder);
- if (seqDecoder->loadFile(_videoFile.c_str(), _videoFrameDelay))
- player->playVideo();
- else
- DebugPrintf("Failed to open movie file %s\n", _videoFile.c_str());
- seqDecoder->closeFile();
- delete player;
- delete seqDecoder;
- } else if (_videoFile.hasSuffix(".avi")) {
- Graphics::AviDecoder *aviDecoder = new Graphics::AviDecoder(g_system->getMixer());
- Graphics::VideoPlayer *player = new Graphics::VideoPlayer(aviDecoder);
- if (aviDecoder->loadFile(_videoFile.c_str()))
- player->playVideo();
- else
- DebugPrintf("Failed to open movie file %s\n", _videoFile.c_str());
- aviDecoder->closeFile();
- delete player;
- delete aviDecoder;
- } else if (_videoFile.hasSuffix(".vmd")) {
+ videoDecoder = new SeqDecoder();
+ ((SeqDecoder *)videoDecoder)->setFrameDelay(_videoFrameDelay);
#ifdef ENABLE_SCI32
- VMDDecoder *vmdDecoder = new VMDDecoder(g_system->getMixer());
- Graphics::VideoPlayer *player = new Graphics::VideoPlayer(vmdDecoder);
- if (vmdDecoder->loadFile(_videoFile.c_str()))
- player->playVideo();
- else
- DebugPrintf("Failed to open movie file %s\n", _videoFile.c_str());
- vmdDecoder->closeFile();
- delete player;
- delete vmdDecoder;
+ } else if (_videoFile.hasSuffix(".vmd")) {
+ videoDecoder = new VMDDecoder(g_system->getMixer());
#endif
+ } else if (_videoFile.hasSuffix(".avi")) {
+ videoDecoder = new Graphics::AviDecoder(g_system->getMixer());
}
- _engine->_gfxCursor->kernelShow();
+ if (videoDecoder && videoDecoder->loadFile(_videoFile)) {
+ uint16 x = (g_system->getWidth() - videoDecoder->getWidth()) / 2;
+ uint16 y = (g_system->getHeight() - videoDecoder->getHeight()) / 2;
+
+ while (!g_engine->shouldQuit() && !videoDecoder->endOfVideo()) {
+ if (videoDecoder->needsUpdate()) {
+ Graphics::Surface *frame = videoDecoder->decodeNextFrame();
+ if (frame) {
+ g_system->copyRectToScreen((byte *)frame->pixels, frame->pitch, x, y, frame->w, frame->h);
+ if (videoDecoder->hasDirtyPalette())
+ videoDecoder->setSystemPalette();
+
+ g_system->updateScreen();
+ }
+ }
+
+ Common::Event event;
+ while (g_system->getEventManager()->pollEvent(event))
+ ;
+
+ g_system->delayMillis(10);
+ }
+
+ delete videoDecoder;
+ } else
+ warning("Could not play video %s\n", _videoFile.c_str());
+
+ _engine->_gfxCursor->kernelShow();
_videoFile.clear();
_videoFrameDelay = 0;
}
diff --git a/engines/sci/engine/kgraphics.cpp b/engines/sci/engine/kgraphics.cpp
index da18bc7e03..d587790b6c 100644
--- a/engines/sci/engine/kgraphics.cpp
+++ b/engines/sci/engine/kgraphics.cpp
@@ -1078,8 +1078,6 @@ reg_t kDisplay(EngineState *s, int argc, reg_t *argv) {
}
reg_t kShowMovie(EngineState *s, int argc, reg_t *argv) {
- bool playedVideo = false;
-
// Hide the cursor if it's showing and then show it again if it was
// previously visible.
bool reshowCursor;
@@ -1087,30 +1085,29 @@ reg_t kShowMovie(EngineState *s, int argc, reg_t *argv) {
reshowCursor = g_sci->_gfxCursor->isVisible();
if (reshowCursor)
g_sci->_gfxCursor->kernelHide();
+
+ Graphics::VideoDecoder *videoDecoder = 0;
if (argv[0].segment != 0) {
+ Common::String filename = s->_segMan->getString(argv[0]);
+
if (g_sci->getPlatform() == Common::kPlatformMacintosh) {
// Mac QuickTime
// The only argument is the string for the video
- warning("TODO: Play QuickTime movie '%s'", s->_segMan->getString(argv[0]).c_str());
+ warning("TODO: Play QuickTime movie '%s'", filename.c_str());
return s->r_acc;
} else {
// DOS SEQ
// SEQ's are called with no subops, just the string and delay
- Common::String filename = s->_segMan->getString(argv[0]);
- int delay = argv[1].toUint16(); // Time between frames in ticks
-
SeqDecoder *seqDecoder = new SeqDecoder();
- Graphics::VideoPlayer *player = new Graphics::VideoPlayer(seqDecoder);
- if (seqDecoder->loadFile(filename.c_str(), delay)) {
- player->playVideo();
- playedVideo = true;
- } else {
+ seqDecoder->setFrameDelay(argv[1].toUint16()); // Time between frames in ticks
+ videoDecoder = seqDecoder;
+
+ if (!videoDecoder->loadFile(filename)) {
warning("Failed to open movie file %s", filename.c_str());
+ delete videoDecoder;
+ videoDecoder = 0;
}
- seqDecoder->closeFile();
- delete player;
- delete seqDecoder;
}
} else {
// Windows AVI (Macintosh QuickTime? Need to check KQ6 Macintosh)
@@ -1130,17 +1127,13 @@ reg_t kShowMovie(EngineState *s, int argc, reg_t *argv) {
switch (argv[0].toUint16()) {
case 0: {
Common::String filename = s->_segMan->getString(argv[1]);
- Graphics::AviDecoder *aviDecoder = new Graphics::AviDecoder(g_system->getMixer());
- Graphics::VideoPlayer *player = new Graphics::VideoPlayer(aviDecoder);
- if (aviDecoder->loadFile(filename.c_str())) {
- player->playVideo();
- playedVideo = true;
- } else {
+ videoDecoder = new Graphics::AviDecoder(g_system->getMixer());
+
+ if (!videoDecoder->loadFile(filename.c_str())) {
warning("Failed to open movie file %s", filename.c_str());
+ delete videoDecoder;
+ videoDecoder = 0;
}
- aviDecoder->closeFile();
- delete player;
- delete aviDecoder;
break;
}
default:
@@ -1148,8 +1141,33 @@ reg_t kShowMovie(EngineState *s, int argc, reg_t *argv) {
}
}
- if (playedVideo)
+ if (videoDecoder) {
+ uint16 x = (g_system->getWidth() - videoDecoder->getWidth()) / 2;
+ uint16 y = (g_system->getHeight() - videoDecoder->getHeight()) / 2;
+
+ while (!g_engine->shouldQuit() && !videoDecoder->endOfVideo()) {
+ if (videoDecoder->needsUpdate()) {
+ Graphics::Surface *frame = videoDecoder->decodeNextFrame();
+ if (frame) {
+ g_system->copyRectToScreen((byte *)frame->pixels, frame->pitch, x, y, frame->w, frame->h);
+
+ if (videoDecoder->hasDirtyPalette())
+ videoDecoder->setSystemPalette();
+
+ g_system->updateScreen();
+ }
+ }
+
+ Common::Event event;
+ while (g_system->getEventManager()->pollEvent(event))
+ ;
+
+ g_system->delayMillis(10);
+ }
+
+ delete videoDecoder;
g_sci->_gfxScreen->kernelSyncWithFramebuffer();
+ }
if (reshowCursor)
g_sci->_gfxCursor->kernelShow();
diff --git a/engines/sci/video/seq_decoder.cpp b/engines/sci/video/seq_decoder.cpp
index ccce873a15..2c117ae329 100644
--- a/engines/sci/video/seq_decoder.cpp
+++ b/engines/sci/video/seq_decoder.cpp
@@ -35,10 +35,6 @@
namespace Sci {
-// SEQ videos always run at 320x200
-#define SCREEN_WIDTH 320
-#define SCREEN_HEIGHT 200
-
enum seqPalTypes {
kSeqPalVariable = 0,
kSeqPalConstant = 1
@@ -49,26 +45,24 @@ enum seqFrameTypes {
kSeqFrameDiff = 1
};
-SeqDecoder::~SeqDecoder() {
- closeFile();
+SeqDecoder::SeqDecoder() {
+ _fileStream = 0;
+ _surface = 0;
+ _dirtyPalette = false;
}
-bool SeqDecoder::loadFile(const char *fileName, int frameDelay) {
- closeFile();
+SeqDecoder::~SeqDecoder() {
+ close();
+}
- _fileStream = SearchMan.createReadStreamForMember(fileName);
- if (!_fileStream)
- return false;
+bool SeqDecoder::load(Common::SeekableReadStream &stream) {
+ close();
- // Seek to the first frame
- _videoInfo.currentFrame = -1;
+ _fileStream = &stream;
+ _surface = new Graphics::Surface();
+ _surface->create(SEQ_SCREEN_WIDTH, SEQ_SCREEN_HEIGHT, 1);
- _videoInfo.width = SCREEN_WIDTH;
- _videoInfo.height = SCREEN_HEIGHT;
- _videoInfo.frameCount = _fileStream->readUint16LE();
- // Our frameDelay is calculated in 1/100 ms, so we convert it here
- _videoInfo.frameDelay = 100 * frameDelay * 1000 / 60;
- _videoFrameBuffer = new byte[_videoInfo.width * _videoInfo.height];
+ _frameCount = _fileStream->readUint16LE();
// Set palette
int paletteSize = _fileStream->readUint32LE();
@@ -81,39 +75,38 @@ bool SeqDecoder::loadFile(const char *fileName, int frameDelay) {
uint16 palColorStart = READ_LE_UINT16(paletteData + 25);
uint16 palColorCount = READ_LE_UINT16(paletteData + 29);
- byte palette[256 * 4];
int palOffset = 37;
for (uint16 colorNo = palColorStart; colorNo < palColorStart + palColorCount; colorNo++) {
if (palFormat == kSeqPalVariable)
palOffset++;
- palette[colorNo * 4 + 0] = paletteData[palOffset++];
- palette[colorNo * 4 + 1] = paletteData[palOffset++];
- palette[colorNo * 4 + 2] = paletteData[palOffset++];
- palette[colorNo * 4 + 3] = 0;
+ _palette[colorNo * 3 + 0] = paletteData[palOffset++];
+ _palette[colorNo * 3 + 1] = paletteData[palOffset++];
+ _palette[colorNo * 3 + 2] = paletteData[palOffset++];
}
- g_system->setPalette(palette, 0, 256);
-
+ _dirtyPalette = true;
delete[] paletteData;
-
- _videoInfo.firstframeOffset = _fileStream->pos();
-
return true;
}
-void SeqDecoder::closeFile() {
+void SeqDecoder::close() {
if (!_fileStream)
return;
+ _frameDelay = 0;
+
delete _fileStream;
_fileStream = 0;
- delete[] _videoFrameBuffer;
- _videoFrameBuffer = 0;
+ _surface->free();
+ delete _surface;
+ _surface = 0;
+
+ reset();
}
-bool SeqDecoder::decodeNextFrame() {
+Graphics::Surface *SeqDecoder::decodeNextFrame() {
int16 frameWidth = _fileStream->readUint16LE();
int16 frameHeight = _fileStream->readUint16LE();
int16 frameLeft = _fileStream->readUint16LE();
@@ -129,42 +122,41 @@ bool SeqDecoder::decodeNextFrame() {
_fileStream->seek(offset);
- _videoInfo.currentFrame++;
-
- if (_videoInfo.currentFrame == 0)
- _videoInfo.startTime = g_system->getMillis();
-
if (frameType == kSeqFrameFull) {
- byte *dst = _videoFrameBuffer + frameTop * SCREEN_WIDTH + frameLeft;
+ byte *dst = (byte *)_surface->pixels + frameTop * SEQ_SCREEN_WIDTH + frameLeft;
byte *linebuf = new byte[frameWidth];
do {
_fileStream->read(linebuf, frameWidth);
memcpy(dst, linebuf, frameWidth);
- dst += SCREEN_WIDTH;
+ dst += SEQ_SCREEN_WIDTH;
} while (--frameHeight);
delete[] linebuf;
} else {
byte *buf = new byte[frameSize];
_fileStream->read(buf, frameSize);
- decodeFrame(buf, rleSize, buf + rleSize, frameSize - rleSize, _videoFrameBuffer + SCREEN_WIDTH * frameTop, frameLeft, frameWidth, frameHeight, colorKey);
+ decodeFrame(buf, rleSize, buf + rleSize, frameSize - rleSize, (byte *)_surface->pixels + SEQ_SCREEN_WIDTH * frameTop, frameLeft, frameWidth, frameHeight, colorKey);
delete[] buf;
}
- return !endOfVideo();
+ if (_curFrame == -1)
+ _startTime = g_system->getMillis();
+
+ _curFrame++;
+ return _surface;
}
#define WRITE_TO_BUFFER(n) \
- if (writeRow * SCREEN_WIDTH + writeCol + (n) > SCREEN_WIDTH * height) { \
+ if (writeRow * SEQ_SCREEN_WIDTH + writeCol + (n) > SEQ_SCREEN_WIDTH * height) { \
warning("SEQ player: writing out of bounds, aborting"); \
return false; \
} \
if (litPos + (n) > litSize) { \
warning("SEQ player: reading out of bounds, aborting"); \
} \
- memcpy(dest + writeRow * SCREEN_WIDTH + writeCol, litData + litPos, n);
+ memcpy(dest + writeRow * SEQ_SCREEN_WIDTH + writeCol, litData + litPos, n);
bool SeqDecoder::decodeFrame(byte *rleData, int rleSize, byte *litData, int litSize, byte *dest, int left, int width, int height, int colorKey) {
int writeRow = 0;
diff --git a/engines/sci/video/seq_decoder.h b/engines/sci/video/seq_decoder.h
index 7c810db05d..416abb78fa 100644
--- a/engines/sci/video/seq_decoder.h
+++ b/engines/sci/video/seq_decoder.h
@@ -26,40 +26,50 @@
#ifndef SEQ_DECODER_H
#define SEQ_DECODER_H
-#include "graphics/video/video_player.h"
+#include "graphics/video/video_decoder.h"
namespace Sci {
/**
* Implementation of the Sierra SEQ decoder, used in KQ6 DOS floppy/CD and GK1 DOS
*/
-class SeqDecoder : public Graphics::VideoDecoder {
+class SeqDecoder : public Graphics::FixedRateVideoDecoder {
public:
- SeqDecoder() {}
+ SeqDecoder();
virtual ~SeqDecoder();
- /**
- * Load a SEQ encoded video file
- * @param filename the filename to load
- */
- bool loadFile(const char *fileName) { return loadFile(fileName, 10); }
+ bool load(Common::SeekableReadStream &stream);
+ void close();
- /**
- * Load a SEQ encoded video file
- * @param filename the filename to load
- * @param frameDelay the delay between frames, in ticks
- */
- bool loadFile(const char *fileName, int frameDelay);
+ void setFrameDelay(int frameDelay) { _frameDelay = frameDelay; }
- /**
- * Close a SEQ encoded video file
- */
- void closeFile();
-
- bool decodeNextFrame();
+ bool isVideoLoaded() const { return _fileStream != 0; }
+ uint16 getWidth() const { return SEQ_SCREEN_WIDTH; }
+ uint16 getHeight() const { return SEQ_SCREEN_HEIGHT; }
+ uint32 getFrameCount() const { return _frameCount; }
+ Graphics::Surface *decodeNextFrame();
+ Graphics::PixelFormat getPixelFormat() const { return Graphics::PixelFormat::createFormatCLUT8(); }
+ byte *getPalette() { _dirtyPalette = false; return _palette; }
+ bool hasDirtyPalette() const { return _dirtyPalette; }
+
+protected:
+ Common::Rational getFrameRate() const { assert(_frameDelay); return Common::Rational(60, _frameDelay); }
private:
+ enum {
+ SEQ_SCREEN_WIDTH = 320,
+ SEQ_SCREEN_HEIGHT = 200
+ };
+
bool decodeFrame(byte *rleData, int rleSize, byte *litData, int litSize, byte *dest, int left, int width, int height, int colorKey);
+
+ uint16 _width, _height;
+ uint16 _frameDelay;
+ Common::SeekableReadStream *_fileStream;
+ byte _palette[256 * 3];
+ bool _dirtyPalette;
+ uint32 _frameCount;
+ Graphics::Surface *_surface;
};
} // End of namespace Sci
diff --git a/engines/sci/video/vmd_decoder.cpp b/engines/sci/video/vmd_decoder.cpp
index 9e95521ebb..93132bc5d6 100644
--- a/engines/sci/video/vmd_decoder.cpp
+++ b/engines/sci/video/vmd_decoder.cpp
@@ -27,7 +27,6 @@
#include "sci/video/vmd_decoder.h"
-#include "common/archive.h"
#include "common/endian.h"
#include "common/util.h"
#include "common/stream.h"
@@ -42,54 +41,39 @@ namespace Sci {
VMDDecoder::VMDDecoder(Audio::Mixer *mixer) : _mixer(mixer) {
_vmdDecoder = new Graphics::Vmd(new Graphics::PaletteLUT(5, Graphics::PaletteLUT::kPaletteYUV));
+ _surface = 0;
+ _dirtyPalette = false;
+ _fileStream = 0;
}
VMDDecoder::~VMDDecoder() {
- closeFile();
-}
-
-uint32 VMDDecoder::getFrameWaitTime() {
- return _vmdDecoder->getFrameWaitTime();
+ close();
}
-bool VMDDecoder::loadFile(const char *fileName) {
- closeFile();
+bool VMDDecoder::load(Common::SeekableReadStream &stream) {
+ close();
- _fileStream = SearchMan.createReadStreamForMember(fileName);
- if (!_fileStream)
+ if (!_vmdDecoder->load(stream))
return false;
- if (!_vmdDecoder->load(*_fileStream))
- return false;
+ _fileStream = &stream;
- if (_vmdDecoder->getFeatures() & Graphics::CoktelVideo::kFeaturesPalette) {
- getPalette();
- setPalette(_palette);
- }
+ if (_vmdDecoder->getFeatures() & Graphics::CoktelVideo::kFeaturesPalette)
+ loadPaletteFromVMD();
if (_vmdDecoder->getFeatures() & Graphics::CoktelVideo::kFeaturesSound)
_vmdDecoder->enableSound(*_mixer);
- _videoInfo.width = _vmdDecoder->getWidth();
- _videoInfo.height = _vmdDecoder->getHeight();
- _videoInfo.frameCount = _vmdDecoder->getFramesCount();
- _videoInfo.frameRate = _vmdDecoder->getFrameRate();
- _videoInfo.frameDelay = _videoInfo.frameRate * 100;
- _videoInfo.currentFrame = -1;
- _videoInfo.firstframeOffset = 0; // not really necessary for VMDs
-
if (_vmdDecoder->hasExtraData())
warning("This VMD video has extra embedded data, which is currently not handled");
- _videoFrameBuffer = new byte[_videoInfo.width * _videoInfo.height];
- memset(_videoFrameBuffer, 0, _videoInfo.width * _videoInfo.height);
-
- _vmdDecoder->setVideoMemory(_videoFrameBuffer, _videoInfo.width, _videoInfo.height);
-
+ _surface = new Graphics::Surface();
+ _surface->create(_vmdDecoder->getWidth(), _vmdDecoder->getHeight(), 1);
+ _vmdDecoder->setVideoMemory((byte *)_surface->pixels, _surface->w, _surface->h);
return true;
}
-void VMDDecoder::closeFile() {
+void VMDDecoder::close() {
if (!_fileStream)
return;
@@ -98,27 +82,27 @@ void VMDDecoder::closeFile() {
delete _fileStream;
_fileStream = 0;
- delete[] _videoFrameBuffer;
- _videoFrameBuffer = 0;
-}
-
-bool VMDDecoder::decodeNextFrame() {
- _videoInfo.currentFrame++;
+ _surface->free();
+ delete _surface;
+ _surface = 0;
- if (_videoInfo.currentFrame == 0)
- _videoInfo.startTime = g_system->getMillis();
+ reset();
+}
+Graphics::Surface *VMDDecoder::decodeNextFrame() {
Graphics::CoktelVideo::State state = _vmdDecoder->nextFrame();
- if (state.flags & Graphics::CoktelVideo::kStatePalette) {
- getPalette();
- setPalette(_palette);
- }
+ if (state.flags & Graphics::CoktelVideo::kStatePalette)
+ loadPaletteFromVMD();
+
+ if (_curFrame == -1)
+ _startTime = g_system->getMillis();
- return !endOfVideo();
+ _curFrame++;
+ return _surface;
}
-void VMDDecoder::getPalette() {
+void VMDDecoder::loadPaletteFromVMD() {
const byte *pal = _vmdDecoder->getPalette();
for (int i = 0; i < 256; i++) {
@@ -126,6 +110,8 @@ void VMDDecoder::getPalette() {
_palette[i * 3 + 1] = pal[i * 3 + 1] << 2;
_palette[i * 3 + 2] = pal[i * 3 + 2] << 2;
}
+
+ _dirtyPalette = true;
}
} // End of namespace Graphics
diff --git a/engines/sci/video/vmd_decoder.h b/engines/sci/video/vmd_decoder.h
index 628be24e82..231da9202e 100644
--- a/engines/sci/video/vmd_decoder.h
+++ b/engines/sci/video/vmd_decoder.h
@@ -29,7 +29,7 @@
#define GRAPHICS_VIDEO_VMD_DECODER_H
#include "graphics/video/coktelvideo/coktelvideo.h"
-#include "graphics/video/video_player.h"
+#include "graphics/video/video_decoder.h"
#include "sound/mixer.h"
namespace Sci {
@@ -49,32 +49,37 @@ namespace Sci {
* - Shivers 2: Harvest of Souls
* - Torin's Passage
*/
-class VMDDecoder : public Graphics::VideoDecoder {
+class VMDDecoder : public Graphics::FixedRateVideoDecoder {
public:
VMDDecoder(Audio::Mixer *mixer);
virtual ~VMDDecoder();
uint32 getFrameWaitTime();
- /**
- * Load a VMD encoded video file
- * @param filename the filename to load
- */
- bool loadFile(const char *filename);
+ bool load(Common::SeekableReadStream &stream);
+ void close();
- /**
- * Close a VMD encoded video file
- */
- void closeFile();
+ bool isVideoLoaded() const { return _fileStream != 0; }
+ uint16 getWidth() const { return _surface->w; }
+ uint16 getHeight() const { return _surface->h; }
+ uint32 getFrameCount() const { return _vmdDecoder->getFramesCount(); }
+ Graphics::Surface *decodeNextFrame();
+ Graphics::PixelFormat getPixelFormat() const { return Graphics::PixelFormat::createFormatCLUT8(); }
+ byte *getPalette() { _dirtyPalette = false; return _palette; }
+ bool hasDirtyPalette() const { return _dirtyPalette; }
- bool decodeNextFrame();
+protected:
+ Common::Rational getFrameRate() const { return _vmdDecoder->getFrameRate(); }
private:
Graphics::Vmd *_vmdDecoder;
Audio::Mixer *_mixer;
+ Graphics::Surface *_surface;
+ Common::SeekableReadStream *_fileStream;
byte _palette[256 * 3];
+ bool _dirtyPalette;
- void getPalette();
+ void loadPaletteFromVMD();
};
} // End of namespace Graphics
diff --git a/engines/scumm/he/animation_he.cpp b/engines/scumm/he/animation_he.cpp
index 5bd60d32e3..9f1bf22c38 100644
--- a/engines/scumm/he/animation_he.cpp
+++ b/engines/scumm/he/animation_he.cpp
@@ -46,23 +46,21 @@ int MoviePlayer::getImageNum() {
}
int MoviePlayer::load(const char *filename, int flags, int image) {
- if (isVideoLoaded()) {
- closeFile();
- }
+ if (isVideoLoaded())
+ close();
if (!loadFile(filename)) {
warning("Failed to load video file %s", filename);
return -1;
}
+
debug(1, "Playing video %s", filename);
- if (flags & 2) {
+ if (flags & 2)
_vm->_wiz->createWizEmptyImage(image, 0, 0, getWidth(), getHeight());
- }
_flags = flags;
_wizResNum = image;
-
return 0;
}
@@ -70,7 +68,11 @@ void MoviePlayer::copyFrameToBuffer(byte *dst, int dstType, uint x, uint y, uint
uint h = getHeight();
uint w = getWidth();
- byte *src = _videoFrameBuffer;
+ Graphics::Surface *surface = decodeNextFrame();
+ byte *src = (byte *)surface->pixels;
+
+ if (hasDirtyPalette())
+ _vm->setPaletteFromPtr(getPalette(), 256);
if (_vm->_game.features & GF_16BIT_COLOR) {
dst += y * pitch + x * 2;
@@ -102,14 +104,11 @@ void MoviePlayer::copyFrameToBuffer(byte *dst, int dstType, uint x, uint y, uint
}
void MoviePlayer::handleNextFrame() {
- if (!isVideoLoaded()) {
+ if (!isVideoLoaded())
return;
- }
VirtScreen *pvs = &_vm->_virtscr[kMainVirtScreen];
- decodeNextFrame();
-
if (_flags & 2) {
uint8 *dstPtr = _vm->getResourceAddress(rtImage, _wizResNum);
assert(dstPtr);
@@ -129,11 +128,7 @@ void MoviePlayer::handleNextFrame() {
}
if (endOfVideo())
- closeFile();
-}
-
-void MoviePlayer::setPalette(byte *pal) {
- _vm->setPaletteFromPtr(pal, 256);
+ close();
}
} // End of namespace Scumm
diff --git a/engines/scumm/he/animation_he.h b/engines/scumm/he/animation_he.h
index 86ded31940..34794b35ac 100644
--- a/engines/scumm/he/animation_he.h
+++ b/engines/scumm/he/animation_he.h
@@ -56,9 +56,6 @@ public:
void copyFrameToBuffer(byte *dst, int dstType, uint x, uint y, uint pitch);
void handleNextFrame();
-
-protected:
- virtual void setPalette(byte *pal);
};
} // End of namespace Scumm
diff --git a/engines/scumm/he/script_v100he.cpp b/engines/scumm/he/script_v100he.cpp
index e32409fe85..3555f55d95 100644
--- a/engines/scumm/he/script_v100he.cpp
+++ b/engines/scumm/he/script_v100he.cpp
@@ -2254,7 +2254,7 @@ void ScummEngine_v100he::o100_videoOps() {
}
} else if (_videoParams.status == 19) {
// Stop video
- _moviePlay->closeFile();
+ _moviePlay->close();
}
break;
default:
diff --git a/engines/scumm/he/script_v90he.cpp b/engines/scumm/he/script_v90he.cpp
index 091bf5027b..6acc16a804 100644
--- a/engines/scumm/he/script_v90he.cpp
+++ b/engines/scumm/he/script_v90he.cpp
@@ -1437,7 +1437,7 @@ void ScummEngine_v90he::o90_videoOps() {
}
} else if (_videoParams.status == 165) {
// Stop video
- _moviePlay->closeFile();
+ _moviePlay->close();
}
break;
default:
diff --git a/engines/sword1/animation.cpp b/engines/sword1/animation.cpp
index 221a20ba45..c0e7be7758 100644
--- a/engines/sword1/animation.cpp
+++ b/engines/sword1/animation.cpp
@@ -68,9 +68,10 @@ static const char *sequenceList[20] = {
///////////////////////////////////////////////////////////////////////////////
MoviePlayer::MoviePlayer(SwordEngine *vm, Text *textMan, Audio::Mixer *snd, OSystem *system, Audio::SoundHandle *bgSoundHandle, Graphics::VideoDecoder *decoder, DecoderType decoderType)
- : _vm(vm), _textMan(textMan), _snd(snd), _bgSoundHandle(bgSoundHandle), _system(system), VideoPlayer(decoder) {
+ : _vm(vm), _textMan(textMan), _snd(snd), _bgSoundHandle(bgSoundHandle), _system(system) {
_bgSoundStream = NULL;
_decoderType = decoderType;
+ _decoder = decoder;
}
MoviePlayer::~MoviePlayer() {
@@ -86,11 +87,10 @@ bool MoviePlayer::load(uint32 id) {
Common::File f;
char filename[20];
- if (_decoderType == kVideoDecoderDXA) {
+ if (_decoderType == kVideoDecoderDXA)
_bgSoundStream = Audio::SeekableAudioStream::openStreamFile(sequenceList[id]);
- } else {
+ else
_bgSoundStream = NULL;
- }
if (SwordEngine::_systemVars.showText) {
sprintf(filename, "%s.txt", sequenceList[id]);
@@ -146,9 +146,9 @@ bool MoviePlayer::load(uint32 id) {
}
void MoviePlayer::play() {
- if (_bgSoundStream) {
+ if (_bgSoundStream)
_snd->playStream(Audio::Mixer::kSFXSoundType, _bgSoundHandle, _bgSoundStream);
- }
+
bool terminated = false;
_textX = 0;
@@ -179,7 +179,7 @@ void MoviePlayer::play() {
void MoviePlayer::performPostProcessing(byte *screen) {
if (!_movieTexts.empty()) {
- if (_decoder->getCurFrame() + 1 == _movieTexts[0]->_startFrame) {
+ if (_decoder->getCurFrame() == _movieTexts[0]->_startFrame) {
_textMan->makeTextSprite(2, (uint8 *)_movieTexts[0]->_text, 600, LETTER_COL);
FrameHeader *frame = _textMan->giveSpriteData(2);
@@ -188,7 +188,7 @@ void MoviePlayer::performPostProcessing(byte *screen) {
_textX = 320 - _textWidth / 2;
_textY = 420 - _textHeight;
}
- if (_decoder->getCurFrame() + 1 == _movieTexts[0]->_endFrame) {
+ if (_decoder->getCurFrame() == _movieTexts[0]->_endFrame) {
_textMan->releaseText(2, false);
delete _movieTexts.remove_at(0);
}
@@ -205,10 +205,10 @@ void MoviePlayer::performPostProcessing(byte *screen) {
for (x = 0; x < _textWidth; x++) {
switch (src[x]) {
case BORDER_COL:
- dst[x] = _decoder->getBlack();
+ dst[x] = findBlackPalIndex();
break;
case LETTER_COL:
- dst[x] = _decoder->getWhite();
+ dst[x] = findWhitePalIndex();
break;
}
}
@@ -228,12 +228,12 @@ void MoviePlayer::performPostProcessing(byte *screen) {
for (y = 0; y < _textHeight; y++) {
if (_textY + y < frameY || _textY + y >= frameY + frameHeight) {
- memset(dst + _textX, _decoder->getBlack(), _textWidth);
+ memset(dst + _textX, findBlackPalIndex(), _textWidth);
} else {
if (frameX > _textX)
- memset(dst + _textX, _decoder->getBlack(), frameX - _textX);
+ memset(dst + _textX, findBlackPalIndex(), frameX - _textX);
if (frameX + frameWidth < _textX + _textWidth)
- memset(dst + frameX + frameWidth, _decoder->getBlack(), _textX + _textWidth - (frameX + frameWidth));
+ memset(dst + frameX + frameWidth, findBlackPalIndex(), _textX + _textWidth - (frameX + frameWidth));
}
dst += _system->getWidth();
@@ -244,25 +244,51 @@ void MoviePlayer::performPostProcessing(byte *screen) {
}
}
-DXADecoderWithSound::DXADecoderWithSound(Audio::Mixer *mixer, Audio::SoundHandle *bgSoundHandle)
- : _mixer(mixer), _bgSoundHandle(bgSoundHandle) {
+bool MoviePlayer::playVideo() {
+ uint16 x = (g_system->getWidth() - _decoder->getWidth()) / 2;
+ uint16 y = (g_system->getHeight() - _decoder->getHeight()) / 2;
+
+ while (!_vm->shouldQuit() && !_decoder->endOfVideo()) {
+ if (_decoder->needsUpdate()) {
+ Graphics::Surface *frame = _decoder->decodeNextFrame();
+ if (frame)
+ _vm->_system->copyRectToScreen((byte *)frame->pixels, frame->pitch, x, y, frame->w, frame->h);
+
+ if (_decoder->hasDirtyPalette())
+ _decoder->setSystemPalette();
+
+ Graphics::Surface *screen = _vm->_system->lockScreen();
+ performPostProcessing((byte *)screen->pixels);
+ _vm->_system->unlockScreen();
+ _vm->_system->updateScreen();
+ }
+
+ Common::Event event;
+ while (_vm->_system->getEventManager()->pollEvent(event))
+ if ((event.type == Common::EVENT_KEYDOWN && event.kbd.keycode == Common::KEYCODE_ESCAPE) || event.type == Common::EVENT_LBUTTONUP)
+ return false;
+ }
+
+ return !_vm->shouldQuit();
}
-int32 DXADecoderWithSound::getAudioLag() {
- if (!_fileStream)
- return 0;
+byte MoviePlayer::findBlackPalIndex() {
+ return 0;
+}
- if (!_mixer->isSoundHandleActive(*_bgSoundHandle))
- return 0;
+byte MoviePlayer::findWhitePalIndex() {
+ return 0xff;
+}
- int32 frameDelay = getFrameDelay();
- int32 videoTime = (_videoInfo.currentFrame + 1) * frameDelay;
- int32 audioTime;
+DXADecoderWithSound::DXADecoderWithSound(Audio::Mixer *mixer, Audio::SoundHandle *bgSoundHandle)
+ : _mixer(mixer), _bgSoundHandle(bgSoundHandle) {
+}
- const Audio::Timestamp ts = _mixer->getElapsedTime(*_bgSoundHandle);
- audioTime = ts.convertToFramerate(100000).totalNumberOfFrames();
+uint32 DXADecoderWithSound::getElapsedTime() const {
+ if (_mixer->isSoundHandleActive(*_bgSoundHandle))
+ return _mixer->getSoundElapsedTime(*_bgSoundHandle);
- return videoTime - audioTime;
+ return VideoDecoder::getElapsedTime();
}
///////////////////////////////////////////////////////////////////////////////
diff --git a/engines/sword1/animation.h b/engines/sword1/animation.h
index e97fc083f6..82343f2800 100644
--- a/engines/sword1/animation.h
+++ b/engines/sword1/animation.h
@@ -28,7 +28,7 @@
#include "graphics/video/dxa_decoder.h"
#include "graphics/video/smk_decoder.h"
-#include "graphics/video/video_player.h"
+#include "graphics/video/video_decoder.h"
#include "common/array.h"
@@ -64,18 +64,20 @@ public:
DXADecoderWithSound(Audio::Mixer *mixer, Audio::SoundHandle *bgSoundHandle);
~DXADecoderWithSound() {}
- int32 getAudioLag();
+ uint32 getElapsedTime() const;
+
private:
Audio::Mixer *_mixer;
Audio::SoundHandle *_bgSoundHandle;
};
-class MoviePlayer : public Graphics::VideoPlayer {
+class MoviePlayer {
public:
MoviePlayer(SwordEngine *vm, Text *textMan, Audio::Mixer *snd, OSystem *system, Audio::SoundHandle *bgSoundHandle, Graphics::VideoDecoder *decoder, DecoderType decoderType);
virtual ~MoviePlayer();
bool load(uint32 id);
void play();
+
protected:
SwordEngine *_vm;
Text *_textMan;
@@ -85,10 +87,15 @@ protected:
int _textX, _textY, _textWidth, _textHeight;
DecoderType _decoderType;
+ Graphics::VideoDecoder *_decoder;
Audio::SoundHandle *_bgSoundHandle;
Audio::AudioStream *_bgSoundStream;
+ bool playVideo();
void performPostProcessing(byte *screen);
+
+ byte findBlackPalIndex();
+ byte findWhitePalIndex();
};
MoviePlayer *makeMoviePlayer(uint32 id, SwordEngine *vm, Text *textMan, Audio::Mixer *snd, OSystem *system);
diff --git a/engines/sword2/animation.cpp b/engines/sword2/animation.cpp
index 1c5c2e5f8c..c3f3e796b2 100644
--- a/engines/sword2/animation.cpp
+++ b/engines/sword2/animation.cpp
@@ -47,9 +47,10 @@ namespace Sword2 {
///////////////////////////////////////////////////////////////////////////////
MoviePlayer::MoviePlayer(Sword2Engine *vm, Audio::Mixer *snd, OSystem *system, Audio::SoundHandle *bgSoundHandle, Graphics::VideoDecoder *decoder, DecoderType decoderType)
- : _vm(vm), _snd(snd), _bgSoundHandle(bgSoundHandle), _system(system), VideoPlayer(decoder) {
+ : _vm(vm), _snd(snd), _bgSoundHandle(bgSoundHandle), _system(system) {
_bgSoundStream = NULL;
_decoderType = decoderType;
+ _decoder = decoder;
}
MoviePlayer:: ~MoviePlayer() {
@@ -62,11 +63,10 @@ MoviePlayer:: ~MoviePlayer() {
* @param id the id of the file
*/
bool MoviePlayer::load(const char *name) {
- if (_decoderType == kVideoDecoderDXA) {
+ if (_decoderType == kVideoDecoderDXA)
_bgSoundStream = Audio::SeekableAudioStream::openStreamFile(name);
- } else {
+ else
_bgSoundStream = NULL;
- }
_textSurface = NULL;
@@ -97,13 +97,11 @@ void MoviePlayer::play(MovieText *movieTexts, uint32 numMovieTexts, uint32 leadI
_currentMovieText = 0;
_leadOut = leadOut;
- if (leadIn) {
+ if (leadIn)
_vm->_sound->playMovieSound(leadIn, kLeadInSound);
- }
- if (_bgSoundStream) {
+ if (_bgSoundStream)
_snd->playStream(Audio::Mixer::kSFXSoundType, _bgSoundHandle, _bgSoundStream);
- }
bool terminated = false;
@@ -186,12 +184,12 @@ void MoviePlayer::closeTextObject(uint32 index, byte *screen) {
for (int y = 0; y < text->_textSprite.h; y++) {
if (_textY + y < frameY || _textY + y >= frameY + frameHeight) {
- memset(dst + _textX, _decoder->getBlack(), text->_textSprite.w);
+ memset(dst + _textX, findBlackPalIndex(), text->_textSprite.w);
} else {
if (frameX > _textX)
- memset(dst + _textX, _decoder->getBlack(), frameX - _textX);
+ memset(dst + _textX, findBlackPalIndex(), frameX - _textX);
if (frameX + frameWidth < _textX + text->_textSprite.w)
- memset(dst + frameX + frameWidth, _decoder->getBlack(), _textX + text->_textSprite.w - (frameX + frameWidth));
+ memset(dst + frameX + frameWidth, findBlackPalIndex(), _textX + text->_textSprite.w - (frameX + frameWidth));
}
dst += _system->getWidth();
@@ -207,8 +205,8 @@ void MoviePlayer::closeTextObject(uint32 index, byte *screen) {
void MoviePlayer::drawTextObject(uint32 index, byte *screen) {
MovieText *text = &_movieTexts[index];
- byte white = _decoder->getWhite();
- byte black = _decoder->getBlack();
+ byte white = findWhitePalIndex();
+ byte black = findBlackPalIndex();
if (text->_textMem && _textSurface) {
byte *src = text->_textSprite.data;
@@ -240,7 +238,7 @@ void MoviePlayer::drawTextObject(uint32 index, byte *screen) {
void MoviePlayer::performPostProcessing(byte *screen) {
MovieText *text;
- int frame = _decoder->getCurFrame() + 1;
+ int frame = _decoder->getCurFrame();
if (_currentMovieText < _numMovieTexts) {
text = &_movieTexts[_currentMovieText];
@@ -272,25 +270,51 @@ void MoviePlayer::performPostProcessing(byte *screen) {
}
}
-DXADecoderWithSound::DXADecoderWithSound(Audio::Mixer *mixer, Audio::SoundHandle *bgSoundHandle)
- : _mixer(mixer), _bgSoundHandle(bgSoundHandle) {
+bool MoviePlayer::playVideo() {
+ uint16 x = (g_system->getWidth() - _decoder->getWidth()) / 2;
+ uint16 y = (g_system->getHeight() - _decoder->getHeight()) / 2;
+
+ while (!_vm->shouldQuit() && !_decoder->endOfVideo()) {
+ if (_decoder->needsUpdate()) {
+ Graphics::Surface *frame = _decoder->decodeNextFrame();
+ if (frame)
+ _vm->_system->copyRectToScreen((byte *)frame->pixels, frame->pitch, x, y, frame->w, frame->h);
+
+ if (_decoder->hasDirtyPalette())
+ _decoder->setSystemPalette();
+
+ Graphics::Surface *screen = _vm->_system->lockScreen();
+ performPostProcessing((byte *)screen->pixels);
+ _vm->_system->unlockScreen();
+ _vm->_system->updateScreen();
+ }
+
+ Common::Event event;
+ while (_vm->_system->getEventManager()->pollEvent(event))
+ if ((event.type == Common::EVENT_KEYDOWN && event.kbd.keycode == Common::KEYCODE_ESCAPE) || event.type == Common::EVENT_LBUTTONUP)
+ return false;
+ }
+
+ return !_vm->shouldQuit();
}
-int32 DXADecoderWithSound::getAudioLag() {
- if (!_fileStream)
- return 0;
+byte MoviePlayer::findBlackPalIndex() {
+ return 0;
+}
- if (!_mixer->isSoundHandleActive(*_bgSoundHandle))
- return 0;
+byte MoviePlayer::findWhitePalIndex() {
+ return 0xff;
+}
- int32 frameDelay = getFrameDelay();
- int32 videoTime = _videoInfo.currentFrame * frameDelay;
- int32 audioTime;
+DXADecoderWithSound::DXADecoderWithSound(Audio::Mixer *mixer, Audio::SoundHandle *bgSoundHandle)
+ : _mixer(mixer), _bgSoundHandle(bgSoundHandle) {
+}
- const Audio::Timestamp ts = _mixer->getElapsedTime(*_bgSoundHandle);
- audioTime = ts.convertToFramerate(100000).totalNumberOfFrames();
+uint32 DXADecoderWithSound::getElapsedTime() const {
+ if (_mixer->isSoundHandleActive(*_bgSoundHandle))
+ return _mixer->getSoundElapsedTime(*_bgSoundHandle);
- return videoTime - audioTime;
+ return VideoDecoder::getElapsedTime();
}
///////////////////////////////////////////////////////////////////////////////
diff --git a/engines/sword2/animation.h b/engines/sword2/animation.h
index 7f9ae0ff2d..bbf83e264c 100644
--- a/engines/sword2/animation.h
+++ b/engines/sword2/animation.h
@@ -30,7 +30,7 @@
#include "graphics/video/dxa_decoder.h"
#include "graphics/video/smk_decoder.h"
-#include "graphics/video/video_player.h"
+#include "graphics/video/video_decoder.h"
#include "sound/mixer.h"
#include "sword2/screen.h"
@@ -63,13 +63,13 @@ public:
DXADecoderWithSound(Audio::Mixer *mixer, Audio::SoundHandle *bgSoundHandle);
~DXADecoderWithSound() {}
- int32 getAudioLag();
+ uint32 getElapsedTime() const;
private:
Audio::Mixer *_mixer;
Audio::SoundHandle *_bgSoundHandle;
};
-class MoviePlayer : public Graphics::VideoPlayer {
+class MoviePlayer {
public:
MoviePlayer(Sword2Engine *vm, Audio::Mixer *snd, OSystem *system, Audio::SoundHandle *bgSoundHandle, Graphics::VideoDecoder *decoder, DecoderType decoderType);
virtual ~MoviePlayer();
@@ -89,6 +89,7 @@ protected:
int _textX, _textY;
DecoderType _decoderType;
+ Graphics::VideoDecoder *_decoder;
Audio::SoundHandle *_bgSoundHandle;
Audio::AudioStream *_bgSoundStream;
@@ -96,10 +97,14 @@ protected:
int _leadOutFrame;
void performPostProcessing(byte *screen);
+ bool playVideo();
void openTextObject(uint32 index);
void closeTextObject(uint32 index, byte *screen);
void drawTextObject(uint32 index, byte *screen);
+
+ byte findBlackPalIndex();
+ byte findWhitePalIndex();
};
MoviePlayer *makeMoviePlayer(const char *name, Sword2Engine *vm, Audio::Mixer *snd, OSystem *system);
diff --git a/engines/tucker/sequences.cpp b/engines/tucker/sequences.cpp
index 02cc695e7c..68f5301a80 100644
--- a/engines/tucker/sequences.cpp
+++ b/engines/tucker/sequences.cpp
@@ -537,9 +537,9 @@ void AnimationSequencePlayer::mainLoop() {
}
// budttle2.flc is shorter in french version ; start the background music
// earlier and skip any sounds effects
- if (_seqNum == 19 && _flicPlayer[0].getFrameCount() == 126) {
+ if (_seqNum == 19 && _flicPlayer[0].getFrameCount() == 127) {
_soundSeqDataIndex = 6;
- _frameCounter = 80;
+ _frameCounter = 79;
}
}
(this->*(_updateFunc[_updateFuncIndex].play))();
@@ -766,19 +766,21 @@ void AnimationSequencePlayer::openAnimation(int index, const char *fileName) {
}
bool AnimationSequencePlayer::decodeNextAnimationFrame(int index) {
- bool framesLeft = _flicPlayer[index].decodeNextFrame();
+ ::Graphics::Surface *surface = _flicPlayer[index].decodeNextFrame();
+
if (_seqNum == 19) {
- _flicPlayer[index].copyFrameToBuffer(_offscreenBuffer, 0, 0, kScreenWidth);
+ for (uint16 y = 0; (y < surface->h) && (y < kScreenHeight); y++)
+ memcpy(_offscreenBuffer + y * kScreenWidth, (byte *)surface->pixels + y * surface->pitch, surface->w);
} else {
_flicPlayer[index].copyDirtyRectsToBuffer(_offscreenBuffer, kScreenWidth);
}
+
++_frameCounter;
- if (index == 0) {
- if (_flicPlayer[index].paletteChanged()) {
- getRGBPalette(index);
- }
- }
- return framesLeft;
+
+ if (index == 0 && _flicPlayer[index].hasDirtyPalette())
+ getRGBPalette(index);
+
+ return !_flicPlayer[index].endOfVideo();
}
void AnimationSequencePlayer::loadIntroSeq17_18() {
@@ -803,20 +805,23 @@ void AnimationSequencePlayer::playIntroSeq19_20() {
// The intro credits animation. This uses 2 animations: the foreground one, which
// is the actual intro credits, and the background one, which is an animation of
// cogs, and is being replayed when an intro credit appears
- if (_flicPlayer[0].getCurFrame() >= 116) {
- if (!_flicPlayer[1].decodeNextFrame()) {
+ ::Graphics::Surface *surface = 0;
+
+ if (_flicPlayer[0].getCurFrame() >= 117) {
+ surface = _flicPlayer[1].decodeNextFrame();
+ if (_flicPlayer[1].endOfVideo())
_flicPlayer[1].reset();
- }
}
+
bool framesLeft = decodeNextAnimationFrame(0);
- for (int i = 0; i < kScreenWidth * kScreenHeight; ++i) {
- if (_offscreenBuffer[i] == 0) {
- _offscreenBuffer[i] = _flicPlayer[1].getPixel(i);
- }
- }
- if (!framesLeft) {
+
+ if (surface)
+ for (int i = 0; i < kScreenWidth * kScreenHeight; ++i)
+ if (_offscreenBuffer[i] == 0)
+ _offscreenBuffer[i] = *((byte *)surface->pixels + i);
+
+ if (!framesLeft)
_changeToNextSequence = true;
- }
}
void AnimationSequencePlayer::displayLoadingScreen() {
@@ -870,7 +875,7 @@ void AnimationSequencePlayer::loadIntroSeq3_4() {
void AnimationSequencePlayer::playIntroSeq3_4() {
if (!_updateScreenPicture) {
bool framesLeft = decodeNextAnimationFrame(0);
- if (_flicPlayer[0].getCurFrame() == 706) {
+ if (_flicPlayer[0].getCurFrame() == 707) {
initPicPart4();
}
if (!framesLeft) {
@@ -909,13 +914,21 @@ void AnimationSequencePlayer::drawPic2Part10() {
}
void AnimationSequencePlayer::drawPic1Part10() {
+ ::Graphics::Surface *surface = _flicPlayer[0].decodeNextFrame();
+ _flicPlayer[0].copyDirtyRectsToBuffer(_offscreenBuffer, kScreenWidth);
+ ++_frameCounter;
+
+ if (_flicPlayer[0].hasDirtyPalette())
+ getRGBPalette(0);
+
int offset = 0;
for (int y = 0; y < kScreenHeight; ++y) {
for (int x = 0; x < kScreenWidth; ++x) {
- byte color = _flicPlayer[0].getPixel(offset);
- if (color == 0) {
+ byte color = *((byte *)surface->pixels + offset);
+
+ if (color == 0)
color = _picBufPtr[800 + y * 640 + _updateScreenWidth + x];
- }
+
_offscreenBuffer[offset++] = color;
}
}
@@ -930,22 +943,22 @@ void AnimationSequencePlayer::loadIntroSeq9_10() {
}
void AnimationSequencePlayer::playIntroSeq9_10() {
- bool framesLeft = decodeNextAnimationFrame(0);
- if (_flicPlayer[0].getCurFrame() >= 264 && _flicPlayer[0].getCurFrame() <= 295) {
+ if (_flicPlayer[0].getCurFrame() >= 265 && _flicPlayer[0].getCurFrame() <= 296) {
drawPic1Part10();
_updateScreenWidth += 6;
- } else if (_flicPlayer[0].getCurFrame() == 984) {
+ } else if (_flicPlayer[0].getCurFrame() == 985) {
+ decodeNextAnimationFrame(0);
drawPic2Part10();
- } else if (_flicPlayer[0].getCurFrame() >= 988 && _flicPlayer[0].getCurFrame() <= 996) {
+ } else if (_flicPlayer[0].getCurFrame() >= 989 && _flicPlayer[0].getCurFrame() <= 997) {
drawPic1Part10();
_updateScreenWidth -= 25;
if (_updateScreenWidth < 0) {
_updateScreenWidth = 0;
}
}
- if (!framesLeft) {
+
+ if (_flicPlayer[0].endOfVideo())
_changeToNextSequence = true;
- }
}
void AnimationSequencePlayer::loadIntroSeq21_22() {