diff options
Diffstat (limited to 'engines')
-rw-r--r-- | engines/mohawk/dialogs.cpp | 1 | ||||
-rw-r--r-- | engines/mohawk/myst.cpp | 43 | ||||
-rw-r--r-- | engines/mohawk/myst.h | 5 | ||||
-rw-r--r-- | engines/mohawk/myst_areas.cpp | 5 | ||||
-rw-r--r-- | engines/mohawk/myst_areas.h | 1 |
5 files changed, 25 insertions, 30 deletions
diff --git a/engines/mohawk/dialogs.cpp b/engines/mohawk/dialogs.cpp index 5700a4641b..b9575ce963 100644 --- a/engines/mohawk/dialogs.cpp +++ b/engines/mohawk/dialogs.cpp @@ -32,6 +32,7 @@ #ifdef ENABLE_MYST #include "mohawk/myst.h" +#include "mohawk/myst_scripts.h" #endif #ifdef ENABLE_RIVEN diff --git a/engines/mohawk/myst.cpp b/engines/mohawk/myst.cpp index d0d3a3c30b..3f7264720b 100644 --- a/engines/mohawk/myst.cpp +++ b/engines/mohawk/myst.cpp @@ -78,13 +78,10 @@ MohawkEngine_Myst::MohawkEngine_Myst(OSystem *syst, const MohawkGameDescription _video = nullptr; _gfx = nullptr; _console = nullptr; - _scriptParser = nullptr; _gameState = nullptr; _optionsDialog = nullptr; _rnd = nullptr; - _prevStack = nullptr; - _mouseClicked = false; _mouseMoved = false; _escapePressed = false; @@ -103,10 +100,8 @@ MohawkEngine_Myst::~MohawkEngine_Myst() { delete _video; delete _sound; delete _console; - delete _scriptParser; delete _gameState; delete _optionsDialog; - delete _prevStack; delete _rnd; } @@ -565,64 +560,60 @@ void MohawkEngine_Myst::changeToStack(uint16 stack, uint16 card, uint16 linkSrcS if (linkSrcSound) playSoundBlocking(linkSrcSound); - _card->leave(); - _card.reset(); - - // Delete the previous stack and move the current stack to the previous one - // There's probably a better way to do this, but the script classes shouldn't - // take up much memory. - delete _prevStack; - _prevStack = _scriptParser; + if (_card) { + _card->leave(); + _card.reset(); + } _curStack = stack; switch (_curStack) { case kChannelwoodStack: _gameState->_globals.currentAge = kChannelwood; - _scriptParser = new MystStacks::Channelwood(this); + _scriptParser = MystScriptParserPtr(new MystStacks::Channelwood(this)); break; case kCreditsStack: - _scriptParser = new MystStacks::Credits(this); + _scriptParser = MystScriptParserPtr(new MystStacks::Credits(this)); break; case kDemoStack: _gameState->_globals.currentAge = kSelenitic; - _scriptParser = new MystStacks::Demo(this); + _scriptParser = MystScriptParserPtr(new MystStacks::Demo(this)); break; case kDniStack: _gameState->_globals.currentAge = kDni; - _scriptParser = new MystStacks::Dni(this); + _scriptParser = MystScriptParserPtr(new MystStacks::Dni(this)); break; case kIntroStack: - _scriptParser = new MystStacks::Intro(this); + _scriptParser = MystScriptParserPtr(new MystStacks::Intro(this)); break; case kMakingOfStack: - _scriptParser = new MystStacks::MakingOf(this); + _scriptParser = MystScriptParserPtr(new MystStacks::MakingOf(this)); break; case kMechanicalStack: _gameState->_globals.currentAge = kMechanical; - _scriptParser = new MystStacks::Mechanical(this); + _scriptParser = MystScriptParserPtr(new MystStacks::Mechanical(this)); break; case kMystStack: _gameState->_globals.currentAge = kMystLibrary; - _scriptParser = new MystStacks::Myst(this); + _scriptParser = MystScriptParserPtr(new MystStacks::Myst(this)); break; case kDemoPreviewStack: - _scriptParser = new MystStacks::Preview(this); + _scriptParser = MystScriptParserPtr(new MystStacks::Preview(this)); break; case kSeleniticStack: _gameState->_globals.currentAge = kSelenitic; - _scriptParser = new MystStacks::Selenitic(this); + _scriptParser = MystScriptParserPtr(new MystStacks::Selenitic(this)); break; case kDemoSlidesStack: _gameState->_globals.currentAge = kStoneship; - _scriptParser = new MystStacks::Slides(this); + _scriptParser = MystScriptParserPtr(new MystStacks::Slides(this)); break; case kStoneshipStack: _gameState->_globals.currentAge = kStoneship; - _scriptParser = new MystStacks::Stoneship(this); + _scriptParser = MystScriptParserPtr(new MystStacks::Stoneship(this)); break; default: - error("Unknown Myst stack"); + error("Unknown Myst stack %d", _curStack); } // If the array is empty, add a new one. Otherwise, delete the first diff --git a/engines/mohawk/myst.h b/engines/mohawk/myst.h index 867131a712..1bd51e8aa8 100644 --- a/engines/mohawk/myst.h +++ b/engines/mohawk/myst.h @@ -26,7 +26,6 @@ #include "mohawk/console.h" #include "mohawk/mohawk.h" #include "mohawk/resource_cache.h" -#include "mohawk/myst_scripts.h" #include "mohawk/video.h" #include "audio/mixer.h" @@ -123,6 +122,7 @@ enum { }; typedef Common::SharedPtr<MystCard> MystCardPtr; +typedef Common::SharedPtr<MystScriptParser> MystScriptParserPtr; class MohawkEngine_Myst : public MohawkEngine { protected: @@ -163,7 +163,7 @@ public: MystSound *_sound; MystGraphics *_gfx; MystGameState *_gameState; - MystScriptParser *_scriptParser; + MystScriptParserPtr _scriptParser; Common::RandomSource *_rnd; MystArea *loadResource(Common::SeekableReadStream *rlstStream, MystArea *parent); @@ -199,7 +199,6 @@ public: private: MystConsole *_console; MystOptionsDialog *_optionsDialog; - MystScriptParser *_prevStack; ResourceCache _cache; uint16 _curStack; diff --git a/engines/mohawk/myst_areas.cpp b/engines/mohawk/myst_areas.cpp index 2d2d3467a9..5fc6cbeed6 100644 --- a/engines/mohawk/myst_areas.cpp +++ b/engines/mohawk/myst_areas.cpp @@ -147,7 +147,10 @@ MystAreaAction::MystAreaAction(MohawkEngine_Myst *vm, ResourceType type, Common: } void MystAreaAction::handleMouseUp() { - _vm->_scriptParser->runScript(_script, this); + // Keep a reference to the stack so it is not freed if a script switches to another stack + MystScriptParserPtr parser = _vm->_scriptParser; + + parser->runScript(_script, this); } const Common::String MystAreaAction::describe() { diff --git a/engines/mohawk/myst_areas.h b/engines/mohawk/myst_areas.h index b389f32ea1..dd6605b1a1 100644 --- a/engines/mohawk/myst_areas.h +++ b/engines/mohawk/myst_areas.h @@ -24,6 +24,7 @@ #define MYST_AREAS_H #include "mohawk/myst.h" +#include "mohawk/myst_scripts.h" #include "mohawk/video.h" #include "common/rect.h" |