aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaweł Kołodziejski2004-01-07 04:50:38 +0000
committerPaweł Kołodziejski2004-01-07 04:50:38 +0000
commitc9c3a83d347a2727e7374a189d344670a0dce02d (patch)
treee3113f092cb92c8cac52744b70d9733fd1f2d8fa
parentaaf54b0a14ce072e18189042c0dc5bed8201ee27 (diff)
downloadscummvm-rg350-c9c3a83d347a2727e7374a189d344670a0dce02d.tar.gz
scummvm-rg350-c9c3a83d347a2727e7374a189d344670a0dce02d.tar.bz2
scummvm-rg350-c9c3a83d347a2727e7374a189d344670a0dce02d.zip
better bundle dir cache
svn-id: r12202
-rw-r--r--scumm/imuse_digi/dimuse_bndmgr.cpp128
-rw-r--r--scumm/imuse_digi/dimuse_bndmgr.h26
-rw-r--r--scumm/imuse_digi/dimuse_sndmgr.cpp6
-rw-r--r--scumm/imuse_digi/dimuse_sndmgr.h2
4 files changed, 103 insertions, 59 deletions
diff --git a/scumm/imuse_digi/dimuse_bndmgr.cpp b/scumm/imuse_digi/dimuse_bndmgr.cpp
index 9de36ab655..a763d78485 100644
--- a/scumm/imuse_digi/dimuse_bndmgr.cpp
+++ b/scumm/imuse_digi/dimuse_bndmgr.cpp
@@ -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 @@ bool BundleMgr::openFile(const char *filename, const char *directory) {
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::decompressSampleByIndex(int32 index, int32 offset, int32 size,
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;
}
diff --git a/scumm/imuse_digi/dimuse_bndmgr.h b/scumm/imuse_digi/dimuse_bndmgr.h
index 350cfeca6b..1473816728 100644
--- a/scumm/imuse_digi/dimuse_bndmgr.h
+++ b/scumm/imuse_digi/dimuse_bndmgr.h
@@ -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 @@ private:
int32 codec;
};
- AudioTable *_bundleTable;
+ BundleDirCache *_cache;
+ BundleDirCache::AudioTable *_bundleTable;
CompTable *_compTable;
int32 _numFiles;
int32 _curSample;
@@ -56,7 +74,7 @@ private:
public:
- BundleMgr();
+ BundleMgr(BundleDirCache *_cache);
~BundleMgr();
bool openFile(const char *filename, const char *directory);
diff --git a/scumm/imuse_digi/dimuse_sndmgr.cpp b/scumm/imuse_digi/dimuse_sndmgr.cpp
index 86c44f54c0..9cd94fe8d1 100644
--- a/scumm/imuse_digi/dimuse_sndmgr.cpp
+++ b/scumm/imuse_digi/dimuse_sndmgr.cpp
@@ -33,6 +33,7 @@ ImuseDigiSndMgr::ImuseDigiSndMgr(ScummEngine *scumm) {
_scumm = scumm;
_mutex = g_system->create_mutex();
_disk = 0;
+ _cacheBundleDir = new BundleDirCache();
BundleCodecs::initializeImcTables();
}
@@ -40,6 +41,7 @@ ImuseDigiSndMgr::~ImuseDigiSndMgr() {
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 @@ int ImuseDigiSndMgr::allocSlot() {
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::openMusicBundle(int slot) {
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());
diff --git a/scumm/imuse_digi/dimuse_sndmgr.h b/scumm/imuse_digi/dimuse_sndmgr.h
index d40bb88062..00b2f07f7c 100644
--- a/scumm/imuse_digi/dimuse_sndmgr.h
+++ b/scumm/imuse_digi/dimuse_sndmgr.h
@@ -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 @@ private:
ScummEngine *_scumm;
OSystem::MutexRef _mutex;
byte _disk;
+ BundleDirCache *_cacheBundleDir;
bool openMusicBundle(int slot);
bool openVoiceBundle(int slot);