aboutsummaryrefslogtreecommitdiff
path: root/engines/agos/animation.cpp
diff options
context:
space:
mode:
authorMatthew Hoops2010-05-18 14:17:24 +0000
committerMatthew Hoops2010-05-18 14:17:24 +0000
commit11cbdd03180a655b2b23ee4a13f1a00a1d782b3c (patch)
tree5b0d84211308ea37a2fa2f7017d6f96314f3c6fb /engines/agos/animation.cpp
parentf3892a506b2f935bae0be6319394c503c786d368 (diff)
downloadscummvm-rg350-11cbdd03180a655b2b23ee4a13f1a00a1d782b3c.tar.gz
scummvm-rg350-11cbdd03180a655b2b23ee4a13f1a00a1d782b3c.tar.bz2
scummvm-rg350-11cbdd03180a655b2b23ee4a13f1a00a1d782b3c.zip
Committing the rest of the VideoDecoder Rewrite from patch #2963496.
svn-id: r49079
Diffstat (limited to 'engines/agos/animation.cpp')
-rw-r--r--engines/agos/animation.cpp117
1 files changed, 62 insertions, 55 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());