[Scummvm-cvs-logs] SF.net SVN: scummvm: [23896] scummvm/trunk/engines/kyra

lordhoto at users.sourceforge.net lordhoto at users.sourceforge.net
Sat Sep 16 22:51:11 CEST 2006


Revision: 23896
          http://svn.sourceforge.net/scummvm/?rev=23896&view=rev
Author:   lordhoto
Date:     2006-09-16 13:51:05 -0700 (Sat, 16 Sep 2006)

Log Message:
-----------
- 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

Modified Paths:
--------------
    scummvm/trunk/engines/kyra/resource.cpp
    scummvm/trunk/engines/kyra/resource.h
    scummvm/trunk/engines/kyra/scene.cpp

Modified: scummvm/trunk/engines/kyra/resource.cpp
===================================================================
--- scummvm/trunk/engines/kyra/resource.cpp	2006-09-16 19:50:41 UTC (rev 23895)
+++ scummvm/trunk/engines/kyra/resource.cpp	2006-09-16 20:51:05 UTC (rev 23896)
@@ -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 @@
 }
 
 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 @@
 
 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 @@
 
 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,17 +183,21 @@
 		// 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;
 
 			if (size)
 				*size = temp;
 
-			buffer = (*start)->getFile(file);
+			buffer = (*start)->getFile(fileHash);
 			break;
 		}
 	}
@@ -205,13 +217,17 @@
 
 	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 @@
 	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 @@
 		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 @@
 	}
 
 	_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 @@
 	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 @@
 	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 @@
 	filehandle.close();
 
 	if (!filehandle.open(_physfile)) {
-		debug(3, "couldn't open pakfile '%s'\n", _filename.c_str());
 		return false;
 	}
 
@@ -416,7 +434,7 @@
 			++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 @@
 		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 @@
 	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 @@
 	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;

Modified: scummvm/trunk/engines/kyra/resource.h
===================================================================
--- scummvm/trunk/engines/kyra/resource.h	2006-09-16 19:50:41 UTC (rev 23895)
+++ scummvm/trunk/engines/kyra/resource.h	2006-09-16 20:51:05 UTC (rev 23896)
@@ -38,23 +38,26 @@
 	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 @@
 	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 @@
 // 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 @@
 	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 {

Modified: scummvm/trunk/engines/kyra/scene.cpp
===================================================================
--- scummvm/trunk/engines/kyra/scene.cpp	2006-09-16 19:50:41 UTC (rev 23895)
+++ scummvm/trunk/engines/kyra/scene.cpp	2006-09-16 20:51:05 UTC (rev 23896)
@@ -1586,13 +1586,16 @@
 	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


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list