From 35fd91793b34b72624a89f2a76f45bc8e59020d2 Mon Sep 17 00:00:00 2001 From: Alyssa Milburn Date: Tue, 28 Aug 2012 14:26:00 +0200 Subject: TONY: Get rid of RMDataStream. --- engines/tony/game.cpp | 7 +- engines/tony/gfxcore.cpp | 12 +- engines/tony/gfxcore.h | 10 +- engines/tony/gfxengine.cpp | 5 +- engines/tony/inventory.cpp | 15 +- engines/tony/loc.cpp | 358 ++++++++++++--------------------------- engines/tony/loc.h | 42 ++--- engines/tony/mpal/mpalutils.cpp | 5 + engines/tony/mpal/mpalutils.h | 6 + engines/tony/tonychar.cpp | 13 +- engines/tony/utils.cpp | 363 ++-------------------------------------- engines/tony/utils.h | 112 +------------ 12 files changed, 180 insertions(+), 768 deletions(-) (limited to 'engines') diff --git a/engines/tony/game.cpp b/engines/tony/game.cpp index 4699a9b9aa..1ba8094ac4 100644 --- a/engines/tony/game.cpp +++ b/engines/tony/game.cpp @@ -1492,11 +1492,10 @@ void RMPointer::init() { for (i = 0; i < 5; i++) { RMRes res(RES_P_PAP1 + i); - RMDataStream ds; - - ds.openBuffer(res); + Common::SeekableReadStream *ds = res.getReadStream(); _specialPointer[i] = new RMItem; - ds >> *_specialPointer[i]; + _specialPointer[i]->readFromStream(*ds); + delete ds; } //m_hotspot[0].set(19,5); diff --git a/engines/tony/gfxcore.cpp b/engines/tony/gfxcore.cpp index f9f7cb02ec..44befa3755 100644 --- a/engines/tony/gfxcore.cpp +++ b/engines/tony/gfxcore.cpp @@ -125,7 +125,7 @@ int RMGfxSourceBuffer::init(const byte *buf, int dimx, int dimy, bool bLoadPalet return dimx * dimy * getBpp() / 8; } -void RMGfxSourceBuffer::init(RMDataStream &ds, int dimx, int dimy, bool bLoadPalette) { +void RMGfxSourceBuffer::init(Common::ReadStream &ds, int dimx, int dimy, bool bLoadPalette) { create(dimx, dimy, getBpp()); ds.read(_buf, dimx * dimy * getBpp() / 8); @@ -489,7 +489,7 @@ int RMGfxSourceBufferPal::init(const byte *buf, int dimx, int dimy, bool bLoadPa return read; } -void RMGfxSourceBufferPal::init(RMDataStream &ds, int dimx, int dimy, bool bLoadPalette) { +void RMGfxSourceBufferPal::init(Common::ReadStream &ds, int dimx, int dimy, bool bLoadPalette) { // Load the RAW image RMGfxSourceBuffer::init(ds, dimx, dimy); @@ -749,13 +749,13 @@ int RMGfxSourceBuffer8RLE::init(const byte *buf, int dimx, int dimy, bool bLoadP return RMGfxSourceBufferPal::init(buf, dimx, dimy, bLoadPalette); } -void RMGfxSourceBuffer8RLE::init(RMDataStream &ds, int dimx, int dimy, bool bLoadPalette) { +void RMGfxSourceBuffer8RLE::init(Common::ReadStream &ds, int dimx, int dimy, bool bLoadPalette) { if (_bNeedRLECompress) { RMGfxSourceBufferPal::init(ds, dimx, dimy, bLoadPalette); } else { int size; - ds >> size; + size = ds.readSint32LE(); _buf = new byte[size]; ds.read(_buf, size); @@ -1826,7 +1826,7 @@ int RMGfxSourceBuffer8RLEByteAA::init(const byte *buf, int dimx, int dimy, bool return RMGfxSourceBuffer8RLE::init(buf, dimx, dimy, bLoadPalette); } -void RMGfxSourceBuffer8RLEByteAA::init(RMDataStream &ds, int dimx, int dimy, bool bLoadPalette) { +void RMGfxSourceBuffer8RLEByteAA::init(Common::ReadStream &ds, int dimx, int dimy, bool bLoadPalette) { RMGfxSourceBuffer8RLE::init(ds, dimx, dimy, bLoadPalette); if (!_bNeedRLECompress) { @@ -1862,7 +1862,7 @@ int RMGfxSourceBuffer8RLEWordAA::init(byte *buf, int dimx, int dimy, bool bLoadP return RMGfxSourceBuffer8RLE::init(buf, dimx, dimy, bLoadPalette); } -void RMGfxSourceBuffer8RLEWordAA::init(RMDataStream &ds, int dimx, int dimy, bool bLoadPalette) { +void RMGfxSourceBuffer8RLEWordAA::init(Common::ReadStream &ds, int dimx, int dimy, bool bLoadPalette) { RMGfxSourceBuffer8RLE::init(ds, dimx, dimy, bLoadPalette); if (!_bNeedRLECompress) { diff --git a/engines/tony/gfxcore.h b/engines/tony/gfxcore.h index cd7830be24..472a4ad13a 100644 --- a/engines/tony/gfxcore.h +++ b/engines/tony/gfxcore.h @@ -290,7 +290,7 @@ public: // Load the data for the surface virtual int init(uint32 resID, int dimx, int dimy, bool bLoadPalette = false); virtual int init(const byte *buf, int dimx, int dimy, bool bLoadPalette = false); - virtual void init(RMDataStream &ds, int dimx, int dimy, bool bLoadPalette = false); + virtual void init(Common::ReadStream &ds, int dimx, int dimy, bool bLoadPalette = false); virtual ~RMGfxSourceBuffer(); @@ -343,7 +343,7 @@ public: virtual ~RMGfxSourceBufferPal(); virtual int init(const byte *buf, int dimx, int dimy, bool bLoadPalette = false); - virtual void init(RMDataStream &ds, int dimx, int dimy, bool bLoadPalette = false); + virtual void init(Common::ReadStream &ds, int dimx, int dimy, bool bLoadPalette = false); int loadPaletteWA(uint32 resID, bool bSwapped = false); int loadPaletteWA(const byte *buf, bool bSwapped = false); @@ -418,7 +418,7 @@ public: virtual ~RMGfxSourceBuffer8RLE(); // Overload of the initialization method - virtual void init(RMDataStream &ds, int dimx, int dimy, bool bLoadPalette = false); + virtual void init(Common::ReadStream &ds, int dimx, int dimy, bool bLoadPalette = false); virtual int init(const byte *buf, int dimx, int dimy, bool bLoadPalette = false); // Draw image with RLE decompression @@ -501,7 +501,7 @@ public: virtual void draw(CORO_PARAM, RMGfxTargetBuffer &bigBuf, RMGfxPrimitive *prim); // Overloaded initialization methods - virtual void init(RMDataStream &ds, int dimx, int dimy, bool bLoadPalette = false); + virtual void init(Common::ReadStream &ds, int dimx, int dimy, bool bLoadPalette = false); virtual int init(const byte *buf, int dimx, int dimy, bool bLoadPalette = false); virtual ~RMGfxSourceBuffer8RLEByteAA(); @@ -515,7 +515,7 @@ public: virtual void draw(CORO_PARAM, RMGfxTargetBuffer &bigBuf, RMGfxPrimitive *prim); // Overloaded initialization methods - virtual void init(RMDataStream &ds, int dimx, int dimy, bool bLoadPalette = false); + virtual void init(Common::ReadStream &ds, int dimx, int dimy, bool bLoadPalette = false); virtual int init(byte *buf, int dimx, int dimy, bool bLoadPalette = false); virtual ~RMGfxSourceBuffer8RLEWordAA(); diff --git a/engines/tony/gfxengine.cpp b/engines/tony/gfxengine.cpp index 25aaa625f4..e8a5df29e9 100644 --- a/engines/tony/gfxengine.cpp +++ b/engines/tony/gfxengine.cpp @@ -416,7 +416,10 @@ uint32 RMGfxEngine::loadLocation(int nLoc, RMPoint ptTonyStart, RMPoint start) { if (!res.isValid()) continue; - _loc.load(res); + Common::SeekableReadStream *ds = res.getReadStream(); + _loc.load(*ds); + delete ds; + initForNewLocation(nLoc, ptTonyStart, start); bLoaded = true; break; diff --git a/engines/tony/inventory.cpp b/engines/tony/inventory.cpp index 175d9fc6a9..dbd3ad6840 100644 --- a/engines/tony/inventory.cpp +++ b/engines/tony/inventory.cpp @@ -95,15 +95,13 @@ void RMInventory::init() { for (i = 0; i <= _nItems; i++) { // Load the items from the resource RMRes res(curres); - RMDataStream ds; - assert(res.isValid()); + Common::SeekableReadStream *ds = res.getReadStream(); // Initialize the MPAL inventory item by reading it in. _items[i]._icon.setInitCurPattern(false); - ds.openBuffer(res); - ds >> _items[i]._icon; - ds.close(); + _items[i]._icon.readFromStream(*ds); + delete ds; // Puts in the default pattern 1 _items[i]._pointer = NULL; @@ -131,13 +129,12 @@ void RMInventory::init() { _items[29]._icon.setPattern(1); // Download interface - RMDataStream ds; RMRes res(RES_I_MINIINTER); assert(res.isValid()); - ds.openBuffer(res); - ds >> _miniInterface; + Common::SeekableReadStream *ds = res.getReadStream(); + _miniInterface.readFromStream(*ds); _miniInterface.setPattern(1); - ds.close(); + delete ds; // Create the text for hints on the mini interface _hints[0].setAlignType(RMText::HCENTER, RMText::VTOP); diff --git a/engines/tony/loc.cpp b/engines/tony/loc.cpp index e767584e9b..32c857ceaa 100644 --- a/engines/tony/loc.cpp +++ b/engines/tony/loc.cpp @@ -42,52 +42,29 @@ using namespace ::Tony::MPAL; * RMPalette Methods \****************************************************************************/ -/** - * Operator for reading palette information from a data stream. - * - * @param ds Data stream - * @param pal Destination palette - * - * @returns Reference to the data stream - */ -RMDataStream &operator>>(RMDataStream &ds, RMPalette &pal) { - ds.read(pal._data, 1024); - return ds; +void RMPalette::readFromStream(Common::ReadStream &ds) { + ds.read(_data, 1024); } /****************************************************************************\ * RMSlot Methods \****************************************************************************/ -/** - * Operator for reading slot information from a data stream. - * - * @param ds Data stream - * @param slot Destination slot - * - * @returns Reference to the data stream - */ -RMDataStream &operator>>(RMDataStream &ds, RMPattern::RMSlot &slot) { - slot.readFromStream(ds); - return ds; -} - - -void RMPattern::RMSlot::readFromStream(RMDataStream &ds, bool bLOX) { +void RMPattern::RMSlot::readFromStream(Common::ReadStream &ds, bool bLOX) { byte type; // Type - ds >> type; + type = ds.readByte(); _type = (RMPattern::RMSlotType)type; // Dati - ds >> _data; + _data = ds.readSint32LE(); // Posizione - ds >> _pos; + _pos.readFromStream(ds); // Flag generica - ds >> _flag; + _flag = ds.readByte(); } @@ -95,42 +72,29 @@ void RMPattern::RMSlot::readFromStream(RMDataStream &ds, bool bLOX) { * Metodi di RMPattern \****************************************************************************/ -/** - * Operator for reading pattern information from a data stream - * - * @param ds Data stream - * @param pat Destination pattern - * - * @returns Reference to the data stream - */ -RMDataStream &operator>>(RMDataStream &ds, RMPattern &pat) { - pat.readFromStream(ds); - return ds; -} - -void RMPattern::readFromStream(RMDataStream &ds, bool bLOX) { +void RMPattern::readFromStream(Common::ReadStream &ds, bool bLOX) { int i; // Pattern name if (!bLOX) - ds >> _name; + _name = readString(ds); // Velocity - ds >> _speed; + _speed = ds.readSint32LE(); // Position - ds >> _pos; + _pos.readFromStream(ds); // Flag for pattern looping - ds >> _bLoop; + _bLoop = ds.readSint32LE(); // Number of slots - ds >> _nSlots; + _nSlots = ds.readSint32LE(); // Create and read the slots _slots = new RMSlot[_nSlots]; - for (i = 0; i < _nSlots && !ds.isError(); i++) { + for (i = 0; i < _nSlots && !ds.err(); i++) { if (bLOX) _slots[i].readFromStream(ds, true); else @@ -302,56 +266,46 @@ RMPattern::~RMPattern() { * RMSprite Methods \****************************************************************************/ -/** - * Operator for reading sprite information from a data stream. - * - * @param ds Data stream - * @param sprite Destination slot - * - * @returns Reference to the data stream - */ -RMDataStream &operator>>(RMDataStream &ds, RMSprite &sprite) { - sprite.readFromStream(ds); - return ds; -} - void RMSprite::init(RMGfxSourceBuffer *buf) { _buf = buf; } -void RMSprite::LOXGetSizeFromStream(RMDataStream &ds, int *dimx, int *dimy) { - int pos = ds.pos(); +void RMSprite::LOXGetSizeFromStream(Common::SeekableReadStream &ds, int *dimx, int *dimy) { + uint32 pos = ds.pos(); - ds >> *dimx >> *dimy; + *dimx = ds.readSint32LE(); + *dimy = ds.readSint32LE(); - ds.seek(pos, ds.START); + ds.seek(pos); } -void RMSprite::getSizeFromStream(RMDataStream &ds, int *dimx, int *dimy) { - int pos = ds.pos(); +void RMSprite::getSizeFromStream(Common::SeekableReadStream &ds, int *dimx, int *dimy) { + uint32 pos = ds.pos(); - ds >> _name; - ds >> *dimx >> *dimy; + _name = readString(ds); + *dimx = ds.readSint32LE(); + *dimy = ds.readSint32LE(); - ds.seek(pos, ds.START); + ds.seek(pos); } -void RMSprite::readFromStream(RMDataStream &ds, bool bLOX) { +void RMSprite::readFromStream(Common::SeekableReadStream &ds, bool bLOX) { int dimx, dimy; // Sprite name if (!bLOX) - ds >> _name; + _name = readString(ds); // Dimensions - ds >> dimx >> dimy; + dimx = ds.readSint32LE(); + dimy = ds.readSint32LE(); // Bounding box - ds >> _rcBox; + _rcBox.readFromStream(ds); // Unused space if (!bLOX) - ds += 32; + ds.skip(32); // Create buffer and read _buf->init(ds, dimx, dimy); @@ -381,26 +335,13 @@ RMSprite::~RMSprite() { * RMSfx Methods \****************************************************************************/ -/** - * Operator for reading SFX information from a data stream. - * - * @param ds Data stream - * @param sfx Destination SFX - * - * @returns Reference to the data stream - */ -RMDataStream &operator>>(RMDataStream &ds, RMSfx &sfx) { - sfx.readFromStream(ds); - return ds; -} - -void RMSfx::readFromStream(RMDataStream &ds, bool bLOX) { +void RMSfx::readFromStream(Common::ReadStream &ds, bool bLOX) { int size; // sfx name - ds >> _name; + _name = readString(ds); - ds >> size; + size = ds.readSint32LE(); // Read the entire buffer into a MemoryReadStream byte *buffer = (byte *)malloc(size); @@ -459,20 +400,6 @@ void RMSfx::stop() { * RMItem Methods \****************************************************************************/ -/** - * Operator for reading item information from a data stream. - * - * @param ds Data stream - * @param tem Destination item - * - * @returns Reference to the data stream - */ -RMDataStream &operator>>(RMDataStream &ds, RMItem &item) { - item.readFromStream(ds); - return ds; -} - - RMGfxSourceBuffer *RMItem::newItemSpriteBuffer(int dimx, int dimy, bool bPreRLE) { if (_cm == CM_256) { RMGfxSourceBuffer8RLE *spr; @@ -524,53 +451,55 @@ bool RMItem::isIn(const RMPoint &pt, int *size) { return rc.ptInRect(pt + _curScroll); } -void RMItem::readFromStream(RMDataStream &ds, bool bLOX) { +void RMItem::readFromStream(Common::SeekableReadStream &ds, bool bLOX) { int i, dimx, dimy; byte cm; // MPAL code - ds >> _mpalCode; + _mpalCode = ds.readSint32LE(); // Object name - ds >> _name; + _name = readString(ds); // Z (signed) - ds >> _z; + _z = ds.readSint32LE(); // Parent position - ds >> _pos; + _pos.readFromStream(ds); // Hotspot - ds >> _hot; + _hot.readFromStream(ds); // Bounding box - ds >> _rcBox; + _rcBox.readFromStream(ds); // Number of sprites, sound effects, and patterns - ds >> _nSprites >> _nSfx >> _nPatterns; + _nSprites = ds.readSint32LE(); + _nSfx = ds.readSint32LE(); + _nPatterns = ds.readSint32LE(); // Color mode - ds >> cm; + cm = ds.readByte(); _cm = (RMColorMode)cm; // Flag for the presence of custom palette differences - ds >> _bPal; + _bPal = ds.readByte(); if (_cm == CM_256) { // If there is a palette, read it in if (_bPal) - ds >> _pal; + _pal.readFromStream(ds); } // MPAL data if (!bLOX) - ds += 20; + ds.skip(20); - ds >> _FX; - ds >> _FXparm; + _FX = ds.readByte(); + _FXparm = ds.readByte(); if (!bLOX) - ds += 106; + ds.skip(106); // Create sub-classes if (_nSprites > 0) @@ -580,8 +509,8 @@ void RMItem::readFromStream(RMDataStream &ds, bool bLOX) { _patterns = new RMPattern[_nPatterns + 1]; // Read in class data - if (!ds.isError()) - for (i = 0; i < _nSprites && !ds.isError(); i++) { + if (!ds.err()) + for (i = 0; i < _nSprites && !ds.err(); i++) { // Download the sprites if (bLOX) { _sprites[i].LOXGetSizeFromStream(ds, &dimx, &dimy); @@ -597,8 +526,8 @@ void RMItem::readFromStream(RMDataStream &ds, bool bLOX) { _sprites[i].setPalette(_pal._data); } - if (!ds.isError()) - for (i = 0; i < _nSfx && !ds.isError(); i++) { + if (!ds.err()) + for (i = 0; i < _nSfx && !ds.err(); i++) { if (bLOX) _sfx[i].readFromStream(ds, true); else @@ -606,8 +535,8 @@ void RMItem::readFromStream(RMDataStream &ds, bool bLOX) { } // Read the pattern from pattern 1 - if (!ds.isError()) - for (i = 1; i <= _nPatterns && !ds.isError(); i++) { + if (!ds.err()) + for (i = 1; i <= _nPatterns && !ds.err(); i++) { if (bLOX) _patterns[i].readFromStream(ds, true); else @@ -899,11 +828,9 @@ void RMWipe::initFade(int type) { _bMustRegister = true; RMRes res(RES_W_CIRCLE); - RMDataStream ds; - - ds.openBuffer(res); - ds >> _wip0r; - ds.close(); + Common::SeekableReadStream *ds = res.getReadStream(); + _wip0r.readFromStream(*ds); + delete ds; _wip0r.setPattern(1); @@ -1706,50 +1633,45 @@ void RMCharacter::linkToBoxes(RMGameBoxes *boxes) { * RMBox Methods \****************************************************************************/ -void RMBox::readFromStream(RMDataStream &ds) { +void RMBox::readFromStream(Common::ReadStream &ds) { uint16 w; int i; byte b; // Bbox - ds >> _left; - ds >> _top; - ds >> _right; - ds >> _bottom; + _left = ds.readSint32LE(); + _top = ds.readSint32LE(); + _right = ds.readSint32LE(); + _bottom = ds.readSint32LE(); // Adjacency for (i = 0; i < MAXBOXES; i++) { - ds >> _adj[i]; + _adj[i] = ds.readSint32LE(); } // Misc - ds >> _numHotspot; - ds >> _destZ; - ds >> b; + _numHotspot = ds.readSint32LE(); + _destZ = ds.readByte(); + b = ds.readByte(); _bActive = b; - ds >> b; + b = ds.readByte(); _bReversed = b; // Reversed expansion space - ds += 30; + for (i = 0; i < 30; i++) + ds.readByte(); // Hotspots for (i = 0; i < _numHotspot; i++) { - ds >> w; + w = ds.readUint16LE(); _hotspot[i]._hotx = w; - ds >> w; + w = ds.readUint16LE(); _hotspot[i]._hoty = w; - ds >> w; + w = ds.readUint16LE(); _hotspot[i]._destination = w; } } -RMDataStream &operator>>(RMDataStream &ds, RMBox &box) { - box.readFromStream(ds); - - return ds; -} - /****************************************************************************\ * RMBoxLoc Methods \****************************************************************************/ @@ -1763,25 +1685,27 @@ RMBoxLoc::~RMBoxLoc() { delete[] _boxes; } -void RMBoxLoc::readFromStream(RMDataStream &ds) { +void RMBoxLoc::readFromStream(Common::ReadStream &ds) { int i; char buf[2]; byte ver; // ID and version - ds >> buf[0] >> buf[1] >> ver; + buf[0] = ds.readByte(); + buf[1] = ds.readByte(); + ver = ds.readByte(); assert(buf[0] == 'B' && buf[1] == 'X'); assert(ver == 3); // Number of boxes - ds >> _numbBox; + _numbBox = ds.readSint32LE(); // Allocate memory for the boxes _boxes = new RMBox[_numbBox]; // Read in boxes for (i = 0; i < _numbBox; i++) - ds >> _boxes[i]; + _boxes[i].readFromStream(ds); } void RMBoxLoc::recalcAllAdj() { @@ -1796,12 +1720,6 @@ void RMBoxLoc::recalcAllAdj() { } } -RMDataStream &operator>>(RMDataStream &ds, RMBoxLoc &bl) { - bl.readFromStream(ds); - - return ds; -} - /****************************************************************************\ * RMGameBoxes methods \****************************************************************************/ @@ -1818,21 +1736,20 @@ RMGameBoxes::~RMGameBoxes() { void RMGameBoxes::init() { int i; - RMDataStream ds; // Load boxes from disk _nLocBoxes = 130; for (i = 1; i <= _nLocBoxes; i++) { RMRes res(10000 + i); - ds.openBuffer(res); + Common::SeekableReadStream *ds = res.getReadStream(); _allBoxes[i] = new RMBoxLoc(); - ds >> *_allBoxes[i]; + _allBoxes[i]->readFromStream(*ds); _allBoxes[i]->recalcAllAdj(); - ds.close(); + delete ds; } } @@ -1946,70 +1863,13 @@ RMLocation::RMLocation() { _cmode = CM_256; } - -/** - * Load a location (.LOC) from a file that is provided. - * - * @param lpszFileName Name of the file - */ -bool RMLocation::load(const char *lpszFileName) { - Common::File f; - bool bRet; - - // Open the file for reading - if (!f.open(lpszFileName)) - return false; - - // Passes to the method variation for loading from the opened file - bRet = load(f); - - // Close the file - f.close(); - - return bRet; -} - - -/** - * Load a location (.LOC) from a given open file - * - * @param hFile File reference - * - * @returns True if succeeded OK, false in case of error. - */ -bool RMLocation::load(Common::File &file) { - bool bRet; - - file.seek(0); - - RMFileStreamSlow fs; - - fs.openFile(file); - bRet = load(fs); - fs.close(); - - return bRet; -} - - -bool RMLocation::load(const byte *buf) { - RMDataStream ds; - bool bRet; - - ds.openBuffer(buf); - bRet = load(ds); - ds.close(); - return bRet; -} - - /** * Load a location (.LOC) from a given data stream * * @param ds Data stream * @returns True if succeeded OK, false in case of error. */ -bool RMLocation::load(RMDataStream &ds) { +bool RMLocation::load(Common::SeekableReadStream &ds) { char id[3]; int dimx, dimy; byte ver; @@ -2021,7 +1881,7 @@ bool RMLocation::load(RMDataStream &ds) { _prevFixedScroll.set(-1, -1); // Check the ID - ds >> id[0] >> id[1] >> id[2]; + ds.read(id, 3); // Check if we are in a LOX if (id[0] == 'L' && id[1] == 'O' && id[2] == 'X') @@ -2032,26 +1892,28 @@ bool RMLocation::load(RMDataStream &ds) { return false; // Version - ds >> ver; + ver = ds.readByte(); assert(ver == 6); // Location name - ds >> _name; + _name = readString(ds); // Skip the MPAL bailouts (64 bytes) - ds >> TEMPNumLoc; - ds >> TEMPTonyStart._x >> TEMPTonyStart._y; - ds += 64 - 4 * 3; + TEMPNumLoc = ds.readSint32LE(); + TEMPTonyStart._x = ds.readSint32LE(); + TEMPTonyStart._y = ds.readSint32LE(); + ds.skip(64 - 4 * 3); // Skip flag associated with the background (?) - ds += 1; + ds.skip(1); // Location dimensions - ds >> dimx >> dimy; + dimx = ds.readSint32LE(); + dimy = ds.readSint32LE(); _curScroll.set(0, 0); // Read the color mode - ds >> cm; + cm = ds.readByte(); _cmode = (RMColorMode)cm; // Initialize the source buffer and read the location @@ -2076,7 +1938,7 @@ bool RMLocation::load(RMDataStream &ds) { // assert(dimy!=512); // Number of objects - ds >> _nItems; + _nItems = ds.readSint32LE(); // Create and read in the objects if (_nItems > 0) @@ -2084,32 +1946,34 @@ bool RMLocation::load(RMDataStream &ds) { g_vm->freezeTime(); - for (i = 0; i < _nItems && !ds.isError(); i++) - ds >> _items[i]; + for (i = 0; i < _nItems && !ds.err(); i++) + _items[i].readFromStream(ds); g_vm->unfreezeTime(); - return ds.isError(); + return ds.err(); } -bool RMLocation::loadLOX(RMDataStream &ds) { +bool RMLocation::loadLOX(Common::SeekableReadStream &ds) { int dimx, dimy; byte ver; int i; // Version - ds >> ver; + ver = ds.readByte(); assert(ver == 1); // Location name - ds >> _name; + _name = readString(ds); // Location number - ds >> TEMPNumLoc; - ds >> TEMPTonyStart._x >> TEMPTonyStart._y; + TEMPNumLoc = ds.readSint32LE(); + TEMPTonyStart._x = ds.readSint32LE(); + TEMPTonyStart._y = ds.readSint32LE(); // Dimensions - ds >> dimx >> dimy; + dimx = ds.readSint32LE(); + dimy = ds.readSint32LE(); _curScroll.set(0, 0); // It's always 65K (16-bit) mode @@ -2120,16 +1984,16 @@ bool RMLocation::loadLOX(RMDataStream &ds) { _buf->init(ds, dimx, dimy, true); // Number of items - ds >> _nItems; + _nItems = ds.readSint32LE(); // Create and read objects if (_nItems > 0) _items = new RMItem[_nItems]; - for (i = 0; i < _nItems && !ds.isError(); i++) + for (i = 0; i < _nItems && !ds.err(); i++) _items[i].readFromStream(ds, true); - return ds.isError(); + return ds.err(); } diff --git a/engines/tony/loc.h b/engines/tony/loc.h index acfbd45cdb..7b0a2ddd6b 100644 --- a/engines/tony/loc.h +++ b/engines/tony/loc.h @@ -62,7 +62,7 @@ public: byte _data[1024]; public: - friend RMDataStream &operator>>(RMDataStream &ds, RMPalette &pal); + void readFromStream(Common::ReadStream &ds); }; @@ -79,14 +79,12 @@ public: RMSfx(); virtual ~RMSfx(); - friend RMDataStream &operator>>(RMDataStream &ds, RMSfx &sfx); - void play(bool bLoop = false); void setVolume(int vol); void pause(bool bPause); void stop(); - void readFromStream(RMDataStream &ds, bool bLOX = false); + void readFromStream(Common::ReadStream &ds, bool bLOX = false); }; @@ -116,13 +114,11 @@ public: byte _flag; public: - friend RMDataStream &operator>>(RMDataStream &ds, RMSlot &slot); - RMPoint pos() { return _pos; } - void readFromStream(RMDataStream &ds, bool bLOX = false); + void readFromStream(Common::ReadStream &ds, bool bLOX = false); }; public: @@ -145,8 +141,6 @@ public: RMPattern(); virtual ~RMPattern(); - friend RMDataStream &operator>>(RMDataStream &ds, RMPattern &pat); - // A warning that the pattern now and the current int init(RMSfx *sfx, bool bPlayP0 = false, byte *bFlag = NULL); @@ -162,7 +156,7 @@ public: return _curPos; } - void readFromStream(RMDataStream &ds, bool bLOX = false); + void readFromStream(Common::ReadStream &ds, bool bLOX = false); private: void updateCoord(); @@ -185,13 +179,12 @@ public: virtual ~RMSprite(); void init(RMGfxSourceBuffer *buf); - friend RMDataStream &operator>>(RMDataStream &ds, RMSprite &sprite); virtual void draw(CORO_PARAM, RMGfxTargetBuffer &bigBuf, RMGfxPrimitive *prim); void setPalette(byte *lpBuf); - void getSizeFromStream(RMDataStream &ds, int *dimx, int *dimy); - void LOXGetSizeFromStream(RMDataStream &ds, int *dimx, int *dimy); + void getSizeFromStream(Common::SeekableReadStream &ds, int *dimx, int *dimy); + void LOXGetSizeFromStream(Common::SeekableReadStream &ds, int *dimx, int *dimy); - void readFromStream(RMDataStream &ds, bool bLOX = false); + void readFromStream(Common::SeekableReadStream &ds, bool bLOX = false); }; @@ -241,8 +234,6 @@ public: RMItem(); virtual ~RMItem(); - friend RMDataStream &operator>>(RMDataStream &ds, RMItem &item); - // Process to make the object move on any animations. // Returns TRUE if it should be redrawn on the next frame bool doFrame(RMGfxTargetBuffer *bigBuf, bool bAddToList = true); @@ -296,7 +287,7 @@ public: void playSfx(int nSfx); - void readFromStream(RMDataStream &ds, bool bLOX = false); + void readFromStream(Common::SeekableReadStream &ds, bool bLOX = false); void pauseSound(bool bPause); @@ -329,11 +320,7 @@ public: bool _bActive; bool _bReversed; -private: - void readFromStream(RMDataStream &ds); - -public: - friend RMDataStream &operator>>(RMDataStream &ds, RMBox &box); + void readFromStream(Common::ReadStream &ds); }; @@ -342,14 +329,12 @@ public: int _numbBox; RMBox *_boxes; -private: - void readFromStream(RMDataStream &ds); + void readFromStream(Common::ReadStream &ds); public: RMBoxLoc(); virtual ~RMBoxLoc(); - friend RMDataStream &operator >>(RMDataStream &ds, RMBoxLoc &bl); void recalcAllAdj(); }; @@ -559,11 +544,8 @@ public: virtual ~RMLocation(); // Load variations - bool load(const char *lpszFileName); - bool load(Common::File &file); - bool load(const byte *buf); - bool load(RMDataStream &ds); - bool loadLOX(RMDataStream &ds); + bool load(Common::SeekableReadStream &ds); + bool loadLOX(Common::SeekableReadStream &ds); // Unload void unload(); diff --git a/engines/tony/mpal/mpalutils.cpp b/engines/tony/mpal/mpalutils.cpp index aa22456a4b..bfc97a5f3d 100644 --- a/engines/tony/mpal/mpalutils.cpp +++ b/engines/tony/mpal/mpalutils.cpp @@ -23,6 +23,7 @@ #include "tony/mpal/mpalutils.h" #include "tony/tony.h" +#include "common/memstream.h" namespace Tony { @@ -75,6 +76,10 @@ unsigned int RMRes::size() { return globalSize(_h); } +Common::SeekableReadStream *RMRes::getReadStream() { + return new Common::MemoryReadStream(_buf, size()); +} + /****************************************************************************\ * RMResRaw methods \****************************************************************************/ diff --git a/engines/tony/mpal/mpalutils.h b/engines/tony/mpal/mpalutils.h index 19810cf3a1..19e4fa7778 100644 --- a/engines/tony/mpal/mpalutils.h +++ b/engines/tony/mpal/mpalutils.h @@ -27,6 +27,10 @@ #include "common/scummsys.h" #include "tony/mpal/memory.h" +namespace Common { + class SeekableReadStream; +} + namespace Tony { namespace MPAL { @@ -47,6 +51,8 @@ public: // Casting for access to data operator const byte*(); + + Common::SeekableReadStream *getReadStream(); }; class RMResRaw : public RMRes { diff --git a/engines/tony/tonychar.cpp b/engines/tony/tonychar.cpp index 8593ece480..9caa10bd46 100644 --- a/engines/tony/tonychar.cpp +++ b/engines/tony/tonychar.cpp @@ -87,7 +87,6 @@ RMGfxSourceBuffer *RMTony::newItemSpriteBuffer(int dimx, int dimy, bool bPreRLE) void RMTony::init() { RMRes tony(0); RMRes body(9999); - RMDataStream ds; // Tony is shown by default _bShow = _bShowShadow = true; @@ -101,18 +100,18 @@ void RMTony::init() { _bIsStaticTalk = false; // Opens the buffer - ds.openBuffer(tony); + Common::SeekableReadStream *ds = tony.getReadStream(); // Reads his details from the stream - readFromStream(ds, true); + readFromStream(*ds, true); // Closes the buffer - ds.close(); + delete ds; // Reads Tony's body - ds.openBuffer(body); - _body.readFromStream(ds, true); - ds.close(); + ds = body.getReadStream(); + _body.readFromStream(*ds, true); + delete ds; _body.setPattern(0); _nTimeLastStep = g_vm->getTime(); diff --git a/engines/tony/utils.cpp b/engines/tony/utils.cpp index 8dc1f5d615..a3f79decaf 100644 --- a/engines/tony/utils.cpp +++ b/engines/tony/utils.cpp @@ -35,360 +35,21 @@ namespace Tony { /** * Extracts a string from a data stream * @param df data stream - * @param var String */ -RMDataStream &operator>>(RMDataStream &df, Common::String &var) { +Common::String readString(Common::ReadStream &df) { + Common::String var; uint8 len; int i; - df >> len; + len = df.readByte(); for (i = 0; i < len; i++) { char c; - df >> c; + c = df.readByte(); var += c; } - return df; -} - -/****************************************************************************\ -* RMFileStreamSlow Methods -\****************************************************************************/ - -RMFileStreamSlow::RMFileStreamSlow() : RMDataStream() { - _stream = NULL; -} - -RMFileStreamSlow::~RMFileStreamSlow() { - close(); -} - -void RMFileStreamSlow::close() { - delete _stream; -} - -bool RMFileStreamSlow::openFile(Common::File &file) { - _stream = file.readStream(file.size()); - - _length = _stream->pos(); - - return true; -} - -bool RMFileStreamSlow::openFile(const char *lpFN) { - // Open file for reading - Common::File f; - if (!f.open(lpFN)) - return false; - - _length = f.size(); - _stream = f.readStream(f.size()); - - return true; -} - -RMDataStream &RMFileStreamSlow::operator+=(int nBytes) { - seek(nBytes); - return *this; -} - -int RMFileStreamSlow::pos() { - return _stream->pos(); -} - -bool RMFileStreamSlow::isEOF() { - return (pos() >= _length); -} - -int RMFileStreamSlow::seek(int nBytes, RMDSPos where) { - switch (where) { - case START: - return _stream->seek(nBytes); - - case END: - return _stream->seek(nBytes, SEEK_END); - - case CUR: - return _stream->seek(nBytes, SEEK_CUR); - - default: - return 0; - } -} - -bool RMFileStreamSlow::read(void *buf, int size) { - uint32 dwRead; - - dwRead = _stream->read(buf, size); - return ((int)dwRead == size); -} - -RMFileStreamSlow &operator>>(RMFileStreamSlow &df, char &var) { - df.read(&var, 1); - return df; -} - -RMFileStreamSlow &operator>>(RMFileStreamSlow &df, byte &var) { - df.read(&var, 1); - return df; -} - -RMFileStreamSlow &operator>>(RMFileStreamSlow &df, uint16 &var) { - uint16 v; - df.read(&v, 2); - v = FROM_LE_16(v); - return df; -} - -RMFileStreamSlow &operator>>(RMFileStreamSlow &df, int16 &var) { - uint16 v; - df.read(&v, 2); - var = (int16)FROM_LE_16(v); - return df; -} - -RMFileStreamSlow &operator>>(RMFileStreamSlow &df, int &var) { - int v; - df.read(&v, 4); - var = FROM_LE_32(v); - return df; -} - -RMFileStreamSlow &operator>>(RMFileStreamSlow &df, uint32 &var) { - uint32 v; - df.read(&v, 4); - var = FROM_LE_32(v); - return df; -} - -/****************************************************************************\ -* RMDataStream methods -\****************************************************************************/ - -/** - * Constructor - */ -RMDataStream::RMDataStream() { - _length = 0; - _pos = 0; - _bError = false; - - _buf = NULL; - _ecode = 0; -} - -/** - * Destructor - */ -RMDataStream::~RMDataStream() { - close(); -} - -/** - * Close a stream - */ -void RMDataStream::close() { - _length = 0; - _pos = 0; -} - -/** - * Takes the address of the buffer from which will be read the data. - * @param lpBuf Data buffer - * @param size Size of the buffer - * @remarks If the length of the buffer is not known, and cannot be - * specified, then EOF() and Seek() to end won't work. - */ -void RMDataStream::openBuffer(const byte *lpBuf, int size) { - _length = size; - _buf = lpBuf; - _bError = false; - _pos = 0; -} - -/** - * Returns the length of the stream - * @returns Stream length - */ -int RMDataStream::length() { - return _length; -} - -/** - * Determines if the end of the stream has been reached - * @returns true if end of stream reached, false if not - */ -bool RMDataStream::isEOF() { - return (_pos >= _length); -} - -/** - * Extracts data from the stream - * @param df Stream - * @param var Variable of a supported type - * @returns Value read from the stream - */ -RMDataStream &operator>>(RMDataStream &df, char &var) { - df.read(&var, 1); - return df; -} - -/** - * Extracts data from the stream - * @param df Stream - * @param var Variable of a supported type - * @returns Value read from the stream - */ -RMDataStream &operator>>(RMDataStream &df, uint8 &var) { - df.read(&var, 1); - return df; -} - -/** - * Extracts data from the stream - * @param df Stream - * @param var Variable of a supported type - * @returns Value read from the stream - */ -RMDataStream &operator>>(RMDataStream &df, uint16 &var) { - uint16 v; - df.read(&v, 2); - - var = FROM_LE_16(v); - return df; -} - -/** - * Extracts data from the stream - * @param df Stream - * @param var Variable of a supported type - * @returns Value read from the stream - */ -RMDataStream &operator>>(RMDataStream &df, int16 &var) { - uint16 v; - df.read(&v, 2); - - var = (int16)FROM_LE_16(v); - return df; -} - -/** - * Extracts data from the stream - * @param df Stream - * @param var Variable of a supported type - * @returns Value read from the stream - */ -RMDataStream &operator>>(RMDataStream &df, int &var) { - uint32 v; - df.read(&v, 4); - - var = (int)FROM_LE_32(v); - return df; -} - -/** - * Extracts data from the stream - * @param df Stream - * @param var Variable of a supported type - * @returns Value read from the stream - */ -RMDataStream &operator>>(RMDataStream &df, uint32 &var) { - uint32 v; - df.read(&v, 4); - - var = FROM_LE_32(v); - return df; -} - -/** - * Reads a series of data from the stream in a buffer - * @param lpBuf Data buffer - * @param size Size of the buffer - * @returns true if we have reached the end, false if not - */ -bool RMDataStream::read(void *lpBuf, int size) { - byte *dest = (byte *)lpBuf; - - if ((_pos + size) > _length) { - Common::copy(_buf + _pos, _buf + _pos + (_length - _pos), dest); - - return true; - } else { - Common::copy(_buf + _pos, _buf + _pos + size, dest); - - _pos += size; - return false; - } -} - -/** - * Skips a number of bytes in the stream - * @param nBytres Number of bytes to skip - * @returns The stream - */ -RMDataStream &RMDataStream::operator+=(int nBytes) { - _pos += nBytes; - return *this; -} - -/** - * Seeks to a position within the stream - * @param nBytes Number of bytes from specified origin - * @param origin Origin to do offset from - * @returns The absolute current position in bytes - */ -int RMDataStream::seek(int nBytes, RMDSPos origin) { - switch (origin) { - case CUR: - break; - - case START: - _pos = 0; - break; - - case END: - if (_length == SIZENOTKNOWN) - return _pos; - _pos = _length; - break; - } - - _pos += nBytes; - return _pos; -} - -/** - * Returns the current position of the stream - * @returns The current position - */ -int RMDataStream::pos() { - return _pos; -} - -/** - * Check if an error occurred during reading the stream - * @returns true if there was an error, false otherwise - */ -bool RMDataStream::isError() { - return _bError; -} - -/** - * Sets an error code for the stream - * @param code Error code - */ -void RMDataStream::setError(int code) { - _bError = true; - _ecode = code; -} - -/** - * Returns the error code for the stream - * @returns Error code - */ -int RMDataStream::getError() { - return _ecode; + return var; } /****************************************************************************\ @@ -507,9 +168,9 @@ bool RMPoint::operator!=(RMPoint p) { /** * Reads a point from a stream */ -RMDataStream &operator>>(RMDataStream &ds, RMPoint &p) { - ds >> p._x >> p._y; - return ds; +void RMPoint::readFromStream(Common::ReadStream &ds) { + _x = ds.readSint32LE(); + _y = ds.readSint32LE(); } /****************************************************************************\ @@ -663,9 +324,11 @@ void RMRect::normalizeRect() { setRect(MIN(_x1, _x2), MIN(_y1, _y2), MAX(_x1, _x2), MAX(_y1, _y2)); } -RMDataStream &operator>>(RMDataStream &ds, RMRect &rc) { - ds >> rc._x1 >> rc._y1 >> rc._x2 >> rc._y2; - return ds; +void RMRect::readFromStream(Common::ReadStream &ds) { + _x1 = ds.readSint32LE(); + _y1 = ds.readSint32LE(); + _x2 = ds.readSint32LE(); + _y2 = ds.readSint32LE(); } /****************************************************************************\ diff --git a/engines/tony/utils.h b/engines/tony/utils.h index 50b18d8aa7..d3f93e06ef 100644 --- a/engines/tony/utils.h +++ b/engines/tony/utils.h @@ -39,113 +39,7 @@ namespace Tony { using namespace ::Tony::MPAL; -/** - * Data stream for reading data - */ -class RMDataStream { -protected: - const byte *_buf; - int _length; - int _pos; - bool _bError; - int _ecode; - -public: - enum RMDSPos { - CUR, - START, - END - }; - -private: - enum { - SIZENOTKNOWN = 0x7FFFFFFF - }; - -public: - // Constructor and destructor - RMDataStream(); - virtual ~RMDataStream(); - - // Loading buffer - void openBuffer(const byte *buf, int size = SIZENOTKNOWN); - void close(); - - // Attributei - int length(); - virtual int pos(); - - // EOF - virtual bool isEOF(); - - // Read methods - friend RMDataStream &operator>>(RMDataStream &df, char &var); - friend RMDataStream &operator>>(RMDataStream &df, byte &var); - friend RMDataStream &operator>>(RMDataStream &df, uint16 &var); - friend RMDataStream &operator>>(RMDataStream &df, int16 &var); - friend RMDataStream &operator>>(RMDataStream &df, int &var); - friend RMDataStream &operator>>(RMDataStream &df, uint32 &var); - - // General read - virtual bool read(void *buf, int size); - - // Skipping & Seeking - virtual RMDataStream &operator+=(int nBytes); - virtual int seek(int nBytes, RMDSPos origin = CUR); - - // Error handling - void setError(int ecode); - int getError(); - bool isError(); -}; - -/** - * Data stream per lettura di dati aperto da file - */ -class RMFileStream : public RMDataStream { -private: - byte *_buf; - -public: - RMFileStream(); - virtual ~RMFileStream(); - - // Methods for opening file - bool openFile(const char *lpFN); - bool openFile(Common::File &file); - - void close(); -}; - -class RMFileStreamSlow : public RMDataStream { -private: - Common::SeekableReadStream *_stream; -public: - RMFileStreamSlow(); - virtual ~RMFileStreamSlow(); - - bool openFile(const char *lpFN); - bool openFile(Common::File &file); - - void close(); - - RMDataStream &operator+=(int nBytes); - int seek(int nBytes, RMDSPos where = CUR); - - int pos(); - virtual bool isEOF(); - - bool read(void *buf, int size); - - friend RMFileStreamSlow &operator>>(RMFileStreamSlow &df, char &var); - friend RMFileStreamSlow &operator>>(RMFileStreamSlow &df, byte &var); - friend RMFileStreamSlow &operator>>(RMFileStreamSlow &df, uint16 &var); - friend RMFileStreamSlow &operator>>(RMFileStreamSlow &df, int16 &var); - friend RMFileStreamSlow &operator>>(RMFileStreamSlow &df, int &var); - friend RMFileStreamSlow &operator>>(RMFileStreamSlow &df, uint32 &var); -}; - -RMDataStream &operator>>(RMDataStream &df, Common::String &var); +Common::String readString(Common::ReadStream &ds); /** * Point class @@ -186,7 +80,7 @@ public: operator Common::Point() const; // Extraction from data streams - friend RMDataStream &operator>>(RMDataStream &ds, RMPoint &p); + void readFromStream(Common::ReadStream &ds); }; class RMPointReference { @@ -256,7 +150,7 @@ public: } // Extract from data stream - friend RMDataStream &operator>>(RMDataStream &ds, RMRect &rc); + void readFromStream(Common::ReadStream &ds); }; /** -- cgit v1.2.3