openmw-tes3coop/apps/openmw/mwscript/transformationextensions.cpp

173 lines
6.5 KiB
C++
Raw Normal View History

2012-07-09 16:47:59 +00:00
#include <boost/algorithm/string.hpp>
#include <components/esm_store/store.hpp>
#include <components/compiler/extensions.hpp>
#include <components/interpreter/interpreter.hpp>
#include <components/interpreter/runtime.hpp>
#include <components/interpreter/opcodes.hpp>
#include "../mwbase/environment.hpp"
#include "../mwworld/class.hpp"
#include "interpretercontext.hpp"
#include "ref.hpp"
#include "OgreSceneNode.h"
2012-07-09 16:47:59 +00:00
namespace MWScript
{
namespace Transformation
{
template<class R>
class OpSetScale : public Interpreter::Opcode0
{
public:
virtual void execute (Interpreter::Runtime& runtime)
{
MWWorld::Ptr ptr = R()(runtime);
Interpreter::Type_Float scale = runtime[0].mFloat;
2012-07-09 16:47:59 +00:00
runtime.pop();
MWBase::Environment::get().getWorld()->scaleObject(ptr,scale);
}
};
template<class R>
class OpGetScale : public Interpreter::Opcode0
{
public:
virtual void execute (Interpreter::Runtime& runtime)
{
MWWorld::Ptr ptr = R()(runtime);
runtime.push(ptr.getCellRef().scale);
}
};
2012-07-09 16:47:59 +00:00
template<class R>
class OpSetAngle : 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();
Interpreter::Type_Float angle = runtime[0].mFloat;
2012-07-09 16:47:59 +00:00
runtime.pop();
2012-07-10 09:15:46 +00:00
float ax = Ogre::Radian(ptr.getRefData().getPosition().rot[0]).valueDegrees();
float ay = Ogre::Radian(ptr.getRefData().getPosition().rot[1]).valueDegrees();
float az = Ogre::Radian(ptr.getRefData().getPosition().rot[2]).valueDegrees();
2012-07-09 16:47:59 +00:00
if(axis == "X")
{
2012-07-10 09:15:46 +00:00
MWBase::Environment::get().getWorld()->rotateObject(ptr,angle,ay,az);
2012-07-09 16:47:59 +00:00
}
if(axis == "Y")
{
2012-07-10 09:15:46 +00:00
MWBase::Environment::get().getWorld()->rotateObject(ptr,ax,angle,az);
2012-07-09 16:47:59 +00:00
}
if(axis == "Z")
{
2012-07-10 09:15:46 +00:00
MWBase::Environment::get().getWorld()->rotateObject(ptr,ax,ay,angle);
2012-07-09 16:47:59 +00:00
}
}
};
template<class R>
2012-08-01 10:21:42 +00:00
class OpGetStartingAngle : 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")
{
2012-07-10 09:15:46 +00:00
runtime.push(Ogre::Radian(ptr.getRefData().getPosition().rot[0]).valueDegrees());
}
if(axis == "Y")
{
2012-07-10 09:15:46 +00:00
runtime.push(Ogre::Radian(ptr.getRefData().getPosition().rot[1]).valueDegrees());
}
if(axis == "Z")
{
2012-07-10 09:15:46 +00:00
runtime.push(Ogre::Radian(ptr.getRefData().getPosition().rot[2]).valueDegrees());
}
}
};
2012-08-01 10:21:42 +00:00
template<class R>
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();
2012-08-01 10:21:42 +00:00
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());
}
}
};
2012-07-09 16:47:59 +00:00
const int opcodeSetScale = 0x2000164;
const int opcodeSetScaleExplicit = 0x2000165;
const int opcodeSetAngle = 0x2000166;
const int opcodeSetAngleExplicit = 0x2000167;
const int opcodeGetScale = 0x2000168;
const int opcodeGetScaleExplicit = 0x2000169;
const int opcodeGetAngle = 0x200016a;
const int opcodeGetAngleExplicit = 0x200016b;
const int opcodeGetStartingAngle = 0x2000172;
const int opcodeGetStartingAngleExplicit = 0x2000173;
2012-07-09 16:47:59 +00:00
void registerExtensions (Compiler::Extensions& extensions)
{
extensions.registerInstruction("setscale","f",opcodeSetScale,opcodeSetScaleExplicit);
extensions.registerFunction("getscale",'f',"",opcodeGetScale,opcodeGetScaleExplicit);
extensions.registerInstruction("setangle","Sf",opcodeSetAngle,opcodeSetAngleExplicit);
extensions.registerFunction("getangle",'f',"S",opcodeGetAngle,opcodeGetAngleExplicit);
2012-08-01 10:21:42 +00:00
extensions.registerFunction("getstartingangle",'f',"S",opcodeGetStartingAngle,opcodeGetStartingAngleExplicit);
2012-07-09 16:47:59 +00:00
}
void installOpcodes (Interpreter::Interpreter& interpreter)
{
interpreter.installSegment5(opcodeSetScale,new OpSetScale<ImplicitRef>);
interpreter.installSegment5(opcodeSetScaleExplicit,new OpSetScale<ExplicitRef>);
interpreter.installSegment5(opcodeSetAngle,new OpSetAngle<ImplicitRef>);
interpreter.installSegment5(opcodeSetAngleExplicit,new OpSetAngle<ExplicitRef>);
interpreter.installSegment5(opcodeGetScale,new OpGetScale<ImplicitRef>);
interpreter.installSegment5(opcodeGetScaleExplicit,new OpGetScale<ExplicitRef>);
interpreter.installSegment5(opcodeGetAngle,new OpGetAngle<ImplicitRef>);
interpreter.installSegment5(opcodeGetAngleExplicit,new OpGetAngle<ExplicitRef>);
2012-08-01 10:21:42 +00:00
interpreter.installSegment5(opcodeGetStartingAngle,new OpGetStartingAngle<ImplicitRef>);
interpreter.installSegment5(opcodeGetStartingAngleExplicit,new OpGetStartingAngle<ExplicitRef>);
2012-07-09 16:47:59 +00:00
}
}
}