From badb8d97444767b7d8fea0f877ac044249696a5f Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Fri, 28 Feb 2014 20:37:42 -0500 Subject: MADS: More work implementing scene info loading --- engines/mads/msurface.cpp | 215 ++-------------------------------------------- 1 file changed, 5 insertions(+), 210 deletions(-) (limited to 'engines/mads/msurface.cpp') diff --git a/engines/mads/msurface.cpp b/engines/mads/msurface.cpp index 4c17b3a159..ca75a50bde 100644 --- a/engines/mads/msurface.cpp +++ b/engines/mads/msurface.cpp @@ -249,219 +249,14 @@ void MSurface::copyFrom(MSurface *src, const Common::Rect &srcBounds, } } -void MSurface::translate(RGBList *list, bool isTransparent) { - byte *p = getBasePtr(0, 0); - byte *palIndexes = list->palIndexes(); - - for (int i = 0; i < getWidth() * getHeight(); ++i, ++p) { - if (!isTransparent || (*p != 0)) { - assert(*p < list->size()); - *p = palIndexes[*p]; - } - } -} - -/*------------------------------------------------------------------------*/ -/* -void MSurfaceMADS::loadBackground(int roomNumber, RGBList **palData) { - // clear previous data - empty(); - - // Get a MadsPack reference to the tile set and mapping - char resourceName[20]; - int i; - - // Uncompressed tile map resource - sprintf(resourceName, "rm%d.mm", roomNumber); - MadsPack tileMapFile(resourceName, _vm); - Common::SeekableReadStream *mapStream = tileMapFile.getItemStream(0); - - // Get the details of the tiles and map - mapStream->readUint32LE(); - int tileCountX = mapStream->readUint16LE(); - int tileCountY = mapStream->readUint16LE(); - int tileWidthMap = mapStream->readUint16LE(); - int tileHeightMap = mapStream->readUint16LE(); - int screenWidth = mapStream->readUint16LE(); - int screenHeight = mapStream->readUint16LE(); - int tileCountMap = tileCountX * tileCountY; - delete mapStream; - - // Obtain tile map information - typedef Common::List > TileSetList; - typedef TileSetList::iterator TileSetIterator; - TileSetList tileSet; - uint16 *tileMap = new uint16[tileCountMap]; - mapStream = tileMapFile.getItemStream(1); - for (i = 0; i < tileCountMap; ++i) - tileMap[i] = mapStream->readUint16LE(); - delete mapStream; - -// _vm->_resources->toss(resourceName); - - // -------------------------------------------------------------------------------- - - // Tile map data, which needs to be kept compressed, as the tile offsets refer to - // the compressed data. Each tile is then uncompressed separately - sprintf(resourceName, "rm%d.tt", roomNumber); - Common::SeekableReadStream *tileDataComp = nullptr; //_vm->_resources->get(resourceName); - MadsPack tileData(tileDataComp); - Common::SeekableReadStream *tileDataUncomp = tileData.getItemStream(0); - - // Validate that the data matches between the tiles and tile map file and is valid - int tileCount = tileDataUncomp->readUint16LE(); - int tileWidth = tileDataUncomp->readUint16LE(); - int tileHeight = tileDataUncomp->readUint16LE(); - delete tileDataUncomp; - assert(tileCountMap == tileCount); - assert(tileWidth == tileWidthMap); - assert(tileHeight == tileHeightMap); - assert(screenWidth == _vm->_screen->getWidth()); - assert(screenHeight <= _vm->_screen->getHeight()); - - // -------------------------------------------------------------------------------- - - // Get the palette to use - tileDataUncomp = tileData.getItemStream(2); - // Set palette - if (!palData) { - _vm->_palette->loadPalette(tileDataUncomp, 4); - } else { - int numColors; - byte *rgbList = _vm->_palette->decodePalette(tileDataUncomp, &numColors); - *palData = new RGBList(numColors, rgbList, true); - } - delete tileDataUncomp; - - // -------------------------------------------------------------------------------- - - // Get tile data - - tileDataUncomp = tileData.getItemStream(1); - FabDecompressor fab; - uint32 compressedTileDataSize = 0; - - for (i = 0; i < tileCount; i++) { - tileDataUncomp->seek(i * 4, SEEK_SET); - uint32 tileOfs = tileDataUncomp->readUint32LE(); - MSurface *newTile = new MSurface(tileWidth, tileHeight); +void MSurface::translate(Common::Array &palette) { + for (int y = 0; y < this->h; ++y) { + byte *pDest = getBasePtr(0, y); - if (i == tileCount - 1) - compressedTileDataSize = tileDataComp->size() - tileOfs; - else - compressedTileDataSize = tileDataUncomp->readUint32LE() - tileOfs; - - //printf("Tile: %i, compressed size: %i\n", i, compressedTileDataSize); - - newTile->empty(); - - byte *compressedTileData = new byte[compressedTileDataSize]; - - tileDataComp->seek(tileData.getDataOffset() + tileOfs, SEEK_SET); - tileDataComp->read(compressedTileData, compressedTileDataSize); - - fab.decompress(compressedTileData, compressedTileDataSize, newTile->getData(), - tileWidth * tileHeight); - tileSet.push_back(TileSetList::value_type(newTile)); - delete[] compressedTileData; - } - - delete tileDataUncomp; - - // -------------------------------------------------------------------------------- - - // Loop through the mapping data to place the tiles on the screen - - uint16 *tIndex = &tileMap[0]; - for (int y = 0; y < tileCountY; y++) { - for (int x = 0; x < tileCountX; x++) { - int tileIndex = *tIndex++; - assert(tileIndex < tileCount); - TileSetIterator tile = tileSet.begin(); - for (i = 0; i < tileIndex; i++) - ++tile; - ((*tile).get())->copyTo(this, Common::Point(x * tileWidth, y * tileHeight)); + for (int x = 0; x < this->w; ++x, ++pDest) { + *pDest = palette[*pDest].palIndex; } } - tileSet.clear(); -// _vm->_resources->toss(resourceName); -} - -void MSurfaceMADS::loadInterface(int index, RGBList **palData) { - char resourceName[20]; - sprintf(resourceName, "i%d.int", index); - MadsPack intFile(resourceName, _vm); - byte *palette = new byte[16 * 3]; - - // Chunk 0, palette - Common::SeekableReadStream *intStream = intFile.getItemStream(0); - - for (int i = 0; i < 16; i++) { - palette[i * 3] = intStream->readByte() << 2; - palette[i * 3 + 1] = intStream->readByte() << 2; - palette[i * 3 + 2] = intStream->readByte() << 2; - intStream->skip(3); - } - *palData = new RGBList(16, palette, true); - delete intStream; - - // Chunk 1, data - intStream = intFile.getItemStream(1); - setSize(MADS_SCREEN_WIDTH, MADS_INTERFACE_HEIGHT); - intStream->read(pixels, MADS_SCREEN_WIDTH * MADS_INTERFACE_HEIGHT); - delete intStream; -} - ------------------------------------------------------------------------- - -void MSurfaceNebular::loadBackground(int roomNumber, RGBList **palData) { - // clear previous data - empty(); - - Common::String resourceName = Common::String::format("rm%d.art", roomNumber); - Common::SeekableReadStream *stream = nullptr; //_vm->_resources->get(resourceName); - loadBackgroundStream(stream, palData); - -// _vm->_resources->toss(resourceName); -} - -void MSurfaceNebular::loadBackgroundStream(Common::SeekableReadStream *source, RGBList **palData) { - MadsPack packData(source); - Common::MemoryReadStream *sourceUnc = packData.getItemStream(0); - - int sceneWidth = sourceUnc->readUint16LE(); - int sceneHeight = sourceUnc->readUint16LE(); - int sceneSize = sceneWidth * sceneHeight; - if (sceneWidth > this->getWidth()) { - warning("Background width is %i, too large to fit in screen. Setting it to %i", sceneWidth, getWidth()); - sceneWidth = this->getWidth(); - sceneSize = sceneWidth * sceneHeight; - } - if (sceneHeight > getHeight()) { - warning("Background height is %i, too large to fit in screen.Setting it to %i", sceneHeight, getHeight()); - sceneHeight = getHeight(); - sceneSize = sceneWidth * sceneHeight; - } - - // Set palette - if (!palData) { - _vm->_palette->loadPalette(sourceUnc, 4); - } else { - int numColors; - byte *rgbList = _vm->_palette->decodePalette(sourceUnc, &numColors); - *palData = new RGBList(numColors, rgbList, true); - } - delete sourceUnc; - - // Get the raw data for the background - sourceUnc = packData.getItemStream(1); - assert((int)sourceUnc->size() >= sceneSize); - - byte *pData = (byte *)pixels; - sourceUnc->read(pData, sceneSize); - - delete sourceUnc; } -*/ } // End of namespace MADS -- cgit v1.2.3