diff options
Diffstat (limited to 'engines/mads/animation.cpp')
-rw-r--r-- | engines/mads/animation.cpp | 84 |
1 files changed, 50 insertions, 34 deletions
diff --git a/engines/mads/animation.cpp b/engines/mads/animation.cpp index 512a3979f9..2b999fa305 100644 --- a/engines/mads/animation.cpp +++ b/engines/mads/animation.cpp @@ -32,10 +32,8 @@ void AAHeader::load(Common::SeekableReadStream *f) { _miscEntriesCount = f->readUint16LE(); _frameEntriesCount = f->readUint16LE(); _messagesCount = f->readUint16LE(); - f->skip(1); - _flags = f->readByte(); - - f->skip(2); + _loadFlags = f->readUint16LE(); + _charSpacing = f->readSint16LE(); _bgType = (AnimBgType)f->readUint16LE(); _roomNumber = f->readUint16LE(); f->skip(2); @@ -49,7 +47,7 @@ void AAHeader::load(Common::SeekableReadStream *f) { char buffer[FILENAME_SIZE]; f->read(buffer, FILENAME_SIZE); buffer[FILENAME_SIZE - 1] = '\0'; - _interfaceFile = Common::String(buffer); + _backgroundFile = Common::String(buffer); for (int i = 0; i < 50; ++i) { f->read(buffer, FILENAME_SIZE); @@ -134,7 +132,8 @@ void AnimMiscEntry::load(Common::SeekableReadStream *f) { _numTicks = f->readUint16LE(); _posAdjust.x = f->readSint16LE(); _posAdjust.y = f->readSint16LE(); - _field8 = f->readUint16LE(); + _scroll.x = f->readSByte(); + _scroll.y = f->readSByte(); } /*------------------------------------------------------------------------*/ @@ -160,6 +159,7 @@ Animation *Animation::init(MADSEngine *vm, Scene *scene) { } Animation::Animation(MADSEngine *vm, Scene *scene) : _vm(vm), _scene(scene) { + _flags = 0; _font = nullptr; _resetFlag = false; _messageCtr = 0; @@ -175,6 +175,8 @@ Animation::Animation(MADSEngine *vm, Scene *scene) : _vm(vm), _scene(scene) { _actionDetails._indirectObjectId = -1; _currentFrame = 0; _oldFrameEntry = 0; + _rgbResult = -1; + _palIndex1 = _palIndex2 = -1; } Animation::~Animation() { @@ -189,7 +191,7 @@ Animation::~Animation() { } } -void Animation::load(UserInterface &interfaceSurface, DepthSurface &depthSurface, +void Animation::load(MSurface &backSurface, DepthSurface &depthSurface, const Common::String &resName, int flags, Common::Array<PaletteCycle> *palCycles, SceneInfo *sceneInfo) { Common::String resourceName = resName; @@ -205,9 +207,10 @@ void Animation::load(UserInterface &interfaceSurface, DepthSurface &depthSurface if (_header._bgType == ANIMBG_INTERFACE) flags |= PALFLAG_RESERVED; + _flags = flags; if (flags & ANIMFLAG_LOAD_BACKGROUND) { - loadInterface(interfaceSurface, depthSurface, _header, flags, palCycles, sceneInfo); + loadBackground(backSurface, depthSurface, _header, flags, palCycles, sceneInfo); } if (flags & ANIMFLAG_LOAD_BACKGROUND_ONLY) { // No data @@ -243,7 +246,7 @@ void Animation::load(UserInterface &interfaceSurface, DepthSurface &depthSurface for (int i = 0; i < _header._frameEntriesCount; i++) { AnimFrameEntry rec; - rec.load(frameStream, flags & ANIMFLAG_LOAD_BACKGROUND); + rec.load(frameStream, _header._bgType == ANIMBG_INTERFACE); _frameEntries.push_back(rec); } @@ -256,7 +259,7 @@ void Animation::load(UserInterface &interfaceSurface, DepthSurface &depthSurface // Chunk 4: Misc Data Common::SeekableReadStream *miscStream = madsPack.getItemStream(streamIndex++); - if (flags & ANIMFLAG_LOAD_BACKGROUND) { + if (_header._bgType == ANIMBG_INTERFACE) { for (int i = 0; i < _header._miscEntriesCount; ++i) { AnimUIEntry rec; rec.load(miscStream); @@ -275,7 +278,7 @@ void Animation::load(UserInterface &interfaceSurface, DepthSurface &depthSurface // If the animation specifies a font, then load it for access delete _font; - if (_header._flags & ANIMFLAG_CUSTOM_FONT) { + if (_header._loadFlags & ANIMFLAG_CUSTOM_FONT) { Common::String fontName = "*" + _header._fontResource; _font = _vm->_font->getFont(fontName.c_str()); } else { @@ -337,9 +340,6 @@ void Animation::startAnimation(int endTrigger) { _unkIndex = -1; //SpriteAsset *asset = _scene->_sprites[_spriteListIndexes[_header._spritesIndex]]; - // TODO: Weird stuff with _unkList. Seems like it's treated as pointers - // here, but in processText, it's used as POINTs? - loadFrame(1); } @@ -385,12 +385,12 @@ bool Animation::drawFrame(SpriteAsset &spriteSet, const Common::Point &pt, int f return 0; } -void Animation::loadInterface(UserInterface &interfaceSurface, DepthSurface &depthSurface, +void Animation::loadBackground(MSurface &backSurface, DepthSurface &depthSurface, AAHeader &header, int flags, Common::Array<PaletteCycle> *palCycles, SceneInfo *sceneInfo) { _scene->_depthStyle = 0; if (header._bgType <= ANIMBG_FULL_SIZE) { _vm->_palette->_paletteUsage.setEmpty(); - sceneInfo->load(header._roomNumber, flags, header._interfaceFile, 0, depthSurface, interfaceSurface); + sceneInfo->load(header._roomNumber, 0, header._backgroundFile, flags, depthSurface, backSurface); _scene->_depthStyle = sceneInfo->_depthStyle == 2 ? 1 : 0; if (palCycles) { palCycles->clear(); @@ -399,8 +399,8 @@ void Animation::loadInterface(UserInterface &interfaceSurface, DepthSurface &dep } } else if (header._bgType == ANIMBG_INTERFACE) { // Load a scene interface - Common::String resourceName = "*" + header._interfaceFile; - interfaceSurface.load(resourceName); + Common::String resourceName = "*" + header._backgroundFile; + backSurface.load(resourceName); if (palCycles) palCycles->clear(); @@ -415,6 +415,7 @@ bool Animation::hasScroll() const { void Animation::update() { Scene &scene = _vm->_game->_scene; + Palette &palette = *_vm->_palette; if (_header._manualFlag) { int spriteListIndex = _spriteListIndexes[_header._spritesIndex]; @@ -534,28 +535,43 @@ void Animation::update() { // Start displaying the message AnimMessage &me = _messages[idx]; - // The color index to use is dependant on how many messages are currently on-screen - uint8 colIndex; - switch (_messageCtr) { - case 1: - colIndex = 252; - break; - case 2: - colIndex = 16; - break; - default: - colIndex = 250; - break; - } + if (_flags & ANIMFLAG_ANIMVIEW) { + _rgbResult = palette._paletteUsage.checkRGB(me._rgb1, -1, true, &_palIndex1); + _rgbResult = palette._paletteUsage.checkRGB(me._rgb2, _rgbResult, true, &_palIndex2); + + // Update the palette with the two needed colors + int palStart = MIN(_palIndex1, _palIndex2); + int palCount = ABS(_palIndex2 - _palIndex1) + 1; + palette.setPalette(&palette._mainPalette[palStart * 3], palStart, palCount); + } else { + // The color index to use is dependant on how many messages are currently on-screen + switch (_messageCtr) { + case 1: + _palIndex1 = 252; + break; + case 2: + _palIndex1 = 16; + break; + default: + _palIndex1 = 250; + break; + } + _palIndex2 = _palIndex1 + 1; - _vm->_palette->setEntry(colIndex, me._rgb1[0], me._rgb1[1], me._rgb1[2]); - _vm->_palette->setEntry(colIndex + 1, me._rgb2[0], me._rgb2[1], me._rgb2[2]); + _vm->_palette->setEntry(_palIndex1, me._rgb1[0], me._rgb1[1], me._rgb1[2]); + _vm->_palette->setEntry(_palIndex2, me._rgb2[0], me._rgb2[1], me._rgb2[2]); + } // Add a kernel message to display the given text - me._kernelMsgIndex = scene._kernelMessages.add(me._pos, colIndex * 0x101 + 0x100, + me._kernelMsgIndex = scene._kernelMessages.add(me._pos, + _palIndex1 | (_palIndex2 << 8), 0, 0, INDEFINITE_TIMEOUT, me._msg); assert(me._kernelMsgIndex >= 0); ++_messageCtr; + + // If there's an accompanying sound, also play it + if (me._soundId > 0) + _vm->_audio->playSound(me._soundId - 1); } } |