[Scummvm-cvs-logs] CVS: scummvm/kyra kyra.cpp,1.84,1.85 resource.cpp,1.25,1.26 resource.h,1.15,1.16 staticres.cpp,1.22,1.23
Johannes Schickel
lordhoto at users.sourceforge.net
Mon Dec 12 09:40:01 CET 2005
Update of /cvsroot/scummvm/scummvm/kyra
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5662
Modified Files:
kyra.cpp resource.cpp resource.h staticres.cpp
Log Message:
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).
Index: kyra.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/kyra/kyra.cpp,v
retrieving revision 1.84
retrieving revision 1.85
diff -u -d -r1.84 -r1.85
--- kyra.cpp 10 Dec 2005 19:02:53 -0000 1.84
+++ kyra.cpp 12 Dec 2005 17:39:01 -0000 1.85
@@ -911,7 +911,7 @@
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;
Index: resource.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/kyra/resource.cpp,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -d -r1.25 -r1.26
--- resource.cpp 26 Nov 2005 16:45:53 -0000 1.25
+++ resource.cpp 12 Dec 2005 17:39:01 -0000 1.26
@@ -65,7 +65,9 @@
"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 @@
_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 @@
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 @@
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 @@
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 @@
#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 @@
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 @@
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;
}
Index: resource.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/kyra/resource.h,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- resource.h 18 Oct 2005 01:30:18 -0000 1.15
+++ resource.h 12 Dec 2005 17:39:01 -0000 1.16
@@ -35,8 +35,8 @@
// 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 @@
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
};
Index: staticres.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/kyra/staticres.cpp,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -d -r1.22 -r1.23
--- staticres.cpp 9 Dec 2005 14:52:31 -0000 1.22
+++ staticres.cpp 12 Dec 2005 17:39:01 -0000 1.23
@@ -36,10 +36,7 @@
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 {
More information about the Scummvm-git-logs
mailing list