diff options
author | Sven Hesse | 2011-09-01 14:00:17 +0200 |
---|---|---|
committer | Sven Hesse | 2011-09-03 18:00:09 +0200 |
commit | 37964e8e85137ff7cb3a317c34b6a6210b7564d4 (patch) | |
tree | 740cd679c271f985fea6c35702a97a09f1c072a7 | |
parent | 2985f118b802d231aa5ec328c8b61e1419c14e48 (diff) | |
download | scummvm-rg350-37964e8e85137ff7cb3a317c34b6a6210b7564d4.tar.gz scummvm-rg350-37964e8e85137ff7cb3a317c34b6a6210b7564d4.tar.bz2 scummvm-rg350-37964e8e85137ff7cb3a317c34b6a6210b7564d4.zip |
GOB: Add class DECFile
Handles DEC files, describing "decals" (backgrounds).
Used in hardcoded "actiony" parts of gob games, like
Geisha's minigames.
-rw-r--r-- | engines/gob/decfile.cpp | 214 | ||||
-rw-r--r-- | engines/gob/decfile.h | 111 | ||||
-rw-r--r-- | engines/gob/module.mk | 1 |
3 files changed, 326 insertions, 0 deletions
diff --git a/engines/gob/decfile.cpp b/engines/gob/decfile.cpp new file mode 100644 index 0000000000..f5910f0654 --- /dev/null +++ b/engines/gob/decfile.cpp @@ -0,0 +1,214 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#include "common/str.h" +#include "common/stream.h" +#include "common/substream.h" + +#include "gob/gob.h" +#include "gob/util.h" +#include "gob/dataio.h" +#include "gob/surface.h" +#include "gob/video.h" +#include "gob/rxyfile.h" +#include "gob/decfile.h" + +namespace Gob { + +DECFile::Layer::Layer() : surface(0), coordinates(0) { +} + +DECFile::Layer::~Layer() { + delete coordinates; + delete surface; +} + + +DECFile::DECFile(GobEngine *vm, const Common::String &fileName, + uint16 width, uint16 height, uint8 bpp) : _vm(vm), + _width(width), _height(height), _bpp(bpp), _hasPadding(false) { + + _backdrop = new Surface(_width, _height, _bpp); + + Common::SeekableReadStream *dec = _vm->_dataIO->getFile(fileName); + if (dec) { + Common::SeekableSubReadStreamEndian sub(dec, 0, dec->size(), false, DisposeAfterUse::YES); + + load(sub, fileName); + return; + } + + // File doesn't exist, try to open the big-endian'd alternate file + Common::String alternateFileName = fileName; + alternateFileName.setChar('_', 0); + + dec = _vm->_dataIO->getFile(alternateFileName); + if (dec) { + Common::SeekableSubReadStreamEndian sub(dec, 0, dec->size(), true, DisposeAfterUse::YES); + + // The big endian version pads a few fields to even size + _hasPadding = true; + + load(sub, fileName); + return; + } + + warning("DECFile::DECFile(): No such file \"%s\"", fileName.c_str()); +} + +DECFile::~DECFile() { + delete _backdrop; +} + +void DECFile::load(Common::SeekableSubReadStreamEndian &dec, const Common::String &fileName) { + dec.skip(2); // Unused + + int16 backdropCount = dec.readUint16(); + int16 layerCount = dec.readUint16(); + + // Sanity checks + if (backdropCount > 1) + warning("DECFile::load(): More than one backdrop (%d) in file \"%s\"", + backdropCount, fileName.c_str()); + if (layerCount < 1) + warning("DECFile::load(): Less than one layer (%d) in file \"%s\"", + layerCount, fileName.c_str()); + + // Load the backdrop + if (backdropCount > 0) { + loadBackdrop(dec); + + // We only support one backdrop, skip the rest + dec.skip((backdropCount - 1) * (13 + (_hasPadding ? 1 : 0))); + } + + // Load the layers + _layers.resize(MAX(0, layerCount - 1)); + for (LayerArray::iterator l = _layers.begin(); l != _layers.end(); ++l) + loadLayer(*l, dec); + + // Load the backdrop parts + if (backdropCount > 0) + loadParts(dec); +} + +void DECFile::loadBackdrop(Common::SeekableSubReadStreamEndian &dec) { + // Interestingly, DEC files reference "FOO.LBM" instead of "FOO.CMP" + Common::String file = Util::setExtension(Util::readString(dec, 13), ".CMP"); + if (_hasPadding) + dec.skip(1); + + if (file.empty() || !_vm->_dataIO->hasFile(file)) + return; + + _vm->_video->drawPackedSprite(file.c_str(), *_backdrop); +} + +void DECFile::loadLayer(Layer &layer, Common::SeekableSubReadStreamEndian &dec) { + Common::String file = Util::readString(dec, 13); + if (_hasPadding) + dec.skip(1); + + if (file.empty()) + return; + + Common::String fileRXY = Util::setExtension(file, ".RXY"); + Common::String fileCMP = Util::setExtension(file, ".CMP"); + if (!_vm->_dataIO->hasFile(fileRXY) || !_vm->_dataIO->hasFile(fileCMP)) + return; + + loadLayer(layer, fileRXY, fileCMP); +} + +void DECFile::loadLayer(Layer &layer, const Common::String &fileRXY, + const Common::String &fileCMP) { + + Common::SeekableReadStream *dataRXY = _vm->_dataIO->getFile(fileRXY); + if (!dataRXY) + return; + + layer.coordinates = new RXYFile(*dataRXY); + layer.surface = new Surface(_width, layer.coordinates->getHeight(), _bpp); + + _vm->_video->drawPackedSprite(fileCMP.c_str(), *layer.surface); +} + +void DECFile::loadParts(Common::SeekableSubReadStreamEndian &dec) { + dec.skip(13); // Name + if (_hasPadding) + dec.skip(1); + + dec.skip(13); // File? + if (_hasPadding) + dec.skip(1); + + uint16 partCount = dec.readUint16(); + + _parts.resize(partCount); + for (PartArray::iterator p = _parts.begin(); p != _parts.end(); ++p) + loadPart(*p, dec); +} + +void DECFile::loadPart(Part &part, Common::SeekableSubReadStreamEndian &dec) { + part.layer = dec.readByte() - 1; + part.part = dec.readByte(); + + dec.skip(1); // Unknown + + part.x = dec.readUint16(); + part.y = dec.readUint16(); + + part.transp = dec.readByte() != 0; +} + +void DECFile::draw(Surface &dest) const { + drawBackdrop(dest); + + for (PartArray::const_iterator p = _parts.begin(); p != _parts.end(); ++p) + drawLayer(dest, p->layer, p->part, p->x, p->y, p->transp ? 0 : -1); +} + +void DECFile::drawBackdrop(Surface &dest) const { + dest.blit(*_backdrop); +} + +void DECFile::drawLayer(Surface &dest, uint16 layer, uint16 part, + uint16 x, uint16 y, int32 transp) const { + + if (layer >= _layers.size()) + return; + + const Layer &l = _layers[layer]; + if (!l.surface || !l.coordinates) + return; + + if (part >= l.coordinates->size()) + return; + + const RXYFile::Coordinates &c = (*l.coordinates)[part]; + if (c.left == 0xFFFF) + return; + + dest.blit(*l.surface, c.left, c.top, c.right, c.bottom, x, y, transp); +} + +} // End of namespace Gob diff --git a/engines/gob/decfile.h b/engines/gob/decfile.h new file mode 100644 index 0000000000..31d90180d3 --- /dev/null +++ b/engines/gob/decfile.h @@ -0,0 +1,111 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#ifndef GOB_DECFILE_H +#define GOB_DECFILE_H + +#include "common/system.h" + +namespace Common { + class String; + class SeekableSubReadStreamEndian; +} + +namespace Gob { + +class GobEngine; +class Surface; +class RXYFile; + +/** A DEC file, describing a "decal" (background). + * + * Used in hardcoded "actiony" parts of gob games. + * The principle is similar to a Static in Scenery (see scenery.cpp), but + * instead of referencing indices in the sprites array, DECs reference sprites + * directly by filename. + */ +class DECFile { +public: + DECFile(GobEngine *vm, const Common::String &fileName, + uint16 width, uint16 height, uint8 bpp = 1); + ~DECFile(); + + /** Draw the background, including all default layer parts. */ + void draw(Surface &dest) const; + + /** Explicitly draw the backdrop. */ + void drawBackdrop(Surface &dest) const; + + /** Explicitly draw a layer part. */ + void drawLayer(Surface &dest, uint16 layer, uint16 part, + uint16 x, uint16 y, int32 transp = -1) const; + +private: + struct Layer { + Surface *surface; ///< The surface containing the layer sprite. + RXYFile *coordinates; ///< The coordinates describing the layer sprite parts. + + Layer(); + ~Layer(); + }; + + struct Part { + uint8 layer; + uint8 part; + + uint16 x; + uint16 y; + bool transp; + }; + + typedef Common::Array<Layer> LayerArray; + typedef Common::Array<Part> PartArray; + + GobEngine *_vm; + + uint16 _width; + uint16 _height; + uint8 _bpp; + + byte _hasPadding; + + Surface *_backdrop; + + LayerArray _layers; + PartArray _parts; + + + void load(Common::SeekableSubReadStreamEndian &dec, const Common::String &fileName); + + void loadBackdrop(Common::SeekableSubReadStreamEndian &dec); + + void loadLayer(Layer &layer, Common::SeekableSubReadStreamEndian &dec); + void loadLayer(Layer &layer, const Common::String &fileRXY, + const Common::String &fileCMP); + + void loadParts(Common::SeekableSubReadStreamEndian &dec); + void loadPart(Part &part, Common::SeekableSubReadStreamEndian &dec); +}; + +} // End of namespace Gob + +#endif // GOB_DECFILE_H diff --git a/engines/gob/module.mk b/engines/gob/module.mk index a0269649a3..0fdbdf9762 100644 --- a/engines/gob/module.mk +++ b/engines/gob/module.mk @@ -5,6 +5,7 @@ MODULE_OBJS := \ dataio.o \ databases.o \ dbase.o \ + decfile.o \ detection.o \ draw.o \ draw_v1.o \ |