diff options
Diffstat (limited to 'engines/m4/assets.cpp')
-rw-r--r-- | engines/m4/assets.cpp | 86 |
1 files changed, 78 insertions, 8 deletions
diff --git a/engines/m4/assets.cpp b/engines/m4/assets.cpp index 1f3cf278ae..23122eb960 100644 --- a/engines/m4/assets.cpp +++ b/engines/m4/assets.cpp @@ -98,7 +98,8 @@ long *DataAsset::getRow(int index) { return &_data[_recSize * index]; } -SpriteAsset::SpriteAsset(MadsM4Engine *vm, Common::SeekableReadStream* stream, int size, const char *name, bool asStream) : +SpriteAsset::SpriteAsset(MadsM4Engine *vm, Common::SeekableReadStream* stream, int size, const char *name, + bool asStream, int flags) : BaseAsset(vm) { _stream = stream; _palInterface = NULL; @@ -107,7 +108,7 @@ SpriteAsset::SpriteAsset(MadsM4Engine *vm, Common::SeekableReadStream* stream, i if (_vm->isM4()) { loadM4SpriteAsset(vm, stream, asStream); } else { - loadMadsSpriteAsset(vm, stream); + loadMadsSpriteAsset(vm, stream, flags); } } @@ -119,7 +120,7 @@ SpriteAsset::SpriteAsset(MadsM4Engine *vm, const char *name): BaseAsset(vm) { if (_vm->isM4()) { loadM4SpriteAsset(vm, _stream, true); } else { - loadMadsSpriteAsset(vm, _stream); + loadMadsSpriteAsset(vm, _stream, 0); } vm->res()->toss(name); @@ -136,6 +137,8 @@ SpriteAsset::~SpriteAsset() { for (Common::Array<SpriteAssetFrame>::iterator it = _frames.begin(); it != _frames.end(); ++it) { delete (*it).frame; } + + delete _charInfo; } void SpriteAsset::loadM4SpriteAsset(MadsM4Engine *vm, Common::SeekableReadStream* stream, bool asStream) { @@ -200,7 +203,7 @@ void SpriteAsset::loadM4SpriteAsset(MadsM4Engine *vm, Common::SeekableReadStream } -void SpriteAsset::loadMadsSpriteAsset(MadsM4Engine *vm, Common::SeekableReadStream* stream) { +void SpriteAsset::loadMadsSpriteAsset(MadsM4Engine *vm, Common::SeekableReadStream* stream, int flags) { int curFrame = 0; uint32 frameOffset = 0; MadsPack sprite(stream); @@ -217,7 +220,12 @@ void SpriteAsset::loadMadsSpriteAsset(MadsM4Engine *vm, Common::SeekableReadStre _isBackground = (type1 != 0) && (type2 < 4); spriteStream->skip(32); _frameCount = spriteStream->readUint16LE(); - // we skip the rest of the data + + if (_vm->isM4() || ((flags & SPRITE_SET_CHAR_INFO) == 0)) + _charInfo = NULL; + else + _charInfo = new MadsSpriteSetCharInfo(spriteStream); + delete spriteStream; // Get the palette data @@ -234,12 +242,15 @@ void SpriteAsset::loadMadsSpriteAsset(MadsM4Engine *vm, Common::SeekableReadStre spriteStream = sprite.getItemStream(1); Common::SeekableReadStream *spriteDataStream = sprite.getItemStream(3); SpriteAssetFrame frame; + Common::Array<int> frameSizes; for (curFrame = 0; curFrame < _frameCount; curFrame++) { frame.stream = 0; frame.comp = 0; frameOffset = spriteStream->readUint32LE(); _frameOffsets.push_back(frameOffset); - spriteStream->readUint32LE(); // frame size + uint32 frameSize = spriteStream->readUint32LE(); + frameSizes.push_back(frameSize); + frame.x = spriteStream->readUint16LE(); frame.y = spriteStream->readUint16LE(); frame.w = spriteStream->readUint16LE(); @@ -247,9 +258,44 @@ void SpriteAsset::loadMadsSpriteAsset(MadsM4Engine *vm, Common::SeekableReadStre if (curFrame == 0) debugC(1, kDebugGraphics, "%i frames, x = %i, y = %i, w = %i, h = %i\n", _frameCount, frame.x, frame.y, frame.w, frame.h); - frame.frame = new M4Sprite(spriteDataStream, frame.x, frame.y, frame.w, frame.h, false); + if (_mode == 0) { + // Create a frame and decompress the raw pixel data + uint32 currPos = (uint32)spriteDataStream->pos(); + frame.frame = new M4Sprite(spriteDataStream, frame.x, frame.y, frame.w, frame.h, false); + assert((uint32)spriteDataStream->pos() == (currPos + frameSize)); + } + _frames.push_back(frame); } + + if (_mode != 0) { + // Handle decompressing Fab encoded data + for (curFrame = 0; curFrame < _frameCount; curFrame++) { + FabDecompressor fab; + + int srcSize = (curFrame == (_frameCount - 1)) ? spriteDataStream->size() - _frameOffsets[curFrame] : + _frameOffsets[curFrame + 1] - _frameOffsets[curFrame]; + byte *srcData = (byte *)malloc(srcSize); + assert(srcData); + spriteDataStream->read(srcData, srcSize); + + byte *destData = (byte *)malloc(frameSizes[curFrame]); + assert(destData); + + fab.decompress(srcData, srcSize, destData, frameSizes[curFrame]); + + // Load the frame + Common::MemoryReadStream *rs = new Common::MemoryReadStream(destData, frameSizes[curFrame]); + _frames[curFrame].frame = new M4Sprite(rs, _frames[curFrame].x, _frames[curFrame].y, + _frames[curFrame].w, _frames[curFrame].h, false); + delete rs; + + free(srcData); + free(destData); + } + } + + delete spriteStream; delete spriteDataStream; } @@ -320,7 +366,12 @@ void SpriteAsset::loadFrameHeader(SpriteAssetFrame &frameHeader, bool isBigEndia } M4Sprite *SpriteAsset::getFrame(int frameIndex) { - return _frames[frameIndex].frame; + if ((uint)frameIndex < _frames.size()) { + return _frames[frameIndex].frame; + } else { + warning("SpriteAsset::getFrame: Invalid frame %d, out of %d", frameIndex, _frames.size()); + return _frames[_frames.size() - 1].frame; + } } void SpriteAsset::loadStreamingFrame(M4Sprite *frame, int frameIndex, int destX, int destY) { @@ -578,4 +629,23 @@ int32 AssetManager::getSpriteFrameCount(int32 hash) { return _CELS[hash]->getCount(); } +//-------------------------------------------------------------------------- + +MadsSpriteSetCharInfo::MadsSpriteSetCharInfo(Common::SeekableReadStream *s) { + _totalFrames = s->readByte(); + s->skip(1); + _numEntries = s->readUint16LE(); + + for (int i = 0; i < 16; ++i) + _frameList[i] = s->readUint16LE(); + for (int i = 0; i < 16; ++i) + _frameList2[i] = s->readUint16LE(); + for (int i = 0; i < 16; ++i) + _ticksList[i] = s->readUint16LE(); + + _unk1 = s->readUint16LE(); + _ticksAmount = s->readByte(); + _yScale = s->readByte(); +} + } // End of namespace M4 |