diff options
| author | Johannes Schickel | 2005-12-12 17:39:01 +0000 |
|---|---|---|
| committer | Johannes Schickel | 2005-12-12 17:39:01 +0000 |
| commit | 080039cf1437bfc2de9716f40612dd4379dc7853 (patch) | |
| tree | 66fbee33590feed132fee869583bc132f3be30dd | |
| parent | 701bdbda9dabac0884bbf7de14bea3593a7377ce (diff) | |
| download | scummvm-rg350-080039cf1437bfc2de9716f40612dd4379dc7853.tar.gz scummvm-rg350-080039cf1437bfc2de9716f40612dd4379dc7853.tar.bz2 scummvm-rg350-080039cf1437bfc2de9716f40612dd4379dc7853.zip | |
Reworked the resource manager. Now it doesn't load all package files into
memory but loads the needed part from the original files if needed.
Also added CHAPTER1.VRM to the default CD filelist to fix that scummvm
quits then looking at items in the CD version. (CHAPTER[2-5].VRM is NOT needed
since they are the same files as CHAPTER1.VRM).
svn-id: r19784
| -rw-r--r-- | kyra/kyra.cpp | 2 | ||||
| -rw-r--r-- | kyra/resource.cpp | 67 | ||||
| -rw-r--r-- | kyra/resource.h | 10 | ||||
| -rw-r--r-- | kyra/staticres.cpp | 5 |
4 files changed, 46 insertions, 38 deletions
diff --git a/kyra/kyra.cpp b/kyra/kyra.cpp index b3f7e0deb8..91b8fdac69 100644 --- a/kyra/kyra.cpp +++ b/kyra/kyra.cpp @@ -911,7 +911,7 @@ void KyraEngine::snd_playSoundEffect(int track) { void KyraEngine::snd_playVoiceFile(int id) { debug(9, "KyraEngine::snd_playVoiceFile(%d)", id); char vocFile[8]; - assert(id >= 0 && id < 1000); + assert(id >= 0 && id < 9999); sprintf(vocFile, "%03d.VOC", id); uint32 fileSize = 0; byte *fileData = 0; diff --git a/kyra/resource.cpp b/kyra/resource.cpp index 13212194d7..26a06dc174 100644 --- a/kyra/resource.cpp +++ b/kyra/resource.cpp @@ -65,7 +65,9 @@ Resource::Resource(KyraEngine* engine) { "FSOUTHB.PAK", "GRAVE.PAK", "LAGOON.PAK", "NCLIFFB.PAK", "SND.PAK", "TRUNK.PAK", "ZROCK.PAK", "BONKBG.PAK", "CGATE.PAK", "EDGEB.PAK", "FINALE.PAK", "FWSTSTH.PAK", "GRTHALL.PAK", "LANDING.PAK", "NWCLIFB.PAK", "SONG.PAK", "UPSTAIR.PAK", "BRIDGE.PAK", "CHASM.PAK", "EMCAV.PAK", "FNORTH.PAK", - "GATECV.PAK", "HEALER.PAK", "LAVA.PAK", "NWCLIFF.PAK", "SORROW.PAK", "WELL.PAK", 0 + "GATECV.PAK", "HEALER.PAK", "LAVA.PAK", "NWCLIFF.PAK", "SORROW.PAK", "WELL.PAK", + + "CHAPTER1.VRM", 0 }; const char** usedFilelist = 0; @@ -89,7 +91,7 @@ Resource::Resource(KyraEngine* engine) { _pakfiles.push_back(newPak); else { delete file; - debug("couldn't load file '%s' correctly", usedFilelist[tmp]); + debug(3, "couldn't load file '%s' correctly", usedFilelist[tmp]); } } } @@ -108,7 +110,7 @@ bool Resource::loadPakFile(const char *filename) { return true; PAKFile* file = new PAKFile(filename); if (!file) { - error("Couldn't load file: '%s'", filename); + error("couldn't load file: '%s'", filename); } PakFileEntry newPak; newPak._file = file; @@ -152,7 +154,6 @@ uint8* Resource::fileData(const char* file, uint32* size) { file_.read(buffer, *size); file_.close(); - } else { // opens the file in a PAK File Common::List<PakFileEntry>::iterator start = _pakfiles.begin(); @@ -163,18 +164,9 @@ uint8* Resource::fileData(const char* file, uint32* size) { if (!(*size)) continue; - buffer = new uint8[*size]; - assert(buffer); - - const uint8 *from = start->_file->getFile(file); - assert(from); - - // creates a copy of the file - memcpy(buffer, from, *size); - + buffer = start->_file->getFile(file); break; } - } if (!buffer || !(*size)) { @@ -189,25 +181,25 @@ uint8* Resource::fileData(const char* file, uint32* size) { #define PAKFile_Iterate Common::List<PakChunk*>::iterator start=_files.begin();start != _files.end(); ++start PAKFile::PAKFile(const Common::String& file) { Common::File pakfile; - _buffer = 0; + uint8 *buffer = 0; _open = false; if (!pakfile.open(file.c_str())) { - debug("couldn't open pakfile '%s'\n", file.c_str()); + debug(3, "couldn't open pakfile '%s'\n", file.c_str()); return; } uint32 filesize = pakfile.size(); - _buffer = new uint8[filesize]; - assert(_buffer); + buffer = new uint8[filesize]; + assert(buffer); - pakfile.read(_buffer, filesize); + pakfile.read(buffer, filesize); pakfile.close(); // works with the file uint32 pos = 0, startoffset = 0, endoffset = 0; - startoffset = READ_LE_UINT32(_buffer + pos); + startoffset = READ_LE_UINT32(buffer + pos); pos += 4; while (pos < filesize) { @@ -215,19 +207,21 @@ PAKFile::PAKFile(const Common::String& file) { assert(chunk); // saves the name - chunk->_name = reinterpret_cast<const char*>(_buffer + pos); + chunk->_name = new char[strlen((const char*)buffer + pos) + 1]; + assert(chunk->_name); + strcpy(chunk->_name, (const char*)buffer + pos); pos += strlen(chunk->_name) + 1; if (!(*chunk->_name)) break; - endoffset = READ_LE_UINT32(_buffer + pos); + endoffset = READ_LE_UINT32(buffer + pos); pos += 4; if (endoffset == 0) { endoffset = filesize; } - chunk->_data = _buffer + startoffset; + chunk->_start = startoffset; chunk->_size = endoffset - startoffset; _files.push_back(chunk); @@ -238,23 +232,40 @@ PAKFile::PAKFile(const Common::String& file) { startoffset = endoffset; } _open = true; + delete [] buffer; + + _filename = new char[file.size()+1]; + assert(_filename); + strcpy(_filename, file.c_str()); } PAKFile::~PAKFile() { - delete [] _buffer; - _buffer = 0; + delete [] _filename; + _filename = 0; _open = false; for (PAKFile_Iterate) { + delete [] (*start)->_name; + (*start)->_name = 0; delete *start; *start = 0; } } -const uint8* PAKFile::getFile(const char* file) { +uint8* PAKFile::getFile(const char* file) { for (PAKFile_Iterate) { - if (!scumm_stricmp((*start)->_name, file)) - return (*start)->_data; + if (!scumm_stricmp((*start)->_name, file)) { + Common::File pakfile; + if (!pakfile.open(_filename)) { + debug(3, "couldn't open pakfile '%s'\n", _filename); + return 0; + } + pakfile.seek((*start)->_start); + uint8 *buffer = new uint8[(*start)->_size]; + assert(buffer); + pakfile.read(buffer, (*start)->_size); + return buffer; + } } return 0; } diff --git a/kyra/resource.h b/kyra/resource.h index daa6de866a..72c2c239c4 100644 --- a/kyra/resource.h +++ b/kyra/resource.h @@ -35,8 +35,8 @@ namespace Kyra { // standard Package format for Kyrandia games class PAKFile { struct PakChunk { - const char* _name; - const uint8* _data; + char* _name; + uint32 _start; uint32 _size; }; @@ -45,16 +45,16 @@ public: PAKFile(const Common::String& file); ~PAKFile(); - const uint8* getFile(const char* file); + uint8* getFile(const char* file); uint32 getFileSize(const char* file); - bool isValid(void) const { return (_buffer != 0); } + bool isValid(void) const { return (_filename != 0); } bool isOpen(void) const { return _open; } private: bool _open; - uint8* _buffer; // the whole file + char *_filename; Common::List<PakChunk*> _files; // the entries }; diff --git a/kyra/staticres.cpp b/kyra/staticres.cpp index ee71bcaee2..6128097521 100644 --- a/kyra/staticres.cpp +++ b/kyra/staticres.cpp @@ -36,10 +36,7 @@ byte *getFile(PAKFile &res, const char *filename) { size = res.getFileSize(filename); if (!size) return 0; - const byte *src = res.getFile(filename); - byte *dst = new byte[size]; - memcpy(dst, src, size); - return dst; + return res.getFile(filename); } struct LanguageTypes { |
