2011-11-21 14:08:44 +01:00
|
|
|
#include "animationextensions.hpp"
|
|
|
|
|
2015-01-31 23:27:34 +01:00
|
|
|
#include <limits>
|
2011-11-21 14:08:44 +01:00
|
|
|
#include <stdexcept>
|
|
|
|
|
2013-08-06 20:38:41 -04:00
|
|
|
#include <components/compiler/opcodes.hpp>
|
2011-11-21 14:08:44 +01:00
|
|
|
|
|
|
|
#include <components/interpreter/interpreter.hpp>
|
|
|
|
#include <components/interpreter/opcodes.hpp>
|
|
|
|
#include <components/interpreter/runtime.hpp>
|
|
|
|
|
2015-02-09 17:45:48 +01:00
|
|
|
#include "../mwbase/environment.hpp"
|
2013-01-16 17:53:18 -08:00
|
|
|
#include "../mwbase/mechanicsmanager.hpp"
|
2011-11-21 14:08:44 +01:00
|
|
|
|
|
|
|
#include "ref.hpp"
|
|
|
|
|
|
|
|
namespace MWScript
|
|
|
|
{
|
|
|
|
namespace Animation
|
|
|
|
{
|
|
|
|
template <class R>
|
|
|
|
class OpSkipAnim : public Interpreter::Opcode0
|
|
|
|
{
|
|
|
|
public:
|
2020-10-16 22:18:54 +04:00
|
|
|
void execute(Interpreter::Runtime& runtime) override
|
2022-09-22 21:26:05 +03:00
|
|
|
{
|
2011-11-21 14:08:44 +01:00
|
|
|
MWWorld::Ptr ptr = R()(runtime);
|
|
|
|
|
2013-01-16 17:53:18 -08:00
|
|
|
MWBase::Environment::get().getMechanicsManager()->skipAnimation(ptr);
|
2011-11-21 14:08:44 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class R>
|
|
|
|
class OpPlayAnim : public Interpreter::Opcode1
|
|
|
|
{
|
|
|
|
public:
|
2020-10-16 22:18:54 +04:00
|
|
|
void execute(Interpreter::Runtime& runtime, unsigned int arg0) override
|
2011-11-21 14:08:44 +01:00
|
|
|
{
|
|
|
|
MWWorld::Ptr ptr = R()(runtime);
|
|
|
|
|
2017-04-21 23:22:55 +09:00
|
|
|
if (!ptr.getRefData().isEnabled())
|
|
|
|
return;
|
|
|
|
|
2022-05-21 01:21:55 +02:00
|
|
|
std::string_view group = runtime.getStringLiteral(runtime[0].mInteger);
|
2011-11-21 14:08:44 +01:00
|
|
|
runtime.pop();
|
|
|
|
|
|
|
|
Interpreter::Type_Integer mode = 0;
|
|
|
|
|
|
|
|
if (arg0 == 1)
|
|
|
|
{
|
|
|
|
mode = runtime[0].mInteger;
|
|
|
|
runtime.pop();
|
|
|
|
|
|
|
|
if (mode < 0 || mode > 2)
|
|
|
|
throw std::runtime_error("animation mode out of range");
|
|
|
|
}
|
|
|
|
|
2022-08-23 18:25:25 +02:00
|
|
|
MWBase::Environment::get().getMechanicsManager()->playAnimationGroup(
|
2024-01-27 18:57:51 +01:00
|
|
|
ptr, group, mode, std::numeric_limits<uint32_t>::max(), true);
|
2011-11-21 14:08:44 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class R>
|
|
|
|
class OpLoopAnim : public Interpreter::Opcode1
|
|
|
|
{
|
|
|
|
public:
|
2020-10-16 22:18:54 +04:00
|
|
|
void execute(Interpreter::Runtime& runtime, unsigned int arg0) override
|
2011-11-21 14:08:44 +01:00
|
|
|
{
|
|
|
|
MWWorld::Ptr ptr = R()(runtime);
|
|
|
|
|
2017-04-21 23:22:55 +09:00
|
|
|
if (!ptr.getRefData().isEnabled())
|
|
|
|
return;
|
|
|
|
|
2022-05-21 01:21:55 +02:00
|
|
|
std::string_view group = runtime.getStringLiteral(runtime[0].mInteger);
|
2011-11-21 14:08:44 +01:00
|
|
|
runtime.pop();
|
|
|
|
|
|
|
|
Interpreter::Type_Integer loops = runtime[0].mInteger;
|
|
|
|
runtime.pop();
|
|
|
|
|
|
|
|
if (loops < 0)
|
|
|
|
throw std::runtime_error("number of animation loops must be non-negative");
|
|
|
|
|
|
|
|
Interpreter::Type_Integer mode = 0;
|
|
|
|
|
|
|
|
if (arg0 == 1)
|
|
|
|
{
|
|
|
|
mode = runtime[0].mInteger;
|
|
|
|
runtime.pop();
|
|
|
|
|
|
|
|
if (mode < 0 || mode > 2)
|
|
|
|
throw std::runtime_error("animation mode out of range");
|
|
|
|
}
|
|
|
|
|
2023-12-05 14:13:35 +00:00
|
|
|
MWBase::Environment::get().getMechanicsManager()->playAnimationGroup(ptr, group, mode, loops, true);
|
2011-11-21 14:08:44 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
void installOpcodes(Interpreter::Interpreter& interpreter)
|
|
|
|
{
|
2022-01-27 19:18:57 +00:00
|
|
|
interpreter.installSegment5<OpSkipAnim<ImplicitRef>>(Compiler::Animation::opcodeSkipAnim);
|
|
|
|
interpreter.installSegment5<OpSkipAnim<ExplicitRef>>(Compiler::Animation::opcodeSkipAnimExplicit);
|
|
|
|
interpreter.installSegment3<OpPlayAnim<ImplicitRef>>(Compiler::Animation::opcodePlayAnim);
|
|
|
|
interpreter.installSegment3<OpPlayAnim<ExplicitRef>>(Compiler::Animation::opcodePlayAnimExplicit);
|
|
|
|
interpreter.installSegment3<OpLoopAnim<ImplicitRef>>(Compiler::Animation::opcodeLoopAnim);
|
|
|
|
interpreter.installSegment3<OpLoopAnim<ExplicitRef>>(Compiler::Animation::opcodeLoopAnimExplicit);
|
2011-11-21 14:08:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|