diff options
author | Max Horn | 2005-03-07 00:38:18 +0000 |
---|---|---|
committer | Max Horn | 2005-03-07 00:38:18 +0000 |
commit | 7dd8a39ad03ab8944d9ad37ea647bf90e26c735a (patch) | |
tree | 7c2da94b57d2f85cb250c02437732a5c3a7c75bf /scumm | |
parent | 68dce52387191fa3354cf439f426a106749d3413 (diff) | |
download | scummvm-rg350-7dd8a39ad03ab8944d9ad37ea647bf90e26c735a.tar.gz scummvm-rg350-7dd8a39ad03ab8944d9ad37ea647bf90e26c735a.tar.bz2 scummvm-rg350-7dd8a39ad03ab8944d9ad37ea647bf90e26c735a.zip |
Allocate new file objects (and real new file handles) for subchunks/subfiles -- this might (or might not) help some of the odd bugs in FT... testing, esp. on Windows, is needed
svn-id: r17018
Diffstat (limited to 'scumm')
-rw-r--r-- | scumm/smush/chunk.cpp | 58 | ||||
-rw-r--r-- | scumm/smush/chunk.h | 10 |
2 files changed, 29 insertions, 39 deletions
diff --git a/scumm/smush/chunk.cpp b/scumm/smush/chunk.cpp index 53591309c1..e8585dc4aa 100644 --- a/scumm/smush/chunk.cpp +++ b/scumm/smush/chunk.cpp @@ -85,35 +85,24 @@ bool BaseChunk::seek(int32 delta, seek_type dir) { return true; } -FileChunk::FileChunk() : - _data(0) { -} - -FileChunk::FileChunk(const char *fname) { - _data = new ScummFile(); - if (!g_scumm->openFile(*_data, fname)) - error("FileChunk: Unable to open file %s", fname); - - _type = _data->readUint32BE(); - _size = _data->readUint32BE(); - _offset = sizeof(Chunk::type) + sizeof(uint32); +FileChunk::FileChunk(const Common::String &name, int offset) + : _name(name) { + if (!g_scumm->openFile(_data, name.c_str())) + error("FileChunk: Unable to open file %s", name.c_str()); + + _data.seek(offset); + _type = _data.readUint32BE(); + _size = _data.readUint32BE(); + _offset = _data.pos(); _curPos = 0; } FileChunk::~FileChunk() { - if (_data) - _data->decRef(); } Chunk *FileChunk::subBlock() { - FileChunk *ptr = new FileChunk(); - ptr->_data = _data; - _data->incRef(); - _data->seek(_offset + _curPos); - ptr->_type = _data->readUint32BE(); - ptr->_size = _data->readUint32BE(); - ptr->_offset = _offset + _curPos + sizeof(Chunk::type) + sizeof(uint32); - ptr->_curPos = 0; + FileChunk *ptr = new FileChunk(_name, _offset + _curPos); + _data.seek(_offset + _curPos + sizeof(Chunk::type) + sizeof(uint32)); seek(sizeof(Chunk::type) + sizeof(uint32) + ptr->getSize()); return ptr; } @@ -122,8 +111,8 @@ bool FileChunk::read(void *buffer, uint32 size) { if (size <= 0 || (_curPos + size) > _size) error("invalid buffer read request"); - _data->seek(_offset + _curPos); - _data->read(buffer, size); +// _data.seek(_offset + _curPos); + _data.read(buffer, size); _curPos += size; return true; } @@ -133,13 +122,13 @@ int8 FileChunk::getChar() { } byte FileChunk::getByte() { - _data->seek(_offset + _curPos); +// _data.seek(_offset + _curPos); _curPos++; if (_curPos > _size) error("invalid byte read request"); - return _data->readByte(); + return _data.readByte(); } int16 FileChunk::getShort() { @@ -147,30 +136,31 @@ int16 FileChunk::getShort() { } uint16 FileChunk::getWord() { - _data->seek(_offset + _curPos); +// _data.seek(_offset + _curPos); _curPos += 2; if (_curPos > _size) error("invalid word read request"); - return _data->readUint16LE(); + return _data.readUint16LE(); } uint32 FileChunk::getDword() { - _data->seek(_offset + _curPos); +// _data.seek(_offset + _curPos); _curPos += 4; if (_curPos > _size) error("invalid dword read request"); - return _data->readUint32LE(); + return _data.readUint32LE(); } void FileChunk::reinit(uint32 offset) { - _offset = 0; - _data->seek(0); - _type = _data->readUint32BE(); - _size = _data->readUint32BE(); + assert(offset == 0); // FIXME: Fingolfin added this assert, because the old code used to ignore offset!!! + _data.seek(offset); + _type = _data.readUint32BE(); + _size = _data.readUint32BE(); + _offset = _data.pos(); _curPos = 0; } diff --git a/scumm/smush/chunk.h b/scumm/smush/chunk.h index f8299ef0a0..0586094dc0 100644 --- a/scumm/smush/chunk.h +++ b/scumm/smush/chunk.h @@ -23,6 +23,8 @@ #define CHUNK_H #include "common/scummsys.h" +#include "common/str.h" +#include "scumm/util.h" namespace Scumm { @@ -67,14 +69,12 @@ public: class FileChunk : public BaseChunk { private: - ScummFile *_data; + Common::String _name; + ScummFile _data; uint32 _offset; -protected: - FileChunk(); - public: - FileChunk(const char *fname); + FileChunk(const Common::String &name, int offset = 0); virtual ~FileChunk(); Chunk *subBlock(); bool read(void *buffer, uint32 size); |