aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Bouclet2017-07-09 14:22:18 +0200
committerBastien Bouclet2017-07-22 20:38:56 +0200
commit8f59348ec33ec7c4357b639e810ff131ab6461e1 (patch)
tree80a5a4c4f6fe9131c18225e8b65cff7e46c44fbf
parentee9328323b7f6fc9796df51d88ed76e3a7ca67dd (diff)
downloadscummvm-rg350-8f59348ec33ec7c4357b639e810ff131ab6461e1.tar.gz
scummvm-rg350-8f59348ec33ec7c4357b639e810ff131ab6461e1.tar.bz2
scummvm-rg350-8f59348ec33ec7c4357b639e810ff131ab6461e1.zip
MOHAWK: Myst: Start reworking mainloop detection
-rw-r--r--engines/mohawk/myst.cpp33
-rw-r--r--engines/mohawk/myst.h6
-rw-r--r--engines/mohawk/myst_scripts.cpp12
-rw-r--r--engines/mohawk/myst_scripts.h8
4 files changed, 36 insertions, 23 deletions
diff --git a/engines/mohawk/myst.cpp b/engines/mohawk/myst.cpp
index 35b1b6809f..7804fb52bd 100644
--- a/engines/mohawk/myst.cpp
+++ b/engines/mohawk/myst.cpp
@@ -70,7 +70,6 @@ MohawkEngine_Myst::MohawkEngine_Myst(OSystem *syst, const MohawkGameDescription
_mainCursor = kDefaultMystCursor;
_showResourceRects = false;
_curCard = 0;
- _canSafelySaveLoad = false;
_hoverResource = nullptr;
_activeResource = nullptr;
@@ -275,7 +274,7 @@ void MohawkEngine_Myst::doFrame() {
_scriptParser->runPersistentScripts();
Common::Event event;
- while (pollEvent(event)) {
+ while (_system->getEventManager()->pollEvent(event)) {
switch (event.type) {
case Common::EVENT_MOUSEMOVE: {
if (_clickedResource && _clickedResource->isEnabled()) {
@@ -312,11 +311,9 @@ void MohawkEngine_Myst::doFrame() {
_needsShowDemoMenu = false;
_needsShowCredits = false;
- _canSafelySaveLoad = true;
runDialog(*_optionsDialog);
if (_optionsDialog->getLoadSlot() >= 0)
loadGameState(_optionsDialog->getLoadSlot());
- _canSafelySaveLoad = false;
if (_needsPageDrop) {
dropPage();
@@ -356,15 +353,6 @@ void MohawkEngine_Myst::doFrame() {
_system->delayMillis(10);
}
-bool MohawkEngine_Myst::pollEvent(Common::Event &event) {
- // Saving / Loading is allowed from the GMM only when the main event loop is running
- _canSafelySaveLoad = true;
- bool eventReturned = _eventMan->pollEvent(event);
- _canSafelySaveLoad = false;
-
- return eventReturned;
-}
-
bool MohawkEngine_Myst::wait(uint32 duration, bool skippable) {
uint32 end = getTotalPlayTime() + duration;
bool skipped = false;
@@ -1122,12 +1110,25 @@ bool MohawkEngine_Myst::hasGameSaveSupport() const {
}
bool MohawkEngine_Myst::canLoadGameStateCurrently() {
- // No loading in the demo/makingof
- return _canSafelySaveLoad && hasGameSaveSupport();
+ if (_scriptParser->isScriptRunning()) {
+ return false;
+ }
+
+ if (_clickedResource) {
+ // Can't save while dragging resources
+ return false;
+ }
+
+ if (!hasGameSaveSupport()) {
+ // No loading in the demo/makingof
+ return false;
+ }
+
+ return true;
}
bool MohawkEngine_Myst::canSaveGameStateCurrently() {
- if (!_canSafelySaveLoad) {
+ if (!canLoadGameStateCurrently()) {
return false;
}
diff --git a/engines/mohawk/myst.h b/engines/mohawk/myst.h
index dc07f453ea..a5a5494408 100644
--- a/engines/mohawk/myst.h
+++ b/engines/mohawk/myst.h
@@ -246,14 +246,8 @@ private:
bool _runExitScript;
- /**
- * Saving / Loading is only allowed from the main event loop
- */
- bool _canSafelySaveLoad;
bool hasGameSaveSupport() const;
- bool pollEvent(Common::Event &event);
-
void dropPage();
void loadCard();
diff --git a/engines/mohawk/myst_scripts.cpp b/engines/mohawk/myst_scripts.cpp
index 267d644b65..34806506c4 100644
--- a/engines/mohawk/myst_scripts.cpp
+++ b/engines/mohawk/myst_scripts.cpp
@@ -85,6 +85,7 @@ MystScriptParser::MystScriptParser(MohawkEngine_Myst *vm) :
_savedCardId = 0;
_savedCursorId = 0;
_tempVar = 0;
+ _scriptNestingLevel = 0;
}
MystScriptParser::~MystScriptParser() {
@@ -160,6 +161,7 @@ void MystScriptParser::runScript(MystScript script, MystArea *invokingResource)
// Scripted drawing takes more time to simulate older hardware
// This way opcodes can't overwrite what the previous ones drew too quickly
_vm->_gfx->enableDrawingTimeSimulation(true);
+ _scriptNestingLevel++;
for (uint16 i = 0; i < script->size(); i++) {
MystScriptEntry &entry = (*script)[i];
@@ -173,12 +175,14 @@ void MystScriptParser::runScript(MystScript script, MystArea *invokingResource)
runOpcode(entry.opcode, entry.var, entry.argc, entry.argv);
}
+ _scriptNestingLevel--;
_vm->_gfx->enableDrawingTimeSimulation(false);
}
void MystScriptParser::runOpcode(uint16 op, uint16 var, uint16 argc, uint16 *argv) {
- bool ranOpcode = false;
+ _scriptNestingLevel++;
+ bool ranOpcode = false;
for (uint16 i = 0; i < _opcodes.size(); i++)
if (_opcodes[i]->op == op) {
(this->*(_opcodes[i]->proc)) (op, var, argc, argv);
@@ -188,6 +192,12 @@ void MystScriptParser::runOpcode(uint16 op, uint16 var, uint16 argc, uint16 *arg
if (!ranOpcode)
warning("Trying to run invalid opcode %d", op);
+
+ _scriptNestingLevel--;
+}
+
+bool MystScriptParser::isScriptRunning() const {
+ return _scriptNestingLevel > 0;
}
const Common::String MystScriptParser::getOpcodeDesc(uint16 op) {
diff --git a/engines/mohawk/myst_scripts.h b/engines/mohawk/myst_scripts.h
index 69052b10f5..1ec821b60b 100644
--- a/engines/mohawk/myst_scripts.h
+++ b/engines/mohawk/myst_scripts.h
@@ -69,6 +69,13 @@ public:
MystScript readScript(Common::SeekableReadStream *stream, MystScriptType type);
void setInvokingResource(MystArea *resource) { _invokingResource = resource; }
+ /**
+ * Is a script is running?
+ *
+ * Allows to detect if some inner loop is running instead of the main loop.
+ */
+ bool isScriptRunning() const;
+
virtual void disablePersistentScripts() = 0;
virtual void runPersistentScripts() = 0;
@@ -167,6 +174,7 @@ protected:
private:
MystArea *_invokingResource;
+ int32 _scriptNestingLevel;
};
template<class T>