Skip to content

Commit

Permalink
MOHAWK: Only allow saving/loading from the main event loop
Browse files Browse the repository at this point in the history
  • Loading branch information
bgK committed Feb 22, 2016
1 parent becbe41 commit d688110
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
20 changes: 18 additions & 2 deletions engines/mohawk/myst.cpp
Expand Up @@ -76,6 +76,7 @@ MohawkEngine_Myst::MohawkEngine_Myst(OSystem *syst, const MohawkGameDescription
_showResourceRects = false;
_curCard = 0;
_needsUpdate = false;
_canSafelySaveLoad = false;
_curResource = -1;
_hoverResource = nullptr;

Expand Down Expand Up @@ -267,7 +268,7 @@ Common::Error MohawkEngine_Myst::run() {
_needsUpdate = _video->updateMovies();
_scriptParser->runPersistentScripts();

while (_eventMan->pollEvent(event)) {
while (pollEvent(event)) {
switch (event.type) {
case Common::EVENT_MOUSEMOVE: {
_needsUpdate = true;
Expand Down Expand Up @@ -312,7 +313,9 @@ Common::Error MohawkEngine_Myst::run() {
_needsShowMap = false;
_needsShowDemoMenu = false;

_canSafelySaveLoad = true;
runDialog(*_optionsDialog);
_canSafelySaveLoad = false;

if (_needsPageDrop) {
dropPage();
Expand Down Expand Up @@ -350,6 +353,15 @@ Common::Error MohawkEngine_Myst::run() {
return Common::kNoError;
}

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::skippableWait(uint32 duration) {
uint32 end = _system->getMillis() + duration;
bool skipped = false;
Expand Down Expand Up @@ -1083,10 +1095,14 @@ Common::Error MohawkEngine_Myst::saveGameState(int slot, const Common::String &d

bool MohawkEngine_Myst::canLoadGameStateCurrently() {
// No loading in the demo/makingof
return !(getFeatures() & GF_DEMO) && getGameType() != GType_MAKINGOF;
return _canSafelySaveLoad && !(getFeatures() & GF_DEMO) && getGameType() != GType_MAKINGOF;
}

bool MohawkEngine_Myst::canSaveGameStateCurrently() {
if (!_canSafelySaveLoad) {
return false;
}

// There's a limited number of stacks the game can save in
switch (_curStack) {
case kChannelwoodStack:
Expand Down
8 changes: 8 additions & 0 deletions engines/mohawk/myst.h
Expand Up @@ -28,6 +28,7 @@
#include "mohawk/resource_cache.h"
#include "mohawk/myst_scripts.h"

#include "common/events.h"
#include "common/random.h"

namespace Mohawk {
Expand Down Expand Up @@ -240,6 +241,13 @@ class MohawkEngine_Myst : public MohawkEngine {

bool _runExitScript;

/**
* Saving / Loading is only allowed from the main event loop
*/
bool _canSafelySaveLoad;

bool pollEvent(Common::Event &event);

void dropPage();

void loadCard();
Expand Down

0 comments on commit d688110

Please sign in to comment.