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
svn-id: r27797
This commit is contained in:
parent
6064b87625
commit
fed38a794f
4 changed files with 87 additions and 45 deletions
|
@ -29,6 +29,8 @@
|
||||||
#include "common/config-manager.h"
|
#include "common/config-manager.h"
|
||||||
#include "common/system.h"
|
#include "common/system.h"
|
||||||
#include "backends/events/default/default-events.h"
|
#include "backends/events/default/default-events.h"
|
||||||
|
|
||||||
|
#include "engines/engine.h"
|
||||||
#include "gui/message.h"
|
#include "gui/message.h"
|
||||||
|
|
||||||
DefaultEventManager::DefaultEventManager(OSystem *boss) :
|
DefaultEventManager::DefaultEventManager(OSystem *boss) :
|
||||||
|
@ -96,12 +98,10 @@ bool DefaultEventManager::pollEvent(Common::Event &event) {
|
||||||
|
|
||||||
case Common::EVENT_QUIT:
|
case Common::EVENT_QUIT:
|
||||||
if (ConfMan.getBool("confirm_exit")) {
|
if (ConfMan.getBool("confirm_exit")) {
|
||||||
|
g_engine->pauseEngine(true);
|
||||||
GUI::MessageDialog alert("Do you really want to quit?", "Yes", "No");
|
GUI::MessageDialog alert("Do you really want to quit?", "Yes", "No");
|
||||||
if (alert.runModal() == GUI::kMessageOK)
|
result = _shouldQuit = (alert.runModal() == GUI::kMessageOK);
|
||||||
_shouldQuit = true;
|
g_engine->pauseEngine(false);
|
||||||
else
|
|
||||||
result = false;
|
|
||||||
|
|
||||||
} else
|
} else
|
||||||
_shouldQuit = true;
|
_shouldQuit = true;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -79,22 +79,35 @@ public:
|
||||||
/** Specific for each engine: prepare error string. */
|
/** Specific for each engine: prepare error string. */
|
||||||
virtual void errorString(const char *buf_input, char *buf_output);
|
virtual void errorString(const char *buf_input, char *buf_output);
|
||||||
|
|
||||||
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. */
|
|
||||||
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
|
* Return the engine's debugger instance, if any. Used by error() to
|
||||||
* invoke the debugger when a severe error is reported.
|
* invoke the debugger when a severe error is reported.
|
||||||
*/
|
*/
|
||||||
virtual GUI::Debugger *getDebugger() { return 0; }
|
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. */
|
||||||
|
bool shouldPerformAutoSave(int lastSaveTime);
|
||||||
|
|
||||||
|
/** Initialized graphics and shows error message. */
|
||||||
|
void GUIErrorMessage(const Common::String msg);
|
||||||
};
|
};
|
||||||
|
|
||||||
extern Engine *g_engine;
|
extern Engine *g_engine;
|
||||||
|
|
|
@ -121,6 +121,8 @@ ScummEngine::ScummEngine(OSystem *syst, const DetectorResult &dr)
|
||||||
}
|
}
|
||||||
_res = new ResourceManager(this);
|
_res = new ResourceManager(this);
|
||||||
|
|
||||||
|
_pauseLevel = 0;
|
||||||
|
|
||||||
// Convert MD5 checksum back into a digest
|
// Convert MD5 checksum back into a digest
|
||||||
for (int i = 0; i < 16; ++i) {
|
for (int i = 0; i < 16; ++i) {
|
||||||
char tmpStr[3] = "00";
|
char tmpStr[3] = "00";
|
||||||
|
@ -2236,31 +2238,50 @@ void ScummEngine::startManiac() {
|
||||||
#pragma mark --- GUI ---
|
#pragma mark --- GUI ---
|
||||||
#pragma mark -
|
#pragma mark -
|
||||||
|
|
||||||
int ScummEngine::runDialog(Dialog &dialog) {
|
void ScummEngine::pauseEngine(bool pause) {
|
||||||
_dialogStartTime = _system->getMillis() / 1000;
|
assert((pause && _pauseLevel >= 0) || (!pause && _pauseLevel));
|
||||||
|
|
||||||
|
if (pause)
|
||||||
|
_pauseLevel++;
|
||||||
|
else
|
||||||
|
_pauseLevel--;
|
||||||
|
|
||||||
|
if (_pauseLevel == 1) {
|
||||||
|
_pauseStartTime = _system->getMillis();
|
||||||
|
|
||||||
// Pause sound & video
|
// Pause sound & video
|
||||||
bool old_soundsPaused = _sound->_soundsPaused;
|
_oldSoundsPaused = _sound->_soundsPaused;
|
||||||
_sound->pauseSounds(true);
|
_sound->pauseSounds(true);
|
||||||
|
|
||||||
bool visible = CursorMan.isVisible();
|
//bool visible = CursorMan.isVisible();
|
||||||
|
|
||||||
// Open & run the dialog
|
} else if (_pauseLevel == 0) {
|
||||||
int result = dialog.runModal();
|
// Restore old cursor -- FIXME: Should be obsolete thanks to CursorMan
|
||||||
|
//updateCursor();
|
||||||
// Restore old cursor
|
//CursorMan.showMouse(visible);
|
||||||
updateCursor();
|
|
||||||
CursorMan.showMouse(visible);
|
|
||||||
|
|
||||||
// Update the screen to make it less likely that the player will see a
|
// Update the screen to make it less likely that the player will see a
|
||||||
// brief cursor palette glitch when the GUI is disabled.
|
// brief cursor palette glitch when the GUI is disabled.
|
||||||
_system->updateScreen();
|
_system->updateScreen();
|
||||||
|
|
||||||
// Resume sound & video
|
// Resume sound & video
|
||||||
_sound->pauseSounds(old_soundsPaused);
|
_sound->pauseSounds(_oldSoundsPaused);
|
||||||
|
|
||||||
_engineStartTime += (_system->getMillis() / 1000) - _dialogStartTime;
|
// Adjust engine start time
|
||||||
_dialogStartTime = 0;
|
_engineStartTime += (_system->getMillis() - _pauseStartTime) / 1000;
|
||||||
|
_pauseStartTime = 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 the result
|
||||||
return result;
|
return result;
|
||||||
|
|
|
@ -406,9 +406,6 @@ class ScummEngine : public Engine {
|
||||||
friend class CharsetRenderer;
|
friend class CharsetRenderer;
|
||||||
friend class ResourceManager;
|
friend class ResourceManager;
|
||||||
|
|
||||||
GUI::Debugger *getDebugger();
|
|
||||||
void errorString(const char *buf_input, char *buf_output);
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/* Put often used variables at the top.
|
/* Put often used variables at the top.
|
||||||
* That results in a shorter form of the opcode
|
* That results in a shorter form of the opcode
|
||||||
|
@ -438,16 +435,27 @@ public:
|
||||||
protected:
|
protected:
|
||||||
VirtualMachineState vm;
|
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:
|
public:
|
||||||
// Constructor / Destructor
|
// Constructor / Destructor
|
||||||
ScummEngine(OSystem *syst, const DetectorResult &dr);
|
ScummEngine(OSystem *syst, const DetectorResult &dr);
|
||||||
virtual ~ScummEngine();
|
virtual ~ScummEngine();
|
||||||
|
|
||||||
/** Startup function, main loop. */
|
// Engine APIs
|
||||||
int go();
|
virtual int init();
|
||||||
|
virtual int go();
|
||||||
// Init functions
|
virtual void errorString(const char *buf_input, char *buf_output);
|
||||||
int init();
|
virtual GUI::Debugger *getDebugger();
|
||||||
|
virtual void pauseEngine(bool pause);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void setupScumm();
|
virtual void setupScumm();
|
||||||
|
@ -638,7 +646,7 @@ protected:
|
||||||
void saveInfos(Common::OutSaveFile* file);
|
void saveInfos(Common::OutSaveFile* file);
|
||||||
|
|
||||||
int32 _engineStartTime;
|
int32 _engineStartTime;
|
||||||
int32 _dialogStartTime;
|
int32 _pauseStartTime;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/* Script VM - should be in Script class */
|
/* Script VM - should be in Script class */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue