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

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Sat Jun 30 20:22:21 CEST 2007


Revision: 27797
          http://scummvm.svn.sourceforge.net/scummvm/?rev=27797&view=rev
Author:   fingolfin
Date:     2007-06-30 11:22:21 -0700 (Sat, 30 Jun 2007)

Log Message:
-----------
Added Engine::pauseEngine method (allows outside code, like the backend, to pause/resume the active engine); made the global 'confirm exit' dialog use that feature; implemented ScummEngine::pauseEngine

Modified Paths:
--------------
    scummvm/trunk/backends/events/default/default-events.cpp
    scummvm/trunk/engines/engine.h
    scummvm/trunk/engines/scumm/scumm.cpp
    scummvm/trunk/engines/scumm/scumm.h

Modified: scummvm/trunk/backends/events/default/default-events.cpp
===================================================================
--- scummvm/trunk/backends/events/default/default-events.cpp	2007-06-30 18:10:39 UTC (rev 27796)
+++ scummvm/trunk/backends/events/default/default-events.cpp	2007-06-30 18:22:21 UTC (rev 27797)
@@ -29,6 +29,8 @@
 #include "common/config-manager.h"
 #include "common/system.h"
 #include "backends/events/default/default-events.h"
+
+#include "engines/engine.h"
 #include "gui/message.h"
 
 DefaultEventManager::DefaultEventManager(OSystem *boss) :
@@ -96,12 +98,10 @@
 
 		case Common::EVENT_QUIT:
 			if (ConfMan.getBool("confirm_exit")) {
+				g_engine->pauseEngine(true);
 				GUI::MessageDialog alert("Do you really want to quit?", "Yes", "No");
-				if (alert.runModal() == GUI::kMessageOK)
-					_shouldQuit = true;
-				else
-					result = false;
-
+				result = _shouldQuit = (alert.runModal() == GUI::kMessageOK);
+				g_engine->pauseEngine(false);
 			} else
 				_shouldQuit = true;
 			break;

Modified: scummvm/trunk/engines/engine.h
===================================================================
--- scummvm/trunk/engines/engine.h	2007-06-30 18:10:39 UTC (rev 27796)
+++ scummvm/trunk/engines/engine.h	2007-06-30 18:22:21 UTC (rev 27797)
@@ -79,22 +79,35 @@
 	/** Specific for each engine: prepare error string. */
 	virtual void errorString(const char *buf_input, char *buf_output);
 
+	/**
+	 * Return the engine's debugger instance, if any. Used by error() to
+	 * invoke the debugger when a severe error is reported.
+	 */
+	virtual GUI::Debugger *getDebugger() { return 0; }
+	
+	/**
+	 * Pause or resume the engine. This should stop/resume any audio playback
+	 * and other stuff. Called right before the system runs a global dialog
+	 * (like a global pause, main menu, options or 'confirm exit' dialog).
+	 *
+	 * @param pause		true to pause the engine, false to resume it
+	 */
+	virtual void pauseEngine(bool pause) {}
+
+
+public:
+
+	/** Setup the backend's graphics mode. */
 	void initCommonGFX(bool defaultTo1XScaler);
 
 	/** On some systems, check if the game appears to be run from CD. */
 	void checkCD();
 
-	/* Indicate if an autosave should be performed. */
+	/** Indicate if an autosave should be performed. */
 	bool shouldPerformAutoSave(int lastSaveTime);
 
 	/** Initialized graphics and shows error message. */
 	void GUIErrorMessage(const Common::String msg);
-
-	/**
-	 * Return the engine's debugger instance, if any. Used by error() to
-	 * invoke the debugger when a severe error is reported.
-	 */
-	virtual GUI::Debugger *getDebugger() { return 0; }
 };
 
 extern Engine *g_engine;

Modified: scummvm/trunk/engines/scumm/scumm.cpp
===================================================================
--- scummvm/trunk/engines/scumm/scumm.cpp	2007-06-30 18:10:39 UTC (rev 27796)
+++ scummvm/trunk/engines/scumm/scumm.cpp	2007-06-30 18:22:21 UTC (rev 27797)
@@ -120,6 +120,8 @@
 		_gdi = new Gdi(this);
 	}
 	_res = new ResourceManager(this);
+	
+	_pauseLevel = 0;
 
 	// Convert MD5 checksum back into a digest
 	for (int i = 0; i < 16; ++i) {
@@ -2236,32 +2238,51 @@
 #pragma mark --- GUI ---
 #pragma mark -
 
-int ScummEngine::runDialog(Dialog &dialog) {
-	_dialogStartTime = _system->getMillis() / 1000;
+void ScummEngine::pauseEngine(bool pause) {
+	assert((pause && _pauseLevel >= 0) || (!pause && _pauseLevel));
 
-	// Pause sound & video
-	bool old_soundsPaused = _sound->_soundsPaused;
-	_sound->pauseSounds(true);
+	if (pause)
+		_pauseLevel++;
+	else
+		_pauseLevel--;
 
-	bool visible = CursorMan.isVisible();
+	if (_pauseLevel == 1) {
+		_pauseStartTime = _system->getMillis();
 
-	// Open & run the dialog
-	int result = dialog.runModal();
+		// Pause sound & video
+		_oldSoundsPaused = _sound->_soundsPaused;
+		_sound->pauseSounds(true);
+	
+		//bool visible = CursorMan.isVisible();
+	
+	} else if (_pauseLevel == 0) {
+		// Restore old cursor -- FIXME: Should be obsolete thanks to CursorMan
+		//updateCursor();
+		//CursorMan.showMouse(visible);
 
-	// Restore old cursor
-	updateCursor();
-	CursorMan.showMouse(visible);
+		// Update the screen to make it less likely that the player will see a
+		// brief cursor palette glitch when the GUI is disabled.
+		_system->updateScreen();
 
-	// Update the screen to make it less likely that the player will see a
-	// brief cursor palette glitch when the GUI is disabled.
-	_system->updateScreen();
+		// Resume sound & video
+		_sound->pauseSounds(_oldSoundsPaused);
 
-	// Resume sound & video
-	_sound->pauseSounds(old_soundsPaused);
+		// Adjust engine start time
+		_engineStartTime += (_system->getMillis() - _pauseStartTime) / 1000;
+		_pauseStartTime = 0;
+	}
+}
 
-	_engineStartTime += (_system->getMillis() / 1000) - _dialogStartTime;
-	_dialogStartTime = 0;
+int ScummEngine::runDialog(Dialog &dialog) {
+	// Pause engine
+	pauseEngine(true);
 
+	// Open & run the dialog
+	int result = dialog.runModal();
+
+	// Resume engine
+	pauseEngine(false);
+
 	// Return the result
 	return result;
 }

Modified: scummvm/trunk/engines/scumm/scumm.h
===================================================================
--- scummvm/trunk/engines/scumm/scumm.h	2007-06-30 18:10:39 UTC (rev 27796)
+++ scummvm/trunk/engines/scumm/scumm.h	2007-06-30 18:22:21 UTC (rev 27797)
@@ -406,9 +406,6 @@
 	friend class CharsetRenderer;
 	friend class ResourceManager;
 
-	GUI::Debugger *getDebugger();
-	void errorString(const char *buf_input, char *buf_output);
-
 public:
 	/* Put often used variables at the top.
 	 * That results in a shorter form of the opcode
@@ -437,18 +434,29 @@
 
 protected:
 	VirtualMachineState vm;
+	
+	/**
+	 * The pause level, 0 means 'running', a positive value indicates
+	 * how often the engine has been paused (and hence how often it has
+	 * to be un-paused before it resumes running). This makes it possible
+	 * to nest code which pauses the engine.
+	 */
+	int _pauseLevel;
+	
+	bool _oldSoundsPaused;
 
 public:
 	// Constructor / Destructor
 	ScummEngine(OSystem *syst, const DetectorResult &dr);
 	virtual ~ScummEngine();
 
-	/** Startup function, main loop. */
-	int go();
+	// Engine APIs
+	virtual int init();
+	virtual int go();
+	virtual void errorString(const char *buf_input, char *buf_output);
+	virtual GUI::Debugger *getDebugger();
+	virtual void pauseEngine(bool pause);
 
-	// Init functions
-	int init();
-
 protected:
 	virtual void setupScumm();
 	virtual void resetScumm();
@@ -638,7 +646,7 @@
 	void saveInfos(Common::OutSaveFile* file);
 
 	int32 _engineStartTime;
-	int32 _dialogStartTime;
+	int32 _pauseStartTime;
 
 protected:
 	/* Script VM - should be in Script class */


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