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

peres001 at users.sourceforge.net peres001 at users.sourceforge.net
Wed Apr 29 18:59:10 CEST 2009


Revision: 40210
          http://scummvm.svn.sourceforge.net/scummvm/?rev=40210&view=rev
Author:   peres001
Date:     2009-04-29 16:59:10 +0000 (Wed, 29 Apr 2009)

Log Message:
-----------
Refactoring.

Modified Paths:
--------------
    scummvm/trunk/engines/parallaction/disk.h
    scummvm/trunk/engines/parallaction/disk_br.cpp
    scummvm/trunk/engines/parallaction/disk_ns.cpp
    scummvm/trunk/engines/parallaction/objects.cpp
    scummvm/trunk/engines/parallaction/objects.h

Modified: scummvm/trunk/engines/parallaction/disk.h
===================================================================
--- scummvm/trunk/engines/parallaction/disk.h	2009-04-29 16:43:07 UTC (rev 40209)
+++ scummvm/trunk/engines/parallaction/disk.h	2009-04-29 16:59:10 UTC (rev 40210)
@@ -97,12 +97,18 @@
 
 	void addArchive(const Common::String& name, int priority);
 
+	virtual void decodeCnv(byte *data, uint16 numFrames, uint16 width, uint16 height, Common::SeekableReadStream *stream) = 0;
+	Cnv *makeCnv(Common::SeekableReadStream *stream);
+
 public:
 	Disk_ns(Parallaction *vm);
 	virtual ~Disk_ns();
 
 	Common::String selectArchive(const Common::String &name);
 	void setLanguage(uint16 language);
+
+	virtual Script* loadLocation(const char *name);
+	virtual Script* loadScript(const char* name);
 };
 
 class DosDisk_ns : public Disk_ns {
@@ -111,14 +117,14 @@
 	void unpackBackground(Common::ReadStream *stream, byte *screen, byte *mask, byte *path);
 	Cnv* loadCnv(const char *filename);
 	void loadBackground(BackgroundInfo& info, const char *filename);
-	void loadMaskAndPath(BackgroundInfo& info, const char *name);
+	void createMaskAndPathBuffers(BackgroundInfo &info);
 	void parseDepths(BackgroundInfo &info, Common::SeekableReadStream &stream);
-	void parseBackground(BackgroundInfo& info, Common::SeekableReadStream &stream);
 	Font *createFont(const char *name, Cnv* cnv);
 
 protected:
 	Gfx	 *_gfx;
 	virtual Common::SeekableReadStream *tryOpenFile(const char* name);
+	virtual void decodeCnv(byte *data, uint16 numFrames, uint16 width, uint16 height, Common::SeekableReadStream *stream);
 
 public:
 	DosDisk_ns(Parallaction *vm);
@@ -126,8 +132,6 @@
 
 	void init();
 
-	Script* loadLocation(const char *name);
-	Script* loadScript(const char* name);
 	GfxObj* loadTalk(const char *name);
 	GfxObj* loadObjects(const char *name, uint8 part = 0);
 	Frames* loadPointer(const char *name);
@@ -145,7 +149,6 @@
 class AmigaDisk_ns : public Disk_ns {
 
 protected:
-	Cnv* makeCnv(Common::SeekableReadStream *stream);
 	void patchFrame(byte *dst, byte *dlta, uint16 bytesPerPlane, uint16 height);
 	void unpackFrame(byte *dst, byte *src, uint16 planeSize);
 	void unpackBitmap(byte *dst, byte *src, uint16 numFrames, uint16 bytesPerPlane, uint16 height);
@@ -156,14 +159,14 @@
 	void loadBackground(BackgroundInfo& info, const char *name);
 	void buildMask(byte* buf);
 
+	virtual void decodeCnv(byte *data, uint16 numFrames, uint16 width, uint16 height, Common::SeekableReadStream *stream);
+
 public:
 	AmigaDisk_ns(Parallaction *vm);
 	virtual ~AmigaDisk_ns();
 
 	void init();
 
-	Script* loadLocation(const char *name);
-	Script* loadScript(const char* name);
 	GfxObj* loadTalk(const char *name);
 	GfxObj* loadObjects(const char *name, uint8 part = 0);
 	Frames* loadPointer(const char *name);

Modified: scummvm/trunk/engines/parallaction/disk_br.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/disk_br.cpp	2009-04-29 16:43:07 UTC (rev 40209)
+++ scummvm/trunk/engines/parallaction/disk_br.cpp	2009-04-29 16:59:10 UTC (rev 40210)
@@ -396,10 +396,7 @@
 
 Table* DosDisk_br::loadTable(const char* name) {
 	debugC(5, kDebugDisk, "DosDisk_br::loadTable");
-	Common::SeekableReadStream *stream = openFile(name, ".tab");
-	Table *t = createTableFromStream(100, *stream);
-	delete stream;
-	return t;
+	return createTableFromStream(100, openFile(name, ".tab"));
 }
 
 Common::SeekableReadStream* DosDisk_br::loadMusic(const char* name) {

Modified: scummvm/trunk/engines/parallaction/disk_ns.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/disk_ns.cpp	2009-04-29 16:43:07 UTC (rev 40209)
+++ scummvm/trunk/engines/parallaction/disk_ns.cpp	2009-04-29 16:59:10 UTC (rev 40210)
@@ -266,16 +266,49 @@
 	return _sset.createReadStreamForMember(path);
 }
 
+Script* Disk_ns::loadLocation(const char *name) {
+	char path[PATH_LEN];
 
-Cnv* DosDisk_ns::loadCnv(const char *filename) {
-	Common::SeekableReadStream *stream = openFile(filename);
+	sprintf(path, "%s%s/%s.loc", _vm->_char.getBaseName(), _language.c_str(), name);
+	debugC(3, kDebugDisk, "Disk_ns::loadLocation(%s): trying '%s'", name, path);
+	Common::SeekableReadStream *stream = tryOpenFile(path);
 
+	if (!stream) {
+		sprintf(path, "%s/%s.loc", _language.c_str(), name);
+		debugC(3, kDebugDisk, "DosDisk_ns::loadLocation(%s): trying '%s'", name, path);
+		stream = openFile(path);
+	}
+	return new Script(stream, true);
+}
+
+Script* Disk_ns::loadScript(const char* name) {
+	debugC(1, kDebugDisk, "Disk_ns::loadScript '%s'", name);
+	char path[PATH_LEN];
+	sprintf(path, "%s.script", name);
+	Common::SeekableReadStream *stream = openFile(path);
+	return new Script(stream, true);
+}
+
+Cnv *Disk_ns::makeCnv(Common::SeekableReadStream *stream) {
+	assert(stream);
+
 	uint16 numFrames = stream->readByte();
 	uint16 width = stream->readByte();
+	assert((width & 7) == 0);
 	uint16 height = stream->readByte();
-	int32 decsize = numFrames * width * height;
+	uint32 decsize = numFrames * width * height;
 	byte *data = new byte[decsize];
+	assert(data);
+	memset(data, 0, decsize);
 
+	decodeCnv(data, numFrames, width, height, stream);
+
+	delete stream;
+	return new Cnv(numFrames, width, height, data, true);
+}
+
+void DosDisk_ns::decodeCnv(byte *data, uint16 numFrames, uint16 width, uint16 height, Common::SeekableReadStream *stream) {
+	int32 decsize = numFrames * width * height;
 	bool packed = (stream->size() - stream->pos()) != decsize;
 	if (packed) {
 		Graphics::PackBitsReadStream decoder(*stream);
@@ -283,20 +316,21 @@
 	} else {
 		stream->read(data, decsize);
 	}
+}
 
-	delete stream;
-
-	return new Cnv(numFrames, width, height, data, true);
+Cnv* DosDisk_ns::loadCnv(const char *filename) {
+	Common::SeekableReadStream *stream = openFile(filename);
+	assert(stream);
+	return makeCnv(stream);
 }
 
 
 GfxObj* DosDisk_ns::loadTalk(const char *name) {
 
 	const char *ext = strstr(name, ".talk");
-	if (ext != NULL) {
+	if (ext) {
 		// npc talk
 		return new GfxObj(0, loadCnv(name), name);
-
 	}
 
 	char v20[30];
@@ -309,30 +343,7 @@
 	return new GfxObj(0, loadCnv(v20), name);
 }
 
-Script* DosDisk_ns::loadLocation(const char *name) {
 
-	char archivefile[PATH_LEN];
-	sprintf(archivefile, "%s%s/%s.loc", _vm->_char.getBaseName(), _language.c_str(), name);
-
-	debugC(3, kDebugDisk, "DosDisk_ns::loadLocation(%s): trying '%s'", name, archivefile);
-
-	Common::SeekableReadStream *stream = tryOpenFile(archivefile);
-	if  (!stream) {
-		sprintf(archivefile, "%s/%s.loc", _language.c_str(), name);
-		debugC(3, kDebugDisk, "DosDisk_ns::loadLocation(%s): trying '%s'", name, archivefile);
-		stream = openFile(archivefile);
-	}
-
-	return new Script(stream, true);
-}
-
-Script* DosDisk_ns::loadScript(const char* name) {
-	char path[PATH_LEN];
-	sprintf(path, "%s.script", name);
-	Common::SeekableReadStream *stream = openFile(path);
-	return new Script(stream, true);
-}
-
 GfxObj* DosDisk_ns::loadHead(const char* name) {
 	char path[PATH_LEN];
 	sprintf(path, "%shead", name);
@@ -424,106 +435,93 @@
 	info.layers[3] = stream.readByte();
 }
 
+void DosDisk_ns::createMaskAndPathBuffers(BackgroundInfo &info) {
+	info._mask = new MaskBuffer;
+	assert(info._mask);
+	info._mask->create(info.width, info.height);
+	info._mask->bigEndian = true;
 
-void DosDisk_ns::parseBackground(BackgroundInfo& info, Common::SeekableReadStream &stream) {
+	info._path = new PathBuffer;
+	assert(info._path);
+	info._path->create(info.width, info.height);
+	info._path->bigEndian = true;
+}
 
-	byte tmp[3];
+void DosDisk_ns::loadBackground(BackgroundInfo& info, const char *filename) {
+	Common::SeekableReadStream *stream = openFile(filename);
 
+	info.width = _vm->_screenWidth;	// 320
+	info.height = _vm->_screenHeight;	// 200
+
+	// read palette
+	byte tmp[3];
 	for (uint i = 0; i < 32; i++) {
-		tmp[0] = stream.readByte();
-		tmp[1] = stream.readByte();
-		tmp[2] = stream.readByte();
+		tmp[0] = stream->readByte();
+		tmp[1] = stream->readByte();
+		tmp[2] = stream->readByte();
 		info.palette.setEntry(i, tmp[0], tmp[1], tmp[2]);
 	}
 
-	parseDepths(info, stream);
+	// read z coordinates
+	parseDepths(info, *stream);
 
+	// read palette rotation parameters
 	PaletteFxRange range;
 	for (uint32 _si = 0; _si < 6; _si++) {
-		range._timer = stream.readUint16BE();
-		range._step = stream.readUint16BE();
-		range._flags = stream.readUint16BE();
-		range._first = stream.readByte();
-		range._last = stream.readByte();
-
+		range._timer = stream->readUint16BE();
+		range._step = stream->readUint16BE();
+		range._flags = stream->readUint16BE();
+		range._first = stream->readByte();
+		range._last = stream->readByte();
 		info.setPaletteRange(_si, range);
 	}
 
-}
-
-void DosDisk_ns::loadBackground(BackgroundInfo& info, const char *filename) {
-	Common::SeekableReadStream *stream = openFile(filename);
-
-	info.width = _vm->_screenWidth;	// 320
-	info.height = _vm->_screenHeight;	// 200
-
-	parseBackground(info, *stream);
-
+	// read bitmap, mask and path data and extract them into the 3 buffers
 	info.bg.create(info.width, info.height, 1);
-	info._mask = new MaskBuffer;
-	info._mask->create(info.width, info.height);
-	info._mask->bigEndian = true;
-
-	info._path = new PathBuffer;
-	info._path->create(info.width, info.height);
-	info._path->bigEndian = true;
-
+	createMaskAndPathBuffers(info);
 	unpackBackground(stream, (byte*)info.bg.pixels, info._mask->data, info._path->data);
 
 	delete stream;
 }
 
-//
-//	read background path and mask from a file
-//
-//	mask and path are normally combined (via OR) into the background picture itself
-//	read the comment on the top of this file for more
-//
-void DosDisk_ns::loadMaskAndPath(BackgroundInfo& info, const char *name) {
-	char path[PATH_LEN];
-	sprintf(path, "%s.msk", name);
-	Common::SeekableReadStream *stream = openFile(path);
-	parseDepths(info, *stream);
-	info._path = new PathBuffer;
-	info._path->create(info.width, info.height);
-	info._path->bigEndian = true;
-	stream->read(info._path->data, info._path->size);
-	info._mask = new MaskBuffer;
-	info._mask->create(info.width, info.height);
-	info._mask->bigEndian = true;
-	stream->read(info._mask->data, info._mask->size);
-	delete stream;
-}
 
 void DosDisk_ns::loadSlide(BackgroundInfo& info, const char *filename) {
 	char path[PATH_LEN];
 	sprintf(path, "%s.slide", filename);
 	loadBackground(info, path);
-
-	return;
 }
 
 void DosDisk_ns::loadScenery(BackgroundInfo& info, const char *name, const char *mask, const char* path) {
 	char filename[PATH_LEN];
 	sprintf(filename, "%s.dyn", name);
 
+	// load bitmap
 	loadBackground(info, filename);
 
-	if (mask != NULL) {
-		// load external masks and paths only for certain locations
-		loadMaskAndPath(info, mask);
+	if (mask == 0) {
+		return;
 	}
 
-	return;
+	// load external mask and path if present (overwriting the ones loaded by loadBackground)
+	char maskPath[PATH_LEN];
+	sprintf(maskPath, "%s.msk", mask);
+
+	Common::SeekableReadStream *stream = openFile(maskPath);
+	assert(stream);
+
+	parseDepths(info, *stream);
+
+	createMaskAndPathBuffers(info);
+	stream->read(info._path->data, info._path->size);
+	stream->read(info._mask->data, info._mask->size);
+
+	delete stream;
 }
 
 Table* DosDisk_ns::loadTable(const char* name) {
 	char path[PATH_LEN];
 	sprintf(path, "%s.tab", name);
-	Common::SeekableReadStream *stream = openFile(path);
-	Table *t = createTableFromStream(100, *stream);
-	delete stream;
-	return t;
+	return createTableFromStream(100, openFile(path));
 }
 
 Common::SeekableReadStream* DosDisk_ns::loadMusic(const char* name) {
@@ -534,7 +532,7 @@
 
 
 Common::SeekableReadStream* DosDisk_ns::loadSound(const char* name) {
-	return NULL;
+	return 0;
 }
 
 
@@ -583,7 +581,7 @@
 		byte *buf, *out, *dest_end, *off_lens, bits_left = 0, bit_cnt;
 		uint32 bit_buffer = 0, x, todo, offbits, offset, written = 0;
 
-		if (src == NULL || dest == NULL) return 0;
+		if (!src || !dest) return 0;
 
 		/* set up input and output pointers */
 		off_lens = src; src = &src[4];
@@ -829,59 +827,18 @@
 }
 
 
-Cnv* AmigaDisk_ns::makeCnv(Common::SeekableReadStream *stream) {
-	assert(stream);
-
-	uint16 numFrames = stream->readByte();
-	uint16 width = stream->readByte();
-	uint16 height = stream->readByte();
-
-	assert((width & 7) == 0);
-
+void AmigaDisk_ns::decodeCnv(byte *data, uint16 numFrames, uint16 width, uint16 height, Common::SeekableReadStream *stream) {
 	byte bytesPerPlane = width / 8;
-
 	uint32 rawsize = numFrames * bytesPerPlane * NUM_PLANES * height;
-	byte *buf = (byte*)malloc(rawsize);
+	byte *buf = new byte[rawsize];
+	assert(buf);
 	stream->read(buf, rawsize);
-
-	uint32 decsize = numFrames * width * height;
-	byte *data = new byte[decsize];
-	memset(data, 0, decsize);
-
 	unpackBitmap(data, buf, numFrames, bytesPerPlane, height);
-
-	free(buf);
-
-	delete stream;
-
-	return new Cnv(numFrames, width, height, data, true);
+	delete []buf;
 }
+
 #undef NUM_PLANES
 
-Script* AmigaDisk_ns::loadLocation(const char *name) {
-	debugC(1, kDebugDisk, "AmigaDisk_ns()::loadLocation '%s'", name);
-
-	char path[PATH_LEN];
-	sprintf(path, "%s%s/%s.loc", _vm->_char.getBaseName(), _language.c_str(), name);
-
-	Common::SeekableReadStream *stream = tryOpenFile(path);
-	if (!stream) {
-		sprintf(path, "%s/%s.loc", _language.c_str(), name);
-		stream = openFile(path);
-	}
-
-	debugC(3, kDebugDisk, "location file found: %s", path);
-	return new Script(stream, true);
-}
-
-Script* AmigaDisk_ns::loadScript(const char* name) {
-	debugC(1, kDebugDisk, "AmigaDisk_ns::loadScript '%s'", name);
-	char path[PATH_LEN];
-	sprintf(path, "%s.script", name);
-	Common::SeekableReadStream *stream = openFile(path);
-	return new Script(stream, true);
-}
-
 Frames* AmigaDisk_ns::loadPointer(const char* name) {
 	debugC(1, kDebugDisk, "AmigaDisk_ns::loadPointer");
 	Common::SeekableReadStream *stream = openFile(name);
@@ -1072,7 +1029,7 @@
 
 	loadBackground(info, filename);
 
-	if (mask == NULL) {
+	if (mask == 0) {
 		loadMask(info, background);
 		loadPath(info, background);
 	} else {
@@ -1154,11 +1111,7 @@
 			sprintf(path, "%s.table", name);
 	}
 
-	Common::SeekableReadStream *stream = openFile(path);
-	Table *t = createTableFromStream(100, *stream);
-	delete stream;
-
-	return t;
+	return createTableFromStream(100, openFile(path));
 }
 
 Font* AmigaDisk_ns::loadFont(const char* name) {

Modified: scummvm/trunk/engines/parallaction/objects.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/objects.cpp	2009-04-29 16:43:07 UTC (rev 40209)
+++ scummvm/trunk/engines/parallaction/objects.cpp	2009-04-29 16:59:10 UTC (rev 40210)
@@ -423,18 +423,19 @@
 	_used -= deleted;
 }
 
-Table* createTableFromStream(uint32 size, Common::SeekableReadStream &stream) {
+Table* createTableFromStream(uint32 size, Common::SeekableReadStream *stream) {
+	assert(stream);
 
 	Table *t = new Table(size);
+	assert(t);
 
-	Script s(&stream, false);
-
+	Script s(stream, false);
 	s.readLineToken();
 	while (scumm_stricmp(_tokens[0], "ENDTABLE")) {
 		t->addData(_tokens[0]);
 		s.readLineToken();
 	}
-
+	delete stream;
 	return t;
 }
 

Modified: scummvm/trunk/engines/parallaction/objects.h
===================================================================
--- scummvm/trunk/engines/parallaction/objects.h	2009-04-29 16:43:07 UTC (rev 40209)
+++ scummvm/trunk/engines/parallaction/objects.h	2009-04-29 16:59:10 UTC (rev 40210)
@@ -541,7 +541,7 @@
 	void clear();
 };
 
-Table* createTableFromStream(uint32 size, Common::SeekableReadStream &stream);
+Table* createTableFromStream(uint32 size, Common::SeekableReadStream *stream);
 
 } // namespace Parallaction
 


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