[Scummvm-cvs-logs] CVS: scummvm/scumm/imuse_digi dimuse_bndmgr.cpp,1.5,1.6 dimuse_bndmgr.h,1.2,1.3 dimuse_sndmgr.cpp,1.4,1.5 dimuse_sndmgr.h,1.3,1.4

Pawel Kolodziejski aquadran at users.sourceforge.net
Tue Jan 6 20:51:01 CET 2004


Update of /cvsroot/scummvm/scummvm/scumm/imuse_digi
In directory sc8-pr-cvs1:/tmp/cvs-serv27353

Modified Files:
	dimuse_bndmgr.cpp dimuse_bndmgr.h dimuse_sndmgr.cpp 
	dimuse_sndmgr.h 
Log Message:
better bundle dir cache

Index: dimuse_bndmgr.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/imuse_digi/dimuse_bndmgr.cpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- dimuse_bndmgr.cpp	7 Jan 2004 03:53:36 -0000	1.5
+++ dimuse_bndmgr.cpp	7 Jan 2004 04:50:38 -0000	1.6
@@ -25,89 +25,117 @@
 
 namespace Scumm {
 
-struct FileDirCache {
-	char fileName[20];
-	BundleMgr::AudioTable *bundleTable;
-	int32 numFiles;
-	int32 instance;
-} static budleDirCache[4];
-
-BundleMgr::BundleMgr() {
-	_bundleTable = NULL;
-	_compTable = NULL;
-	_numFiles = 0;
-	_curSample = -1;
-	_fileBundleId = -1;
+BundleDirCache::BundleDirCache() {
+	for (int fileId = 0; fileId < ARRAYSIZE(_budleDirCache); fileId++) {
+		_budleDirCache[fileId].bundleTable = NULL;
+	}
 }
 
-BundleMgr::~BundleMgr() {
-	closeFile();
+BundleDirCache::~BundleDirCache() {
+	for (int fileId = 0; fileId < ARRAYSIZE(_budleDirCache); fileId++) {
+		if (_budleDirCache[fileId].bundleTable != NULL)
+			free (_budleDirCache[fileId].bundleTable);
+	}
 }
 
-bool BundleMgr::openFile(const char *filename, const char *directory) {
-	int32 tag, offset;
-
-	if (_file.isOpen())
-		return true;
+BundleDirCache::AudioTable *BundleDirCache::getTable(const char *filename, const char *directory) {
+	int slot = matchFile(filename, directory);
+	assert(slot != -1);
+	return _budleDirCache[slot].bundleTable;
+}
 
-	if (_file.open(filename, directory) == false) {
-		warning("BundleMgr::openFile() Can't open bundle file: %s", filename);
-		return false;
-	}
+int32 BundleDirCache::getNumFiles(const char *filename, const char *directory) {
+	int slot = matchFile(filename, directory);
+	assert(slot != -1);
+	return _budleDirCache[slot].numFiles;
+}
 
+int BundleDirCache::matchFile(const char *filename, const char *directory) {
+	int32 tag, offset;
 	bool found = false;
 	int freeSlot = -1;
 	int fileId;
 
-	for (fileId = 0; fileId < ARRAYSIZE(budleDirCache); fileId++) {
-		if ((budleDirCache[fileId].instance == 0) && (freeSlot == -1)) {
+	for (fileId = 0; fileId < ARRAYSIZE(_budleDirCache); fileId++) {
+		if ((_budleDirCache[fileId].bundleTable == NULL) && (freeSlot == -1)) {
 			freeSlot = fileId;
 		}
-		if (scumm_stricmp(filename, budleDirCache[fileId].fileName) == 0) {
+		if (scumm_stricmp(filename, _budleDirCache[fileId].fileName) == 0) {
 			found = true;
+			break;
 		}
 	}
 
 	if (!found) {
+		File file;
+
+		if (file.open(filename, directory) == false) {
+			warning("BundleDirCache::matchFile() Can't open bundle file: %s", filename);
+			return false;
+		}
+
 		if (freeSlot == -1)
-			error("BundleMgr::openFile() Can't find free slot for file bundle dir cache");
+			error("BundleDirCache::matchFileFile() Can't find free slot for file bundle dir cache");
 
-		tag = _file.readUint32BE();
-		offset = _file.readUint32BE();
+		tag = file.readUint32BE();
+		offset = file.readUint32BE();
 		
-		strcpy(budleDirCache[freeSlot].fileName, filename);
-		budleDirCache[freeSlot].numFiles = _numFiles = _file.readUint32BE();
-		budleDirCache[freeSlot].bundleTable = _bundleTable = (AudioTable *) malloc(_numFiles * sizeof(AudioTable));
+		strcpy(_budleDirCache[freeSlot].fileName, filename);
+		_budleDirCache[freeSlot].numFiles = file.readUint32BE();
+		_budleDirCache[freeSlot].bundleTable = (AudioTable *) malloc(_budleDirCache[freeSlot].numFiles * sizeof(AudioTable));
 
-		_file.seek(offset, SEEK_SET);
+		file.seek(offset, SEEK_SET);
 
-		for (int32 i = 0; i < _numFiles; i++) {
+		for (int32 i = 0; i < _budleDirCache[freeSlot].numFiles; i++) {
 			char name[13], c;
 			int32 z = 0;
 			int32 z2;
 
 			for (z2 = 0; z2 < 8; z2++)
-				if ((c = _file.readByte()) != 0)
+				if ((c = file.readByte()) != 0)
 					name[z++] = c;
 			name[z++] = '.';
 			for (z2 = 0; z2 < 4; z2++)
-				if ((c = _file.readByte()) != 0)
+				if ((c = file.readByte()) != 0)
 					name[z++] = c;
 
 			name[z] = '\0';
-			strcpy(_bundleTable[i].filename, name);
-			_bundleTable[i].offset = _file.readUint32BE();
-			_bundleTable[i].size = _file.readUint32BE();
+			strcpy(_budleDirCache[freeSlot].bundleTable[i].filename, name);
+			_budleDirCache[freeSlot].bundleTable[i].offset = file.readUint32BE();
+			_budleDirCache[freeSlot].bundleTable[i].size = file.readUint32BE();
 		}
-		budleDirCache[freeSlot].instance++;
-		_fileBundleId = freeSlot;
+		return freeSlot;
 	} else {
-		_fileBundleId = fileId;
-		_numFiles = budleDirCache[fileId].numFiles;
-		_bundleTable = budleDirCache[fileId].bundleTable;
-		budleDirCache[fileId].instance++;
+		return fileId;
+	}
+}
+
+BundleMgr::BundleMgr(BundleDirCache *cache) {
+	_cache = cache;
+	_bundleTable = NULL;
+	_compTable = NULL;
+	_numFiles = 0;
+	_curSample = -1;
+	_fileBundleId = -1;
+}
+
+BundleMgr::~BundleMgr() {
+	closeFile();
+}
+
+bool BundleMgr::openFile(const char *filename, const char *directory) {
+	if (_file.isOpen())
+		return true;
+
+	if (_file.open(filename, directory) == false) {
+		warning("BundleMgr::openFile() Can't open bundle file: %s", filename);
+		return false;
 	}
 
+	_numFiles = _cache->getNumFiles(filename, directory);
+	assert(_numFiles);
+	_bundleTable = _cache->getTable(filename, directory);
+	assert(_bundleTable);
 	_compTableLoaded = false;
 	_lastCacheOutputSize = 0;
 	_lastBlock = -1;
@@ -118,12 +146,6 @@
 void BundleMgr::closeFile() {
 	if (_file.isOpen()) {
 		_file.close();
-		if (--budleDirCache[_fileBundleId].instance <= 0) {
-			free (budleDirCache[_fileBundleId].bundleTable);
-			budleDirCache[_fileBundleId].instance = 0;
-			budleDirCache[_fileBundleId].fileName[0] = 0;
-			budleDirCache[_fileBundleId].numFiles = 0;
-		}
 		_bundleTable = NULL;
 		_numFiles = 0;
 		_compTableLoaded = false;
@@ -225,7 +247,7 @@
 int32 BundleMgr::decompressSampleByName(const char *name, int32 offset, int32 size, byte **comp_final) {
 	int32 final_size = 0, i;
 
-	if (_file.isOpen() == false) {
+	if (!_file.isOpen()) {
 		warning("BundleMgr::decompressSampleByName() File is not open!");
 		return 0;
 	}

Index: dimuse_bndmgr.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/imuse_digi/dimuse_bndmgr.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- dimuse_bndmgr.h	7 Jan 2004 03:34:41 -0000	1.2
+++ dimuse_bndmgr.h	7 Jan 2004 04:50:38 -0000	1.3
@@ -26,15 +26,32 @@
 
 namespace Scumm {
 
-class BundleMgr {
+class BundleDirCache {
 public:
-
 	struct AudioTable {
 		char filename[13];
 		int32 size;
 		int32 offset;
 	};
+private:
+
+	struct FileDirCache {
+		char fileName[20];
+		AudioTable *bundleTable;
+		int32 numFiles;
+	} _budleDirCache[4];
+	
+	int matchFile(const char *filename, const char *directory);
+
+public:
+	BundleDirCache();
+	~BundleDirCache();
+
+	AudioTable *getTable(const char *filename, const char *directory);
+	int32 getNumFiles(const char *filename, const char *directory);
+};
 
+class BundleMgr {
 private:
 
 	struct CompTable {
@@ -43,7 +60,8 @@
 		int32 codec;
 	};
 
-	AudioTable *_bundleTable;
+	BundleDirCache *_cache;
+	BundleDirCache::AudioTable *_bundleTable;
 	CompTable *_compTable;
 	int32 _numFiles;
 	int32 _curSample;
@@ -56,7 +74,7 @@
 
 public:
 
-	BundleMgr();
+	BundleMgr(BundleDirCache *_cache);
 	~BundleMgr();
 
 	bool openFile(const char *filename, const char *directory);

Index: dimuse_sndmgr.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/imuse_digi/dimuse_sndmgr.cpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- dimuse_sndmgr.cpp	6 Jan 2004 20:08:00 -0000	1.4
+++ dimuse_sndmgr.cpp	7 Jan 2004 04:50:38 -0000	1.5
@@ -33,6 +33,7 @@
 	_scumm = scumm;
 	_mutex = g_system->create_mutex();
 	_disk = 0;
+	_cacheBundleDir = new BundleDirCache();
 	BundleCodecs::initializeImcTables();
 }
 
@@ -40,6 +41,7 @@
 	for (int l = 0; l < MAX_IMUSE_SOUNDS; l++) {
 		closeSound(&_sounds[l]);
 	}
+	delete _cacheBundleDir;
 }
 
 void ImuseDigiSndMgr::prepareSound(byte *ptr, int slot) {
@@ -137,7 +139,7 @@
 bool ImuseDigiSndMgr::openMusicBundle(int slot) {
 	bool result = false;
 
-	_sounds[slot]._bundle = new BundleMgr();
+	_sounds[slot]._bundle = new BundleMgr(_cacheBundleDir);
 	if (_scumm->_gameId == GID_CMI) {
 		if (_scumm->_features & GF_DEMO) {
 			result = _sounds[slot]._bundle->openFile("music.bun", _scumm->getGameDataPath());
@@ -164,7 +166,7 @@
 bool ImuseDigiSndMgr::openVoiceBundle(int slot) {
 	bool result = false;
 
-	_sounds[slot]._bundle = new BundleMgr();
+	_sounds[slot]._bundle = new BundleMgr(_cacheBundleDir);
 	if (_scumm->_gameId == GID_CMI) {
 		if (_scumm->_features & GF_DEMO) {
 			result = _sounds[slot]._bundle->openFile("voice.bun", _scumm->getGameDataPath());

Index: dimuse_sndmgr.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/imuse_digi/dimuse_sndmgr.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- dimuse_sndmgr.h	6 Jan 2004 20:04:33 -0000	1.3
+++ dimuse_sndmgr.h	7 Jan 2004 04:50:38 -0000	1.4
@@ -24,6 +24,7 @@
 #include "stdafx.h"
 #include "common/scummsys.h"
 #include "common/system.h"
+#include "scumm/imuse_digi/dimuse_bndmgr.h"
 
 namespace Scumm {
 
@@ -88,6 +89,7 @@
 	ScummEngine *_scumm;
 	OSystem::MutexRef _mutex;
 	byte _disk;
+	BundleDirCache *_cacheBundleDir;
 
 	bool openMusicBundle(int slot);
 	bool openVoiceBundle(int slot);





More information about the Scummvm-git-logs mailing list