[Scummvm-cvs-logs] CVS: scummvm/scumm/smush chunk.cpp,1.36,1.37 chunk.h,1.19,1.20 smush_player.cpp,1.170,1.171
Max Horn
fingolfin at users.sourceforge.net
Sun Jun 26 16:39:01 CEST 2005
Update of /cvsroot/scummvm/scummvm/scumm/smush
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21118
Modified Files:
chunk.cpp chunk.h smush_player.cpp
Log Message:
Avoid creating lots of file handles, reuse them instead (this relies on files being accessed from a single thread)
Index: chunk.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/smush/chunk.cpp,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -d -r1.36 -r1.37
--- chunk.cpp 24 Jun 2005 15:23:23 -0000 1.36
+++ chunk.cpp 26 Jun 2005 23:37:59 -0000 1.37
@@ -85,34 +85,50 @@
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 @@
}
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 @@
}
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 @@
return ptr;
}
+void MemoryChunk::reseek() {
+}
+
bool MemoryChunk::read(void *buffer, uint32 size) {
if (size <= 0 || (_curPos + size) > _size)
error("invalid buffer read request");
Index: chunk.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/smush/chunk.h,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- chunk.h 3 Apr 2005 06:27:43 -0000 1.19
+++ chunk.h 26 Jun 2005 23:37:59 -0000 1.20
@@ -39,6 +39,7 @@
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 @@
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 @@
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 @@
public:
MemoryChunk(byte *data);
Chunk *subBlock();
+ void reseek();
bool read(void *buffer, uint32 size);
int8 getChar();
byte getByte();
Index: smush_player.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/smush/smush_player.cpp,v
retrieving revision 1.170
retrieving revision 1.171
diff -u -d -r1.170 -r1.171
--- smush_player.cpp 25 Jun 2005 15:43:59 -0000 1.170
+++ smush_player.cpp 26 Jun 2005 23:37:59 -0000 1.171
@@ -892,7 +892,6 @@
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 @@
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 @@
}
delete sub;
+ _base->reseek();
+
if (_insanity)
_vm->_sound->processSound();
More information about the Scummvm-git-logs
mailing list