diff options
author | Sven Hesse | 2007-07-31 01:43:32 +0000 |
---|---|---|
committer | Sven Hesse | 2007-07-31 01:43:32 +0000 |
commit | 34292a6b586a44aa8fb9361369dddf854ce999c6 (patch) | |
tree | 4ec8a73772f15db9db8c6157d508aa3a283dbe96 /engines/gob | |
parent | 32d00708687d10152ebc84df86b84aaad2059478 (diff) | |
download | scummvm-rg350-34292a6b586a44aa8fb9361369dddf854ce999c6.tar.gz scummvm-rg350-34292a6b586a44aa8fb9361369dddf854ce999c6.tar.bz2 scummvm-rg350-34292a6b586a44aa8fb9361369dddf854ce999c6.zip |
Minor DataIO-cleanup
svn-id: r28349
Diffstat (limited to 'engines/gob')
-rw-r--r-- | engines/gob/cdrom.cpp | 17 | ||||
-rw-r--r-- | engines/gob/dataio.cpp | 49 | ||||
-rw-r--r-- | engines/gob/dataio.h | 11 | ||||
-rw-r--r-- | engines/gob/game.cpp | 29 | ||||
-rw-r--r-- | engines/gob/init.cpp | 17 | ||||
-rw-r--r-- | engines/gob/inter_v1.cpp | 15 | ||||
-rw-r--r-- | engines/gob/inter_v2.cpp | 12 |
7 files changed, 69 insertions, 81 deletions
diff --git a/engines/gob/cdrom.cpp b/engines/gob/cdrom.cpp index 6b32720cff..2ee8595ad3 100644 --- a/engines/gob/cdrom.cpp +++ b/engines/gob/cdrom.cpp @@ -68,29 +68,30 @@ void CDROM::readLIC(const char *fname) { _vm->_dataIO->getUnpackedData(tmp); handle = _vm->_dataIO->openData(tmp); + DataStream *stream = _vm->_dataIO->openAsStream(handle, true); - version = _vm->_dataIO->readUint16(handle); - startChunk = _vm->_dataIO->readUint16(handle); - _numTracks = _vm->_dataIO->readUint16(handle); + version = stream->readUint16LE(); + startChunk = stream->readUint16LE(); + _numTracks = stream->readUint16LE(); if (version != 3) error("%s: Unknown version %d", fname, version); - _vm->_dataIO->seekData(handle, 50, SEEK_SET); + stream->seek(50); for (int i = 0; i < startChunk; i++) { - pos = _vm->_dataIO->readUint16(handle); + pos = stream->readUint16LE(); if (!pos) break; - _vm->_dataIO->seekData(handle, pos, SEEK_CUR); + stream->skip(pos); } _LICbuffer = new byte[_numTracks * 22]; - _vm->_dataIO->readData(handle, _LICbuffer, _numTracks * 22); + stream->read(_LICbuffer, _numTracks * 22); - _vm->_dataIO->closeData(handle); + delete stream; } void CDROM::freeLICbuffer() { diff --git a/engines/gob/dataio.cpp b/engines/gob/dataio.cpp index 73318adc14..3c5dbed575 100644 --- a/engines/gob/dataio.cpp +++ b/engines/gob/dataio.cpp @@ -480,39 +480,14 @@ DataStream *DataIO::openAsStream(int16 handle, bool dispose) { return new DataStream(*this, handle, size, dispose); } -int32 DataIO::readData(int16 handle, byte *buf, uint16 size) { - int32 res; - - res = readChunk(handle, buf, size); - if (res >= 0) - return res; - - return file_getHandle(handle)->read(buf, size); -} - -byte DataIO::readByte(int16 handle) { - byte buf; - - readData(handle, &buf, 1); - return ((byte) buf); -} - -uint16 DataIO::readUint16(int16 handle) { - byte buf[2]; - - readData(handle, buf, 2); - return READ_LE_UINT16(buf); -} - -uint32 DataIO::readUint32(int16 handle) { - byte buf[4]; +uint32 DataIO::getPos(int16 handle) { + uint32 resPos; - readData(handle, buf, 4); - return READ_LE_UINT32(buf); -} + resPos = getChunkPos(handle); + if (resPos != 0xFFFFFFFF) + return resPos; -int32 DataIO::writeData(int16 handle, byte *buf, uint16 size) { - return file_getHandle(handle)->write(buf, size); + return file_getHandle(handle)->pos(); } void DataIO::seekData(int16 handle, int32 pos, int16 from) { @@ -525,14 +500,14 @@ void DataIO::seekData(int16 handle, int32 pos, int16 from) { file_getHandle(handle)->seek(pos, from); } -uint32 DataIO::getPos(int16 handle) { - uint32 resPos; +int32 DataIO::readData(int16 handle, byte *buf, uint16 size) { + int32 res; - resPos = getChunkPos(handle); - if (resPos != 0xFFFFFFFF) - return resPos; + res = readChunk(handle, buf, size); + if (res >= 0) + return res; - return file_getHandle(handle)->pos(); + return file_getHandle(handle)->read(buf, size); } int32 DataIO::getDataSize(const char *name) { diff --git a/engines/gob/dataio.h b/engines/gob/dataio.h index 3560093d9e..b30a389865 100644 --- a/engines/gob/dataio.h +++ b/engines/gob/dataio.h @@ -83,13 +83,6 @@ public: Common::File::AccessMode mode = Common::File::kFileReadMode); DataStream *openAsStream(int16 handle, bool dispose = false); - int32 readData(int16 handle, byte *buf, uint16 size); - byte readByte(int16 handle); - uint16 readUint16(int16 handle); - uint32 readUint32(int16 handle); - int32 writeData(int16 handle, byte *buf, uint16 size); - void seekData(int16 handle, int32 pos, int16 from); - uint32 getPos(int16 handle); int32 getDataSize(const char *name); byte *getData(const char *path); DataStream *getDataStream(const char *path); @@ -123,6 +116,10 @@ protected: uint32 getChunkPos(int16 handle) const; int32 getChunkSize(const char *chunkName); + uint32 getPos(int16 handle); + void seekData(int16 handle, int32 pos, int16 from); + int32 readData(int16 handle, byte *buf, uint16 size); + friend class DataStream; }; diff --git a/engines/gob/game.cpp b/engines/gob/game.cpp index b625a35258..37817c12a3 100644 --- a/engines/gob/game.cpp +++ b/engines/gob/game.cpp @@ -174,8 +174,10 @@ byte *Game::loadExtData(int16 itemId, int16 *pResWidth, } else handle = _extHandle; + DataStream *stream = _vm->_dataIO->openAsStream(handle); + debugC(7, kDebugFileIO, "off: %d size: %d", offset, tableSize); - _vm->_dataIO->seekData(handle, offset + tableSize, SEEK_SET); + stream->seek(offset + tableSize); realSize = size; if (isPacked) dataBuf = new byte[size + 2]; @@ -185,11 +187,13 @@ byte *Game::loadExtData(int16 itemId, int16 *pResWidth, dataPtr = dataBuf; while (size > 32000) { // BUG: huge->far conversion. Need normalization? - _vm->_dataIO->readData(handle, dataPtr, 32000); + stream->read(dataPtr, 32000); size -= 32000; dataPtr += 32000; } - _vm->_dataIO->readData(handle, dataPtr, size); + stream->read(dataPtr, size); + + delete stream; if (commonHandle != -1) { _vm->_dataIO->closeData(commonHandle); _extHandle = _vm->_dataIO->openData(_curExtFile); @@ -421,23 +425,26 @@ void Game::loadExtTable(void) { if (_extHandle < 0) return; - count = _vm->_dataIO->readUint16(_extHandle); + DataStream *stream = _vm->_dataIO->openAsStream(_extHandle); + count = stream->readUint16LE(); - _vm->_dataIO->seekData(_extHandle, 0, SEEK_SET); + stream->seek(0); _extTable = new ExtTable; _extTable->items = 0; if (count) _extTable->items = new ExtItem[count]; - _extTable->itemsCount = _vm->_dataIO->readUint16(_extHandle); - _extTable->unknown = _vm->_dataIO->readByte(_extHandle); + _extTable->itemsCount = stream->readUint16LE(); + _extTable->unknown = stream->readByte(); for (int i = 0; i < count; i++) { - _extTable->items[i].offset = _vm->_dataIO->readUint32(_extHandle); - _extTable->items[i].size = _vm->_dataIO->readUint16(_extHandle); - _extTable->items[i].width = _vm->_dataIO->readUint16(_extHandle); - _extTable->items[i].height = _vm->_dataIO->readUint16(_extHandle); + _extTable->items[i].offset = stream->readUint32LE(); + _extTable->items[i].size = stream->readUint16LE(); + _extTable->items[i].width = stream->readUint16LE(); + _extTable->items[i].height = stream->readUint16LE(); } + + delete stream; } void Game::loadImFile(void) { diff --git a/engines/gob/init.cpp b/engines/gob/init.cpp index 85f95fb261..4712a19a5d 100644 --- a/engines/gob/init.cpp +++ b/engines/gob/init.cpp @@ -147,10 +147,12 @@ void Init::initGame(const char *totName) { handle = _vm->_dataIO->openData(buffer); if (handle >= 0) { - // Get variables count - _vm->_dataIO->seekData(handle, 0x2C, SEEK_SET); - varsCount = _vm->_dataIO->readUint16(handle); - _vm->_dataIO->closeData(handle); + DataStream *stream = _vm->_dataIO->openAsStream(handle, true); + + stream->seek(0x2C); + varsCount = stream->readUint16LE(); + + delete stream; _vm->_global->_inter_variables = new byte[varsCount * 4]; _vm->_global->_inter_variablesSizes = new byte[varsCount * 4]; @@ -178,9 +180,12 @@ void Init::initGame(const char *totName) { _vm->_draw->closeScreen(); } else if ((imdHandle = _vm->_dataIO->openData("coktel.clt")) >= 0) { _vm->_draw->initScreen(); + + stream = _vm->_dataIO->openAsStream(imdHandle, true); _vm->_util->clearPalette(); - _vm->_dataIO->readData(imdHandle, (byte *) _vm->_draw->_vgaPalette, 768); - _vm->_dataIO->closeData(imdHandle); + stream->read((byte *) _vm->_draw->_vgaPalette, 768); + delete stream; + imdHandle = _vm->_dataIO->openData("coktel.ims"); if (imdHandle >= 0) { byte *sprBuf; diff --git a/engines/gob/inter_v1.cpp b/engines/gob/inter_v1.cpp index 7f5a641c1b..5d74138db1 100644 --- a/engines/gob/inter_v1.cpp +++ b/engines/gob/inter_v1.cpp @@ -2225,22 +2225,23 @@ bool Inter_v1::o1_readData(OpFuncParams ¶ms) { WRITE_VAR(1, 1); handle = _vm->_dataIO->openData(_vm->_global->_inter_resStr); if (handle >= 0) { + DataStream *stream = _vm->_dataIO->openAsStream(handle, true); + _vm->_draw->animateCursor(4); if (offset < 0) - _vm->_dataIO->seekData(handle, -offset - 1, SEEK_END); + stream->seek(-offset - 1, SEEK_END); else - _vm->_dataIO->seekData(handle, offset, SEEK_SET); + stream->seek(offset); if (((dataVar >> 2) == 59) && (size == 4)) - WRITE_VAR(59, _vm->_dataIO->readUint32(handle)); + WRITE_VAR(59, stream->readUint32LE()); else - retSize = _vm->_dataIO->readData(handle, - _vm->_global->_inter_variables + dataVar, size); - - _vm->_dataIO->closeData(handle); + retSize = stream->read(_vm->_global->_inter_variables + dataVar, size); if (retSize == size) WRITE_VAR(1, 0); + + delete stream; } if (_vm->_game->_extHandle >= 0) diff --git a/engines/gob/inter_v2.cpp b/engines/gob/inter_v2.cpp index 58970d9fcd..23abc38f6c 100644 --- a/engines/gob/inter_v2.cpp +++ b/engines/gob/inter_v2.cpp @@ -1903,25 +1903,27 @@ bool Inter_v2::o2_readData(OpFuncParams ¶ms) { if (handle < 0) return false; + DataStream *stream = _vm->_dataIO->openAsStream(handle, true); + _vm->_draw->animateCursor(4); if (offset < 0) - _vm->_dataIO->seekData(handle, -offset - 1, SEEK_END); + stream->seek(-offset - 1, SEEK_END); else - _vm->_dataIO->seekData(handle, offset, SEEK_SET); + stream->seek(offset); if (((dataVar >> 2) == 59) && (size == 4)) { - WRITE_VAR(59, _vm->_dataIO->readUint32(handle)); + WRITE_VAR(59, stream->readUint32LE()); // The scripts in some versions divide through 256^3 then, // effectively doing a LE->BE conversion if ((_vm->_platform != Common::kPlatformPC) && (VAR(59) < 256)) WRITE_VAR(59, SWAP_BYTES_32(VAR(59))); } else - retSize = _vm->_dataIO->readData(handle, buf, size); + retSize = stream->read(buf, size); if (retSize == size) WRITE_VAR(1, 0); - _vm->_dataIO->closeData(handle); + delete stream; return false; } |