1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-02-02 02:15:35 +00:00

Issue #350: console only script instructions

This commit is contained in:
Marc Zinnschlag 2012-07-30 11:43:28 +02:00
parent 04ae3cbadd
commit 90de02b901
15 changed files with 230 additions and 20 deletions

View file

@ -39,7 +39,7 @@ add_openmw_dir (mwscript
locals scriptmanager compilercontext interpretercontext cellextensions miscextensions locals scriptmanager compilercontext interpretercontext cellextensions miscextensions
guiextensions soundextensions skyextensions statsextensions containerextensions guiextensions soundextensions skyextensions statsextensions containerextensions
aiextensions controlextensions extensions globalscripts ref dialogueextensions aiextensions controlextensions extensions globalscripts ref dialogueextensions
animationextensions transformationextensions animationextensions transformationextensions consoleextensions userextensions
) )
add_openmw_dir (mwsound add_openmw_dir (mwsound

View file

@ -129,6 +129,7 @@ OMW::Engine::Engine(Files::ConfigurationManager& configurationManager)
, mCompileAll (false) , mCompileAll (false)
, mScriptContext (0) , mScriptContext (0)
, mFSStrict (false) , mFSStrict (false)
, mScriptConsoleMode (false)
, mCfgMgr(configurationManager) , mCfgMgr(configurationManager)
{ {
std::srand ( std::time(NULL) ); std::srand ( std::time(NULL) );
@ -326,7 +327,8 @@ void OMW::Engine::go()
MWScript::registerExtensions (mExtensions); MWScript::registerExtensions (mExtensions);
mEnvironment.setWindowManager (new MWGui::WindowManager( mEnvironment.setWindowManager (new MWGui::WindowManager(
mExtensions, mFpsLevel, mNewGame, mOgre, mCfgMgr.getLogPath().string() + std::string("/"))); mExtensions, mFpsLevel, mNewGame, mOgre, mCfgMgr.getLogPath().string() + std::string("/"),
mScriptConsoleMode));
// Create sound system // Create sound system
mEnvironment.setSoundManager (new MWSound::SoundManager(mUseSound)); mEnvironment.setSoundManager (new MWSound::SoundManager(mUseSound));
@ -490,3 +492,8 @@ void OMW::Engine::setFallbackValues(std::map<std::string,std::string> fallbackMa
{ {
mFallbackMap = fallbackMap; mFallbackMap = fallbackMap;
} }
void OMW::Engine::setScriptConsoleMode (bool enabled)
{
mScriptConsoleMode = enabled;
}

View file

@ -73,6 +73,7 @@ namespace OMW
bool mCompileAll; bool mCompileAll;
std::string mFocusName; std::string mFocusName;
std::map<std::string,std::string> mFallbackMap; std::map<std::string,std::string> mFallbackMap;
bool mScriptConsoleMode;
Compiler::Extensions mExtensions; Compiler::Extensions mExtensions;
Compiler::Context *mScriptContext; Compiler::Context *mScriptContext;
@ -158,6 +159,9 @@ namespace OMW
void setFallbackValues(std::map<std::string,std::string> map); void setFallbackValues(std::map<std::string,std::string> map);
/// Enable console-only script functionality
void setScriptConsoleMode (bool enabled);
private: private:
Files::ConfigurationManager& mCfgMgr; Files::ConfigurationManager& mCfgMgr;
}; };

View file

@ -124,12 +124,15 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat
("script-verbose", bpo::value<bool>()->implicit_value(true) ("script-verbose", bpo::value<bool>()->implicit_value(true)
->default_value(false), "verbose script output") ->default_value(false), "verbose script output")
("new-game", bpo::value<bool>()->implicit_value(true)
->default_value(false), "activate char gen/new game mechanics")
("script-all", bpo::value<bool>()->implicit_value(true) ("script-all", bpo::value<bool>()->implicit_value(true)
->default_value(false), "compile all scripts (excluding dialogue scripts) at startup") ->default_value(false), "compile all scripts (excluding dialogue scripts) at startup")
("script-console", bpo::value<bool>()->implicit_value(true)
->default_value(false), "enable console-only script functionality")
("new-game", bpo::value<bool>()->implicit_value(true)
->default_value(false), "activate char gen/new game mechanics")
("fs-strict", bpo::value<bool>()->implicit_value(true) ("fs-strict", bpo::value<bool>()->implicit_value(true)
->default_value(false), "strict file system handling (no case folding)") ->default_value(false), "strict file system handling (no case folding)")
@ -249,6 +252,7 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat
engine.setCompileAll(variables["script-all"].as<bool>()); engine.setCompileAll(variables["script-all"].as<bool>());
engine.setAnimationVerbose(variables["anim-verbose"].as<bool>()); engine.setAnimationVerbose(variables["anim-verbose"].as<bool>());
engine.setFallbackValues(variables["fallback"].as<FallbackMap>().mMap); engine.setFallbackValues(variables["fallback"].as<FallbackMap>().mMap);
engine.setScriptConsoleMode (variables["script-console"].as<bool>());
return true; return true;
} }

View file

@ -105,9 +105,10 @@ namespace MWGui
} }
} }
Console::Console(int w, int h, const Compiler::Extensions& extensions) Console::Console(int w, int h, bool consoleOnlyScripts)
: Layout("openmw_console.layout"), : Layout("openmw_console.layout"),
mCompilerContext (MWScript::CompilerContext::Type_Console) mCompilerContext (MWScript::CompilerContext::Type_Console),
mConsoleOnlyScripts (consoleOnlyScripts)
{ {
setCoord(10,10, w-10, h/2); setCoord(10,10, w-10, h/2);
@ -126,7 +127,8 @@ namespace MWGui
history->setVisibleVScroll(true); history->setVisibleVScroll(true);
// compiler // compiler
mCompilerContext.setExtensions (&extensions); MWScript::registerExtensions (mExtensions, mConsoleOnlyScripts);
mCompilerContext.setExtensions (&mExtensions);
} }
void Console::enable() void Console::enable()
@ -246,7 +248,7 @@ namespace MWGui
{ {
ConsoleInterpreterContext interpreterContext (*this, mPtr); ConsoleInterpreterContext interpreterContext (*this, mPtr);
Interpreter::Interpreter interpreter; Interpreter::Interpreter interpreter;
MWScript::installOpcodes (interpreter); MWScript::installOpcodes (interpreter, mConsoleOnlyScripts);
std::vector<Interpreter::Type_Code> code; std::vector<Interpreter::Type_Code> code;
output.getCode (code); output.getCode (code);
interpreter.run (&code[0], code.size(), interpreterContext); interpreter.run (&code[0], code.size(), interpreterContext);

View file

@ -11,6 +11,7 @@
#include <components/compiler/scanner.hpp> #include <components/compiler/scanner.hpp>
#include <components/compiler/locals.hpp> #include <components/compiler/locals.hpp>
#include <components/compiler/output.hpp> #include <components/compiler/output.hpp>
#include <components/compiler/extensions.hpp>
#include <components/interpreter/interpreter.hpp> #include <components/interpreter/interpreter.hpp>
#include "../mwscript/compilercontext.hpp" #include "../mwscript/compilercontext.hpp"
@ -24,8 +25,10 @@ namespace MWGui
{ {
private: private:
Compiler::Extensions mExtensions;
MWScript::CompilerContext mCompilerContext; MWScript::CompilerContext mCompilerContext;
std::vector<std::string> mNames; std::vector<std::string> mNames;
bool mConsoleOnlyScripts;
bool compile (const std::string& cmd, Compiler::Output& output); bool compile (const std::string& cmd, Compiler::Output& output);
@ -62,7 +65,7 @@ namespace MWGui
StringList::iterator current; StringList::iterator current;
std::string editString; std::string editString;
Console(int w, int h, const Compiler::Extensions& extensions); Console(int w, int h, bool consoleOnlyScripts);
void enable(); void enable();

View file

@ -41,7 +41,7 @@
using namespace MWGui; using namespace MWGui;
WindowManager::WindowManager( WindowManager::WindowManager(
const Compiler::Extensions& extensions, int fpsLevel, bool newGame, OEngine::Render::OgreRenderer *mOgre, const std::string& logpath) const Compiler::Extensions& extensions, int fpsLevel, bool newGame, OEngine::Render::OgreRenderer *mOgre, const std::string& logpath, bool consoleOnlyScripts)
: mGuiManager(NULL) : mGuiManager(NULL)
, mHud(NULL) , mHud(NULL)
, mMap(NULL) , mMap(NULL)
@ -113,7 +113,7 @@ WindowManager::WindowManager(
mMenu = new MainMenu(w,h); mMenu = new MainMenu(w,h);
mMap = new MapWindow(*this); mMap = new MapWindow(*this);
mStatsWindow = new StatsWindow(*this); mStatsWindow = new StatsWindow(*this);
mConsole = new Console(w,h, extensions); mConsole = new Console(w,h, consoleOnlyScripts);
mJournal = new JournalWindow(*this); mJournal = new JournalWindow(*this);
mMessageBoxManager = new MessageBoxManager(this); mMessageBoxManager = new MessageBoxManager(this);
mInventoryWindow = new InventoryWindow(*this,mDragAndDrop); mInventoryWindow = new InventoryWindow(*this,mDragAndDrop);

View file

@ -94,7 +94,7 @@ namespace MWGui
typedef std::vector<Faction> FactionList; typedef std::vector<Faction> FactionList;
typedef std::vector<int> SkillList; typedef std::vector<int> SkillList;
WindowManager(const Compiler::Extensions& extensions, int fpsLevel, bool newGame, OEngine::Render::OgreRenderer *mOgre, const std::string& logpath); WindowManager(const Compiler::Extensions& extensions, int fpsLevel, bool newGame, OEngine::Render::OgreRenderer *mOgre, const std::string& logpath, bool consoleOnlyScripts);
virtual ~WindowManager(); virtual ~WindowManager();
/** /**

View file

@ -0,0 +1,24 @@
#include "consoleextensions.hpp"
#include <components/compiler/extensions.hpp>
#include <components/interpreter/interpreter.hpp>
#include <components/interpreter/runtime.hpp>
#include <components/interpreter/opcodes.hpp>
namespace MWScript
{
namespace Console
{
void registerExtensions (Compiler::Extensions& extensions)
{
}
void installOpcodes (Interpreter::Interpreter& interpreter)
{
}
}
}

View file

@ -0,0 +1,25 @@
#ifndef GAME_SCRIPT_CONSOLEEXTENSIONS_H
#define GAME_SCRIPT_CONSOLEEXTENSIONS_H
namespace Compiler
{
class Extensions;
}
namespace Interpreter
{
class Interpreter;
}
namespace MWScript
{
/// \brief Script functionality limited to the console
namespace Console
{
void registerExtensions (Compiler::Extensions& extensions);
void installOpcodes (Interpreter::Interpreter& interpreter);
}
}
#endif

View file

@ -169,5 +169,14 @@ op 0x2000164: SetScale
op 0x2000165: SetScale, explicit reference op 0x2000165: SetScale, explicit reference
op 0x2000166: SetAngle op 0x2000166: SetAngle
op 0x2000167: SetAngle, explicit reference op 0x2000167: SetAngle, explicit reference
opcodes 0x2000168-0x3ffffff unused op 0x2000168: GetScale
op 0x2000169: GetScale, explicit reference
op 0x200016a: GetAngle
op 0x200016b: GetAngle, explicit reference
op 0x200016c: user1 (console only, requires --script-console switch)
op 0x200016d: user2 (console only, requires --script-console switch)
op 0x200016e: user3, explicit reference (console only, requires --script-console switch)
op 0x200016f: user3 (implicit reference, console only, requires --script-console switch)
op 0x2000170: user4, explicit reference (console only, requires --script-console switch)
op 0x2000171: user4 (implicit reference, console only, requires --script-console switch)
opcodes 0x2000172-0x3ffffff unused

View file

@ -16,10 +16,12 @@
#include "dialogueextensions.hpp" #include "dialogueextensions.hpp"
#include "animationextensions.hpp" #include "animationextensions.hpp"
#include "transformationextensions.hpp" #include "transformationextensions.hpp"
#include "consoleextensions.hpp"
#include "userextensions.hpp"
namespace MWScript namespace MWScript
{ {
void registerExtensions (Compiler::Extensions& extensions) void registerExtensions (Compiler::Extensions& extensions, bool consoleOnly)
{ {
Cell::registerExtensions (extensions); Cell::registerExtensions (extensions);
Misc::registerExtensions (extensions); Misc::registerExtensions (extensions);
@ -33,9 +35,15 @@ namespace MWScript
Dialogue::registerExtensions (extensions); Dialogue::registerExtensions (extensions);
Animation::registerExtensions (extensions); Animation::registerExtensions (extensions);
Transformation::registerExtensions (extensions); Transformation::registerExtensions (extensions);
if (consoleOnly)
{
Console::registerExtensions (extensions);
User::registerExtensions (extensions);
}
} }
void installOpcodes (Interpreter::Interpreter& interpreter) void installOpcodes (Interpreter::Interpreter& interpreter, bool consoleOnly)
{ {
Interpreter::installOpcodes (interpreter); Interpreter::installOpcodes (interpreter);
Cell::installOpcodes (interpreter); Cell::installOpcodes (interpreter);
@ -50,5 +58,11 @@ namespace MWScript
Dialogue::installOpcodes (interpreter); Dialogue::installOpcodes (interpreter);
Animation::installOpcodes (interpreter); Animation::installOpcodes (interpreter);
Transformation::installOpcodes (interpreter); Transformation::installOpcodes (interpreter);
if (consoleOnly)
{
Console::installOpcodes (interpreter);
User::installOpcodes (interpreter);
}
} }
} }

View file

@ -13,9 +13,11 @@ namespace Interpreter
namespace MWScript namespace MWScript
{ {
void registerExtensions (Compiler::Extensions& extensions); void registerExtensions (Compiler::Extensions& extensions, bool consoleOnly = false);
///< \param consoleOnly include console only extensions
void installOpcodes (Interpreter::Interpreter& interpreter); void installOpcodes (Interpreter::Interpreter& interpreter, bool consoleOnly = false);
///< \param consoleOnly include console only opcodes
} }
#endif #endif

View file

@ -0,0 +1,91 @@
#include "userextensions.hpp"
#include <components/compiler/extensions.hpp>
#include <components/interpreter/interpreter.hpp>
#include <components/interpreter/runtime.hpp>
#include <components/interpreter/opcodes.hpp>
#include <components/interpreter/context.hpp>
#include "ref.hpp"
namespace MWScript
{
/// Temporary script extensions.
///
/// \attention Do not commit changes to this file to a git repository!
namespace User
{
class OpUser1 : public Interpreter::Opcode0
{
public:
virtual void execute (Interpreter::Runtime& runtime)
{
runtime.getContext().report ("user1: not in use");
}
};
class OpUser2 : public Interpreter::Opcode0
{
public:
virtual void execute (Interpreter::Runtime& runtime)
{
runtime.getContext().report ("user2: not in use");
}
};
template<class R>
class OpUser3 : public Interpreter::Opcode0
{
public:
virtual void execute (Interpreter::Runtime& runtime)
{
// MWWorld::Ptr ptr = R()(runtime);
runtime.getContext().report ("user3: not in use");
}
};
template<class R>
class OpUser4 : public Interpreter::Opcode0
{
public:
virtual void execute (Interpreter::Runtime& runtime)
{
// MWWorld::Ptr ptr = R()(runtime);
runtime.getContext().report ("user4: not in use");
}
};
const int opcodeUser1 = 0x200016c;
const int opcodeUser2 = 0x200016d;
const int opcodeUser3 = 0x200016e;
const int opcodeUser3Explicit = 0x200016f;
const int opcodeUser4 = 0x2000170;
const int opcodeUser4Explicit = 0x2000171;
void registerExtensions (Compiler::Extensions& extensions)
{
extensions.registerInstruction ("user1", "", opcodeUser1);
extensions.registerInstruction ("user2", "", opcodeUser2);
extensions.registerInstruction ("user3", "", opcodeUser3, opcodeUser3);
extensions.registerInstruction ("user4", "", opcodeUser4, opcodeUser4);
}
void installOpcodes (Interpreter::Interpreter& interpreter)
{
interpreter.installSegment5 (opcodeUser1, new OpUser1);
interpreter.installSegment5 (opcodeUser2, new OpUser2);
interpreter.installSegment5 (opcodeUser3, new OpUser3<ImplicitRef>);
interpreter.installSegment5 (opcodeUser3Explicit, new OpUser3<ExplicitRef>);
interpreter.installSegment5 (opcodeUser4, new OpUser4<ImplicitRef>);
interpreter.installSegment5 (opcodeUser4Explicit, new OpUser4<ExplicitRef>);
}
}
}

View file

@ -0,0 +1,25 @@
#ifndef GAME_SCRIPT_USEREXTENSIONS_H
#define GAME_SCRIPT_USEREXTENSIONS_H
namespace Compiler
{
class Extensions;
}
namespace Interpreter
{
class Interpreter;
}
namespace MWScript
{
/// \brief Temporaty script functionality limited to the console
namespace User
{
void registerExtensions (Compiler::Extensions& extensions);
void installOpcodes (Interpreter::Interpreter& interpreter);
}
}
#endif