[Scummvm-cvs-logs] CVS: scummvm/scumm scumm.h,1.61,1.62 scummvm.cpp,1.71,1.72

Max Horn fingolfin at users.sourceforge.net
Sun Nov 10 07:00:01 CET 2002


Update of /cvsroot/scummvm/scummvm/scumm
In directory usw-pr-cvs1:/tmp/cvs-serv499

Modified Files:
	scumm.h scummvm.cpp 
Log Message:
added Scumm::displayError() method; make use of that to display errors if save/load failed; changed runDialog() to return the result of Dialog::runModal(); changed the order in which autosave is performed a little bit

Index: scumm.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/scumm.h,v
retrieving revision 1.61
retrieving revision 1.62
diff -u -d -r1.61 -r1.62
--- scumm.h	8 Nov 2002 18:40:12 -0000	1.61
+++ scumm.h	10 Nov 2002 14:59:15 -0000	1.62
@@ -347,10 +347,11 @@
 	Dialog *_optionsDialog;
 	Dialog *_saveLoadDialog;
 
-	void runDialog(Dialog *dialog);
+	int runDialog(Dialog *dialog);
 	void pauseDialog();
 	void saveloadDialog();
 	void optionsDialog();
+	void displayError(const char *message, ...);
 
 	// Misc startup/event functions
 	void main();

Index: scummvm.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/scummvm.cpp,v
retrieving revision 1.71
retrieving revision 1.72
diff -u -d -r1.71 -r1.72
--- scummvm.cpp	3 Nov 2002 09:20:02 -0000	1.71
+++ scummvm.cpp	10 Nov 2002 14:59:15 -0000	1.72
@@ -428,29 +428,49 @@
 		}
 	}
 
+	// TODO - A fixed 5 minutes autosave interval seems a bit odd, e.g. if the
+	// user just saved a second ago we should not autosave; i.e. the autosave
+	// timer should be reset after each save/load. In fact, we don't need *any*
+	// real timer object for autosave, we could just use a variable in which we
+	// put the system time, and then check here if that time already passed during
+	// every scummLoop iteration, resetting it whenever a save/load occurs. Of
+	// course, that still leaves a small glitch (which is present now, too):
+	// if you are in the GUI for 10 minutes, it'll autosave immediatly after you
+	// close the GUI. 
+	if (_doAutosave && !_saveLoadFlag) {
+		_saveLoadSlot = 0;
+		sprintf(_saveLoadName, "Autosave %d", _saveLoadSlot);
+		_saveLoadFlag = 1;
+		_saveLoadCompatible = false;
+	}
 
 	if (_saveLoadFlag) {
+		bool success;
+		const char *errMsg = NULL;
 		if (_saveLoadFlag == 1) {
-			saveState(_saveLoadSlot, _saveLoadCompatible);
+			success = saveState(_saveLoadSlot, _saveLoadCompatible);
+			if (!success)
+				errMsg = "Failed so save game state to file:\n\n%s";
 			// Ender: Disabled for small_header games, as
 			// can overwrite game variables (eg, Zak256 cashcards)
-			if (_saveLoadCompatible && !(_features & GF_SMALL_HEADER))
+			if (success && _saveLoadCompatible && !(_features & GF_SMALL_HEADER))
  				_vars[VAR_GAME_LOADED] = 201;
 		} else {
-			loadState(_saveLoadSlot, _saveLoadCompatible);
+			success = loadState(_saveLoadSlot, _saveLoadCompatible);
+			if (!success)
+				errMsg = "Failed so load game state from file:\n\n%s";
 			// Ender: Disabled for small_header games, as
 			// can overwrite game variables (eg, Zak256 cashcards)
- 			if (_saveLoadCompatible && !(_features & GF_SMALL_HEADER))
+ 			if (success && _saveLoadCompatible && !(_features & GF_SMALL_HEADER))
 				_vars[VAR_GAME_LOADED] = 203;
 		}
-		_saveLoadFlag = 0;
-	}
 
-	if (_doAutosave) {
-		_saveLoadSlot = 0;
-		sprintf(_saveLoadName, "Autosave %d", _saveLoadSlot);
-		_saveLoadFlag = 1;
-		_saveLoadCompatible = false;
+		if (!success) {
+			char filename[256];
+			makeSavegameName(filename, _saveLoadSlot, _saveLoadCompatible);
+			displayError(errMsg, filename);
+		}
+		_saveLoadFlag = 0;
 		_doAutosave = false;
 	}
 
@@ -945,20 +965,23 @@
 	//_newgui->optionsDialog();
 }
 
-void Scumm::runDialog(Dialog *dialog)
+int Scumm::runDialog(Dialog *dialog)
 {
 	// Pause sound put
 	bool old_soundsPaused = _sound->_soundsPaused;
 	_sound->pauseSounds(true);
 
 	// Open & run the dialog
-	dialog->runModal();
+	int result = dialog->runModal();
 
 	// Restore old cursor
 	updateCursor();
 
 	// Resume sound output
 	_sound->pauseSounds(old_soundsPaused);
+	
+	// Return the result
+	return result;
 }
 
 void Scumm::pauseDialog()
@@ -982,6 +1005,20 @@
 	if (!_optionsDialog)
 		_optionsDialog = new OptionsDialog(_newgui, this);
 	runDialog(_optionsDialog);
+}
+
+void Scumm::displayError(const char *message, ...)
+{
+	char buf[1024];
+	va_list va;
+
+	va_start(va, message);
+	vsprintf(buf, message, va);
+	va_end(va);
+
+	Dialog *dialog = new MessageDialog(_newgui, buf);
+	runDialog(dialog);
+	delete dialog;
 }
 
 void Scumm::shutDown(int i)





More information about the Scummvm-git-logs mailing list