[Scummvm-cvs-logs] CVS: scummvm/scumm/imuse_digi dimuse_bndmgr.cpp,1.38,1.39 dimuse_bndmgr.h,1.21,1.22 dimuse_sndmgr.cpp,1.79,1.80

Pawel Kolodziejski aquadran at users.sourceforge.net
Wed Oct 26 14:18:30 CEST 2005


Update of /cvsroot/scummvm/scummvm/scumm/imuse_digi
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1797

Modified Files:
	dimuse_bndmgr.cpp dimuse_bndmgr.h dimuse_sndmgr.cpp 
Log Message:
added optimisation on sound file name searching

Index: dimuse_bndmgr.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/imuse_digi/dimuse_bndmgr.cpp,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -d -r1.38 -r1.39
--- dimuse_bndmgr.cpp	18 Oct 2005 01:30:21 -0000	1.38
+++ dimuse_bndmgr.cpp	26 Oct 2005 21:17:55 -0000	1.39
@@ -42,14 +42,18 @@
 	}
 }
 
-BundleDirCache::AudioTable *BundleDirCache::getTable(const char *filename, int slot) {
+BundleDirCache::AudioTable *BundleDirCache::getTable(int slot) {
 	return _budleDirCache[slot].bundleTable;
 }
 
-int32 BundleDirCache::getNumFiles(const char *filename, int slot) {
+int32 BundleDirCache::getNumFiles(int slot) {
 	return _budleDirCache[slot].numFiles;
 }
 
+BundleDirCache::IndexNode *BundleDirCache::getIndexTable(int slot) {
+	return _budleDirCache[slot].indexTable;
+}
+
 bool BundleDirCache::isCompressed(int slot) {
 	return _budleDirCache[slot].compressedBun;
 }
@@ -92,6 +96,9 @@
 
 		file.seek(offset, SEEK_SET);
 
+		_budleDirCache[freeSlot].indexTable =
+				(IndexNode *)calloc(_budleDirCache[freeSlot].numFiles, sizeof(IndexNode));
+
 		for (int32 i = 0; i < _budleDirCache[freeSlot].numFiles; i++) {
 			char name[24], c;
 			int32 z = 0;
@@ -113,7 +120,12 @@
 			}
 			_budleDirCache[freeSlot].bundleTable[i].offset = file.readUint32BE();
 			_budleDirCache[freeSlot].bundleTable[i].size = file.readUint32BE();
+			strcpy(_budleDirCache[freeSlot].indexTable[i].filename,
+					_budleDirCache[freeSlot].bundleTable[i].filename);
+			_budleDirCache[freeSlot].indexTable[i].index = i;
 		}
+		qsort(_budleDirCache[freeSlot].indexTable, _budleDirCache[freeSlot].numFiles,
+				sizeof(IndexNode), (int (*)(const void*, const void*))scumm_stricmp);
 		return freeSlot;
 	} else {
 		return fileId;
@@ -136,13 +148,15 @@
 }
 
 Common::File *BundleMgr::getFile(const char *filename, int32 &offset, int32 &size) {
-	for (int i = 0; i < _numFiles; i++) {
-		if (!scumm_stricmp(filename, _bundleTable[i].filename)) {
-			_file.seek(_bundleTable[i].offset, SEEK_SET);
-			offset = _bundleTable[i].offset;
-			size = _bundleTable[i].size;
-			return &_file;
-		}
+	BundleDirCache::IndexNode target;
+	strcpy(target.filename, filename);
+	BundleDirCache::IndexNode *found = (BundleDirCache::IndexNode *)bsearch(&target, _indexTable, _numFiles,
+			sizeof(BundleDirCache::IndexNode), (int (*)(const void*, const void*))scumm_stricmp);
+	if (found) {
+		_file.seek(_bundleTable[found->index].offset, SEEK_SET);
+		offset = _bundleTable[found->index].offset;
+		size = _bundleTable[found->index].size;
+		return &_file;
 	}
 
 	return NULL;
@@ -164,9 +178,10 @@
 	int slot = _cache->matchFile(filename);
 	assert(slot != -1);
 	compressed = _cache->isCompressed(slot);
-	_numFiles = _cache->getNumFiles(filename, slot);
+	_numFiles = _cache->getNumFiles(slot);
 	assert(_numFiles);
-	_bundleTable = _cache->getTable(filename, slot);
+	_bundleTable = _cache->getTable(slot);
+	_indexTable = _cache->getIndexTable(slot);
 	assert(_bundleTable);
 	_compTableLoaded = false;
 	_outputSize = 0;
@@ -304,19 +319,22 @@
 }
 
 int32 BundleMgr::decompressSampleByName(const char *name, int32 offset, int32 size, byte **comp_final, bool header_outside) {
-	int32 final_size = 0, i;
+	int32 final_size = 0;
 
 	if (!_file.isOpen()) {
 		error("BundleMgr::decompressSampleByName() File is not open!");
 		return 0;
 	}
 
-	for (i = 0; i < _numFiles; i++) {
-		if (!scumm_stricmp(name, _bundleTable[i].filename)) {
-			final_size = decompressSampleByIndex(i, offset, size, comp_final, 0, header_outside);
-			return final_size;
-		}
+	BundleDirCache::IndexNode target;
+	strcpy(target.filename, name);
+	BundleDirCache::IndexNode *found = (BundleDirCache::IndexNode *)bsearch(&target, _indexTable, _numFiles,
+			sizeof(BundleDirCache::IndexNode), (int (*)(const void*, const void*))scumm_stricmp);
+	if (found) {
+		final_size = decompressSampleByIndex(found->index, offset, size, comp_final, 0, header_outside);
+		return final_size;
 	}
+
 	debug(2, "BundleMgr::decompressSampleByName() Failed finding voice %s", name);
 	return final_size;
 }

Index: dimuse_bndmgr.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/imuse_digi/dimuse_bndmgr.h,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -d -r1.21 -r1.22
--- dimuse_bndmgr.h	18 Oct 2005 01:30:21 -0000	1.21
+++ dimuse_bndmgr.h	26 Oct 2005 21:17:55 -0000	1.22
@@ -34,6 +34,12 @@
 		int32 offset;
 		int32 size;
 	};
+
+	struct IndexNode {
+		char filename[24];
+		int32 index;
+	};
+
 private:
 
 	struct FileDirCache {
@@ -41,6 +47,7 @@
 		AudioTable *bundleTable;
 		int32 numFiles;
 		bool compressedBun;
+		IndexNode *indexTable;
 	} _budleDirCache[4];
 
 public:
@@ -48,12 +55,14 @@
 	~BundleDirCache();
 
 	int matchFile(const char *filename);
-	AudioTable *getTable(const char *filename, int slot);
-	int32 getNumFiles(const char *filename, int slot);
+	AudioTable *getTable(int slot);
+	IndexNode *getIndexTable(int slot);
+	int32 getNumFiles(int slot);
 	bool isCompressed(int slot);
 };
 
 class BundleMgr {
+
 private:
 
 	struct CompTable {
@@ -64,6 +73,7 @@
 
 	BundleDirCache *_cache;
 	BundleDirCache::AudioTable *_bundleTable;
+	BundleDirCache::IndexNode *_indexTable;
 	CompTable *_compTable;
 	int _numFiles;
 	int _numCompItems;






More information about the Scummvm-git-logs mailing list