From 17e3bfd42c4c66b9bd3ac199f63b8c20c63e8517 Mon Sep 17 00:00:00 2001 From: Sven Hesse Date: Sun, 11 Mar 2012 18:31:39 +0100 Subject: GOB: Add a class for CMP sprites with RXY coordinates --- engines/gob/cmpfile.cpp | 233 ++++++++++++++++++++++++++++++++++++++++++++++++ engines/gob/cmpfile.h | 96 ++++++++++++++++++++ engines/gob/module.mk | 1 + engines/gob/rxyfile.cpp | 9 ++ engines/gob/rxyfile.h | 1 + 5 files changed, 340 insertions(+) create mode 100644 engines/gob/cmpfile.cpp create mode 100644 engines/gob/cmpfile.h (limited to 'engines') diff --git a/engines/gob/cmpfile.cpp b/engines/gob/cmpfile.cpp new file mode 100644 index 0000000000..62ac9f3fa4 --- /dev/null +++ b/engines/gob/cmpfile.cpp @@ -0,0 +1,233 @@ +/* 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/stream.h" +#include "common/str.h" + +#include "gob/gob.h" +#include "gob/util.h" +#include "gob/surface.h" +#include "gob/video.h" +#include "gob/dataio.h" +#include "gob/rxyfile.h" +#include "gob/cmpfile.h" + +namespace Gob { + +CMPFile::CMPFile(GobEngine *vm, const Common::String &baseName, + uint16 width, uint16 height, uint8 bpp) : + _vm(vm), _width(width), _height(height), _bpp(bpp), _maxWidth(0), _maxHeight(0), + _surface(0), _coordinates(0) { + + if (baseName.empty()) + return; + + const Common::String rxyFile = Util::setExtension(baseName, ".RXY"); + const Common::String cmpFile = Util::setExtension(baseName, ".CMP"); + + if (!_vm->_dataIO->hasFile(cmpFile)) + return; + + loadRXY(rxyFile); + createSurface(); + + loadCMP(cmpFile); +} + +CMPFile::CMPFile(GobEngine *vm, const Common::String &cmpFile, const Common::String &rxyFile, + uint16 width, uint16 height, uint8 bpp) : + _vm(vm), _width(width), _height(height), _bpp(bpp), _maxWidth(0), _maxHeight(0), + _surface(0), _coordinates(0) { + + if (cmpFile.empty() || !_vm->_dataIO->hasFile(cmpFile)) + return; + + loadRXY(rxyFile); + createSurface(); + + loadCMP(cmpFile); +} + +CMPFile::CMPFile(GobEngine *vm, Common::SeekableReadStream &cmp, Common::SeekableReadStream &rxy, + uint16 width, uint16 height, uint8 bpp) : + _vm(vm), _width(width), _height(height), _bpp(bpp), _maxWidth(0), _maxHeight(0), + _surface(0), _coordinates(0) { + + loadRXY(rxy); + createSurface(); + + loadCMP(cmp); +} + +CMPFile::CMPFile(GobEngine *vm, Common::SeekableReadStream &cmp, + uint16 width, uint16 height, uint8 bpp) : + _vm(vm), _width(width), _height(height), _bpp(bpp), _maxWidth(0), _maxHeight(0), + _surface(0), _coordinates(0) { + + createRXY(); + createSurface(); + + loadCMP(cmp); +} + +CMPFile::~CMPFile() { + delete _surface; + delete _coordinates; +} + +bool CMPFile::empty() const { + return (_surface == 0) || (_coordinates == 0); +} + +uint16 CMPFile::getSpriteCount() const { + if (empty()) + return 0; + + return _coordinates->size(); +} + +void CMPFile::loadCMP(const Common::String &cmp) { + Common::SeekableReadStream *dataCMP = _vm->_dataIO->getFile(cmp); + if (!dataCMP) + return; + + loadCMP(*dataCMP); + + delete dataCMP; +} + +void CMPFile::loadRXY(const Common::String &rxy) { + Common::SeekableReadStream *dataRXY = 0; + if (!rxy.empty()) + dataRXY = _vm->_dataIO->getFile(rxy); + + if (dataRXY) + loadRXY(*dataRXY); + else + createRXY(); + + _height = _coordinates->getHeight(); + + delete dataRXY; +} + +void CMPFile::loadCMP(Common::SeekableReadStream &cmp) { + uint32 size = cmp.size(); + byte *data = new byte[size]; + + if (cmp.read(data, size) != size) + return; + + _vm->_video->drawPackedSprite(data, _surface->getWidth(), _surface->getHeight(), 0, 0, 0, *_surface); + + delete[] data; +} + +void CMPFile::loadRXY(Common::SeekableReadStream &rxy) { + _coordinates = new RXYFile(rxy); + + for (uint i = 0; i < _coordinates->size(); i++) { + const RXYFile::Coordinates &c = (*_coordinates)[i]; + + if (c.left == 0xFFFF) + continue; + + const uint16 width = c.right - c.left + 1; + const uint16 height = c.bottom - c.top + 1; + + _maxWidth = MAX(_maxWidth , width); + _maxHeight = MAX(_maxHeight, height); + } +} + +void CMPFile::createRXY() { + _coordinates = new RXYFile(_width, _height); + + _maxWidth = _width; + _maxHeight = _height; +} + +void CMPFile::createSurface() { + if (_width == 0) + _width = 320; + if (_height == 0) + _height = 200; + + _surface = new Surface(_width, _height, _bpp); +} + +bool CMPFile::getCoordinates(uint16 sprite, uint16 &left, uint16 &top, uint16 &right, uint16 &bottom) const { + if (empty() || (sprite >= _coordinates->size())) + return false; + + left = (*_coordinates)[sprite].left; + top = (*_coordinates)[sprite].top; + right = (*_coordinates)[sprite].right; + bottom = (*_coordinates)[sprite].bottom; + + return left != 0xFFFF; +} + +uint16 CMPFile::getWidth(uint16 sprite) const { + if (empty() || (sprite >= _coordinates->size())) + return 0; + + return (*_coordinates)[sprite].right - (*_coordinates)[sprite].left + 1; +} + +uint16 CMPFile::getHeight(uint16 sprite) const { + if (empty() || (sprite >= _coordinates->size())) + return 0; + + return (*_coordinates)[sprite].bottom - (*_coordinates)[sprite].top + 1; +} + +void CMPFile::getMaxSize(uint16 &width, uint16 &height) const { + width = _maxWidth; + height = _maxHeight; +} + +void CMPFile::draw(Surface &dest, uint16 sprite, uint16 x, uint16 y, int32 transp) const { + if (empty()) + return; + + if (sprite >= _coordinates->size()) + return; + + const RXYFile::Coordinates &coords = (*_coordinates)[sprite]; + + draw(dest, coords.left, coords.top, coords.right, coords.bottom, x, y, transp); +} + +void CMPFile::draw(Surface &dest, uint16 left, uint16 top, uint16 right, uint16 bottom, + uint16 x, uint16 y, int32 transp) const { + + if (!_surface) + return; + + if (left == 0xFFFF) + return; + + dest.blit(*_surface, left, top, right, bottom, x, y, transp); +} + +} // End of namespace Gob diff --git a/engines/gob/cmpfile.h b/engines/gob/cmpfile.h new file mode 100644 index 0000000000..d409e15161 --- /dev/null +++ b/engines/gob/cmpfile.h @@ -0,0 +1,96 @@ +/* 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_CMPFILE_H +#define GOB_CMPFILE_H + +#include "common/system.h" +#include "common/array.h" + +namespace Common { + class String; + class SeekableReadStream; +} + +namespace Gob { + +class GobEngine; +class Surface; +class RXYFile; + +/** A CMP file, containing a sprite. + * + * Used in hardcoded "actiony" parts of gob games. + */ +class CMPFile { +public: + CMPFile(GobEngine *vm, const Common::String &baseName, + uint16 width, uint16 height, uint8 bpp = 1); + CMPFile(GobEngine *vm, const Common::String &cmpFile, const Common::String &rxyFile, + uint16 width, uint16 height, uint8 bpp = 1); + CMPFile(GobEngine *vm, Common::SeekableReadStream &cmp, Common::SeekableReadStream &rxy, + uint16 width, uint16 height, uint8 bpp = 1); + CMPFile(GobEngine *vm, Common::SeekableReadStream &cmp, + uint16 width, uint16 height, uint8 bpp = 1); + ~CMPFile(); + + bool empty() const; + + uint16 getSpriteCount() const; + + bool getCoordinates(uint16 sprite, uint16 &left, uint16 &top, uint16 &right, uint16 &bottom) const; + + uint16 getWidth (uint16 sprite) const; + uint16 getHeight(uint16 sprite) const; + + void getMaxSize(uint16 &width, uint16 &height) const; + + void draw(Surface &dest, uint16 sprite, uint16 x, uint16 y, int32 transp = -1) const; + void draw(Surface &dest, uint16 left, uint16 top, uint16 right, uint16 bottom, + uint16 x, uint16 y, int32 transp = -1) const; + +private: + GobEngine *_vm; + + uint16 _width; + uint16 _height; + uint16 _bpp; + + uint16 _maxWidth; + uint16 _maxHeight; + + Surface *_surface; + RXYFile *_coordinates; + + void loadCMP(const Common::String &cmp); + void loadRXY(const Common::String &rxy); + + void loadCMP(Common::SeekableReadStream &cmp); + void loadRXY(Common::SeekableReadStream &rxy); + + void createRXY(); + void createSurface(); +}; + +} // End of namespace Gob + +#endif // GOB_CMPFILE_H diff --git a/engines/gob/module.mk b/engines/gob/module.mk index 1c83b4ae40..9da5a82de2 100644 --- a/engines/gob/module.mk +++ b/engines/gob/module.mk @@ -5,6 +5,7 @@ MODULE_OBJS := \ aniobject.o \ cheater.o \ cheater_geisha.o \ + cmpfile.o \ console.o \ dataio.o \ databases.o \ diff --git a/engines/gob/rxyfile.cpp b/engines/gob/rxyfile.cpp index 5311eece0f..06a07bdc9c 100644 --- a/engines/gob/rxyfile.cpp +++ b/engines/gob/rxyfile.cpp @@ -30,6 +30,15 @@ RXYFile::RXYFile(Common::SeekableReadStream &rxy) : _width(0), _height(0) { load(rxy); } +RXYFile::RXYFile(uint16 width, uint16 height) : _realCount(1), _width(width), _height(height) { + _coords.resize(1); + + _coords[0].left = 0; + _coords[0].top = 0; + _coords[0].right = _width - 1; + _coords[0].bottom = _height - 1; +} + RXYFile::~RXYFile() { } diff --git a/engines/gob/rxyfile.h b/engines/gob/rxyfile.h index 828f8b73c7..3b4d3de636 100644 --- a/engines/gob/rxyfile.h +++ b/engines/gob/rxyfile.h @@ -46,6 +46,7 @@ public: }; RXYFile(Common::SeekableReadStream &rxy); + RXYFile(uint16 width, uint16 height); ~RXYFile(); uint size() const; -- cgit v1.2.3