added opcode for running scripts with explicit references (targeted scripts)

deque
Marc Zinnschlag 10 years ago
parent e9377ad5c4
commit 75ab8de3d2

@ -24,7 +24,7 @@ namespace MWScript
addStartup();
}
void GlobalScripts::addScript (const std::string& name)
void GlobalScripts::addScript (const std::string& name, const std::string& targetId)
{
std::map<std::string, GlobalScriptDesc>::iterator iter =
mScripts.find (::Misc::StringUtils::lowerCase (name));
@ -36,12 +36,16 @@ namespace MWScript
GlobalScriptDesc desc;
desc.mRunning = true;
desc.mLocals.configure (*script);
desc.mId = targetId;
mScripts.insert (std::make_pair (name, desc));
}
}
else
else if (!iter->second.mRunning)
{
iter->second.mRunning = true;
iter->second.mId = targetId;
}
}
void GlobalScripts::removeScript (const std::string& name)

@ -44,7 +44,7 @@ namespace MWScript
GlobalScripts (const MWWorld::ESMStore& store);
void addScript (const std::string& name);
void addScript (const std::string& name, const std::string& targetId = "");
void removeScript (const std::string& name);

@ -366,9 +366,9 @@ namespace MWScript
return MWBase::Environment::get().getScriptManager()->getGlobalScripts().isRunning (name);
}
void InterpreterContext::startScript (const std::string& name)
void InterpreterContext::startScript (const std::string& name, const std::string& targetId)
{
MWBase::Environment::get().getScriptManager()->getGlobalScripts().addScript (name);
MWBase::Environment::get().getScriptManager()->getGlobalScripts().addScript (name, targetId);
}
void InterpreterContext::stopScript (const std::string& name)

@ -113,7 +113,7 @@ namespace MWScript
virtual bool isScriptRunning (const std::string& name) const;
virtual void startScript (const std::string& name);
virtual void startScript (const std::string& name, const std::string& targetId = "");
virtual void stopScript (const std::string& name);

@ -81,7 +81,7 @@ namespace Interpreter
virtual bool isScriptRunning (const std::string& name) const = 0;
virtual void startScript (const std::string& name) = 0;
virtual void startScript (const std::string& name, const std::string& targetId = "") = 0;
virtual void stopScript (const std::string& name) = 0;

@ -133,5 +133,6 @@ op 67: store stack[0] in member float stack[2] of global script with ID stack[1]
op 68: replace stack[0] with member short stack[1] of global script with ID stack[0]
op 69: replace stack[0] with member short stack[1] of global script with ID stack[0]
op 70: replace stack[0] with member short stack[1] of global script with ID stack[0]
opcodes 71-33554431 unused
op 71: explicit reference (target) = stack[0]; pop; start script stack[0] and pop
opcodes 72-33554431 unused
opcodes 33554432-67108863 reserved for extensions

@ -113,6 +113,7 @@ namespace Interpreter
interpreter.installSegment5 (46, new OpScriptRunning);
interpreter.installSegment5 (47, new OpStartScript);
interpreter.installSegment5 (48, new OpStopScript);
interpreter.installSegment5 (71, new OpStartScriptExplicit);
// spacial
interpreter.installSegment5 (49, new OpGetDistance);

@ -10,36 +10,52 @@ namespace Interpreter
class OpScriptRunning : public Opcode0
{
public:
virtual void execute (Runtime& runtime)
{
std::string name = runtime.getStringLiteral (runtime[0].mInteger);
runtime[0].mInteger = runtime.getContext().isScriptRunning (name);
}
}
};
class OpStartScript : public Opcode0
{
public:
virtual void execute (Runtime& runtime)
{
std::string name = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop();
runtime.getContext().startScript (name);
}
}
};
class OpStartScriptExplicit : public Opcode0
{
public:
virtual void execute (Runtime& runtime)
{
std::string targetId = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop();
std::string name = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop();
runtime.getContext().startScript (name, targetId);
}
};
class OpStopScript : public Opcode0
{
public:
virtual void execute (Runtime& runtime)
{
std::string name = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop();
runtime.getContext().stopScript (name);
}
}
};
}

Loading…
Cancel
Save