From ebd8b064f64fa7d1f5c0e346135c0c0d5c06173a Mon Sep 17 00:00:00 2001 From: gugus Date: Wed, 1 Aug 2012 12:21:42 +0200 Subject: [PATCH] getStartingAngle script instruction --- apps/openmw/mwscript/docs/vmformat.txt | 8 ++++- .../mwscript/transformationextensions.cpp | 34 ++++++++++++++++++- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/apps/openmw/mwscript/docs/vmformat.txt b/apps/openmw/mwscript/docs/vmformat.txt index b979420dd..2f08353db 100644 --- a/apps/openmw/mwscript/docs/vmformat.txt +++ b/apps/openmw/mwscript/docs/vmformat.txt @@ -169,5 +169,11 @@ op 0x2000164: SetScale op 0x2000165: SetScale, explicit reference op 0x2000166: SetAngle 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: GetStartingAngle +op 0x200016d: GetStartingAngle, explicit reference +opcodes 0x200016e-0x3ffffff unused diff --git a/apps/openmw/mwscript/transformationextensions.cpp b/apps/openmw/mwscript/transformationextensions.cpp index 2ea80c0d8..1c6940710 100644 --- a/apps/openmw/mwscript/transformationextensions.cpp +++ b/apps/openmw/mwscript/transformationextensions.cpp @@ -82,7 +82,7 @@ namespace MWScript }; template - class OpGetAngle : public Interpreter::Opcode0 + class OpGetStartingAngle : public Interpreter::Opcode0 { public: @@ -108,6 +108,33 @@ namespace MWScript } }; + template + class OpGetAngle : public Interpreter::Opcode0 + { + public: + + virtual void execute (Interpreter::Runtime& runtime) + { + MWWorld::Ptr ptr = R()(runtime); + + std::string axis = runtime.getStringLiteral (runtime[0].mInteger); + runtime.pop(); + + if(axis == "X") + { + runtime.push(Ogre::Radian(ptr.getCellRef().pos.rot[0]).valueDegrees()); + } + if(axis == "Y") + { + runtime.push(Ogre::Radian(ptr.getCellRef().pos.rot[1]).valueDegrees()); + } + if(axis == "Z") + { + runtime.push(Ogre::Radian(ptr.getCellRef().pos.rot[2]).valueDegrees()); + } + } + }; + const int opcodeSetScale = 0x2000164; const int opcodeSetScaleExplicit = 0x2000165; const int opcodeSetAngle = 0x2000166; @@ -116,6 +143,8 @@ namespace MWScript const int opcodeGetScaleExplicit = 0x2000169; const int opcodeGetAngle = 0x200016a; const int opcodeGetAngleExplicit = 0x200016b; + const int opcodeGetStartingAngle = 0x200016c; + const int opcodeGetStartingAngleExplicit = 0x200016d; void registerExtensions (Compiler::Extensions& extensions) { @@ -123,6 +152,7 @@ namespace MWScript extensions.registerFunction("getscale",'f',"",opcodeGetScale,opcodeGetScaleExplicit); extensions.registerInstruction("setangle","Sf",opcodeSetAngle,opcodeSetAngleExplicit); extensions.registerFunction("getangle",'f',"S",opcodeGetAngle,opcodeGetAngleExplicit); + extensions.registerFunction("getstartingangle",'f',"S",opcodeGetStartingAngle,opcodeGetStartingAngleExplicit); } void installOpcodes (Interpreter::Interpreter& interpreter) @@ -135,6 +165,8 @@ namespace MWScript interpreter.installSegment5(opcodeGetScaleExplicit,new OpGetScale); interpreter.installSegment5(opcodeGetAngle,new OpGetAngle); interpreter.installSegment5(opcodeGetAngleExplicit,new OpGetAngle); + interpreter.installSegment5(opcodeGetStartingAngle,new OpGetStartingAngle); + interpreter.installSegment5(opcodeGetStartingAngleExplicit,new OpGetStartingAngle); } } }