aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--scumm/smush/chunk.cpp58
-rw-r--r--scumm/smush/chunk.h10
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);