From 3778d8619f7cef27f400a550b75547b0968467a7 Mon Sep 17 00:00:00 2001 From: Sven Hesse Date: Tue, 21 Aug 2007 20:44:32 +0000 Subject: Fixed the cutscenes in the CD version of Lost in Time (There's still something wrong with the second one, the one with the agent, though. Probably has to do with the sound key command 10) svn-id: r28693 --- engines/gob/cdrom.cpp | 75 +++++++++++++++++++++++++++++++----------------- engines/gob/cdrom.h | 7 +++-- engines/gob/inter_v2.cpp | 2 +- 3 files changed, 54 insertions(+), 30 deletions(-) diff --git a/engines/gob/cdrom.cpp b/engines/gob/cdrom.cpp index 2ee8595ad3..1c26199bc1 100644 --- a/engines/gob/cdrom.cpp +++ b/engines/gob/cdrom.cpp @@ -151,40 +151,27 @@ void CDROM::playMultMusic() { } } -void CDROM::startTrack(const char *trackname) { - byte *curPtr, *matchPtr; - +void CDROM::startTrack(const char *trackName) { if (!_LICbuffer) return; - debugC(1, kDebugMusic, "CDROM::startTrack(%s)", trackname); - - matchPtr = 0; - curPtr = _LICbuffer; - - for (int i = 0; i < _numTracks; i++) { - if (!scumm_stricmp((char *)curPtr, trackname)) { - matchPtr = curPtr; - break; - } - curPtr += 22; - } + debugC(1, kDebugMusic, "CDROM::startTrack(%s)", trackName); + byte *matchPtr = getTrackBuffer(trackName); if (!matchPtr) { - warning("Track \"%s\" not found", trackname); + warning("Track \"%s\" not found", trackName); return; } - strncpy0(_curTrack, trackname, 15); + strncpy0(_curTrack, trackName, 15); stopPlaying(); + _curTrackBuffer = matchPtr; - while (getTrackPos() != -1); - - uint32 start, end; + while (getTrackPos() >= 0); - start = READ_LE_UINT32(matchPtr + 12); - end = READ_LE_UINT32(matchPtr + 16); + uint32 start = READ_LE_UINT32(matchPtr + 12); + uint32 end = READ_LE_UINT32(matchPtr + 16); play(start, end); @@ -205,12 +192,27 @@ void CDROM::play(uint32 from, uint32 to) { _cdPlaying = true; } -int32 CDROM::getTrackPos() { - uint32 curPos = _vm->_util->getTimeKey() - _startTime; +int32 CDROM::getTrackPos(const char *keyTrack) { + byte *keyBuffer = getTrackBuffer(keyTrack); + uint32 curPos = (_vm->_util->getTimeKey() - _startTime) * 3 / 40; + + if (_cdPlaying && (_vm->_util->getTimeKey() < _trackStop)) { + if (keyBuffer && _curTrackBuffer && (keyBuffer != _curTrackBuffer)) { + uint32 kStart = READ_LE_UINT32(keyBuffer + 12); + uint32 kEnd = READ_LE_UINT32(keyBuffer + 16); + uint32 cStart = READ_LE_UINT32(_curTrackBuffer + 12); + uint32 cEnd = READ_LE_UINT32(_curTrackBuffer + 16); + + if ((kStart >= cStart) && (kEnd <= cEnd)) { + if ((kStart - cStart) > curPos) + return -2; + if ((kEnd - cStart) < curPos) + return -1; + } + } - if (_cdPlaying && (_vm->_util->getTimeKey() < _trackStop)) - return curPos * 3 / 40; - else + return curPos; + } else return -1; } @@ -227,6 +229,7 @@ void CDROM::stopPlaying() { void CDROM::stop() { debugC(1, kDebugMusic, "CDROM::stop()"); + _curTrackBuffer = 0; AudioCD.stop(); _cdPlaying = false; } @@ -245,4 +248,22 @@ void CDROM::testCD(int trySubst, const char *label) { // CD secor reading } +byte *CDROM::getTrackBuffer(const char *trackName) { + if (!_LICbuffer || !trackName) + return 0; + + byte *matchPtr = 0; + byte *curPtr = _LICbuffer; + + for (int i = 0; i < _numTracks; i++) { + if (!scumm_stricmp((char *) curPtr, trackName)) { + matchPtr = curPtr; + break; + } + curPtr += 22; + } + + return matchPtr; +} + } // End of namespace Gob diff --git a/engines/gob/cdrom.h b/engines/gob/cdrom.h index e977adcd6d..f847addaeb 100644 --- a/engines/gob/cdrom.h +++ b/engines/gob/cdrom.h @@ -35,11 +35,11 @@ public: void readLIC(const char *fname); void freeLICbuffer(); - void startTrack(const char *s); + void startTrack(const char *trackName); void playBgMusic(); void playMultMusic(); void play(uint32 from, uint32 to); - int32 getTrackPos(); + int32 getTrackPos(const char *keyTrack = 0); const char *getCurTrack(); void stopPlaying(); void stop(); @@ -49,11 +49,14 @@ public: protected: byte *_LICbuffer; + byte *_curTrackBuffer; char _curTrack[16]; uint16 _numTracks; uint32 _trackStop; uint32 _startTime; GobEngine *_vm; + + byte *getTrackBuffer(const char *trackName); }; } // End of namespace Gob diff --git a/engines/gob/inter_v2.cpp b/engines/gob/inter_v2.cpp index f51578f20b..b2ca8716be 100644 --- a/engines/gob/inter_v2.cpp +++ b/engines/gob/inter_v2.cpp @@ -1105,7 +1105,7 @@ void Inter_v2::o2_getCDTrackPos() { varPos = _vm->_parse->parseVarIndex(); varName = _vm->_parse->parseVarIndex(); - WRITE_VAR_OFFSET(varPos, _vm->_cdrom->getTrackPos()); + WRITE_VAR_OFFSET(varPos, _vm->_cdrom->getTrackPos(GET_VARO_STR(varName))); WRITE_VARO_STR(varName, _vm->_cdrom->getCurTrack()); } -- cgit v1.2.3