[Scummvm-cvs-logs] CVS: scummvm/scumm/smush chunk.cpp,1.30,1.31 chunk.h,1.17,1.18

Max Horn fingolfin at users.sourceforge.net
Sun Mar 6 16:38:40 CET 2005


Update of /cvsroot/scummvm/scummvm/scumm/smush
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12475

Modified Files:
	chunk.cpp chunk.h 
Log Message:
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

Index: chunk.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/smush/chunk.cpp,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -d -r1.30 -r1.31
--- chunk.cpp	1 Jan 2005 16:09:18 -0000	1.30
+++ chunk.cpp	7 Mar 2005 00:38:18 -0000	1.31
@@ -85,35 +85,24 @@
 	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);
+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());
 
-	_type = _data->readUint32BE();
-	_size = _data->readUint32BE();
-	_offset = sizeof(Chunk::type) + sizeof(uint32);
+	_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 @@
 	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 @@
 }
 
 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 @@
 }
 
 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;
 }
 

Index: chunk.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/smush/chunk.h,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- chunk.h	1 Jan 2005 16:09:18 -0000	1.17
+++ chunk.h	7 Mar 2005 00:38:18 -0000	1.18
@@ -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 @@
 
 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);





More information about the Scummvm-git-logs mailing list