[Scummvm-cvs-logs] SF.net SVN: scummvm: [21811] scummvm/trunk/common

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Tue Apr 11 15:30:59 CEST 2006


Revision: 21811
Author:   fingolfin
Date:     2006-04-11 15:29:51 -0700 (Tue, 11 Apr 2006)
ViewCVS:  http://svn.sourceforge.net/scummvm/?rev=21811&view=rev

Log Message:
-----------
Removed the PalmOS specific hack in file.cpp in favor for code that should work everywhere (and hopefully will help the GP32 port, too).

Modified Paths:
--------------
    scummvm/trunk/backends/PalmOS/Src/native/zodiacARM.cpp
    scummvm/trunk/common/file.cpp
Modified: scummvm/trunk/backends/PalmOS/Src/native/zodiacARM.cpp
===================================================================
--- scummvm/trunk/backends/PalmOS/Src/native/zodiacARM.cpp	2006-04-11 22:11:12 UTC (rev 21810)
+++ scummvm/trunk/backends/PalmOS/Src/native/zodiacARM.cpp	2006-04-11 22:29:51 UTC (rev 21811)
@@ -60,15 +60,8 @@
 
 	assert(g_system);
 
-	// Invoke the actual ScummVM main entry point:
-	extern void initGlobalHashes();
-	initGlobalHashes();
-
 	scummvm_main(argc, argvP);
 
-	extern void freeGlobalHashes();
-	freeGlobalHashes();
-
 	g_system->quit();	// TODO: Consider removing / replacing this!
 }
 

Modified: scummvm/trunk/common/file.cpp
===================================================================
--- scummvm/trunk/common/file.cpp	2006-04-11 22:11:12 UTC (rev 21810)
+++ scummvm/trunk/common/file.cpp	2006-04-11 22:29:51 UTC (rev 21811)
@@ -37,21 +37,9 @@
 // The following two objects could be turned into static members of class
 // File. However, then we would be forced to #include hashmap in file.h
 // which seems to be a high price just for a simple beautification...
-#if !(defined(PALMOS_ARM) || defined(PALMOS_DEBUG))
-static StringIntMap _defaultDirectories;
-static FilesMap _filesMap;
+static StringIntMap *_defaultDirectories;
+static FilesMap *_filesMap;
 
-#else
-// This is a very bad hack to make these global objects work with PalmOS ARM version.
-// In fact global objects are correctly allocated but constructors/destructors are not called
-// and so, the object is not correctly initialized. See also the 2 functions at end of file.
-// This is related to how ARM apps are handled in PalmOS, there is no problem with 68k version.
-static StringIntMap *__defaultDirectories;
-static FilesMap *__filesMap;
-#define _defaultDirectories	(*__defaultDirectories)
-#define _filesMap	(*__filesMap)
-#endif
-
 static FILE *fopenNoCase(const char *filename, const char *directory, const char *mode) {
 	FILE *file;
 	char buf[512];
@@ -133,9 +121,12 @@
 	if (level <= 0)
 		return;
 
+	if (!_defaultDirectories)
+		_defaultDirectories = new StringIntMap;
+
 	// Do not add directories multiple times, unless this time they are added
 	// with a bigger depth.
-	if (_defaultDirectories.contains(directory) && _defaultDirectories[directory] >= level)
+	if (_defaultDirectories->contains(directory) && (*_defaultDirectories)[directory] >= level)
 		return;
 
 	FilesystemNode dir(directory.c_str());
@@ -144,8 +135,11 @@
 	if (!dir.isDirectory())
 		return;
 
-	_defaultDirectories[directory] = level;
+	(*_defaultDirectories)[directory] = level;
 
+	if (!_filesMap)
+		_filesMap = new FilesMap;
+
 	const FSList fslist(dir.listDir(FilesystemNode::kListAllNoRoot));
 	
 	for (FSList::const_iterator file = fslist.begin(); file != fslist.end(); ++file) {
@@ -154,15 +148,18 @@
 		} else {
 			String lfn = file->displayName();
 			lfn.toLowercase();
-			if (!_filesMap.contains(lfn))
-				_filesMap[lfn] = file->path();
+			if (!_filesMap->contains(lfn))
+				(*_filesMap)[lfn] = file->path();
 		}
 	}
 }
 
 void File::resetDefaultDirectories() {
-	_defaultDirectories.clear();
-	_filesMap.clear();
+	delete _defaultDirectories;
+	delete _filesMap;
+	
+	_defaultDirectories = 0;
+	_filesMap = 0;
 }
 
 File::File()
@@ -214,21 +211,28 @@
 	const char *modeStr = (mode == kFileReadMode) ? "rb" : "wb";
 	if (mode == kFileWriteMode || directory) {
 		_handle = fopenNoCase(filename, directory ? directory : "", modeStr);
-	} else if (_filesMap.contains(fname)) {
-		debug(3, "Opening hashed: %s", _filesMap[fname].c_str());
-		_handle = fopen(_filesMap[fname].c_str(), modeStr);
-	} else if (_filesMap.contains(fname + ".")) {
+	} else if (_filesMap && _filesMap->contains(fname)) {
+		fname = (*_filesMap)[fname];
+		debug(3, "Opening hashed: %s", fname.c_str());
+		_handle = fopen(fname.c_str(), modeStr);
+	} else if (_filesMap && _filesMap->contains(fname + ".")) {
 		// WORKAROUND: Bug #1458388: "SIMON1: Game Detection fails"
 		// sometimes instead of "GAMEPC" we get "GAMEPC." (note trailing dot)
-		debug(3, "Opening hashed: %s", _filesMap[fname].c_str());
-		_handle = fopen(_filesMap[fname].c_str(), modeStr);
+		
+		// FIXME: Shouldn't we add a '+ "."' after fname here?
+		fname = (*_filesMap)[fname];
+		debug(3, "Opening hashed: %s", fname.c_str());
+		_handle = fopen(fname.c_str(), modeStr);
 	} else {
 
-		StringIntMap::const_iterator x;
-		// Try all default directories
-		for (x = _defaultDirectories.begin(); _handle == NULL && x != _defaultDirectories.end(); ++x) {
-			_handle = fopenNoCase(filename, x->_key.c_str(), modeStr);
+		if (_defaultDirectories) {
+			// Try all default directories
+			StringIntMap::const_iterator x(_defaultDirectories->begin());
+			for (; _handle == NULL && x != _defaultDirectories->end(); ++x) {
+				_handle = fopenNoCase(filename, x->_key.c_str(), modeStr);
+			}
 		}
+
 		// Last resort: try the current directory
 		if (_handle == NULL)
 			_handle = fopenNoCase(filename, "", modeStr);
@@ -370,14 +374,3 @@
 }
 
 }	// End of namespace Common
-
-#if defined(PALMOS_ARM) || defined(PALMOS_DEBUG)
-void initGlobalHashes() {
-	Common::__defaultDirectories = new Common::StringIntMap;
-	Common::__filesMap = new Common::FilesMap;
-}
-void freeGlobalHashes() {
-	delete Common::__defaultDirectories;
-	delete Common::__filesMap;
-}
-#endif


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