[Scummvm-cvs-logs] SF.net SVN: scummvm:[34711] scummvm/trunk/engines/agi/wagparser.cpp

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Tue Sep 30 18:53:08 CEST 2008


Revision: 34711
          http://scummvm.svn.sourceforge.net/scummvm/?rev=34711&view=rev
Author:   fingolfin
Date:     2008-09-30 16:53:04 +0000 (Tue, 30 Sep 2008)

Log Message:
-----------
AGI: Simplify WagFileParser by not reading data into a memory stream first (this was there to improve performance on systems with slow seeking; those systems should use another approach, see scummvm-devel)

Modified Paths:
--------------
    scummvm/trunk/engines/agi/wagparser.cpp

Modified: scummvm/trunk/engines/agi/wagparser.cpp
===================================================================
--- scummvm/trunk/engines/agi/wagparser.cpp	2008-09-30 16:38:46 UTC (rev 34710)
+++ scummvm/trunk/engines/agi/wagparser.cpp	2008-09-30 16:53:04 UTC (rev 34711)
@@ -174,39 +174,35 @@
 }
 
 bool WagFileParser::parse(const Common::FilesystemNode &node) {
-	Common::File file;
 	WagProperty property; // Temporary property used for reading
-	Common::MemoryReadStream *stream = NULL; // The file is to be read fully into memory and handled using this
+	Common::SeekableReadStream *stream = NULL; // The file stream
 
 	_parsedOk = false; // We haven't parsed the file yet
 
-	if (file.open(node)) { // Open the file
-		stream = file.readStream(file.size()); // Read the file into memory
-		if (stream != NULL && stream->size() == file.size()) { // Check that the whole file was read into memory
-			if (checkWagVersion(*stream)) { // Check that WinAGI version string is valid
-				// It seems we've got a valid *.wag file so let's parse its properties from the start.
-				stream->seek(0); // Rewind the stream
-				if (!_propList.empty()) _propList.clear(); // Clear out old properties (If any)
+	stream = node.openForReading(); // Open the file
+	if (stream) { // Check that opening the file was succesful
+		if (checkWagVersion(*stream)) { // Check that WinAGI version string is valid
+			// It seems we've got a valid *.wag file so let's parse its properties from the start.
+			stream->seek(0); // Rewind the stream
+			if (!_propList.empty()) _propList.clear(); // Clear out old properties (If any)
 
-				do { // Parse the properties
-					if (property.read(*stream)) { // Read the property and check it was read ok
-						_propList.push_back(property); // Add read property to properties list
-						debug(4, "WagFileParser::parse: Read property with code %d, type %d, number %d, size %d, data \"%s\"",
-							property.getCode(), property.getType(), property.getNumber(), property.getSize(), property.getData());
-					} else // Reading failed, let's bail out
-						break;
-				} while (!endOfProperties(*stream)); // Loop until the end of properties
+			do { // Parse the properties
+				if (property.read(*stream)) { // Read the property and check it was read ok
+					_propList.push_back(property); // Add read property to properties list
+					debug(4, "WagFileParser::parse: Read property with code %d, type %d, number %d, size %d, data \"%s\"",
+						property.getCode(), property.getType(), property.getNumber(), property.getSize(), property.getData());
+				} else // Reading failed, let's bail out
+					break;
+			} while (!endOfProperties(*stream)); // Loop until the end of properties
 
-				// File was parsed successfully only if we got to the end of properties
-				// and all the properties were read successfully (Also the last).
-				_parsedOk = endOfProperties(*stream) && property.readOk();
+			// File was parsed successfully only if we got to the end of properties
+			// and all the properties were read successfully (Also the last).
+			_parsedOk = endOfProperties(*stream) && property.readOk();
 
-				if (!_parsedOk) // Error parsing stream
-					warning("Error parsing WAG file (%s). WAG file ignored", node.getPath().c_str());
-			} else // Invalid WinAGI version string or it couldn't be read
-				warning("Invalid WAG file (%s) version or error reading it. WAG file ignored", node.getPath().c_str());
-		} else // Couldn't fully read file into memory
-			warning("Error reading WAG file (%s) into memory. WAG file ignored", node.getPath().c_str());
+			if (!_parsedOk) // Error parsing stream
+				warning("Error parsing WAG file (%s). WAG file ignored", node.getPath().c_str());
+		} else // Invalid WinAGI version string or it couldn't be read
+			warning("Invalid WAG file (%s) version or error reading it. WAG file ignored", node.getPath().c_str());
 	} else // Couldn't open file
 		warning("Couldn't open WAG file (%s). WAG file ignored", node.getPath().c_str());
 


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