[Scummvm-cvs-logs] SF.net SVN: scummvm: [22043] scummvm/trunk/engines/simon

kirben at users.sourceforge.net kirben at users.sourceforge.net
Wed Apr 19 17:44:03 CEST 2006


Revision: 22043
Author:   kirben
Date:     2006-04-19 17:42:54 -0700 (Wed, 19 Apr 2006)
ViewCVS:  http://svn.sourceforge.net/scummvm/?rev=22043&view=rev

Log Message:
-----------
Update resource managment for FF, this method is more efficent for Simon 1/2 too

Modified Paths:
--------------
    scummvm/trunk/engines/simon/res.cpp
    scummvm/trunk/engines/simon/simon.cpp
    scummvm/trunk/engines/simon/simon.h
Modified: scummvm/trunk/engines/simon/res.cpp
===================================================================
--- scummvm/trunk/engines/simon/res.cpp	2006-04-19 23:01:31 UTC (rev 22042)
+++ scummvm/trunk/engines/simon/res.cpp	2006-04-20 00:42:54 UTC (rev 22043)
@@ -557,10 +557,11 @@
 #undef SD_TYPE_MATCH
 
 void SimonEngine::read_vga_from_datfile_1(uint vga_id) {
+	uint32 offs, size;
+
 	if (getFeatures() & GF_OLD_BUNDLE) {
 		File in;
 		char filename[15];
-		uint32 size;
 		if (vga_id == 23)
 			vga_id = 112;
 		if (vga_id == 328)
@@ -578,44 +579,47 @@
 		in.open(filename);
 		if (in.isOpen() == false)
 			error("read_vga_from_datfile_1: can't open %s", filename);
+
 		size = in.size();
-
 		if (getFeatures() & GF_CRUNCHED) {
-			byte *buffer = new byte[size];
-			if (in.read(buffer, size) != size)
+			byte *srcBuffer = (byte *)malloc(size);
+			if (in.read(srcBuffer, size) != size)
 				error("read_vga_from_datfile_1: read failed");
-			decrunchFile(buffer, _vgaBufferPointers[11].vgaFile2, size);
-			delete [] buffer;
+			decrunchFile(srcBuffer, _vgaBufferPointers[11].vgaFile2, size);
+			free(srcBuffer);
 		} else {
 			if (in.read(_vgaBufferPointers[11].vgaFile2, size) != size)
 				error("read_vga_from_datfile_1: read failed");
 		}
 		in.close();
 	} else {
-		uint32 offs_a = _gameOffsetsPtr[vga_id];
-		uint32 size = _gameOffsetsPtr[vga_id + 1] - offs_a;
+		offs = _gameOffsetsPtr[vga_id];
 
-		resfile_read(_vgaBufferPointers[11].vgaFile2, offs_a, size);
+		size = _gameOffsetsPtr[vga_id + 1] - offs;
+		resfile_read(_vgaBufferPointers[11].vgaFile2, offs, size);
 	}
 }
 
-byte *SimonEngine::read_vga_from_datfile_2(uint id, uint type) {
+byte *SimonEngine::loadVGAFile(uint id, uint type, uint &dstSize) {
 	File in;
 	char filename[15];
 	byte *dst = NULL;
+	uint32 file, offs, srcSize;
+	uint extraBuffer = 0;
 
-	// !!! HACK !!!
-	// allocate more space for text to cope with foreign languages that use
-	// up more space than english. I hope 6400 bytes are enough. This number
-	// is base on: 2 (lines) * 320 (screen width) * 10 (textheight) -- olki
-	int extraBuffer = (id == 5 ? 6400 : 0);
+	if (getGameType() == GType_SIMON1 || getGameType() == GType_SIMON2) {
+		// !!! HACK !!!
+		// Allocate more space for text to cope with foreign languages that use
+		// up more space than english. I hope 6400 bytes are enough. This number
+		// is base on: 2 (lines) * 320 (screen width) * 10 (textheight) -- olki
+		extraBuffer = (id == 5 ? 6400 : 0);
+	}
 
 	if (getFeatures() & GF_ZLIBCOMP) {
-		uint32 file, offset, srcSize, dstSize;
 		if (getPlatform() == Common::kPlatformAmiga) {
-			loadOffsets((const char*)"gfxindex.dat", id / 2 * 3 + type, file, offset, srcSize, dstSize);
+			loadOffsets((const char*)"gfxindex.dat", id / 2 * 3 + type, file, offs, srcSize, dstSize);
 		} else {
-			loadOffsets((const char*)"graphics.vga", id / 2 * 3 + type, file, offset, srcSize, dstSize);
+			loadOffsets((const char*)"graphics.vga", id / 2 * 3 + type, file, offs, srcSize, dstSize);
 		}
 
 		if (getPlatform() == Common::kPlatformAmiga)
@@ -623,11 +627,9 @@
 		else
 			sprintf(filename, "graphics.vga");
 
-		dst = allocBlock(dstSize);
-		decompressData(filename, dst, offset, srcSize, dstSize);
-		return dst;
+		dst = allocBlock(dstSize + extraBuffer);
+		decompressData(filename, dst, offs, srcSize, dstSize);
 	} else if (getFeatures() & GF_OLD_BUNDLE) {
-		uint32 size;
 		if (getPlatform() == Common::kPlatformAmiga) {
 			if (getFeatures() & GF_TALKIE)
 				sprintf(filename, "%.3d%d.out", id / 2, type);
@@ -642,36 +644,43 @@
 			if (type == 3) 
 				return NULL;
 			else
-				error("read_vga_from_datfile_2: can't open %s", filename);
+				error("loadVGAFile: can't open %s", filename);
 		}
-		size = in.size();
 
+		dstSize = srcSize = in.size();
 		if (getFeatures() & GF_CRUNCHED) {
-			byte *buffer = new byte[size];
-			if (in.read(buffer, size) != size)
-				error("read_vga_from_datfile_2: read failed");
-			dst = allocBlock (READ_BE_UINT32(buffer + size - 4) + extraBuffer);
-			decrunchFile(buffer, dst, size);
-			delete[] buffer;
+			byte *srcBuffer = (byte *)malloc(srcSize);
+			if (in.read(srcBuffer, srcSize) != srcSize)
+				error("loadVGAFile: read failed");
+
+			dstSize = READ_BE_UINT32(srcBuffer + srcSize - 4);
+			dst = allocBlock (dstSize + extraBuffer);
+			decrunchFile(srcBuffer, dst, srcSize);
+			free(srcBuffer);
 		} else {
-			dst = allocBlock(size + extraBuffer);
-			if (in.read(dst, size) != size)
-				error("read_vga_from_datfile_2: read failed");
+			dst = allocBlock(dstSize + extraBuffer);
+			if (in.read(dst, dstSize) != dstSize)
+				error("loadVGAFile: read failed");
 		}
 		in.close();
-
-		return dst;
 	} else {
-		uint32 offs_a = _gameOffsetsPtr[id];
-		uint32 size = _gameOffsetsPtr[id + 1] - offs_a;
+		offs = _gameOffsetsPtr[id];
 
-		dst = allocBlock(size + extraBuffer);
-		resfile_read(dst, offs_a, size);
+		dstSize = _gameOffsetsPtr[id + 1] - offs;
+		dst = allocBlock(dstSize + extraBuffer);
+		resfile_read(dst, offs, dstSize);
+	}
 
-		return dst;
-	}
+	dstSize += extraBuffer;
+	return dst;
 }
 
+void SimonEngine::resfile_read(void *dst, uint32 offs, uint32 size) {
+	_gameFile->seek(offs, SEEK_SET);
+	if (_gameFile->read(dst, size) != size)
+		error("resfile_read(%d,%d) read failed", offs, size);
+}
+
 void SimonEngine::loadSound(uint sound, uint pan, uint vol, uint type) {
 	byte *dst;
 

Modified: scummvm/trunk/engines/simon/simon.cpp
===================================================================
--- scummvm/trunk/engines/simon/simon.cpp	2006-04-19 23:01:31 UTC (rev 22042)
+++ scummvm/trunk/engines/simon/simon.cpp	2006-04-20 00:42:54 UTC (rev 22043)
@@ -2152,6 +2152,7 @@
 
 void SimonEngine::loadZone(uint vga_res) {
 	VgaPointersEntry *vpe;
+	uint32 size;
 
 	CHECK_BOUNDS(vga_res, _vgaBufferPointers);
 
@@ -2159,18 +2160,23 @@
 	if (vpe->vgaFile1 != NULL)
 		return;
 
-	vpe->vgaFile1 = read_vga_from_datfile_2(vga_res * 2, 1);
-	vpe->vgaFile2 = read_vga_from_datfile_2(vga_res * 2 + 1, 2);
+	vpe->vgaFile1 = loadVGAFile(vga_res * 2, 1, size);
+	vpe->vgaFile1End = vpe->vgaFile1 + size;
 
+	vpe->vgaFile2 = loadVGAFile(vga_res * 2 + 1, 2, size);
+	vpe->vgaFile2End = vpe->vgaFile2 + size;
+
 	vpe->sfxFile = NULL;
-	if (getGameType() == GType_FF && getPlatform() == Common::kPlatformWindows)
-		vpe->sfxFile = read_vga_from_datfile_2(vga_res * 2, 3);
+	if (getGameType() == GType_FF && getPlatform() == Common::kPlatformWindows) {
+		vpe->sfxFile = loadVGAFile(vga_res * 2, 3, size);
+		vpe->sfxFileEnd = vpe->sfxFile + size;
+	}
 }
 
 byte *SimonEngine::allocBlock(uint32 size) {
 	byte *block, *blockEnd;
 
-	_rejectCount = 0;
+	_rejectCount = false;
 
 	for (;;) {
 		block = _vgaBufFreeStart;
@@ -2217,13 +2223,20 @@
 
 	vpe = &_vgaBufferPointers[_noOverWrite];
 
-	if (_vgaBufFreeStart <= vpe->vgaFile1 && end >= vpe->vgaFile1 ||
-			_vgaBufFreeStart <= vpe->vgaFile2 && end >= vpe->vgaFile2) {
-		_rejectBlock = 1;
+	if (_vgaBufFreeStart <= vpe->vgaFile1 && end >= vpe->vgaFile1End) {
+		_rejectBlock = true;
 		_rejectCount++;
-		_vgaBufFreeStart = vpe->vgaFile1 + 0x5000;
+		_vgaBufFreeStart = vpe->vgaFile1End;
+	} else if (_vgaBufFreeStart <= vpe->vgaFile2 && end >= vpe->vgaFile2End) {
+		_rejectBlock = true;
+		_rejectCount++;
+		_vgaBufFreeStart = vpe->vgaFile2End;
+	} else if (_vgaBufFreeStart <= vpe->sfxFile && end >= vpe->sfxFileEnd) {
+		_rejectBlock = true;
+		_rejectCount++;
+		_vgaBufFreeStart = vpe->sfxFileEnd;
 	} else {
-		_rejectBlock = 0;
+		_rejectBlock = false;
 	}
 }
 
@@ -2245,11 +2258,15 @@
 	uint count = ARRAYSIZE(_vgaBufferPointers);
 	VgaPointersEntry *vpe = _vgaBufferPointers;
 	do {
-		if (_vgaBufFreeStart <= vpe->vgaFile1 && end >= vpe->vgaFile1 ||
-				_vgaBufFreeStart <= vpe->vgaFile2 && end >= vpe->vgaFile2) {
-			vpe->sfxFile = NULL;
+		if (_vgaBufFreeStart <= vpe->vgaFile1 && end >= vpe->vgaFile1End ||
+				_vgaBufFreeStart <= vpe->vgaFile2 && end >= vpe->vgaFile2End ||
+				_vgaBufFreeStart <= vpe->sfxFile && end >= vpe->sfxFileEnd) {
 			vpe->vgaFile1 = NULL;
+			vpe->vgaFile1End = NULL;
 			vpe->vgaFile2 = NULL;
+			vpe->vgaFile2End = NULL;
+			vpe->sfxFile = NULL;
+			vpe->sfxFileEnd = NULL;
 		}
 
 	} while (++vpe, --count);
@@ -2260,11 +2277,18 @@
 
 	vpe = &_vgaBufferPointers[a];
 
-	if (_vgaBufFreeStart <= vpe->vgaFile1 && end >= vpe->vgaFile1 ||
-			_vgaBufFreeStart <= vpe->vgaFile2 && end >= vpe->vgaFile2) {
+	if (_vgaBufFreeStart <= vpe->vgaFile1 && end >= vpe->vgaFile1End) {
 		_rejectBlock = true;
 		_rejectCount++;
-		_vgaBufFreeStart = vpe->vgaFile1 + 0x5000;
+		_vgaBufFreeStart = vpe->vgaFile1End;
+	} else if (_vgaBufFreeStart <= vpe->vgaFile2 && end >= vpe->vgaFile2End) {
+		_rejectBlock = true;
+		_rejectCount++;
+		_vgaBufFreeStart = vpe->vgaFile2End;
+	} else if (_vgaBufFreeStart <= vpe->sfxFile && end >= vpe->sfxFileEnd) {
+		_rejectBlock = true;
+		_rejectCount++;
+		_vgaBufFreeStart = vpe->sfxFileEnd;
 	} else {
 		_rejectBlock = false;
 	}
@@ -3309,12 +3333,6 @@
 	}
 }
 
-void SimonEngine::resfile_read(void *dst, uint32 offs, uint32 size) {
-	_gameFile->seek(offs, SEEK_SET);
-	if (_gameFile->read(dst, size) != size)
-		error("resfile_read(%d,%d) read failed", offs, size);
-}
-
 void SimonEngine::openGameFile() {
 	if (!(getFeatures() & GF_OLD_BUNDLE)) {
 		_gameFile = new File();

Modified: scummvm/trunk/engines/simon/simon.h
===================================================================
--- scummvm/trunk/engines/simon/simon.h	2006-04-19 23:01:31 UTC (rev 22042)
+++ scummvm/trunk/engines/simon/simon.h	2006-04-20 00:42:54 UTC (rev 22043)
@@ -75,8 +75,11 @@
 
 struct VgaPointersEntry {
 	byte *vgaFile1;
+	byte *vgaFile1End;
 	byte *vgaFile2;
+	byte *vgaFile2End;
 	byte *sfxFile;
+	byte *sfxFileEnd;
 	VgaPointersEntry() { memset(this, 0, sizeof(*this)); }
 };
 
@@ -1043,7 +1046,7 @@
 	byte *getBackGround();
 	byte *getScaleBuf();
 
-	byte *read_vga_from_datfile_2(uint id, uint type);
+	byte *loadVGAFile(uint id, uint type, uint &dstSize);
 
 	void resfile_read(void *dst, uint32 offs, uint32 size);
 


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