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

peres001 at users.sourceforge.net peres001 at users.sourceforge.net
Thu Mar 29 21:03:52 CEST 2007


Revision: 26318
          http://scummvm.svn.sourceforge.net/scummvm/?rev=26318&view=rev
Author:   peres001
Date:     2007-03-29 12:03:51 -0700 (Thu, 29 Mar 2007)

Log Message:
-----------
- changed Cnv to use a single large buffer for frames instead of small chunks of memory, to simplify loading by Disk.
- added a new constructor with parameters to Cnv

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

Modified: scummvm/trunk/engines/parallaction/defs.h
===================================================================
--- scummvm/trunk/engines/parallaction/defs.h	2007-03-29 18:34:31 UTC (rev 26317)
+++ scummvm/trunk/engines/parallaction/defs.h	2007-03-29 19:03:51 UTC (rev 26318)
@@ -88,34 +88,32 @@
 };
 
 
-struct Cnv {
+class Cnv {
+	uint16	_count; 	// # of frames
 	uint16	_width; 	//
 	uint16	_height;	//
 	byte**	field_8;	// unused
-	uint16	_count; 	// # of frames
-	byte**	_array; 	// frames data
+	byte*	_data;
 
 public:
 	Cnv() {
 		_width = _height = _count = 0;
-		_array = NULL;
+		_data = NULL;
 	}
 
-	~Cnv() {
-		if (_count == 0 || _array == NULL) return;
+	Cnv(uint16 numFrames, uint16 width, uint16 height, byte* data) : _count(numFrames), _width(width), _height(height), _data(data) {
 
-		for (uint16 _si = 0; _si < _count; _si++) {
-			if (_array[_si])
-				free(_array[_si]);
-		}
+	}
 
-		free(_array);
+	~Cnv() {
+		if (_count == 0 || _data == NULL) return;
+		free(_data);
 	}
 
 	byte* getFramePtr(uint16 index) {
 		if (index >= _count)
 			return NULL;
-		return _array[index];
+		return &_data[index * _width * _height];
 	}
 };
 

Modified: scummvm/trunk/engines/parallaction/disk.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/disk.cpp	2007-03-29 18:34:31 UTC (rev 26317)
+++ scummvm/trunk/engines/parallaction/disk.cpp	2007-03-29 19:03:51 UTC (rev 26318)
@@ -120,7 +120,7 @@
 //
 // loads a cnv from an external file
 //
-void DosDisk::loadExternalCnv(const char *filename, Cnv *cnv) {
+Cnv* DosDisk::loadExternalCnv(const char *filename) {
 //	printf("Gfx::loadExternalCnv(%s)...", filename);
 
 	char path[PATH_LEN];
@@ -132,22 +132,15 @@
 	if (!stream.open(path))
 		errorFileNotFound(path);
 
-	cnv->_count = stream.readByte();
-	cnv->_width = stream.readByte();
-	cnv->_height = stream.readByte();
+	uint16 numFrames = stream.readByte();
+	uint16 width = stream.readByte();
+	uint16 height = stream.readByte();
 
-	cnv->_array = (byte**)malloc(cnv->_count * sizeof(byte*));
+	uint32 decsize = numFrames * width * height;
+	byte *data = (byte*)malloc(decsize);
+	stream.read(data, decsize);
 
-	uint16 size = cnv->_width*cnv->_height;
-	for (uint16 i = 0; i < cnv->_count; i++) {
-		cnv->_array[i] = (byte*)malloc(size);
-		stream.read(cnv->_array[i], size);
-	}
-
-//	printf("done\n");
-
-
-	return;
+	return new Cnv(numFrames, width, height, data);
 }
 
 void DosDisk::loadExternalStaticCnv(const char *filename, StaticCnv *cnv) {
@@ -175,7 +168,7 @@
 	return;
 }
 
-void DosDisk::loadCnv(const char *filename, Cnv *cnv) {
+Cnv* DosDisk::loadCnv(const char *filename) {
 //	printf("Gfx::loadCnv(%s)\n", filename);
 
 	char path[PATH_LEN];
@@ -187,69 +180,50 @@
 			errorFileNotFound(path);
 	}
 
-	cnv->_count = _archive.readByte();
-	cnv->_width = _archive.readByte();
-	cnv->_height = _archive.readByte();
+	uint16 numFrames = _archive.readByte();
+	uint16 width = _archive.readByte();
+	uint16 height = _archive.readByte();
 
-	uint16 framesize = cnv->_width*cnv->_height;
+	uint32 rawsize = _archive.size() - 3;
+	byte *buf = (byte*)malloc(rawsize);
+	_archive.read(buf, rawsize);
 
-	cnv->_array = (byte**)malloc(cnv->_count * sizeof(byte*));
+	uint32 decsize = numFrames * width * height;
+	byte *data = (byte*)malloc(decsize);
+	decompressChunk(buf, data, decsize);
 
-	uint32 size = _archive.size() - 3;
-
-	byte *buf = (byte*)malloc(size);
-	_archive.read(buf, size);
-
-	byte *s = buf;
-
-	for (uint16 i = 0; i < cnv->_count; i++) {
-		cnv->_array[i] = (byte*)malloc(framesize);
-		uint16 read = decompressChunk(s, cnv->_array[i], framesize);
-
-//		printf("frame %i decompressed: %i --> %i\n", i, read, framesize);
-
-		s += read;
-	}
-
-	free(buf);
-
-	return;
+	return new Cnv(numFrames, width, height, data);
 }
 
 Cnv* DosDisk::loadTalk(const char *name) {
 
-	Cnv *cnv = new Cnv;
-
 	const char *ext = strstr(name, ".talk");
 	if (ext != NULL) {
 		// npc talk
-		loadCnv(name, cnv);
+		return loadCnv(name);
 
-	} else {
-		// character talk
+	}
+
+	// character talk
 /*
-		if (scumm_stricmp(name, _doughName) &&
-			scumm_stricmp(name, _dinoName) &&
-			scumm_stricmp(name, _donnaName) &&
-			scumm_stricmp(name, _drkiName)) return;
+	if (scumm_stricmp(name, _doughName) &&
+		scumm_stricmp(name, _dinoName) &&
+		scumm_stricmp(name, _donnaName) &&
+		scumm_stricmp(name, _drkiName)) return;
 */
-		char v20[PATH_LEN];
-		char *v24 = const_cast<char*>(name);
-		if (IS_MINI_CHARACTER(v24)) {
-			v24+=4;
-		}
+	char v20[PATH_LEN];
+	char *v24 = const_cast<char*>(name);
+	if (IS_MINI_CHARACTER(v24)) {
+		v24+=4;
+	}
 
-		if (_engineFlags & kEngineTransformedDonna) {
-			sprintf(v20, "%stta", v24);
-		} else {
-			sprintf(v20, "%stal", v24);
-		}
-
-		loadExternalCnv(v20, cnv);
-
+	if (_engineFlags & kEngineTransformedDonna) {
+		sprintf(v20, "%stta", v24);
+	} else {
+		sprintf(v20, "%stal", v24);
 	}
 
-	return cnv;
+	return loadExternalCnv(v20);
 }
 
 Script* DosDisk::loadLocation(const char *name) {
@@ -334,12 +308,8 @@
 
 Cnv* DosDisk::loadFont(const char* name) {
 	char path[PATH_LEN];
-
 	sprintf(path, "%scnv", name);
-
-	Cnv* cnv = new Cnv;
-	loadExternalCnv(path, cnv);
-	return cnv;
+	return loadExternalCnv(path);
 }
 
 // loads character's icons set
@@ -352,10 +322,7 @@
 
 	char path[PATH_LEN];
 	sprintf(path, "%sobj", name);
-
-	Cnv* cnv = new Cnv;
-	loadExternalCnv(path, cnv);
-	return cnv;
+	return loadExternalCnv(path);
 }
 
 
@@ -391,9 +358,7 @@
 }
 
 Cnv* DosDisk::loadFrames(const char* name) {
-	Cnv* cnv = new Cnv;
-	loadCnv(name, cnv);
-	return cnv;
+	return loadCnv(name);
 }
 
 //

Modified: scummvm/trunk/engines/parallaction/disk.h
===================================================================
--- scummvm/trunk/engines/parallaction/disk.h	2007-03-29 18:34:31 UTC (rev 26317)
+++ scummvm/trunk/engines/parallaction/disk.h	2007-03-29 19:03:51 UTC (rev 26318)
@@ -111,8 +111,8 @@
 private:
 	uint16 decompressChunk(byte *src, byte *dst, uint16 size);
 	void unpackBackgroundScanline(byte *src, byte *screen, byte *mask, byte *path);
-	void loadExternalCnv(const char *filename, Cnv *cnv);
-	void loadCnv(const char *filename, Cnv *cnv);
+	Cnv* loadExternalCnv(const char *filename);
+	Cnv* loadCnv(const char *filename);
 	void loadExternalStaticCnv(const char *filename, StaticCnv *cnv);
 	void loadBackground(const char *filename);
 	void loadMaskAndPath(const char *name);


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