diff options
-rw-r--r-- | engines/director/cast.cpp | 27 | ||||
-rw-r--r-- | engines/director/cast.h | 7 | ||||
-rw-r--r-- | engines/director/frame.cpp | 26 | ||||
-rw-r--r-- | engines/director/lingo/lingo-code.cpp | 7 | ||||
-rw-r--r-- | engines/director/lingo/lingo-the.cpp | 16 | ||||
-rw-r--r-- | engines/director/lingo/lingo.cpp | 7 | ||||
-rw-r--r-- | engines/director/score.cpp | 280 | ||||
-rw-r--r-- | engines/director/score.h | 8 | ||||
-rw-r--r-- | engines/director/sprite.cpp | 20 | ||||
-rw-r--r-- | engines/director/sprite.h | 7 |
10 files changed, 169 insertions, 236 deletions
diff --git a/engines/director/cast.cpp b/engines/director/cast.cpp index e7f30d8461..6e87c7a6de 100644 --- a/engines/director/cast.cpp +++ b/engines/director/cast.cpp @@ -31,6 +31,8 @@ namespace Director { BitmapCast::BitmapCast(Common::ReadStreamEndian &stream, uint32 castTag, uint16 version) { + _type = kCastBitmap; + if (version < 4) { _pitch = 0; _flags = stream.readByte(); // region: 0 - auto, 1 - matte, 2 - disabled @@ -106,6 +108,8 @@ BitmapCast::BitmapCast(Common::ReadStreamEndian &stream, uint32 castTag, uint16 } TextCast::TextCast(Common::ReadStreamEndian &stream, uint16 version) { + _type = kCastText; + _borderSize = kSizeNone; _gutterSize = kSizeNone; _boxShadow = kSizeNone; @@ -260,6 +264,8 @@ void TextCast::setText(const char *text) { } ShapeCast::ShapeCast(Common::ReadStreamEndian &stream, uint16 version) { + _type = kCastShape; + byte flags, unk1; _ink = kInkTypeCopy; @@ -300,6 +306,8 @@ ShapeCast::ShapeCast(Common::ReadStreamEndian &stream, uint16 version) { } ButtonCast::ButtonCast(Common::ReadStreamEndian &stream, uint16 version) : TextCast(stream, version) { + _type = kCastButton; + if (version < 4) { _buttonType = static_cast<ButtonType>(stream.readUint16BE()); } else { @@ -316,6 +324,8 @@ ButtonCast::ButtonCast(Common::ReadStreamEndian &stream, uint16 version) : TextC } ScriptCast::ScriptCast(Common::ReadStreamEndian &stream, uint16 version) { + _type = kCastLingoScript; + if (version < 4) { error("Unhandled Script cast"); } else if (version == 4) { @@ -347,4 +357,21 @@ ScriptCast::ScriptCast(Common::ReadStreamEndian &stream, uint16 version) { _modified = 0; } +RTECast::RTECast(Common::ReadStreamEndian &stream, uint16 version) : TextCast(stream, version) { + + _type = kCastRTE; +} + +void RTECast::loadChunks() { + //TODO: Actually load RTEs correctly, don't just make fake STXT. +#if 0 + Common::SeekableReadStream *rte1 = _movieArchive->getResource(res->children[child].tag, res->children[child].index); + byte *buffer = new byte[rte1->size() + 2]; + rte1->read(buffer, rte1->size()); + buffer[rte1->size()] = '\n'; + buffer[rte1->size() + 1] = '\0'; + _loadedText->getVal(id)->importRTE(buffer); +#endif +} + } // End of namespace Director diff --git a/engines/director/cast.h b/engines/director/cast.h index 9e80545353..03767ecea2 100644 --- a/engines/director/cast.h +++ b/engines/director/cast.h @@ -123,6 +123,13 @@ public: uint32 _id; }; +class RTECast : public TextCast { +public: + RTECast(Common::ReadStreamEndian &stream, uint16 version); + + void loadChunks(); +}; + struct CastInfo { Common::String script; Common::String name; diff --git a/engines/director/frame.cpp b/engines/director/frame.cpp index ccd82c63d5..0770f7656c 100644 --- a/engines/director/frame.cpp +++ b/engines/director/frame.cpp @@ -626,23 +626,25 @@ void Frame::renderSprites(Graphics::ManagedSurface &surface, bool renderTrail) { } else if (castType == kCastButton) { renderButton(surface, i); } else { - if (!_sprites[i]->_bitmapCast) { + if (!_sprites[i]->_cast || _sprites[i]->_cast->_type != kCastBitmap) { warning("Frame::renderSprites(): No cast ID for sprite %d", i); continue; } - int32 regX = _sprites[i]->_bitmapCast->_regX; - int32 regY = _sprites[i]->_bitmapCast->_regY; - int32 rectLeft = _sprites[i]->_bitmapCast->_initialRect.left; - int32 rectTop = _sprites[i]->_bitmapCast->_initialRect.top; + BitmapCast *bc = (BitmapCast *)_sprites[i]->_cast; + + int32 regX = bc->_regX; + int32 regY = bc->_regY; + int32 rectLeft = bc->_initialRect.left; + int32 rectTop = bc->_initialRect.top; int x = _sprites[i]->_startPoint.x - regX + rectLeft; int y = _sprites[i]->_startPoint.y - regY + rectTop; int height = _sprites[i]->_height; - int width = _vm->getVersion() > 4 ? _sprites[i]->_bitmapCast->_initialRect.width() : _sprites[i]->_width; + int width = _vm->getVersion() > 4 ? bc->_initialRect.width() : _sprites[i]->_width; Common::Rect drawRect(x, y, x + width, y + height); addDrawRect(i, drawRect); - inkBasedBlit(surface, *(_sprites[i]->_bitmapCast->_surface), i, drawRect); + inkBasedBlit(surface, *(bc->_surface), i, drawRect); } } } @@ -658,9 +660,9 @@ void Frame::addDrawRect(uint16 spriteId, Common::Rect &rect) { void Frame::renderShape(Graphics::ManagedSurface &surface, uint16 spriteId) { Sprite *sp = _sprites[spriteId]; - if (sp->_shapeCast != NULL) { - sp->_foreColor = sp->_shapeCast->_fgCol; - sp->_backColor = sp->_shapeCast->_bgCol; + if (sp->_cast != NULL) { + sp->_foreColor = ((ShapeCast *)sp->_cast)->_fgCol; + sp->_backColor = ((ShapeCast *)sp->_cast)->_bgCol; //sp->_ink = sp->_shapeCast->_ink; } @@ -717,7 +719,7 @@ void Frame::renderShape(Graphics::ManagedSurface &surface, uint16 spriteId) { void Frame::renderButton(Graphics::ManagedSurface &surface, uint16 spriteId) { uint16 castId = _sprites[spriteId]->_castId; - ButtonCast *button = _vm->getCurrentScore()->_loadedButtons->getVal(castId); + ButtonCast *button = (ButtonCast *)_vm->getCurrentScore()->_loadedCast->getVal(castId); uint32 rectLeft = button->_initialRect.left; uint32 rectTop = button->_initialRect.top; @@ -760,7 +762,7 @@ void Frame::renderButton(Graphics::ManagedSurface &surface, uint16 spriteId) { } void Frame::renderText(Graphics::ManagedSurface &surface, uint16 spriteId, Common::Rect *textSize) { - TextCast *textCast = _sprites[spriteId]->_buttonCast != nullptr ? (TextCast*)_sprites[spriteId]->_buttonCast : _sprites[spriteId]->_textCast; + TextCast *textCast = (TextCast*)_sprites[spriteId]->_cast; int x = _sprites[spriteId]->_startPoint.x; // +rectLeft; int y = _sprites[spriteId]->_startPoint.y; // +rectTop; diff --git a/engines/director/lingo/lingo-code.cpp b/engines/director/lingo/lingo-code.cpp index 57eae5112c..c4ee5feeb1 100644 --- a/engines/director/lingo/lingo-code.cpp +++ b/engines/director/lingo/lingo-code.cpp @@ -337,8 +337,9 @@ void Lingo::c_assign() { } if (d1.type == REFERENCE) { - if (!g_director->getCurrentScore()->_loadedText->contains(d1.u.i)) { - if (!g_director->getCurrentScore()->_loadedText->contains(d1.u.i - 1024)) { + Score *score = g_director->getCurrentScore(); + if (!score->_loadedCast->contains(d1.u.i)) { + if (!score->_loadedCast->contains(d1.u.i - score->_castIDoffset)) { warning("c_assign: Unknown REFERENCE %d", d1.u.i); g_lingo->pushVoid(); return; @@ -349,7 +350,7 @@ void Lingo::c_assign() { d2.toString(); - g_director->getCurrentScore()->_loadedText->getVal(d1.u.i)->setText(d2.u.s->c_str()); + ((TextCast *)score->_loadedCast->getVal(d1.u.i))->setText(d2.u.s->c_str()); return; } diff --git a/engines/director/lingo/lingo-the.cpp b/engines/director/lingo/lingo-the.cpp index a987f9c3c2..09a9fc8a55 100644 --- a/engines/director/lingo/lingo-the.cpp +++ b/engines/director/lingo/lingo-the.cpp @@ -704,7 +704,7 @@ Datum Lingo::getTheCast(Datum &id1, int field) { return d; } - ShapeCast *shape = _vm->getCurrentScore()->_loadedShapes->getVal(id); + ShapeCast *shape = (ShapeCast *)_vm->getCurrentScore()->_loadedCast->getVal(id); d.u.i = shape->_bgCol; } break; @@ -716,7 +716,7 @@ Datum Lingo::getTheCast(Datum &id1, int field) { return d; } - ShapeCast *shape = _vm->getCurrentScore()->_loadedShapes->getVal(id); + ShapeCast *shape = (ShapeCast *)_vm->getCurrentScore()->_loadedCast->getVal(id); d.u.i = shape->_fgCol; } break; @@ -797,7 +797,7 @@ void Lingo::setTheCast(Datum &id1, int field, Datum &d) { if (castType != kCastShape) { warning("Lingo::setTheCast(): Field %d of cast %d not found", field, id); } - ShapeCast *shape = score->_loadedShapes->getVal(id); + ShapeCast *shape = (ShapeCast *)score->_loadedCast->getVal(id); d.toInt(); shape->_bgCol = d.u.i; @@ -810,19 +810,19 @@ void Lingo::setTheCast(Datum &id1, int field, Datum &d) { warning("Lingo::setTheCast(): Field %d of cast %d not found", field, id); return; } - ShapeCast *shape = score->_loadedShapes->getVal(id); + ShapeCast *shape = (ShapeCast *)score->_loadedCast->getVal(id); shape->_fgCol = d.u.i; shape->_modified = 1; } break; case kTheText: if (castType == kCastText) { - if (!score->_loadedText->contains(id)) { + if (score->_loadedCast->contains(id) && score->_loadedCast->getVal(id)->_type == kCastText) { + d.toString(); + ((TextCast *)score->_loadedCast->getVal(id))->setText(d.u.s->c_str()); + } else { warning("Lingo::setTheCast(): Unknown STXT cast id %d", id); return; - } else { - d.toString(); - score->_loadedText->getVal(id)->setText(d.u.s->c_str()); } } else { warning("Lingo::setTheCast(): Unprocessed setting text of cast %d type %d", id, castType); diff --git a/engines/director/lingo/lingo.cpp b/engines/director/lingo/lingo.cpp index 9c94bc6a96..3f9f4fc204 100644 --- a/engines/director/lingo/lingo.cpp +++ b/engines/director/lingo/lingo.cpp @@ -378,9 +378,10 @@ Common::String *Datum::toString() { case REFERENCE: { int idx = u.i; + Score *score = g_director->getCurrentScore(); - if (!g_director->getCurrentScore()->_loadedText->contains(idx)) { - if (!g_director->getCurrentScore()->_loadedText->contains(idx - 1024)) { + if (!score->_loadedCast->contains(idx)) { + if (!score->_loadedCast->contains(idx - score->_castIDoffset)) { warning("toString(): Unknown REFERENCE %d", idx); *s = ""; break; @@ -389,7 +390,7 @@ Common::String *Datum::toString() { } } - *s = g_director->getCurrentScore()->_loadedText->getVal(idx)->_ptext; + *s = ((TextCast *)score->_loadedCast->getVal(idx))->_ptext; } break; default: diff --git a/engines/director/score.cpp b/engines/director/score.cpp index 17d6b8d11c..10a13d8aaa 100644 --- a/engines/director/score.cpp +++ b/engines/director/score.cpp @@ -95,12 +95,8 @@ Score::Score(DirectorEngine *vm) { _castIDoffset = 0; - _loadedBitmaps = new Common::HashMap<int, BitmapCast *>(); - _loadedText = new Common::HashMap<int, TextCast *>(); - _loadedButtons = new Common::HashMap<int, ButtonCast *>(); - _loadedShapes = new Common::HashMap<int, ShapeCast *>(); - _loadedScripts = new Common::HashMap<int, ScriptCast *>(); _loadedStxts = new Common::HashMap<int, const Stxt *>(); + _loadedCast = new Common::HashMap<int, Cast *>(); } void Score::setArchive(Archive *archive) { @@ -270,30 +266,18 @@ void Score::loadArchive() { } void Score::copyCastStxts() { - debugC(2, kDebugLoading,"######### copyCastStxts(), %d texts", _loadedText->size()); - Common::HashMap<int, TextCast *>::iterator tc; - for (tc = _loadedText->begin(); tc != _loadedText->end(); ++tc) { - uint stxtid = (_vm->getVersion() < 4) ? - tc->_key + _castIDoffset : - tc->_value->_children[0].index; - if (_loadedStxts->getVal(stxtid)) { - const Stxt *stxt = _loadedStxts->getVal(stxtid); - tc->_value->importStxt(stxt); - } - } + for (Common::HashMap<int, Cast *>::iterator c = _loadedCast->begin(); c != _loadedCast->end(); ++c) { + if (c->_value->_type != kCastText && c->_value->_type != kCastButton) + continue; - debugC(2, kDebugLoading,"######### copyCastStxts(), %d buttons", _loadedButtons->size()); - Common::HashMap<int, ButtonCast *>::iterator bc; - for (bc = _loadedButtons->begin(); bc != _loadedButtons->end(); ++bc) { uint stxtid = (_vm->getVersion() < 4) ? - bc->_key + _castIDoffset : - bc->_value->_children[0].index; + c->_key + _castIDoffset : + c->_value->_children[0].index; + if (_loadedStxts->getVal(stxtid)) { - debugC(3, "Yes to STXT: %d", stxtid); const Stxt *stxt = _loadedStxts->getVal(stxtid); - bc->_value->importStxt(stxt); - } else { - debugC(3, "No to STXT: %d", stxtid); + TextCast *tc = (TextCast *)c->_value; + tc->importStxt(stxt); } } } @@ -301,67 +285,70 @@ void Score::copyCastStxts() { void Score::loadSpriteImages(bool isSharedCast) { debugC(1, kDebugLoading, "****** Preloading sprite images"); - Common::HashMap<int, BitmapCast *>::iterator bc; - for (bc = _loadedBitmaps->begin(); bc != _loadedBitmaps->end(); ++bc) { - if (bc->_value) { - uint32 tag = bc->_value->_tag; - uint16 imgId = (uint16)(bc->_key + _castIDoffset); - BitmapCast *bitmapCast = bc->_value; + for (Common::HashMap<int, Cast *>::iterator c = _loadedCast->begin(); c != _loadedCast->end(); ++c) { + if (!c->_value) + continue; - if (_vm->getVersion() >= 4 && bitmapCast->_children.size() > 0) { - imgId = bitmapCast->_children[0].index; - tag = bitmapCast->_children[0].tag; - } + if (c->_value->_type != kCastBitmap) + continue; - Image::ImageDecoder *img = NULL; - Common::SeekableReadStream *pic = NULL; - - switch (tag) { - case MKTAG('D', 'I', 'B', ' '): - if (_movieArchive->hasResource(MKTAG('D', 'I', 'B', ' '), imgId)) { - debugC(2, kDebugLoading, "****** Loading 'DIB ' id: %d", imgId); - img = new DIBDecoder(); - img->loadStream(*_movieArchive->getResource(MKTAG('D', 'I', 'B', ' '), imgId)); - bitmapCast->_surface = img->getSurface(); - } else if (isSharedCast && _vm->getSharedDIB() != NULL && _vm->getSharedDIB()->contains(imgId)) { - debugC(2, kDebugLoading, "****** Loading 'DIB ' id: %d from shared cast", imgId); - img = new DIBDecoder(); - img->loadStream(*_vm->getSharedDIB()->getVal(imgId)); - bitmapCast->_surface = img->getSurface(); - } - break; - case MKTAG('B', 'I', 'T', 'D'): - if (isSharedCast) { - debugC(2, kDebugLoading, "****** Loading 'BITD' id: %d from shared cast", imgId); - pic = _vm->getSharedBMP()->getVal(imgId); - if (pic != NULL) - pic->seek(0); // TODO: this actually gets re-read every loop... we need to rewind it! - } else if (_movieArchive->hasResource(MKTAG('B', 'I', 'T', 'D'), imgId)) { - debugC(2, kDebugLoading, "****** Loading 'BITD' id: %d", imgId); - pic = _movieArchive->getResource(MKTAG('B', 'I', 'T', 'D'), imgId); - } - break; - default: - warning("Unknown Bitmap Cast Tag: [%d] %s", tag, tag2str(tag)); - break; - } + BitmapCast *bitmapCast = (BitmapCast *)c->_value; + uint32 tag = bitmapCast->_tag; + uint16 imgId = (uint16)(c->_key + _castIDoffset); - int w = bitmapCast->_initialRect.width(), h = bitmapCast->_initialRect.height(); - debugC(4, kDebugImages, "Score::loadSpriteImages(): id: %d, w: %d, h: %d, flags: %x, bytes: %x, bpp: %d clut: %x", - imgId, w, h, bitmapCast->_flags, bitmapCast->_bytes, bitmapCast->_bitsPerPixel, bitmapCast->_clut); + if (_vm->getVersion() >= 4 && bitmapCast->_children.size() > 0) { + imgId = bitmapCast->_children[0].index; + tag = bitmapCast->_children[0].tag; + } - if (pic != NULL && bitmapCast != NULL && w > 0 && h > 0) { - if (_vm->getVersion() < 6) { - img = new BITDDecoder(w, h, bitmapCast->_bitsPerPixel, bitmapCast->_pitch); - } else { - img = new Image::BitmapDecoder(); - } + Image::ImageDecoder *img = NULL; + Common::SeekableReadStream *pic = NULL; - img->loadStream(*pic); + switch (tag) { + case MKTAG('D', 'I', 'B', ' '): + if (_movieArchive->hasResource(MKTAG('D', 'I', 'B', ' '), imgId)) { + debugC(2, kDebugLoading, "****** Loading 'DIB ' id: %d", imgId); + img = new DIBDecoder(); + img->loadStream(*_movieArchive->getResource(MKTAG('D', 'I', 'B', ' '), imgId)); + bitmapCast->_surface = img->getSurface(); + } else if (isSharedCast && _vm->getSharedDIB() != NULL && _vm->getSharedDIB()->contains(imgId)) { + debugC(2, kDebugLoading, "****** Loading 'DIB ' id: %d from shared cast", imgId); + img = new DIBDecoder(); + img->loadStream(*_vm->getSharedDIB()->getVal(imgId)); bitmapCast->_surface = img->getSurface(); + } + break; + case MKTAG('B', 'I', 'T', 'D'): + if (isSharedCast) { + debugC(2, kDebugLoading, "****** Loading 'BITD' id: %d from shared cast", imgId); + pic = _vm->getSharedBMP()->getVal(imgId); + if (pic != NULL) + pic->seek(0); // TODO: this actually gets re-read every loop... we need to rewind it! + } else if (_movieArchive->hasResource(MKTAG('B', 'I', 'T', 'D'), imgId)) { + debugC(2, kDebugLoading, "****** Loading 'BITD' id: %d", imgId); + pic = _movieArchive->getResource(MKTAG('B', 'I', 'T', 'D'), imgId); + } + break; + default: + warning("Unknown Bitmap Cast Tag: [%d] %s", tag, tag2str(tag)); + break; + } + + int w = bitmapCast->_initialRect.width(), h = bitmapCast->_initialRect.height(); + debugC(4, kDebugImages, "Score::loadSpriteImages(): id: %d, w: %d, h: %d, flags: %x, bytes: %x, bpp: %d clut: %x", + imgId, w, h, bitmapCast->_flags, bitmapCast->_bytes, bitmapCast->_bitsPerPixel, bitmapCast->_clut); + + if (pic != NULL && bitmapCast != NULL && w > 0 && h > 0) { + if (_vm->getVersion() < 6) { + img = new BITDDecoder(w, h, bitmapCast->_bitsPerPixel, bitmapCast->_pitch); } else { - warning("Image %d not found", imgId); + img = new Image::BitmapDecoder(); } + + img->loadStream(*pic); + bitmapCast->_surface = img->getSurface(); + } else { + warning("Image %d not found", imgId); } } } @@ -387,6 +374,7 @@ Score::~Score() { delete _font; delete _labels; delete _loadedStxts; + delete _loadedCast; } void Score::loadPalette(Common::SeekableSubReadStreamEndian &stream) { @@ -577,22 +565,22 @@ void Score::loadCastDataVWCR(Common::SeekableSubReadStreamEndian &stream) { case kCastBitmap: debugC(3, kDebugLoading, "Score::loadCastDataVWCR(): CastTypes id: %d(%s) BitmapCast", id, numToCastNum(id)); // TODO: Work out the proper tag! - _loadedBitmaps->setVal(id, new BitmapCast(stream, MKTAG('B', 'I', 'T', 'D'), _vm->getVersion())); + _loadedCast->setVal(id, new BitmapCast(stream, MKTAG('B', 'I', 'T', 'D'), _vm->getVersion())); _castTypes[id] = kCastBitmap; break; case kCastText: debugC(3, kDebugLoading, "Score::loadCastDataVWCR(): CastTypes id: %d(%s) TextCast", id, numToCastNum(id)); - _loadedText->setVal(id, new TextCast(stream, _vm->getVersion())); + _loadedCast->setVal(id, new TextCast(stream, _vm->getVersion())); _castTypes[id] = kCastText; break; case kCastShape: debugC(3, kDebugLoading, "Score::loadCastDataVWCR(): CastTypes id: %d(%s) ShapeCast", id, numToCastNum(id)); - _loadedShapes->setVal(id, new ShapeCast(stream, _vm->getVersion())); + _loadedCast->setVal(id, new ShapeCast(stream, _vm->getVersion())); _castTypes[id] = kCastShape; break; case kCastButton: debugC(3, kDebugLoading, "Score::loadCastDataVWCR(): CastTypes id: %d(%s) ButtonCast", id, numToCastNum(id)); - _loadedButtons->setVal(id, new ButtonCast(stream, _vm->getVersion())); + _loadedCast->setVal(id, new ButtonCast(stream, _vm->getVersion())); _castTypes[id] = kCastButton; break; default: @@ -612,37 +600,10 @@ void Score::setSpriteCasts() { if (castId == 0) continue; - if (_vm->getSharedScore() != nullptr && _vm->getSharedScore()->_loadedBitmaps->contains(castId)) { - _frames[i]->_sprites[j]->_bitmapCast = _vm->getSharedScore()->_loadedBitmaps->getVal(castId); - } else if (_loadedBitmaps->contains(castId)) { - _frames[i]->_sprites[j]->_bitmapCast = _loadedBitmaps->getVal(castId); - } - - if (_vm->getSharedScore() != nullptr && _vm->getSharedScore()->_loadedButtons->contains(castId)) { - _frames[i]->_sprites[j]->_buttonCast = _vm->getSharedScore()->_loadedButtons->getVal(castId); - if (_frames[i]->_sprites[j]->_buttonCast->_children.size() == 1) { - _frames[i]->_sprites[j]->_textCast = - _vm->getSharedScore()->_loadedText->getVal(_frames[i]->_sprites[j]->_buttonCast->_children[0].index); - } else if (_frames[i]->_sprites[j]->_buttonCast->_children.size() > 0) { - warning("Cast %d has too many children!", j); - } - } else if (_loadedButtons->contains(castId)) { - _frames[i]->_sprites[j]->_buttonCast = _loadedButtons->getVal(castId); - } - - //if (_loadedScripts->contains(castId)) - // _frames[i]->_sprites[j]->_bitmapCast = _loadedBitmaps->getVal(castId); - - if (_vm->getSharedScore() != nullptr && _vm->getSharedScore()->_loadedText->contains(castId)) { - _frames[i]->_sprites[j]->_textCast = _vm->getSharedScore()->_loadedText->getVal(castId); - } else if (_loadedText->contains(castId)) { - _frames[i]->_sprites[j]->_textCast = _loadedText->getVal(castId); - } - - if (_vm->getSharedScore() != nullptr && _vm->getSharedScore()->_loadedShapes->contains(castId)) { - _frames[i]->_sprites[j]->_shapeCast = _vm->getSharedScore()->_loadedShapes->getVal(castId); - } else if (_loadedShapes->contains(castId)) { - _frames[i]->_sprites[j]->_shapeCast = _loadedShapes->getVal(castId); + if (_vm->getSharedScore() != nullptr && _vm->getSharedScore()->_loadedCast->contains(castId)) { + _frames[i]->_sprites[j]->_cast = _vm->getSharedScore()->_loadedCast->getVal(castId); + } else if (_loadedCast->contains(castId)) { + _frames[i]->_sprites[j]->_cast = _loadedCast->getVal(castId); } } } @@ -711,53 +672,33 @@ void Score::loadCastData(Common::SeekableSubReadStreamEndian &stream, uint16 id, switch (castType) { case kCastBitmap: - _loadedBitmaps->setVal(id, new BitmapCast(castStream, res->tag, _vm->getVersion())); - for (uint child = 0; child < res->children.size(); child++) - _loadedBitmaps->getVal(id)->_children.push_back(res->children[child]); + _loadedCast->setVal(id, new BitmapCast(castStream, res->tag, _vm->getVersion())); _castTypes[id] = kCastBitmap; debugC(3, kDebugLoading, "Score::loadCastData(): loaded kCastBitmap (%d)", res->children.size()); break; case kCastText: - _loadedText->setVal(id, new TextCast(castStream, _vm->getVersion())); - for (uint child = 0; child < res->children.size(); child++) - _loadedText->getVal(id)->_children.push_back(res->children[child]); + _loadedCast->setVal(id, new TextCast(castStream, _vm->getVersion())); _castTypes[id] = kCastText; debugC(3, kDebugLoading, "Score::loadCastData(): loaded kCastText (%d)", res->children.size()); break; case kCastShape: - _loadedShapes->setVal(id, new ShapeCast(castStream, _vm->getVersion())); - for (uint child = 0; child < res->children.size(); child++) - _loadedShapes->getVal(id)->_children.push_back(res->children[child]); + _loadedCast->setVal(id, new ShapeCast(castStream, _vm->getVersion())); _castTypes[id] = kCastShape; debugC(3, kDebugLoading, "Score::loadCastData(): loaded kCastShape (%d)", res->children.size()); break; case kCastButton: - _loadedButtons->setVal(id, new ButtonCast(castStream, _vm->getVersion())); - for (uint child = 0; child < res->children.size(); child++) - _loadedButtons->getVal(id)->_children.push_back(res->children[child]); + _loadedCast->setVal(id, new ButtonCast(castStream, _vm->getVersion())); _castTypes[id] = kCastButton; debugC(3, kDebugLoading, "Score::loadCastData(): loaded kCastButton (%d)", res->children.size()); break; case kCastLingoScript: - _loadedScripts->setVal(id, new ScriptCast(castStream, _vm->getVersion())); + _loadedCast->setVal(id, new ScriptCast(castStream, _vm->getVersion())); _castTypes[id] = kCastLingoScript; debugC(3, kDebugLoading, "Score::loadCastData(): loaded kCastLingoScript"); break; case kCastRTE: - //TODO: Actually load RTEs correctly, don't just make fake STXT. _castTypes[id] = kCastRTE; - _loadedText->setVal(id, new TextCast(castStream, _vm->getVersion())); - for (uint child = 0; child < res->children.size(); child++) { - _loadedText->getVal(id)->_children.push_back(res->children[child]); - if (child == 1) { - Common::SeekableReadStream *rte1 = _movieArchive->getResource(res->children[child].tag, res->children[child].index); - byte *buffer = new byte[rte1->size() + 2]; - rte1->read(buffer, rte1->size()); - buffer[rte1->size()] = '\n'; - buffer[rte1->size() + 1] = '\0'; - _loadedText->getVal(id)->importRTE(buffer); - } - } + _loadedCast->setVal(id, new RTECast(castStream, _vm->getVersion())); debugC(3, kDebugLoading, "Score::loadCastData(): loaded kCastRTE (%d)", res->children.size()); break; case kCastFilmLoop: @@ -791,6 +732,9 @@ void Score::loadCastData(Common::SeekableSubReadStreamEndian &stream, uint16 id, break; } + for (uint child = 0; child < res->children.size(); child++) + _loadedCast->getVal(id)->_children.push_back(res->children[child]); + free(data); if (size2 && _vm->getVersion() < 5) { @@ -819,7 +763,7 @@ void Score::loadCastData(Common::SeekableSubReadStreamEndian &stream, uint16 id, // FIXME. Disabled by default, requires --debugflags=bytecode for now if (_vm->getVersion() >= 4 && castType == kCastLingoScript && debugChannelSet(-1, kDebugBytecode)) { // Try and load the compiled Lingo script associated with this cast - uint scriptId = (*_loadedScripts)[id]->_id - 1; + uint scriptId = ((ScriptCast *)(*_loadedCast)[id])->_id - 1; if (scriptId < _castScriptIds.size()) { int resourceId = _castScriptIds[scriptId]; _lingo->addCodeV4(*_movieArchive->getResource(MKTAG('L', 's', 'c', 'r'), resourceId), kCastScript, id); @@ -844,57 +788,29 @@ void Score::loadCastData(Common::SeekableSubReadStreamEndian &stream, uint16 id, } void Score::loadCastInto(Sprite *sprite, int castId) { - switch (_castTypes[castId]) { - case kCastBitmap: - sprite->_bitmapCast = _loadedBitmaps->getVal(castId); - break; - case kCastShape: - sprite->_shapeCast = _loadedShapes->getVal(castId); - break; - case kCastButton: - sprite->_buttonCast = _loadedButtons->getVal(castId); - break; - case kCastText: - sprite->_textCast = _loadedText->getVal(castId); - break; - default: - warning("Score::loadCastInto(..., %d): Unhandled castType %d", castId, _castTypes[castId]); - } + sprite->_cast = _loadedCast->getVal(castId); } Common::Rect Score::getCastMemberInitialRect(int castId) { - switch (_castTypes[castId]) { - case kCastBitmap: - return _loadedBitmaps->getVal(castId)->_initialRect; - case kCastShape: - return _loadedShapes->getVal(castId)->_initialRect; - case kCastButton: - return _loadedButtons->getVal(castId)->_initialRect; - case kCastText: - return _loadedText->getVal(castId)->_initialRect; - default: - warning("Score::getCastMemberInitialRect(%d): Unhandled castType %d", castId, _castTypes[castId]); + Cast *cast = _loadedCast->getVal(castId); + + if (!cast) { + warning("Score::getCastMemberInitialRect(%d): empty cast", castId); return Common::Rect(0, 0); } + + return cast->_initialRect; } void Score::setCastMemberModified(int castId) { - switch (_castTypes[castId]) { - case kCastBitmap: - _loadedBitmaps->getVal(castId)->_modified = 1; - break; - case kCastShape: - _loadedShapes->getVal(castId)->_modified = 1; - break; - case kCastButton: - _loadedButtons->getVal(castId)->_modified = 1; - break; - case kCastText: - _loadedText->getVal(castId)->_modified = 1; - break; - default: - warning("Score::setCastMemberModified(%d): Unhandled castType %d", castId, _castTypes[castId]); + Cast *cast = _loadedCast->getVal(castId); + + if (!cast) { + warning("Score::setCastMemberModified(%d): empty cast", castId); + return; } + + cast->_modified = 1; } void Score::loadLabels(Common::SeekableSubReadStreamEndian &stream) { diff --git a/engines/director/score.h b/engines/director/score.h index 39e126ed30..aeda616729 100644 --- a/engines/director/score.h +++ b/engines/director/score.h @@ -142,12 +142,8 @@ public: bool _stopPlay; uint32 _nextFrameTime; - Common::HashMap<int, ButtonCast *> *_loadedButtons; - Common::HashMap<int, TextCast *> *_loadedText; - //Common::HashMap<int, SoundCast *> _loadedSound; - Common::HashMap<int, BitmapCast *> *_loadedBitmaps; - Common::HashMap<int, ShapeCast *> *_loadedShapes; - Common::HashMap<int, ScriptCast *> *_loadedScripts; + Common::HashMap<int, Cast *> *_loadedCast; + Common::HashMap<int, const Stxt *> *_loadedStxts; uint16 _castIDoffset; diff --git a/engines/director/sprite.cpp b/engines/director/sprite.cpp index da86c0cf01..3fd5b6a470 100644 --- a/engines/director/sprite.cpp +++ b/engines/director/sprite.cpp @@ -52,10 +52,7 @@ Sprite::Sprite() { _stretch = 0; _type = kInactiveSprite; - _bitmapCast = nullptr; - _textCast = nullptr; - _buttonCast = nullptr; - _shapeCast = nullptr; + _cast = nullptr; _blend = 0; _lineSize = 1; @@ -91,10 +88,7 @@ Sprite::Sprite(const Sprite &sprite) { _stretch = sprite._stretch; _type = sprite._type; - _bitmapCast = sprite._bitmapCast; - _shapeCast = sprite._shapeCast; - _textCast = sprite._textCast; - _buttonCast = sprite._buttonCast; + _cast = sprite._cast; _constraint = sprite._constraint; _moveable = sprite._moveable; @@ -110,14 +104,8 @@ Sprite::Sprite(const Sprite &sprite) { } Sprite::~Sprite() { - if (_bitmapCast) - delete _bitmapCast; - if (_shapeCast) - delete _shapeCast; - if (_textCast) - delete _textCast; - if (_buttonCast) - delete _buttonCast; + if (_cast) + delete _cast; } uint16 Sprite::getPattern() { diff --git a/engines/director/sprite.h b/engines/director/sprite.h index 07cbc54a08..0c12a0d234 100644 --- a/engines/director/sprite.h +++ b/engines/director/sprite.h @@ -77,12 +77,7 @@ public: InkType _ink; uint16 _trails; - BitmapCast *_bitmapCast; - ShapeCast *_shapeCast; - //SoundCast *_soundCast; - TextCast *_textCast; - ButtonCast *_buttonCast; - //ScriptCast *_scriptCast; + Cast *_cast; uint16 _flags; Common::Point _startPoint; |