1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-16 09:49:55 +00:00
openmw-tes3mp/apps/openmw/mwscript/miscextensions.cpp

145 lines
5 KiB
C++
Raw Normal View History

2010-07-05 11:15:49 +00:00
#include "miscextensions.hpp"
#include <components/compiler/extensions.hpp>
#include <components/interpreter/interpreter.hpp>
#include <components/interpreter/runtime.hpp>
#include <components/interpreter/opcodes.hpp>
2010-08-30 10:30:34 +00:00
#include "../mwworld/class.hpp"
#include "interpretercontext.hpp"
#include "ref.hpp"
2010-07-05 11:15:49 +00:00
namespace MWScript
{
namespace Misc
{
class OpXBox : public Interpreter::Opcode0
{
public:
2010-07-05 11:15:49 +00:00
virtual void execute (Interpreter::Runtime& runtime)
{
runtime.push (0);
}
2010-07-05 11:15:49 +00:00
};
2010-07-06 08:25:42 +00:00
class OpOnActivate : public Interpreter::Opcode0
{
public:
2010-07-06 08:25:42 +00:00
virtual void execute (Interpreter::Runtime& runtime)
{
InterpreterContext& context =
static_cast<InterpreterContext&> (runtime.getContext());
MWWorld::Ptr ptr = context.getReference();
runtime.push (context.hasBeenActivated (ptr));
}
2010-07-06 08:25:42 +00:00
};
2010-08-05 13:52:07 +00:00
class OpActivate : public Interpreter::Opcode0
{
public:
virtual void execute (Interpreter::Runtime& runtime)
{
InterpreterContext& context =
static_cast<InterpreterContext&> (runtime.getContext());
MWWorld::Ptr ptr = context.getReference();
context.executeActivation();
}
};
template<class R>
2010-08-30 10:30:34 +00:00
class OpLock : public Interpreter::Opcode1
{
public:
virtual void execute (Interpreter::Runtime& runtime, unsigned int arg0)
{
MWWorld::Ptr ptr = R()(runtime);
2010-08-30 10:30:34 +00:00
Interpreter::Type_Integer lockLevel = 100;
if (arg0==1)
{
lockLevel = runtime[0].mInteger;
runtime.pop();
}
MWWorld::Class::get (ptr).lock (ptr, lockLevel);
}
};
template<class R>
2010-08-30 10:30:34 +00:00
class OpUnlock : public Interpreter::Opcode0
{
public:
virtual void execute (Interpreter::Runtime& runtime)
{
MWWorld::Ptr ptr = R()(runtime);
2010-08-30 10:30:34 +00:00
MWWorld::Class::get (ptr).unlock (ptr);
}
};
class OpToggleCollisionDebug : public Interpreter::Opcode0
{
public:
virtual void execute (Interpreter::Runtime& runtime)
{
InterpreterContext& context =
static_cast<InterpreterContext&> (runtime.getContext());
bool enabled =
context.getWorld().toggleRenderMode (MWWorld::World::Render_CollisionDebug);
context.report (enabled ?
"Collsion Mesh Rendering -> On" : "Collision Mesh Rendering -> Off");
}
};
2010-08-30 10:30:34 +00:00
2010-07-05 11:15:49 +00:00
const int opcodeXBox = 0x200000c;
const int opcodeOnActivate = 0x200000d;
2010-08-05 13:52:07 +00:00
const int opcodeActivate = 0x2000075;
2010-08-30 10:30:34 +00:00
const int opcodeLock = 0x20004;
const int opcodeLockExplicit = 0x20005;
const int opcodeUnlock = 0x200008c;
const int opcodeUnlockExplicit = 0x200008d;
const int opcodeToggleCollisionDebug = 0x2000132;
2010-07-05 11:15:49 +00:00
void registerExtensions (Compiler::Extensions& extensions)
{
extensions.registerFunction ("xbox", 'l', "", opcodeXBox);
2010-07-06 08:25:42 +00:00
extensions.registerFunction ("onactivate", 'l', "", opcodeOnActivate);
2010-08-05 13:52:07 +00:00
extensions.registerInstruction ("activate", "", opcodeActivate);
2010-08-30 10:30:34 +00:00
extensions.registerInstruction ("lock", "/l", opcodeLock, opcodeLockExplicit);
extensions.registerInstruction ("unlock", "", opcodeUnlock, opcodeUnlockExplicit);
extensions.registerInstruction ("togglecollisionboxes", "", opcodeToggleCollisionDebug);
extensions.registerInstruction ("togglecollisiongrid", "", opcodeToggleCollisionDebug);
extensions.registerInstruction ("tcb", "", opcodeToggleCollisionDebug);
extensions.registerInstruction ("tcg", "", opcodeToggleCollisionDebug);
2010-07-05 11:15:49 +00:00
}
2010-07-05 11:15:49 +00:00
void installOpcodes (Interpreter::Interpreter& interpreter)
{
interpreter.installSegment5 (opcodeXBox, new OpXBox);
2010-07-06 08:25:42 +00:00
interpreter.installSegment5 (opcodeOnActivate, new OpOnActivate);
2010-08-05 13:52:07 +00:00
interpreter.installSegment5 (opcodeActivate, new OpActivate);
interpreter.installSegment3 (opcodeLock, new OpLock<ImplicitRef>);
interpreter.installSegment3 (opcodeLockExplicit, new OpLock<ExplicitRef>);
interpreter.installSegment5 (opcodeUnlock, new OpUnlock<ImplicitRef>);
interpreter.installSegment5 (opcodeUnlockExplicit, new OpUnlock<ExplicitRef>);
interpreter.installSegment5 (opcodeToggleCollisionDebug, new OpToggleCollisionDebug);
}
}
2010-07-05 11:15:49 +00:00
}