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

peres001 at users.sourceforge.net peres001 at users.sourceforge.net
Wed Oct 29 08:57:48 CET 2008


Revision: 34860
          http://scummvm.svn.sourceforge.net/scummvm/?rev=34860&view=rev
Author:   peres001
Date:     2008-10-29 07:57:48 +0000 (Wed, 29 Oct 2008)

Log Message:
-----------
Cleanup of Nippon Safes disk code.

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

Modified: scummvm/trunk/engines/parallaction/disk.h
===================================================================
--- scummvm/trunk/engines/parallaction/disk.h	2008-10-28 19:37:20 UTC (rev 34859)
+++ scummvm/trunk/engines/parallaction/disk.h	2008-10-29 07:57:48 UTC (rev 34860)
@@ -124,6 +124,7 @@
 
 protected:
 	void errorFileNotFound(const char *s);
+	Common::SeekableReadStream *openFile(const char *filename);
 
 public:
 	Disk_ns(Parallaction *vm);
@@ -138,8 +139,7 @@
 private:
 	void unpackBackground(Common::ReadStream *stream, byte *screen, byte *mask, byte *path);
 	Cnv* loadExternalCnv(const char *filename);
-	Cnv* loadCnv(const char *filename);
-	Frames* loadExternalStaticCnv(const char *filename);
+	Frames* loadCnv(const char *filename);
 	void loadBackground(BackgroundInfo& info, const char *filename);
 	void loadMaskAndPath(BackgroundInfo& info, const char *name);
 	void parseDepths(BackgroundInfo &info, Common::SeekableReadStream &stream);

Modified: scummvm/trunk/engines/parallaction/disk_ns.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/disk_ns.cpp	2008-10-28 19:37:20 UTC (rev 34859)
+++ scummvm/trunk/engines/parallaction/disk_ns.cpp	2008-10-29 07:57:48 UTC (rev 34860)
@@ -250,10 +250,6 @@
 
 
 
-void Disk_ns::errorFileNotFound(const char *s) {
-	error("File '%s' not found", s);
-}
-
 Disk_ns::Disk_ns(Parallaction *vm) : _vm(vm) {
 
 }
@@ -262,7 +258,18 @@
 
 }
 
+void Disk_ns::errorFileNotFound(const char *s) {
+	error("File '%s' not found", s);
+}
 
+Common::SeekableReadStream *Disk_ns::openFile(const char *filename) {
+	Common::File *stream = new Common::File;
+	if (!stream->open(filename))
+		errorFileNotFound(filename);
+	return stream;
+}
+
+
 Common::String Disk_ns::selectArchive(const Common::String& name) {
 	Common::String oldName = _resArchive.name();
 	_resArchive.open(name.c_str());
@@ -271,34 +278,10 @@
 
 void Disk_ns::setLanguage(uint16 language) {
 	debugC(1, kDebugDisk, "setLanguage(%i)", language);
-
-	switch (language) {
-	case 0:
-		strcpy(_languageDir, "it/");
-		break;
-
-	case 1:
-		strcpy(_languageDir, "fr/");
-		break;
-
-	case 2:
-		strcpy(_languageDir, "en/");
-		break;
-
-	case 3:
-		strcpy(_languageDir, "ge/");
-		break;
-
-	default:
-		error("unknown language");
-
-	}
-
-	_languageDir[2] = '\0';
-	_locArchive.open(_languageDir);
-	_languageDir[2] = '/';
-
-	return;
+	assert(language < 4);
+	const char *languages[] = { "it", "fr", "en", "ge" };
+	sprintf(_languageDir, "%s/", languages[language]);
+	_locArchive.open(languages[language]);
 }
 
 #pragma mark -
@@ -312,7 +295,6 @@
 DosDisk_ns::~DosDisk_ns() {
 }
 
-
 //
 // loads a cnv from an external file
 //
@@ -322,47 +304,24 @@
 
 	sprintf(path, "%s.cnv", filename);
 
-	Common::File stream;
+	Common::SeekableReadStream *stream = openFile(path);
 
-	if (!stream.open(path))
-		errorFileNotFound(path);
-
-	uint16 numFrames = stream.readByte();
-	uint16 width = stream.readByte();
-	uint16 height = stream.readByte();
-
+	uint16 numFrames = stream->readByte();
+	uint16 width = stream->readByte();
+	uint16 height = stream->readByte();
 	uint32 decsize = numFrames * width * height;
 	byte *data = (byte*)malloc(decsize);
-	stream.read(data, decsize);
+	stream->read(data, decsize);
+	Cnv *cnv = new Cnv(numFrames, width, height, data);
 
-	return new Cnv(numFrames, width, height, data);
-}
+	delete stream;
 
-Frames* DosDisk_ns::loadExternalStaticCnv(const char *filename) {
-
-	char path[PATH_LEN];
-
-	sprintf(path, "%s.cnv", filename);
-
-	Common::File stream;
-
-	if (!stream.open(path))
-		errorFileNotFound(path);
-
-	Graphics::Surface *cnv = new Graphics::Surface;
-
-	stream.skip(1);
-	byte w = stream.readByte();
-	byte h = stream.readByte();
-
-	cnv->create(w, h, 1);
-	stream.read(cnv->pixels, w*h);
-
-	return new SurfaceToFrames(cnv);
+	return cnv;
 }
 
-Cnv* DosDisk_ns::loadCnv(const char *filename) {
 
+Frames* DosDisk_ns::loadCnv(const char *filename) {
+
 	char path[PATH_LEN];
 
 	strcpy(path, filename);
@@ -435,18 +394,15 @@
 }
 
 GfxObj* DosDisk_ns::loadHead(const char* name) {
-
 	char path[PATH_LEN];
-
 	sprintf(path, "%shead", name);
 	path[8] = '\0';
-
-	return new GfxObj(0, loadExternalStaticCnv(path));
+	return new GfxObj(0, loadExternalCnv(path));
 }
 
 
 Frames* DosDisk_ns::loadPointer(const char *name) {
-	return loadExternalStaticCnv(name);
+	return loadExternalCnv(name);
 }
 
 
@@ -458,7 +414,6 @@
 
 
 GfxObj* DosDisk_ns::loadObjects(const char *name) {
-
 	char path[PATH_LEN];
 	sprintf(path, "%sobj", name);
 	return new GfxObj(0, loadExternalCnv(path), name);
@@ -466,28 +421,7 @@
 
 
 GfxObj* DosDisk_ns::loadStatic(const char* name) {
-
-	char path[PATH_LEN];
-
-	strcpy(path, name);
-	if (!_resArchive.openArchivedFile(path)) {
-		sprintf(path, "%s.pp", name);
-		if (!_resArchive.openArchivedFile(path))
-			errorFileNotFound(path);
-	}
-
-	Graphics::Surface* cnv = new Graphics::Surface;
-
-	_resArchive.skip(1);
-	byte w = _resArchive.readByte();
-	byte h = _resArchive.readByte();
-
-	cnv->create(w, h, 1);
-
-	Graphics::PackBitsReadStream decoder(_resArchive);
-	decoder.read(cnv->pixels, w*h);
-
-	return new GfxObj(0, new SurfaceToFrames(cnv), name);
+	return new GfxObj(0, loadCnv(name), name);
 }
 
 Frames* DosDisk_ns::loadFrames(const char* name) {
@@ -624,27 +558,16 @@
 Table* DosDisk_ns::loadTable(const char* name) {
 	char path[PATH_LEN];
 	sprintf(path, "%s.tab", name);
-
-	Common::File	stream;
-	if (!stream.open(path))
-		errorFileNotFound(path);
-
-	Table *t = createTableFromStream(100, stream);
-
-	stream.close();
-
+	Common::SeekableReadStream *stream = openFile(path);
+	Table *t = createTableFromStream(100, *stream);
+	delete stream;
 	return t;
 }
 
 Common::SeekableReadStream* DosDisk_ns::loadMusic(const char* name) {
 	char path[PATH_LEN];
 	sprintf(path, "%s.mid", name);
-
-	Common::File *stream = new Common::File;
-	if (!stream->open(path))
-		errorFileNotFound(path);
-
-	return stream;
+	return openFile(path);
 }
 
 
@@ -1018,11 +941,11 @@
 Frames* AmigaDisk_ns::loadPointer(const char* name) {
 	debugC(1, kDebugDisk, "AmigaDisk_ns::loadPointer");
 
-	Common::File stream;
-	if (!stream.open(name))
-		errorFileNotFound(name);
+	Common::SeekableReadStream *stream = openFile(name);
+	Frames *frames = makeStaticCnv(*stream);
+	delete stream;
 
-	return makeStaticCnv(stream);
+	return frames;
 }
 
 GfxObj* AmigaDisk_ns::loadStatic(const char* name) {
@@ -1342,10 +1265,7 @@
 	Common::SeekableReadStream *stream;
 
 	if (!scumm_stricmp(name, "global")) {
-		Common::File *s = new Common::File;
-		if (!s->open(path))
-			errorFileNotFound(path);
-
+		Common::SeekableReadStream *s = openFile(path);
 		dispose = true;
 		stream = s;
 	} else {
@@ -1371,19 +1291,20 @@
 	char path[PATH_LEN];
 	sprintf(path, "%sfont", name);
 
+	Font *font = 0;
+
 	if (_vm->getFeatures() & GF_LANG_IT) {
 		// Italian version has separate font files
-		Common::File stream;
-		if (!stream.open(path))
-			errorFileNotFound(path);
-
-		return createFont(name, stream);
+		Common::SeekableReadStream *stream = openFile(path);
+		font = createFont(name, *stream);
+		delete stream;
 	} else {
 		if (!_resArchive.openArchivedFile(path))
 			errorFileNotFound(path);
-
-		return createFont(name, _resArchive);
+		font = createFont(name, _resArchive);
 	}
+
+	return font;
 }
 
 


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