diff options
author | Bastien Bouclet | 2017-01-28 14:02:12 +0100 |
---|---|---|
committer | Eugene Sandulenko | 2017-07-03 08:50:10 +0200 |
commit | 79e086ba7b4e15b8281c88f52fd7a68e85dc7579 (patch) | |
tree | 50dcc7cf6adee1a57909074abbbdf77d7c642338 | |
parent | 0ba035eea6e36c3d0bd9058d0b623eb7aad23f82 (diff) | |
download | scummvm-rg350-79e086ba7b4e15b8281c88f52fd7a68e85dc7579.tar.gz scummvm-rg350-79e086ba7b4e15b8281c88f52fd7a68e85dc7579.tar.bz2 scummvm-rg350-79e086ba7b4e15b8281c88f52fd7a68e85dc7579.zip |
MOHAWK: Turn script commands into SharedPtrs
Commands can be shared between scripts when adding commands
from one script to another.
-rw-r--r-- | engines/mohawk/riven_scripts.cpp | 19 | ||||
-rw-r--r-- | engines/mohawk/riven_scripts.h | 7 |
2 files changed, 12 insertions, 14 deletions
diff --git a/engines/mohawk/riven_scripts.cpp b/engines/mohawk/riven_scripts.cpp index 1445731199..331f2261d5 100644 --- a/engines/mohawk/riven_scripts.cpp +++ b/engines/mohawk/riven_scripts.cpp @@ -56,23 +56,23 @@ RivenScriptPtr RivenScriptManager::readScript(Common::ReadStream *stream) { uint16 commandCount = stream->readUint16BE(); for (uint16 i = 0; i < commandCount; i++) { - RivenCommand *command = readCommand(stream); + RivenCommandPtr command = readCommand(stream); script->addCommand(command); } return script; } -RivenCommand *RivenScriptManager::readCommand(Common::ReadStream *stream) { +RivenCommandPtr RivenScriptManager::readCommand(Common::ReadStream *stream) { uint16 type = stream->readUint16BE(); switch (type) { case 8: - return RivenSwitchCommand::createFromStream(_vm, type, stream); + return RivenCommandPtr(RivenSwitchCommand::createFromStream(_vm, type, stream)); case 27: - return RivenStackChangeCommand::createFromStream(_vm, type, stream); + return RivenCommandPtr(RivenStackChangeCommand::createFromStream(_vm, type, stream)); default: - return RivenSimpleCommand::createFromStream(_vm, type, stream); + return RivenCommandPtr(RivenSimpleCommand::createFromStream(_vm, type, stream)); } } @@ -160,7 +160,7 @@ RivenScriptPtr RivenScriptManager::createScriptWithCommand(RivenCommand *command assert(command); RivenScriptPtr script = RivenScriptPtr(new RivenScript()); - script->addCommand(command); + script->addCommand(RivenCommandPtr(command)); return script; } @@ -169,9 +169,6 @@ RivenScript::RivenScript() { } RivenScript::~RivenScript() { - for (uint i = 0; i < _commands.size(); i ++) { - delete _commands[i]; - } } void RivenScript::dumpScript(byte tabs) { @@ -181,12 +178,12 @@ void RivenScript::dumpScript(byte tabs) { } void RivenScript::run() { - for (uint16 i = 0; i < _commands.size() && _continueRunning; i++) { + for (uint i = 0; i < _commands.size() && _continueRunning; i++) { _commands[i]->execute(); } } -void RivenScript::addCommand(RivenCommand *command) { +void RivenScript::addCommand(RivenCommandPtr command) { _commands.push_back(command); } diff --git a/engines/mohawk/riven_scripts.h b/engines/mohawk/riven_scripts.h index 13c415b850..a5c1ccbdad 100644 --- a/engines/mohawk/riven_scripts.h +++ b/engines/mohawk/riven_scripts.h @@ -55,6 +55,7 @@ class RivenCommand; class RivenScript; typedef Common::SharedPtr<RivenScript> RivenScriptPtr; +typedef Common::SharedPtr<RivenCommand> RivenCommandPtr; /** * Scripts in Riven are a list of Commands @@ -68,7 +69,7 @@ public: ~RivenScript(); /** Append a command to the script */ - void addCommand(RivenCommand *command); + void addCommand(RivenCommandPtr command); /** True if the script does not contain any command */ bool empty() const; @@ -94,7 +95,7 @@ public: static const char *getTypeName(uint16 type); private: - Common::Array<RivenCommand *> _commands; + Common::Array<RivenCommandPtr> _commands; bool _continueRunning; }; @@ -163,7 +164,7 @@ private: Common::Array<RivenScriptPtr> _queue; StoredMovieOpcode _storedMovieOpcode; - RivenCommand *readCommand(Common::ReadStream *stream); + RivenCommandPtr readCommand(Common::ReadStream *stream); }; /** |