aboutsummaryrefslogtreecommitdiff
path: root/scumm
diff options
context:
space:
mode:
authorMax Horn2005-06-26 23:37:59 +0000
committerMax Horn2005-06-26 23:37:59 +0000
commit0baaea85ed96a8f848d24c49d34524aa43b50ae6 (patch)
tree088b892734ebbc42a8ea64fc0594a2e67adea04e /scumm
parentf001a43830d86fd3e8d4a2b6c70ef5e7a9cb0740 (diff)
downloadscummvm-rg350-0baaea85ed96a8f848d24c49d34524aa43b50ae6.tar.gz
scummvm-rg350-0baaea85ed96a8f848d24c49d34524aa43b50ae6.tar.bz2
scummvm-rg350-0baaea85ed96a8f848d24c49d34524aa43b50ae6.zip
Avoid creating lots of file handles, reuse them instead (this relies on files being accessed from a single thread)
svn-id: r18468
Diffstat (limited to 'scumm')
-rw-r--r--scumm/smush/chunk.cpp50
-rw-r--r--scumm/smush/chunk.h10
-rw-r--r--scumm/smush/smush_player.cpp8
3 files changed, 47 insertions, 21 deletions
diff --git a/scumm/smush/chunk.cpp b/scumm/smush/chunk.cpp
index b2c2b0aeab..888e0f9fce 100644
--- a/scumm/smush/chunk.cpp
+++ b/scumm/smush/chunk.cpp
@@ -85,34 +85,50 @@ bool BaseChunk::seek(int32 delta, seek_type dir) {
return true;
}
-FileChunk::FileChunk(const Common::String &name, int offset)
- : _name(name) {
- if (!g_scumm->openFile(_data, name.c_str()))
+FileChunk::FileChunk(ScummFile *data, int offset) {
+ _data = data;
+ _deleteData = false;
+
+ _data->seek(offset, seek_start);
+ _type = _data->readUint32BE();
+ _size = _data->readUint32BE();
+ _offset = _data->pos();
+ _curPos = 0;
+}
+
+FileChunk::FileChunk(const Common::String &name, int offset) {
+ _data = new ScummFile();
+ _deleteData = true;
+ 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();
+ _data->seek(offset, seek_start);
+ _type = _data->readUint32BE();
+ _size = _data->readUint32BE();
+ _offset = _data->pos();
_curPos = 0;
}
FileChunk::~FileChunk() {
+ if (_deleteData)
+ delete _data;
}
Chunk *FileChunk::subBlock() {
- FileChunk *ptr = new FileChunk(_name, _offset + _curPos);
- _data.seek(_offset + _curPos + sizeof(Chunk::type) + sizeof(uint32));
+ FileChunk *ptr = new FileChunk(_data, _offset + _curPos);
seek(sizeof(Chunk::type) + sizeof(uint32) + ptr->getSize());
return ptr;
}
+void FileChunk::reseek() {
+ _data->seek(_offset + _curPos);
+}
+
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->read(buffer, size);
_curPos += size;
return true;
}
@@ -122,13 +138,12 @@ int8 FileChunk::getChar() {
}
byte FileChunk::getByte() {
-// _data.seek(_offset + _curPos);
_curPos++;
if (_curPos > _size)
error("invalid byte read request");
- return _data.readByte();
+ return _data->readByte();
}
int16 FileChunk::getShort() {
@@ -136,23 +151,21 @@ int16 FileChunk::getShort() {
}
uint16 FileChunk::getWord() {
-// _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);
_curPos += 4;
if (_curPos > _size)
error("invalid dword read request");
- return _data.readUint32LE();
+ return _data->readUint32LE();
}
MemoryChunk::MemoryChunk(byte *data) {
@@ -171,6 +184,9 @@ Chunk *MemoryChunk::subBlock() {
return ptr;
}
+void MemoryChunk::reseek() {
+}
+
bool MemoryChunk::read(void *buffer, uint32 size) {
if (size <= 0 || (_curPos + size) > _size)
error("invalid buffer read request");
diff --git a/scumm/smush/chunk.h b/scumm/smush/chunk.h
index f16fe22d28..ee967e21cf 100644
--- a/scumm/smush/chunk.h
+++ b/scumm/smush/chunk.h
@@ -39,6 +39,7 @@ public:
virtual type getType() const = 0;
virtual uint32 getSize() const = 0;
virtual Chunk *subBlock() = 0;
+ virtual void reseek() = 0;
virtual bool eof() const = 0;
virtual uint32 tell() const = 0;
virtual bool seek(int32 delta, seek_type dir = seek_cur) = 0;
@@ -47,7 +48,7 @@ public:
virtual byte getByte() = 0;
virtual int16 getShort() = 0;
virtual uint16 getWord() = 0;
- virtual uint32 getDword()= 0;
+ virtual uint32 getDword() = 0;
};
// Common functionality for concrete chunks (FileChunk, MemoryChunk)
@@ -69,14 +70,16 @@ public:
class FileChunk : public BaseChunk {
private:
- Common::String _name;
- ScummFile _data;
+ ScummFile *_data;
+ bool _deleteData;
uint32 _offset;
+ FileChunk(ScummFile *data, int offset);
public:
FileChunk(const Common::String &name, int offset = 0);
virtual ~FileChunk();
Chunk *subBlock();
+ void reseek();
bool read(void *buffer, uint32 size);
int8 getChar();
byte getByte();
@@ -92,6 +95,7 @@ private:
public:
MemoryChunk(byte *data);
Chunk *subBlock();
+ void reseek();
bool read(void *buffer, uint32 size);
int8 getChar();
byte getByte();
diff --git a/scumm/smush/smush_player.cpp b/scumm/smush/smush_player.cpp
index 62879b4e19..4da332f2fb 100644
--- a/scumm/smush/smush_player.cpp
+++ b/scumm/smush/smush_player.cpp
@@ -892,7 +892,6 @@ void SmushPlayer::handleFrame(Chunk &b) {
while (!b.eof()) {
Chunk *sub = b.subBlock();
- if (sub->getSize() & 1) b.seek(1);
switch (sub->getType()) {
case TYPE_NPAL:
handleNewPalette(*sub);
@@ -942,6 +941,11 @@ void SmushPlayer::handleFrame(Chunk &b) {
default:
error("Unknown frame subChunk found : %s, %d", Chunk::ChunkString(sub->getType()), sub->getSize());
}
+
+ b.reseek();
+ if (sub->getSize() & 1)
+ b.seek(1);
+
delete sub;
}
@@ -1085,6 +1089,8 @@ void SmushPlayer::parseNextFrame() {
}
delete sub;
+ _base->reseek();
+
if (_insanity)
_vm->_sound->processSound();