From 30973352e8320a61fb7a14b7ad63b415e94a4151 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Tue, 13 Aug 2013 04:36:20 -0700 Subject: [PATCH] Implement ShowVars (SV) console function --- apps/openmw/mwscript/docs/vmformat.txt | 4 +- apps/openmw/mwscript/miscextensions.cpp | 97 +++++++++++++++++++++++++ components/compiler/extensions0.cpp | 2 + components/compiler/locals.hpp | 4 +- components/compiler/opcodes.hpp | 2 + 5 files changed, 106 insertions(+), 3 deletions(-) diff --git a/apps/openmw/mwscript/docs/vmformat.txt b/apps/openmw/mwscript/docs/vmformat.txt index af80e88b0..08b499175 100644 --- a/apps/openmw/mwscript/docs/vmformat.txt +++ b/apps/openmw/mwscript/docs/vmformat.txt @@ -349,5 +349,7 @@ op 0x2000219: UndoWerewolf op 0x200021a: UndoWerewolfExplicit op 0x200021b: SetWerewolfAcrobatics op 0x200021c: SetWerewolfAcrobaticsExplicit +op 0x200021d: ShowVars +op 0x200021e: ShowVarsExplicit -opcodes 0x200021d-0x3ffffff unused +opcodes 0x200021f-0x3ffffff unused diff --git a/apps/openmw/mwscript/miscextensions.cpp b/apps/openmw/mwscript/miscextensions.cpp index 9dc5327d9..54d778e89 100644 --- a/apps/openmw/mwscript/miscextensions.cpp +++ b/apps/openmw/mwscript/miscextensions.cpp @@ -5,6 +5,7 @@ #include #include +#include #include #include @@ -12,6 +13,7 @@ #include "../mwbase/environment.hpp" #include "../mwbase/windowmanager.hpp" +#include "../mwbase/scriptmanager.hpp" #include "../mwworld/class.hpp" #include "../mwworld/player.hpp" @@ -630,6 +632,99 @@ namespace MWScript }; + class OpShowVarsExplicit : public Interpreter::Opcode0 + { + protected: + void printLocalVars(Interpreter::Runtime &runtime, const MWWorld::Ptr &ptr) + { + std::stringstream str; + + const std::string script = MWWorld::Class::get(ptr).getScript(ptr); + if(script.empty()) + str<< ptr.getCellRef().mRefID<<" ("<getLocals(script); + + const std::vector *names = &complocals.get('s'); + for(size_t i = 0;i < names->size();++i) + { + if(i >= locals.mShorts.size()) + break; + str<size();++i) + { + if(i >= locals.mLongs.size()) + break; + str<size();++i) + { + if(i >= locals.mFloats.size()) + break; + str< names = world->getGlobals(); + for(size_t i = 0;i < names.size();++i) + { + char type = world->getGlobalVariableType(names[i]); + if(type == 's') + str<); interpreter.installSegment5 (Compiler::Misc::opcodeDisableTeleporting, new OpEnableTeleporting); interpreter.installSegment5 (Compiler::Misc::opcodeEnableTeleporting, new OpEnableTeleporting); + interpreter.installSegment5 (Compiler::Misc::opcodeShowVars, new OpShowVarsImplicit); + interpreter.installSegment5 (Compiler::Misc::opcodeShowVarsExplicit, new OpShowVarsExplicit); } } } diff --git a/components/compiler/extensions0.cpp b/components/compiler/extensions0.cpp index 419755251..692b50052 100644 --- a/components/compiler/extensions0.cpp +++ b/components/compiler/extensions0.cpp @@ -256,6 +256,8 @@ namespace Compiler extensions.registerFunction ("hitonme", 'l', "S", opcodeHitOnMe, opcodeHitOnMeExplicit); extensions.registerInstruction ("disableteleporting", "", opcodeDisableTeleporting); extensions.registerInstruction ("enableteleporting", "", opcodeEnableTeleporting); + extensions.registerInstruction ("showvars", "", opcodeShowVars, opcodeShowVarsExplicit); + extensions.registerInstruction ("sv", "", opcodeShowVars, opcodeShowVarsExplicit); } } diff --git a/components/compiler/locals.hpp b/components/compiler/locals.hpp index fdd0a6b29..e54b7798c 100644 --- a/components/compiler/locals.hpp +++ b/components/compiler/locals.hpp @@ -15,8 +15,6 @@ namespace Compiler std::vector mLongs; std::vector mFloats; - const std::vector& get (char type) const; - int searchIndex (char type, const std::string& name) const; bool search (char type, const std::string& name) const; @@ -31,6 +29,8 @@ namespace Compiler int getIndex (const std::string& name) const; ///< return index for local variable \a name (-1: does not exist). + const std::vector& get (char type) const; + void write (std::ostream& localFile) const; ///< write declarations to file. diff --git a/components/compiler/opcodes.hpp b/components/compiler/opcodes.hpp index 2fdf1d2d2..c4e2c1bc6 100644 --- a/components/compiler/opcodes.hpp +++ b/components/compiler/opcodes.hpp @@ -219,6 +219,8 @@ namespace Compiler const int opcodeHitOnMeExplicit = 0x2000214; const int opcodeDisableTeleporting = 0x2000215; const int opcodeEnableTeleporting = 0x2000216; + const int opcodeShowVars = 0x200021d; + const int opcodeShowVarsExplicit = 0x200021e; } namespace Sky