[Scummvm-cvs-logs] SF.net SVN: scummvm: [26379] scummvm/trunk/engines/parallaction

peres001 at users.sourceforge.net peres001 at users.sourceforge.net
Wed Apr 4 00:03:22 CEST 2007


Revision: 26379
          http://scummvm.svn.sourceforge.net/scummvm/?rev=26379&view=rev
Author:   peres001
Date:     2007-04-03 15:03:21 -0700 (Tue, 03 Apr 2007)

Log Message:
-----------
- added a new archive member variable to Disk, to decouple resource archives from location archives
- made Script use a stream as input with overall simplification of Disk routines

Modified Paths:
--------------
    scummvm/trunk/engines/parallaction/disk.cpp
    scummvm/trunk/engines/parallaction/disk.h
    scummvm/trunk/engines/parallaction/parser.cpp
    scummvm/trunk/engines/parallaction/parser.h

Modified: scummvm/trunk/engines/parallaction/disk.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/disk.cpp	2007-04-03 21:11:43 UTC (rev 26378)
+++ scummvm/trunk/engines/parallaction/disk.cpp	2007-04-03 22:03:21 UTC (rev 26379)
@@ -116,7 +116,48 @@
 };
 
 
+/*
+	This stream class is just a wrapper around Archive, so
+	deallocation is not a problem. In fact, this class doesn't
+	delete its input (Archive) stream.
+*/
+class DummyArchiveStream : public Common::SeekableReadStream {
 
+	Archive *_input;
+
+public:
+	DummyArchiveStream(Archive &input) : _input(&input) {
+
+	}
+
+	~DummyArchiveStream() {
+		// this class exists to provide this empty destructor
+	}
+
+	bool eos() const {
+		return _input->eos();
+	}
+
+	uint32 read(void* data, uint32 dataSize) {
+		return _input->read(data, dataSize);
+	}
+
+	uint32 pos() const {
+		return _input->pos();
+	}
+
+	uint32 size() const {
+		return _input->size();
+	}
+
+	void seek(int32 offset, int whence) {
+		_input->seek(offset, whence);
+	}
+
+};
+
+
+
 Disk::Disk(Parallaction *vm) : _vm(vm) {
 
 }
@@ -131,7 +172,7 @@
 
 
 void Disk::selectArchive(const char *name) {
-	_archive.open(name);
+	_resArchive.open(name);
 }
 
 void Disk::setLanguage(uint16 language) {
@@ -158,6 +199,10 @@
 
 	}
 
+	_languageDir[2] = '\0';
+	_locArchive.open(_languageDir);
+	_languageDir[2] = '/';
+
 	return;
 }
 
@@ -230,20 +275,20 @@
 	char path[PATH_LEN];
 
 	strcpy(path, filename);
-	if (!_archive.openArchivedFile(path)) {
+	if (!_resArchive.openArchivedFile(path)) {
 		sprintf(path, "%s.pp", filename);
-		if (!_archive.openArchivedFile(path))
+		if (!_resArchive.openArchivedFile(path))
 			errorFileNotFound(path);
 	}
 
-	uint16 numFrames = _archive.readByte();
-	uint16 width = _archive.readByte();
-	uint16 height = _archive.readByte();
+	uint16 numFrames = _resArchive.readByte();
+	uint16 width = _resArchive.readByte();
+	uint16 height = _resArchive.readByte();
 
 	uint32 decsize = numFrames * width * height;
 	byte *data = (byte*)malloc(decsize);
 
-	RLEStream decoder(&_archive);
+	RLEStream decoder(&_resArchive);
 	decoder.read(data, decsize);
 
 	return new Cnv(numFrames, width, height, data);
@@ -289,23 +334,13 @@
 	strcat(archivefile, name);
 	strcat(archivefile, ".loc");
 
-	_languageDir[2] = '\0';
-	_archive.open(_languageDir);
-	_languageDir[2] = '/';
-
-	if (!_archive.openArchivedFile(archivefile)) {
+	if (!_locArchive.openArchivedFile(archivefile)) {
 		sprintf(archivefile, "%s%s.loc", _languageDir, name);
-		if (!_archive.openArchivedFile(archivefile))
+		if (!_locArchive.openArchivedFile(archivefile))
 			errorFileNotFound(name);
 	}
 
-	uint32 size = _archive.size();
-	char *buf = (char*)malloc(size+1);
-	_archive.read(buf, size);
-	buf[size] = '\0';
-
-	return new Script(buf, true);
-
+	return new Script(new DummyArchiveStream(_locArchive), true);
 }
 
 Script* DosDisk::loadScript(const char* name) {
@@ -314,15 +349,10 @@
 
 	sprintf(vC8, "%s.script", name);
 
-	if (!_archive.openArchivedFile(vC8))
+	if (!_resArchive.openArchivedFile(vC8))
 		errorFileNotFound(vC8);
 
-	uint32 size = _archive.size();
-	char *buf = (char*)malloc(size+1);
-	_archive.read(buf, size);
-	buf[size] = '\0';
-
-	return new Script(buf, true);
+	return new Script(new DummyArchiveStream(_resArchive), true);
 }
 
 StaticCnv* DosDisk::loadHead(const char* name) {
@@ -369,22 +399,22 @@
 	char path[PATH_LEN];
 
 	strcpy(path, name);
-	if (!_archive.openArchivedFile(path)) {
+	if (!_resArchive.openArchivedFile(path)) {
 		sprintf(path, "%s.pp", name);
-		if (!_archive.openArchivedFile(path))
+		if (!_resArchive.openArchivedFile(path))
 			errorFileNotFound(path);
 	}
 
 	StaticCnv* cnv = new StaticCnv;
 
-	_archive.skip(1);
-	cnv->_width = _archive.readByte();
-	cnv->_height = _archive.readByte();
+	_resArchive.skip(1);
+	cnv->_width = _resArchive.readByte();
+	cnv->_height = _resArchive.readByte();
 
 	uint16 size = cnv->_width*cnv->_height;
 	cnv->_data0 = (byte*)malloc(size);
 
-	RLEStream decoder(&_archive);
+	RLEStream decoder(&_resArchive);
 	decoder.read(cnv->_data0, size);
 
 	return cnv;
@@ -447,17 +477,17 @@
 
 void DosDisk::loadBackground(const char *filename) {
 
-	if (!_archive.openArchivedFile(filename))
+	if (!_resArchive.openArchivedFile(filename))
 		errorFileNotFound(filename);
 
-	parseBackground(_archive);
+	parseBackground(_resArchive);
 
 	byte *bg = (byte*)calloc(1, SCREEN_WIDTH*SCREEN_HEIGHT);
 	byte *mask = (byte*)calloc(1, SCREENMASK_WIDTH*SCREEN_HEIGHT);
 	byte *path = (byte*)calloc(1, SCREENPATH_WIDTH*SCREEN_HEIGHT);
 
 
-	RLEStream stream(&_archive);
+	RLEStream stream(&_resArchive);
 	unpackBackground(&stream, bg, mask, path);
 
 	_vm->_gfx->setBackground(bg);
@@ -481,16 +511,16 @@
 	char path[PATH_LEN];
 	sprintf(path, "%s.msk", name);
 
-	if (!_archive.openArchivedFile(path))
+	if (!_resArchive.openArchivedFile(path))
 		errorFileNotFound(name);
 
 	byte *maskBuf = (byte*)calloc(1, SCREENMASK_WIDTH*SCREEN_HEIGHT);
 	byte *pathBuf = (byte*)calloc(1, SCREENPATH_WIDTH*SCREEN_HEIGHT);
 
-	parseDepths(_archive);
+	parseDepths(_resArchive);
 
-	_archive.read(pathBuf, SCREENPATH_WIDTH*SCREEN_HEIGHT);
-	_archive.read(maskBuf, SCREENMASK_WIDTH*SCREEN_HEIGHT);
+	_resArchive.read(pathBuf, SCREENPATH_WIDTH*SCREEN_HEIGHT);
+	_resArchive.read(maskBuf, SCREENMASK_WIDTH*SCREEN_HEIGHT);
 
 	_vm->_gfx->setMask(maskBuf);
 	setPath(pathBuf);
@@ -702,48 +732,9 @@
 
 
 
-/*
-	This stream class is just a wrapper around Archive, so
-	deallocation is not a problem. In fact, this class doesn't
-	delete its input (Archive) stream.
-*/
-class DummyArchiveStream : public Common::SeekableReadStream {
 
-	Archive *_input;
 
-public:
-	DummyArchiveStream(Archive &input) : _input(&input) {
 
-	}
-
-	~DummyArchiveStream() {
-		// this class exists to provide this empty destructor
-	}
-
-	bool eos() const {
-		return _input->eos();
-	}
-
-	uint32 read(void* data, uint32 dataSize) {
-		return _input->read(data, dataSize);
-	}
-
-	uint32 pos() const {
-		return _input->pos();
-	}
-
-	uint32 size() const {
-		return _input->size();
-	}
-
-	void seek(int32 offset, int whence) {
-		_input->seek(offset, whence);
-	}
-
-};
-
-
-
 AmigaDisk::AmigaDisk(Parallaction *vm) : Disk(vm) {
 
 }
@@ -842,27 +833,16 @@
 Script* AmigaDisk::loadLocation(const char *name) {
 	debugC(1, kDebugDisk, "AmigaDisk::loadLocation '%s'", name);
 
-	_languageDir[2] = '\0';
-	_archive.open(_languageDir);
-	_languageDir[2] = '/';
-
 	char path[PATH_LEN];
 	sprintf(path, "%s%s%s.loc.pp", _vm->_characterName, _languageDir, name);
-	if (!_archive.openArchivedFile(path)) {
+	if (!_locArchive.openArchivedFile(path)) {
 		sprintf(path, "%s%s.loc.pp", _languageDir, name);
-		if (!_archive.openArchivedFile(path)) {
+		if (!_locArchive.openArchivedFile(path)) {
 			errorFileNotFound(name);
 		}
 	}
 
-	PowerPackerStream stream(_archive);
-
-	uint32 size = stream.size();
-	char *buf = (char*)malloc(size+1);
-	stream.read(buf, size);
-	buf[size] = '\0';
-
-	return new Script(buf, true);
+	return new Script(new PowerPackerStream(_locArchive), true);
 }
 
 Script* AmigaDisk::loadScript(const char* name) {
@@ -872,15 +852,10 @@
 
 	sprintf(vC8, "%s.script", name);
 
-	if (!_archive.openArchivedFile(vC8))
+	if (!_resArchive.openArchivedFile(vC8))
 		errorFileNotFound(vC8);
 
-	uint32 size = _archive.size();
-	char *buf = (char*)malloc(size+1);
-	_archive.read(buf, size);
-	buf[size] = '\0';
-
-	return new Script(buf, true);
+	return new Script(new DummyArchiveStream(_resArchive), true);
 }
 
 Cnv* AmigaDisk::loadTalk(const char *name) {
@@ -948,7 +923,7 @@
 	else
 		strcpy(path, "introfont");
 
-	if (!_archive.openArchivedFile(path))
+	if (!_resArchive.openArchivedFile(path))
 		errorFileNotFound(path);
 
 	// FIXME: actually read data from font file and create
@@ -971,20 +946,20 @@
 
 Common::SeekableReadStream *AmigaDisk::openArchivedFile(const char* name, bool errorOnFileNotFound) {
 
-	if (_archive.openArchivedFile(name)) {
-		return new DummyArchiveStream(_archive);
+	if (_resArchive.openArchivedFile(name)) {
+		return new DummyArchiveStream(_resArchive);
 	}
 
 	char path[PATH_LEN];
 
 	sprintf(path, "%s.pp", name);
-	if (_archive.openArchivedFile(path)) {
-		return new PowerPackerStream(_archive);
+	if (_resArchive.openArchivedFile(path)) {
+		return new PowerPackerStream(_resArchive);
 	}
 
 	sprintf(path, "%s.dd", name);
-	if (_archive.openArchivedFile(path)) {
-		return new PowerPackerStream(_archive);
+	if (_resArchive.openArchivedFile(path)) {
+		return new PowerPackerStream(_resArchive);
 	}
 
 	if (errorOnFileNotFound)
@@ -1119,10 +1094,10 @@
 		dispose = true;
 		stream = s;
 	} else {
-		if (!_archive.openArchivedFile(path))
+		if (!_resArchive.openArchivedFile(path))
 			errorFileNotFound(path);
 
-		stream = &_archive;
+		stream = &_resArchive;
 	}
 
 	Table *t = new Table(100);

Modified: scummvm/trunk/engines/parallaction/disk.h
===================================================================
--- scummvm/trunk/engines/parallaction/disk.h	2007-04-03 21:11:43 UTC (rev 26378)
+++ scummvm/trunk/engines/parallaction/disk.h	2007-04-03 22:03:21 UTC (rev 26379)
@@ -80,9 +80,10 @@
 class Disk {
 
 protected:
-	Archive		  _archive;
-	char		  _languageDir[3];
-	Parallaction *_vm;
+	Archive			_resArchive;
+	Archive			_locArchive;
+	char		  	_languageDir[3];
+	Parallaction 	*_vm;
 
 protected:
 	void errorFileNotFound(const char *s);

Modified: scummvm/trunk/engines/parallaction/parser.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/parser.cpp	2007-04-03 21:11:43 UTC (rev 26378)
+++ scummvm/trunk/engines/parallaction/parser.cpp	2007-04-03 22:03:21 UTC (rev 26379)
@@ -29,13 +29,12 @@
 
 char			_tokens[20][40];
 
-Script::Script(const char* s, bool disposeSource) : _src(s), _disposeSource(disposeSource) {
-	_pos = const_cast<char*>(_src);
+Script::Script(Common::SeekableReadStream *input, bool disposeSource) : _input(input), _disposeSource(disposeSource) {
 }
 
 Script::~Script() {
 	if (_disposeSource)
-		free(const_cast<char*>(_src));
+		delete _input;
 }
 
 char *Script::readLine(char *buf, size_t bufSize) {
@@ -44,12 +43,13 @@
 	char v2 = 0;
 	for ( _si = 0; _si<bufSize; _si++) {
 
-		v2 = *_pos++;
-		if (v2 == 0xA || v2 == -1) break;
-		if (v2 != -1 && _si < bufSize) buf[_si] = v2;
+		v2 = _input->readSByte();
+
+		if (v2 == 0xA || _input->eos()) break;
+		if (!_input->eos() && _si < bufSize) buf[_si] = v2;
 	}
 
-	if (_si == 0 && v2 == -1)
+	if (_si == 0 && _input->eos())
 		return 0;
 
 	buf[_si] = 0xA;

Modified: scummvm/trunk/engines/parallaction/parser.h
===================================================================
--- scummvm/trunk/engines/parallaction/parser.h	2007-04-03 21:11:43 UTC (rev 26378)
+++ scummvm/trunk/engines/parallaction/parser.h	2007-04-03 22:03:21 UTC (rev 26379)
@@ -28,7 +28,6 @@
 
 namespace Parallaction {
 
-void	parseInit(char *s);
 char   *parseNextLine(char *s, uint16 count);
 uint16 fillBuffers(Common::SeekableReadStream &stream, bool errorOnEOF = false);
 char   *parseNextToken(char *s, char *tok, uint16 count, const char *brk);
@@ -37,12 +36,11 @@
 
 class Script : public Common::SeekableReadStream {
 
-	const char*	const _src;
+	Common::SeekableReadStream *_input;
 	bool	_disposeSource;
-	char*	_pos;
 
 public:
-	Script(const char* s, bool _disposeSource = false);
+	Script(Common::SeekableReadStream *, bool _disposeSource = false);
 	~Script();
 
 	uint32 read(void *dataPtr, uint32 dataSize);


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list