diff options
author | Johannes Schickel | 2006-09-16 20:51:05 +0000 |
---|---|---|
committer | Johannes Schickel | 2006-09-16 20:51:05 +0000 |
commit | a8bc979364037e23398c4c3c6f466bb09bcf25a9 (patch) | |
tree | af11dd539ad3e10671813d72ac11d94f2d6ce3d1 /engines/kyra | |
parent | d0735a34a28e33e7f205ac034c4cdfac0b9aa540 (diff) | |
download | scummvm-rg350-a8bc979364037e23398c4c3c6f466bb09bcf25a9.tar.gz scummvm-rg350-a8bc979364037e23398c4c3c6f466bb09bcf25a9.tar.bz2 scummvm-rg350-a8bc979364037e23398c4c3c6f466bb09bcf25a9.zip |
- enables pseudo unloading of loaded pak files (which reduces the loading of pak files on room changes)
- uses Common::hashit_lower instead of scumm_stricmp for filename checking
svn-id: r23896
Diffstat (limited to 'engines/kyra')
-rw-r--r-- | engines/kyra/resource.cpp | 84 | ||||
-rw-r--r-- | engines/kyra/resource.h | 33 | ||||
-rw-r--r-- | engines/kyra/scene.cpp | 9 |
3 files changed, 75 insertions, 51 deletions
diff --git a/engines/kyra/resource.cpp b/engines/kyra/resource.cpp index a2434e42a7..7f633f0a48 100644 --- a/engines/kyra/resource.cpp +++ b/engines/kyra/resource.cpp @@ -25,6 +25,7 @@ #include "common/endian.h" #include "common/file.h" #include "common/fs.h" +#include "common/hash-str.h" #include "gui/message.h" @@ -102,8 +103,14 @@ Resource::~Resource() { } bool Resource::loadPakFile(const Common::String &filename) { - if (isInPakList(filename)) - return true; + Common::List<ResourceFile*>::iterator start = _pakfiles.begin(); + uint hash = Common::hashit_lower(filename.c_str()); + for (;start != _pakfiles.end(); ++start) { + if ((*start)->filename() == hash) { + (*start)->open(); + return true; + } + } uint32 size = 0; @@ -132,10 +139,10 @@ bool Resource::loadPakFile(const Common::String &filename) { void Resource::unloadPakFile(const Common::String &filename) { Common::List<ResourceFile*>::iterator start = _pakfiles.begin(); + uint hash = Common::hashit_lower(filename.c_str()); for (;start != _pakfiles.end(); ++start) { - if (scumm_stricmp((*start)->filename().c_str(), filename.c_str()) == 0) { - delete *start; - _pakfiles.erase(start); + if ((*start)->filename() == hash) { + (*start)->close(); break; } } @@ -144,8 +151,9 @@ void Resource::unloadPakFile(const Common::String &filename) { bool Resource::isInPakList(const Common::String &filename) { Common::List<ResourceFile*>::iterator start = _pakfiles.begin(); + uint hash = Common::hashit_lower(filename.c_str()); for (;start != _pakfiles.end(); ++start) { - if (scumm_stricmp((*start)->filename().c_str(), filename.c_str()) == 0) + if ((*start)->filename() == hash) return true; } return false; @@ -175,9 +183,13 @@ uint8 *Resource::fileData(const char *file, uint32 *size) { // opens the file in a PAK File Common::List<ResourceFile*>::iterator start = _pakfiles.begin(); + uint fileHash = Common::hashit_lower(file); uint32 temp = 0; for (;start != _pakfiles.end(); ++start) { - temp = (*start)->getFileSize(file); + if (!(*start)->isOpen()) + continue; + + temp = (*start)->getFileSize(fileHash); if (!temp) continue; @@ -185,7 +197,7 @@ uint8 *Resource::fileData(const char *file, uint32 *size) { if (size) *size = temp; - buffer = (*start)->getFile(file); + buffer = (*start)->getFile(fileHash); break; } } @@ -205,13 +217,17 @@ bool Resource::getFileHandle(const char *file, uint32 *size, Common::File &fileh Common::List<ResourceFile*>::iterator start = _pakfiles.begin(); + uint fileHash = Common::hashit_lower(file); for (;start != _pakfiles.end(); ++start) { - *size = (*start)->getFileSize(file); + if (!(*start)->isOpen()) + continue; + + *size = (*start)->getFileSize(fileHash); if (!(*size)) continue; - if ((*start)->getFileHandle(file, filehandle)) { + if ((*start)->getFileHandle(fileHash, filehandle)) { return true; } } @@ -226,8 +242,12 @@ uint32 Resource::getFileSize(const char *file) { if (temp.open(file)) return temp.size(); + uint fileHash = Common::hashit_lower(file); for (;start != _pakfiles.end(); ++start) { - uint32 size = (*start)->getFileSize(file); + if (!(*start)->isOpen()) + continue; + + uint32 size = (*start)->getFileSize(fileHash); if (size) return size; @@ -292,7 +312,7 @@ PAKFile::PAKFile(const char *file, const char *physfile, Common::File &pakfile, if (!(*((const char*)buffer))) break; - chunk._name = (const char*)buffer; + chunk._name = Common::hashit_lower((const char*)buffer); nameLength = strlen((const char*)buffer) + 1; if (!_isAmiga) { @@ -318,23 +338,22 @@ PAKFile::PAKFile(const char *file, const char *physfile, Common::File &pakfile, } _open = true; - _filename = file; + _filename = Common::hashit_lower(file); _physfile = physfile; _physOffset = off; } PAKFile::~PAKFile() { - _filename.clear(); _physfile.clear(); _open = false; _files.clear(); } -uint8 *PAKFile::getFile(const char *file) { +uint8 *PAKFile::getFile(uint hash) { for (PAKFile_Iterate) { - if (!scumm_stricmp(start->_name.c_str(), file)) { + if (start->_name == hash) { Common::File pakfile; if (!openFile(pakfile)) return false; @@ -348,11 +367,11 @@ uint8 *PAKFile::getFile(const char *file) { return 0; } -bool PAKFile::getFileHandle(const char *file, Common::File &filehandle) { +bool PAKFile::getFileHandle(uint hash, Common::File &filehandle) { filehandle.close(); for (PAKFile_Iterate) { - if (!scumm_stricmp(start->_name.c_str(), file)) { + if (start->_name == hash) { if (!openFile(filehandle)) return false; filehandle.seek(start->_start, SEEK_CUR); @@ -362,9 +381,9 @@ bool PAKFile::getFileHandle(const char *file, Common::File &filehandle) { return false; } -uint32 PAKFile::getFileSize(const char* file) { +uint32 PAKFile::getFileSize(uint hash) { for (PAKFile_Iterate) { - if (!scumm_stricmp(start->_name.c_str(), file)) + if (start->_name == hash) return start->_size; } return 0; @@ -374,7 +393,6 @@ bool PAKFile::openFile(Common::File &filehandle) { filehandle.close(); if (!filehandle.open(_physfile)) { - debug(3, "couldn't open pakfile '%s'\n", _filename.c_str()); return false; } @@ -416,7 +434,7 @@ INSFile::INSFile(const char *file) : ResourceFile(), _files() { ++i; FileEntry newEntry; - newEntry._name = temp; + newEntry._name = Common::hashit_lower(temp.c_str()); newEntry._start = 0; newEntry._size = 0; _files.push_back(newEntry); @@ -436,23 +454,22 @@ INSFile::INSFile(const char *file) : ResourceFile(), _files() { pakfile.seek(filesize, SEEK_CUR); } - _filename = file; + _filename = Common::hashit_lower(file); + _physfile = file; _open = true; } INSFile::~INSFile() { - _filename.clear(); _open = false; _files.clear(); } -uint8 *INSFile::getFile(const char *file) { +uint8 *INSFile::getFile(uint hash) { for (INSFile_Iterate) { - if (!scumm_stricmp(start->_name.c_str(), file)) { + if (start->_name == hash) { Common::File pakfile; - if (!pakfile.open(_filename)) { - debug(3, "couldn't open insfile '%s'\n", _filename.c_str()); + if (!pakfile.open(_physfile)) { return false; } pakfile.seek(start->_start); @@ -465,11 +482,10 @@ uint8 *INSFile::getFile(const char *file) { return 0; } -bool INSFile::getFileHandle(const char *file, Common::File &filehandle) { +bool INSFile::getFileHandle(uint hash, Common::File &filehandle) { for (INSFile_Iterate) { - if (!scumm_stricmp(start->_name.c_str(), file)) { - if (!filehandle.open(_filename)) { - debug(3, "couldn't open insfile '%s'\n", _filename.c_str()); + if (start->_name == hash) { + if (!filehandle.open(_physfile)) { return false; } filehandle.seek(start->_start, SEEK_CUR); @@ -479,9 +495,9 @@ bool INSFile::getFileHandle(const char *file, Common::File &filehandle) { return false; } -uint32 INSFile::getFileSize(const char *file) { +uint32 INSFile::getFileSize(uint hash) { for (INSFile_Iterate) { - if (!scumm_stricmp(start->_name.c_str(), file)) + if (start->_name == hash) return start->_size; } return 0; diff --git a/engines/kyra/resource.h b/engines/kyra/resource.h index d0b4db93e7..7492688cf0 100644 --- a/engines/kyra/resource.h +++ b/engines/kyra/resource.h @@ -38,23 +38,26 @@ public: ResourceFile() : _open(false), _filename() {} virtual ~ResourceFile() {} - virtual uint8 *getFile(const char *file) = 0; - virtual bool getFileHandle(const char *file, Common::File &filehandle) = 0; - virtual uint32 getFileSize(const char *file) = 0; + virtual uint8 *getFile(uint file) = 0; + virtual bool getFileHandle(uint file, Common::File &filehandle) = 0; + virtual uint32 getFileSize(uint file) = 0; - const Common::String &filename() const { return _filename; } + uint filename() const { return _filename; } - virtual bool isValid(void) const { return !(_filename.empty()); } + virtual bool isValid(void) const { return _filename; } bool isOpen(void) const { return _open; } + + virtual void close() { _open = false; } + virtual void open() { _open = true; } protected: bool _open; - Common::String _filename; + uint _filename; }; // standard Package format for Kyrandia games class PAKFile : public ResourceFile { struct PakChunk { - Common::String _name; + uint _name; uint32 _start; uint32 _size; }; @@ -63,9 +66,9 @@ public: PAKFile(const char *file, const char *physfile, Common::File &pakfile, bool isAmiga = false); ~PAKFile(); - uint8 *getFile(const char *file); - bool getFileHandle(const char *file, Common::File &filehandle); - uint32 getFileSize(const char *file); + uint8 *getFile(uint file); + bool getFileHandle(uint file, Common::File &filehandle); + uint32 getFileSize(uint file); private: bool openFile(Common::File &filehandle); @@ -80,7 +83,7 @@ private: // installation file packages for (Kyra2/)Kyra3 class INSFile : public ResourceFile { struct FileEntry { - Common::String _name; + uint _name; uint32 _start; uint32 _size; }; @@ -88,11 +91,13 @@ public: INSFile(const char *file); ~INSFile(); - uint8 *getFile(const char *file); - bool getFileHandle(const char *file, Common::File &filehandle); - uint32 getFileSize(const char *file); + uint8 *getFile(uint file); + bool getFileHandle(uint file, Common::File &filehandle); + uint32 getFileSize(uint file); protected: Common::List<FileEntry> _files; // the entries + + Common::String _physfile; }; class Resource { diff --git a/engines/kyra/scene.cpp b/engines/kyra/scene.cpp index fe38c69bd3..e3436a1126 100644 --- a/engines/kyra/scene.cpp +++ b/engines/kyra/scene.cpp @@ -1586,13 +1586,16 @@ void KyraEngine::setupSceneResource(int sceneId) { char file[64]; strcpy(file, _roomFilenameTable[tableId]); strcat(file, ".VRM"); - _res->loadPakFile(file); + if (Common::File::exists(file)) + _res->loadPakFile(file); strcpy(file, _roomFilenameTable[tableId]); strcat(file, ".PAK"); - _res->loadPakFile(file); + if (Common::File::exists(file)) + _res->loadPakFile(file); strcpy(file, _roomFilenameTable[tableId]); strcat(file, ".APK"); - _res->loadPakFile(file); + if (Common::File::exists(file)) + _res->loadPakFile(file); } } // end of namespace Kyra |