make MenuMode, Random, GetSecondsPassed regular functions

pull/2841/head
Evil Eye 5 years ago
parent f0e2ee45fa
commit 3875b837bc

@ -192,11 +192,6 @@ namespace MWScript
{ {
} }
bool InterpreterContext::menuMode()
{
return MWBase::Environment::get().getWindowManager()->isGuiMode();
}
int InterpreterContext::getGlobalShort (const std::string& name) const int InterpreterContext::getGlobalShort (const std::string& name) const
{ {
return MWBase::Environment::get().getWorld()->getGlobalInt (name); return MWBase::Environment::get().getWorld()->getGlobalInt (name);
@ -425,11 +420,6 @@ namespace MWScript
} }
} }
float InterpreterContext::getSecondsPassed() const
{
return MWBase::Environment::get().getFrameDuration();
}
int InterpreterContext::getMemberShort (const std::string& id, const std::string& name, int InterpreterContext::getMemberShort (const std::string& id, const std::string& name,
bool global) const bool global) const
{ {

@ -77,8 +77,6 @@ namespace MWScript
virtual void report (const std::string& message); virtual void report (const std::string& message);
///< By default, do nothing. ///< By default, do nothing.
virtual bool menuMode();
virtual int getGlobalShort (const std::string& name) const; virtual int getGlobalShort (const std::string& name) const;
virtual int getGlobalLong (const std::string& name) const; virtual int getGlobalLong (const std::string& name) const;
@ -124,8 +122,6 @@ namespace MWScript
void executeActivation(MWWorld::Ptr ptr, MWWorld::Ptr actor); void executeActivation(MWWorld::Ptr ptr, MWWorld::Ptr actor);
///< Execute the activation action for this ptr. If ptr is mActivated, mark activation as handled. ///< Execute the activation action for this ptr. If ptr is mActivated, mark activation as handled.
virtual float getSecondsPassed() const;
virtual int getMemberShort (const std::string& id, const std::string& name, bool global) const; virtual int getMemberShort (const std::string& id, const std::string& name, bool global) const;
virtual int getMemberLong (const std::string& id, const std::string& name, bool global) const; virtual int getMemberLong (const std::string& id, const std::string& name, bool global) const;

@ -12,6 +12,8 @@
#include <components/interpreter/runtime.hpp> #include <components/interpreter/runtime.hpp>
#include <components/interpreter/opcodes.hpp> #include <components/interpreter/opcodes.hpp>
#include <components/misc/rng.hpp>
#include <components/esm/loadmgef.hpp> #include <components/esm/loadmgef.hpp>
#include <components/esm/loadcrea.hpp> #include <components/esm/loadcrea.hpp>
@ -78,6 +80,33 @@ namespace MWScript
{ {
namespace Misc namespace Misc
{ {
class OpMenuMode : public Interpreter::Opcode0
{
public:
virtual void execute (Interpreter::Runtime& runtime)
{
runtime.push (MWBase::Environment::get().getWindowManager()->isGuiMode());
}
};
class OpRandom : public Interpreter::Opcode0
{
public:
virtual void execute (Interpreter::Runtime& runtime)
{
Interpreter::Type_Integer limit = runtime[0].mInteger;
runtime.pop();
if (limit<0)
throw std::runtime_error (
"random: argument out of range (Don't be so negative!)");
runtime.push (static_cast<Interpreter::Type_Float>(::Misc::Rng::rollDice(limit))); // [o, limit)
}
};
template<class R> template<class R>
class OpStartScript : public Interpreter::Opcode0 class OpStartScript : public Interpreter::Opcode0
{ {
@ -116,6 +145,16 @@ namespace MWScript
} }
}; };
class OpGetSecondsPassed : public Interpreter::Opcode0
{
public:
virtual void execute (Interpreter::Runtime& runtime)
{
runtime.push (MWBase::Environment::get().getFrameDuration());
}
};
template<class R> template<class R>
class OpEnable : public Interpreter::Opcode0 class OpEnable : public Interpreter::Opcode0
{ {
@ -1530,10 +1569,13 @@ namespace MWScript
void installOpcodes (Interpreter::Interpreter& interpreter) void installOpcodes (Interpreter::Interpreter& interpreter)
{ {
interpreter.installSegment5 (Compiler::Misc::opcodeMenuMode, new OpMenuMode);
interpreter.installSegment5 (Compiler::Misc::opcodeRandom, new OpRandom);
interpreter.installSegment5 (Compiler::Misc::opcodeScriptRunning, new OpScriptRunning); interpreter.installSegment5 (Compiler::Misc::opcodeScriptRunning, new OpScriptRunning);
interpreter.installSegment5 (Compiler::Misc::opcodeStartScript, new OpStartScript<ImplicitRef>); interpreter.installSegment5 (Compiler::Misc::opcodeStartScript, new OpStartScript<ImplicitRef>);
interpreter.installSegment5 (Compiler::Misc::opcodeStartScriptExplicit, new OpStartScript<ExplicitRef>); interpreter.installSegment5 (Compiler::Misc::opcodeStartScriptExplicit, new OpStartScript<ExplicitRef>);
interpreter.installSegment5 (Compiler::Misc::opcodeStopScript, new OpStopScript); interpreter.installSegment5 (Compiler::Misc::opcodeStopScript, new OpStopScript);
interpreter.installSegment5 (Compiler::Misc::opcodeGetSecondsPassed, new OpGetSecondsPassed);
interpreter.installSegment5 (Compiler::Misc::opcodeEnable, new OpEnable<ImplicitRef>); interpreter.installSegment5 (Compiler::Misc::opcodeEnable, new OpEnable<ImplicitRef>);
interpreter.installSegment5 (Compiler::Misc::opcodeEnableExplicit, new OpEnable<ExplicitRef>); interpreter.installSegment5 (Compiler::Misc::opcodeEnableExplicit, new OpEnable<ExplicitRef>);
interpreter.installSegment5 (Compiler::Misc::opcodeDisable, new OpDisable<ImplicitRef>); interpreter.installSegment5 (Compiler::Misc::opcodeDisable, new OpDisable<ImplicitRef>);

@ -434,43 +434,6 @@ namespace Compiler
mNextOperand = false; mNextOperand = false;
return true; return true;
} }
else if (keyword==Scanner::K_menumode)
{
start();
mTokenLoc = loc;
Generator::menuMode (mCode);
mOperands.push_back ('l');
mNextOperand = false;
return true;
}
else if (keyword==Scanner::K_random)
{
start();
mTokenLoc = loc;
parseArguments ("l", scanner);
Generator::random (mCode);
mOperands.push_back ('f');
mNextOperand = false;
return true;
}
else if (keyword==Scanner::K_getsecondspassed)
{
start();
mTokenLoc = loc;
Generator::getSecondsPassed (mCode);
mOperands.push_back ('f');
mNextOperand = false;
return true;
}
else else
{ {
// check for custom extensions // check for custom extensions

@ -241,9 +241,12 @@ namespace Compiler
{ {
void registerExtensions (Extensions& extensions) void registerExtensions (Extensions& extensions)
{ {
extensions.registerFunction ("menumode", 'l', "", opcodeMenuMode);
extensions.registerFunction ("random", 'f', "l", opcodeRandom);
extensions.registerFunction ("scriptrunning", 'l', "c", opcodeScriptRunning); extensions.registerFunction ("scriptrunning", 'l', "c", opcodeScriptRunning);
extensions.registerInstruction ("startscript", "c", opcodeStartScript, opcodeStartScriptExplicit); extensions.registerInstruction ("startscript", "c", opcodeStartScript, opcodeStartScriptExplicit);
extensions.registerInstruction ("stopscript", "c", opcodeStopScript); extensions.registerInstruction ("stopscript", "c", opcodeStopScript);
extensions.registerFunction ("getsecondspassed", 'f', "", opcodeGetSecondsPassed);
extensions.registerInstruction ("enable", "", opcodeEnable, opcodeEnableExplicit); extensions.registerInstruction ("enable", "", opcodeEnable, opcodeEnableExplicit);
extensions.registerInstruction ("disable", "", opcodeDisable, opcodeDisableExplicit); extensions.registerInstruction ("disable", "", opcodeDisable, opcodeDisableExplicit);
extensions.registerFunction ("getdisabled", 'l', "x", opcodeGetDisabled, opcodeGetDisabledExplicit); extensions.registerFunction ("getdisabled", 'l', "x", opcodeGetDisabled, opcodeGetDisabledExplicit);

@ -222,11 +222,6 @@ namespace
code.push_back (Compiler::Generator::segment5 (37)); code.push_back (Compiler::Generator::segment5 (37));
} }
void opMenuMode (Compiler::Generator::CodeContainer& code)
{
code.push_back (Compiler::Generator::segment5 (38));
}
void opStoreGlobalShort (Compiler::Generator::CodeContainer& code) void opStoreGlobalShort (Compiler::Generator::CodeContainer& code)
{ {
code.push_back (Compiler::Generator::segment5 (39)); code.push_back (Compiler::Generator::segment5 (39));
@ -286,16 +281,6 @@ namespace
{ {
code.push_back (Compiler::Generator::segment5 (global ? 70 : 64)); code.push_back (Compiler::Generator::segment5 (global ? 70 : 64));
} }
void opRandom (Compiler::Generator::CodeContainer& code)
{
code.push_back (Compiler::Generator::segment5 (45));
}
void opGetSecondsPassed (Compiler::Generator::CodeContainer& code)
{
code.push_back (Compiler::Generator::segment5 (50));
}
} }
namespace Compiler namespace Compiler
@ -590,11 +575,6 @@ namespace Compiler
} }
} }
void menuMode (CodeContainer& code)
{
opMenuMode (code);
}
void assignToGlobal (CodeContainer& code, Literals& literals, char localType, void assignToGlobal (CodeContainer& code, Literals& literals, char localType,
const std::string& name, const CodeContainer& value, char valueType) const std::string& name, const CodeContainer& value, char valueType)
{ {
@ -751,15 +731,5 @@ namespace Compiler
assert (0); assert (0);
} }
} }
void random (CodeContainer& code)
{
opRandom (code);
}
void getSecondsPassed (CodeContainer& code)
{
opGetSecondsPassed (code);
}
} }
} }

@ -91,8 +91,6 @@ namespace Compiler
void compare (CodeContainer& code, char op, char valueType1, char valueType2); void compare (CodeContainer& code, char op, char valueType1, char valueType2);
void menuMode (CodeContainer& code);
void assignToGlobal (CodeContainer& code, Literals& literals, char localType, void assignToGlobal (CodeContainer& code, Literals& literals, char localType,
const std::string& name, const CodeContainer& value, char valueType); const std::string& name, const CodeContainer& value, char valueType);
@ -106,10 +104,6 @@ namespace Compiler
void fetchMember (CodeContainer& code, Literals& literals, char memberType, void fetchMember (CodeContainer& code, Literals& literals, char memberType,
const std::string& name, const std::string& id, bool global); const std::string& name, const std::string& id, bool global);
///< \param global Member of a global script instead of a script of a reference. ///< \param global Member of a global script instead of a script of a reference.
void random (CodeContainer& code);
void getSecondsPassed (CodeContainer& code);
} }
} }

@ -433,18 +433,6 @@ namespace Compiler
return true; return true;
} }
if (mAllowExpression)
{
if (keyword==Scanner::K_getsquareroot || keyword==Scanner::K_menumode ||
keyword==Scanner::K_random || keyword==Scanner::K_getsecondspassed)
{
scanner.putbackKeyword (keyword, loc);
parseExpression (scanner, loc);
mState = EndState;
return true;
}
}
return Parser::parseKeyword (keyword, loc, scanner); return Parser::parseKeyword (keyword, loc, scanner);
} }

@ -201,9 +201,12 @@ namespace Compiler
namespace Misc namespace Misc
{ {
const int opcodeMenuMode = 38;
const int opcodeRandom = 45;
const int opcodeScriptRunning = 46; const int opcodeScriptRunning = 46;
const int opcodeStartScript = 47; const int opcodeStartScript = 47;
const int opcodeStopScript = 48; const int opcodeStopScript = 48;
const int opcodeGetSecondsPassed = 50;
const int opcodeEnable = 51; const int opcodeEnable = 51;
const int opcodeDisable = 52; const int opcodeDisable = 52;
const int opcodeGetDisabled = 53; const int opcodeGetDisabled = 53;

@ -266,9 +266,6 @@ namespace Compiler
"messagebox", "messagebox",
"set", "to", "set", "to",
"getsquareroot", "getsquareroot",
"menumode",
"random",
"getsecondspassed",
0 0
}; };

@ -208,10 +208,7 @@ namespace Compiler
K_return, K_return,
K_messagebox, K_messagebox,
K_set, K_to, K_set, K_to,
K_getsquareroot, K_getsquareroot
K_menumode,
K_random,
K_getsecondspassed
}; };
enum special enum special

@ -63,9 +63,7 @@ namespace Compiler
keyword==Scanner::K_elseif || keyword==Scanner::K_while || keyword==Scanner::K_elseif || keyword==Scanner::K_while ||
keyword==Scanner::K_endwhile || keyword==Scanner::K_return || keyword==Scanner::K_endwhile || keyword==Scanner::K_return ||
keyword==Scanner::K_messagebox || keyword==Scanner::K_set || keyword==Scanner::K_messagebox || keyword==Scanner::K_set ||
keyword==Scanner::K_to || keyword==Scanner::K_getsquareroot || keyword==Scanner::K_to || keyword==Scanner::K_getsquareroot)
keyword==Scanner::K_menumode || keyword==Scanner::K_random ||
keyword==Scanner::K_getsecondspassed)
{ {
return parseName (loc.mLiteral, loc, scanner); return parseName (loc.mLiteral, loc, scanner);
} }

@ -35,8 +35,6 @@ namespace Interpreter
virtual void report (const std::string& message) = 0; virtual void report (const std::string& message) = 0;
virtual bool menuMode() = 0;
virtual int getGlobalShort (const std::string& name) const = 0; virtual int getGlobalShort (const std::string& name) const = 0;
virtual int getGlobalLong (const std::string& name) const = 0; virtual int getGlobalLong (const std::string& name) const = 0;
@ -79,8 +77,6 @@ namespace Interpreter
virtual std::string getCurrentCellName() const = 0; virtual std::string getCurrentCellName() const = 0;
virtual float getSecondsPassed() const = 0;
virtual int getMemberShort (const std::string& id, const std::string& name, bool global) const = 0; virtual int getMemberShort (const std::string& id, const std::string& name, bool global) const = 0;
virtual int getMemberLong (const std::string& id, const std::string& name, bool global) const = 0; virtual int getMemberLong (const std::string& id, const std::string& name, bool global) const = 0;

@ -95,9 +95,6 @@ namespace Interpreter
// misc // misc
interpreter.installSegment3 (0, new OpMessageBox); interpreter.installSegment3 (0, new OpMessageBox);
interpreter.installSegment5 (38, new OpMenuMode);
interpreter.installSegment5 (45, new OpRandom);
interpreter.installSegment5 (50, new OpGetSecondsPassed);
interpreter.installSegment5 (58, new OpReport); interpreter.installSegment5 (58, new OpReport);
} }
} }

@ -11,7 +11,6 @@
#include "runtime.hpp" #include "runtime.hpp"
#include "defines.hpp" #include "defines.hpp"
#include <components/misc/rng.hpp>
#include <components/misc/messageformatparser.hpp> #include <components/misc/messageformatparser.hpp>
namespace Interpreter namespace Interpreter
@ -168,44 +167,6 @@ namespace Interpreter
} }
}; };
class OpMenuMode : public Opcode0
{
public:
virtual void execute (Runtime& runtime)
{
runtime.push (runtime.getContext().menuMode());
}
};
class OpRandom : public Opcode0
{
public:
virtual void execute (Runtime& runtime)
{
Type_Integer limit = runtime[0].mInteger;
if (limit<0)
throw std::runtime_error (
"random: argument out of range (Don't be so negative!)");
runtime[0].mFloat = static_cast<Type_Float>(Misc::Rng::rollDice(limit)); // [o, limit)
}
};
class OpGetSecondsPassed : public Opcode0
{
public:
virtual void execute (Runtime& runtime)
{
Type_Float duration = runtime.getContext().getSecondsPassed();
runtime.push (duration);
}
};
} }
#endif #endif

Loading…
Cancel
Save