MOHAWK: Turn script commands into SharedPtrs

Commands can be shared between scripts when adding commands
from one script to another.
This commit is contained in:
Bastien Bouclet 2017-01-28 14:02:12 +01:00 committed by Eugene Sandulenko
parent 0ba035eea6
commit 79e086ba7b
2 changed files with 12 additions and 14 deletions

View File

@ -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);
}

View File

@ -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);
};
/**