From 91cc02b0eebf17eaaaa410eb7469559ebc42a13d Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Thu, 1 Sep 2016 10:52:11 +0200 Subject: DIRECTOR: Cleanup --- engines/director/director.cpp | 9 ++++-- engines/director/director.h | 4 ++- engines/director/frame.cpp | 46 ++++++++++++++-------------- engines/director/score.cpp | 71 +++++++++++++++++++++++-------------------- engines/director/score.h | 1 + 5 files changed, 70 insertions(+), 61 deletions(-) (limited to 'engines') diff --git a/engines/director/director.cpp b/engines/director/director.cpp index e1f4ef1bdb..26b3387601 100644 --- a/engines/director/director.cpp +++ b/engines/director/director.cpp @@ -112,7 +112,9 @@ Common::Error DirectorEngine::run() { //_mainArchive = new RIFFArchive(); //_mainArchive->openFile("bookshelf_example.mmm"); - loadMMMNames(ConfMan.get("path")); + scanMovies(ConfMan.get("path")); + + loadSharedCastsFrom(_sharedCastFile); loadMainArchive(); _currentScore = new Score(this, _mainArchive); @@ -124,7 +126,7 @@ Common::Error DirectorEngine::run() { return Common::kNoError; } -Common::HashMap DirectorEngine::loadMMMNames(Common::String folder) { +Common::HashMap DirectorEngine::scanMovies(const Common::String &folder) { Common::FSNode directory(folder); Common::FSList movies; const char *sharedMMMname; @@ -142,8 +144,9 @@ Common::HashMap DirectorEngine::loadMMMNames(Common::St if (!movies.empty()) { for (Common::FSList::const_iterator i = movies.begin(); i != movies.end(); ++i) { debugC(2, kDebugLoading, "File: %s", i->getName().c_str()); + if (Common::matchString(i->getName().c_str(), sharedMMMname, true)) { - loadSharedCastsFrom(i->getName()); + _sharedCastFile = i->getName(); continue; } diff --git a/engines/director/director.h b/engines/director/director.h index 4cb8640d5b..f8207f49ce 100644 --- a/engines/director/director.h +++ b/engines/director/director.h @@ -102,7 +102,7 @@ protected: private: const DirectorGameDescription *_gameDescription; - Common::HashMap loadMMMNames(Common::String folder); + Common::HashMap scanMovies(const Common::String &folder); void loadEXE(); void loadEXEv3(Common::SeekableReadStream *stream); void loadEXEv4(Common::SeekableReadStream *stream); @@ -125,6 +125,8 @@ private: byte *_currentPalette; uint16 _currentPaletteLength; Lingo *_lingo; + + Common::String _sharedCastFile; }; } // End of namespace Director diff --git a/engines/director/frame.cpp b/engines/director/frame.cpp index 174581f336..421336d133 100644 --- a/engines/director/frame.cpp +++ b/engines/director/frame.cpp @@ -95,7 +95,7 @@ void Frame::readChannel(Common::SeekableSubReadStreamEndian &stream, uint16 offs if (size <= 16) readSprite(stream, offset, size); else { - //read > 1 sprites channel + // read > 1 sprites channel while (size > 16) { byte spritePosition = (offset - 32) / 16; uint16 nextStart = (spritePosition + 1) * 16 + 32; @@ -125,13 +125,13 @@ void Frame::readMainChannels(Common::SeekableSubReadStreamEndian &stream, uint16 offset++; break; case kTransFlagsPosition: { - uint8 transFlags = stream.readByte(); - if (transFlags & 0x80) - _transArea = 1; - else - _transArea = 0; - _transDuration = transFlags & 0x7f; - offset++; + uint8 transFlags = stream.readByte(); + if (transFlags & 0x80) + _transArea = 1; + else + _transArea = 0; + _transDuration = transFlags & 0x7f; + offset++; } break; case kTransChunkSizePosition: @@ -244,7 +244,7 @@ void Frame::readSprite(Common::SeekableSubReadStreamEndian &stream, uint16 offse fieldPosition += 2; break; default: - //end cycle, go to next sprite channel + // end of channel, go to next sprite channel readSprite(stream, spriteStart + 16, finishPosition - fieldPosition); fieldPosition = finishPosition; break; @@ -257,7 +257,7 @@ void Frame::prepareFrame(Score *score) { renderSprites(*score->_trailSurface, true); if (_transType != 0) - //TODO Handle changing area case + //T ODO Handle changing area case playTransition(score); if (_sound1 != 0 || _sound2 != 0) { @@ -268,16 +268,16 @@ void Frame::prepareFrame(Score *score) { } void Frame::playSoundChannel() { - debug(0, "Sound2 %d", _sound2); debug(0, "Sound1 %d", _sound1); + debug(0, "Sound2 %d", _sound2); } void Frame::playTransition(Score *score) { uint16 duration = _transDuration * 250; // _transDuration in 1/4 of sec - duration = (duration == 0 ? 250 : duration); // director support transition duration = 0, but animation play like value = 1, idk. + duration = (duration == 0 ? 250 : duration); // director supports transition duration = 0, but animation play like value = 1, idk. if (_transChunkSize == 0) - _transChunkSize = 1; //equal 1 step + _transChunkSize = 1; // equal to 1 step uint16 stepDuration = duration / _transChunkSize; uint16 steps = duration / stepDuration; @@ -428,6 +428,7 @@ void Frame::renderSprites(Graphics::ManagedSurface &surface, bool renderTrail) { warning("Cast id %d not found", _sprites[i]->_castId); continue; } else { + warning("Getting cast id %d from shared cast"); cast = _vm->getSharedCasts()->getVal(_sprites[i]->_castId); } } else { @@ -447,10 +448,7 @@ void Frame::renderSprites(Graphics::ManagedSurface &surface, bool renderTrail) { } if (!img->getSurface()) { - //TODO - //BMPDecoder doesnt cover all BITD resources (not all have first two bytes 'BM') - //Some BITD's first two bytes 0x6 0x0 - warning("Can not load image %d", _sprites[i]->_castId); + warning("Frame::renderSprites: Could not load image %d", _sprites[i]->_castId); continue; } @@ -472,7 +470,7 @@ void Frame::renderSprites(Graphics::ManagedSurface &surface, bool renderTrail) { surface.blitFrom(*img->getSurface(), Common::Point(x, y)); break; case kInkTypeTransparent: - //FIXME: is it always white (last entry in pallette)? + // FIXME: is it always white (last entry in pallette)? surface.transBlitFrom(*img->getSurface(), Common::Point(x, y), _vm->getPaletteColorCount() - 1); break; case kInkTypeBackgndTrans: @@ -512,7 +510,7 @@ void Frame::renderButton(Graphics::ManagedSurface &surface, uint16 spriteId) { switch (button->buttonType) { case kTypeCheckBox: - //Magic numbers: checkbox square need to move left about 5px from text and 12px side size (d4) + // Magic numbers: checkbox square need to move left about 5px from text and 12px side size (D4) surface.frameRect(Common::Rect(x - 17, y, x + 12, y + 12), 0); break; case kTypeButton: @@ -624,7 +622,7 @@ void Frame::renderText(Graphics::ManagedSurface &surface, uint16 spriteID) { if (textCast->borderSize != kSizeNone) { uint16 size = textCast->borderSize; - //Indent from borders, measured in d4 + // Indent from borders, measured in d4 x -= 1; y -= 4; @@ -662,7 +660,7 @@ void Frame::renderText(Graphics::ManagedSurface &surface, uint16 spriteID) { } void Frame::drawBackgndTransSprite(Graphics::ManagedSurface &target, const Graphics::Surface &sprite, Common::Rect &drawRect) { - uint8 skipColor = _vm->getPaletteColorCount() - 1; //FIXME is it always white (last entry in pallette) ? + uint8 skipColor = _vm->getPaletteColorCount() - 1; // FIXME is it always white (last entry in pallette) ? for (int ii = 0; ii < sprite.h; ii++) { const byte *src = (const byte *)sprite.getBasePtr(0, ii); @@ -686,7 +684,7 @@ void Frame::drawGhostSprite(Graphics::ManagedSurface &target, const Graphics::Su for (int j = 0; j < drawRect.width(); j++) { if ((getSpriteIDFromPos(Common::Point(drawRect.left + j, drawRect.top + ii)) != 0) && (*src != skipColor)) - *dst = (_vm->getPaletteColorCount() - 1) - *src; //Oposite color + *dst = (_vm->getPaletteColorCount() - 1) - *src; // Oposite color src++; dst++; @@ -772,7 +770,7 @@ void Frame::drawMatteSprite(Graphics::ManagedSurface &target, const Graphics::Su } uint16 Frame::getSpriteIDFromPos(Common::Point pos) { - //Find first from top to bottom + // Find first from top to bottom for (uint16 i = _drawRects.size() - 1; i > 0; i--) { if (_drawRects[i].contains(pos)) return i; @@ -781,4 +779,4 @@ uint16 Frame::getSpriteIDFromPos(Common::Point pos) { return 0; } -} //End of namespace Director +} // End of namespace Director diff --git a/engines/director/score.cpp b/engines/director/score.cpp index 90506519ac..2d3ae798bd 100644 --- a/engines/director/score.cpp +++ b/engines/director/score.cpp @@ -160,7 +160,6 @@ void Score::loadArchive() { } Common::Array vwci = _movieArchive->getResourceIDList(MKTAG('V','W','C','I')); - if (vwci.size() > 0) { Common::Array::iterator iterator; @@ -169,7 +168,6 @@ void Score::loadArchive() { } Common::Array stxt = _movieArchive->getResourceIDList(MKTAG('S','T','X','T')); - if (stxt.size() > 0) { loadScriptText(*_movieArchive->getResource(MKTAG('S','T','X','T'), *stxt.begin())); } @@ -218,6 +216,8 @@ void Score::loadFrames(Common::SeekableSubReadStreamEndian &stream) { if (_vm->getVersion() > 3) { stream.skip(16); + + warning("STUB: Score::loadFrames. Skipping initial bytes"); //Unknown, some bytes - constant (refer to contuinity). } @@ -244,7 +244,6 @@ void Score::loadFrames(Common::SeekableSubReadStreamEndian &stream) { frameSize -= channelSize + 4; } frame->readChannel(stream, channelOffset, channelSize); - } _frames.push_back(frame); @@ -409,10 +408,10 @@ void Score::loadScriptText(Common::SeekableSubReadStreamEndian &stream) { for (uint32 i = 0; i < strLen; i++) { byte ch = stream.readByte(); - if (ch == 0x0d) { - //in old Mac systems \r was the code for end-of-line instead. + // Convert Mac line endings + if (ch == 0x0d) ch = '\n'; - } + script += ch; } @@ -496,8 +495,8 @@ void Score::loadCastInfo(Common::SeekableSubReadStreamEndian &stream, uint16 id) } void Score::gotoloop() { - //This command has the playback head contonuously return to the first marker to to the left and then loop back. - //If no marker are to the left of the playback head, the playback head continues to the right. + // This command has the playback head contonuously return to the first marker to to the left and then loop back. + // If no marker are to the left of the playback head, the playback head continues to the right. Common::SortedArray