2019-02-22 23:16:47 +04:00
|
|
|
#include "soundextensions.hpp"
|
2010-07-03 15:04:00 +02:00
|
|
|
|
2013-08-06 20:38:41 -04:00
|
|
|
#include <components/compiler/opcodes.hpp>
|
2010-07-03 15:04:00 +02:00
|
|
|
|
|
|
|
#include <components/interpreter/interpreter.hpp>
|
|
|
|
#include <components/interpreter/opcodes.hpp>
|
|
|
|
#include <components/interpreter/runtime.hpp>
|
|
|
|
|
2012-04-23 15:27:03 +02:00
|
|
|
#include "../mwbase/environment.hpp"
|
2012-08-09 14:33:21 +02:00
|
|
|
#include "../mwbase/soundmanager.hpp"
|
2012-08-29 11:15:17 +02:00
|
|
|
#include "../mwbase/windowmanager.hpp"
|
2012-07-03 12:30:50 +02:00
|
|
|
#include "../mwbase/world.hpp"
|
2010-07-03 15:17:02 +02:00
|
|
|
|
2017-03-07 19:00:09 +01:00
|
|
|
#include "../mwworld/class.hpp"
|
|
|
|
#include "../mwworld/inventorystore.hpp"
|
|
|
|
|
2010-12-31 19:09:25 +01:00
|
|
|
#include "interpretercontext.hpp"
|
|
|
|
#include "ref.hpp"
|
|
|
|
|
2010-07-10 11:48:05 +02:00
|
|
|
namespace MWScript
|
2010-07-03 15:04:00 +02:00
|
|
|
{
|
2010-07-10 11:48:05 +02:00
|
|
|
namespace Sound
|
2010-07-03 15:04:00 +02:00
|
|
|
{
|
2010-12-31 19:09:25 +01:00
|
|
|
template <class R>
|
2010-07-03 20:35:59 +02:00
|
|
|
class OpSay : public Interpreter::Opcode0
|
|
|
|
{
|
|
|
|
public:
|
2020-10-16 22:18:54 +04:00
|
|
|
void execute(Interpreter::Runtime& runtime) override
|
2010-07-03 20:35:59 +02:00
|
|
|
{
|
2010-12-31 19:09:25 +01:00
|
|
|
MWWorld::Ptr ptr = R()(runtime);
|
|
|
|
|
2010-07-03 20:35:59 +02:00
|
|
|
MWScript::InterpreterContext& context
|
|
|
|
= static_cast<MWScript::InterpreterContext&>(runtime.getContext());
|
2010-08-12 16:29:22 +02:00
|
|
|
|
2022-05-22 09:29:03 +02:00
|
|
|
std::string file{ runtime.getStringLiteral(runtime[0].mInteger) };
|
2010-07-03 20:35:59 +02:00
|
|
|
runtime.pop();
|
|
|
|
|
2022-08-23 22:14:27 +02:00
|
|
|
std::string_view text = runtime.getStringLiteral(runtime[0].mInteger);
|
2010-07-03 20:35:59 +02:00
|
|
|
runtime.pop();
|
2010-08-12 16:29:22 +02:00
|
|
|
|
2022-05-22 09:29:03 +02:00
|
|
|
MWBase::Environment::get().getSoundManager()->say(ptr, file);
|
2012-08-29 11:15:17 +02:00
|
|
|
|
|
|
|
if (MWBase::Environment::get().getWindowManager()->getSubtitlesEnabled())
|
2022-05-22 09:29:03 +02:00
|
|
|
context.messageBox(text);
|
2010-12-31 19:09:25 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class R>
|
2010-07-03 15:04:00 +02:00
|
|
|
class OpSayDone : public Interpreter::Opcode0
|
|
|
|
{
|
|
|
|
public:
|
2020-10-16 22:18:54 +04:00
|
|
|
void execute(Interpreter::Runtime& runtime) override
|
2010-07-03 15:04:00 +02:00
|
|
|
{
|
2010-12-31 19:09:25 +01:00
|
|
|
MWWorld::Ptr ptr = R()(runtime);
|
|
|
|
|
2012-04-23 15:27:03 +02:00
|
|
|
runtime.push(MWBase::Environment::get().getSoundManager()->sayDone(ptr));
|
2010-12-31 19:09:25 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-07-03 20:35:59 +02:00
|
|
|
class OpStreamMusic : public Interpreter::Opcode0
|
|
|
|
{
|
|
|
|
public:
|
2020-10-16 22:18:54 +04:00
|
|
|
void execute(Interpreter::Runtime& runtime) override
|
2010-07-03 20:35:59 +02:00
|
|
|
{
|
2022-05-22 09:29:03 +02:00
|
|
|
std::string sound{ runtime.getStringLiteral(runtime[0].mInteger) };
|
2010-07-03 20:35:59 +02:00
|
|
|
runtime.pop();
|
2022-09-22 21:26:05 +03:00
|
|
|
|
2022-05-22 09:29:03 +02:00
|
|
|
MWBase::Environment::get().getSoundManager()->streamMusic(sound);
|
2010-12-31 19:09:25 +01:00
|
|
|
}
|
|
|
|
};
|
2010-07-03 20:35:59 +02:00
|
|
|
|
|
|
|
class OpPlaySound : public Interpreter::Opcode0
|
|
|
|
{
|
|
|
|
public:
|
2020-10-16 22:18:54 +04:00
|
|
|
void execute(Interpreter::Runtime& runtime) override
|
2010-07-03 20:35:59 +02:00
|
|
|
{
|
2022-05-21 01:21:55 +02:00
|
|
|
std::string_view sound = runtime.getStringLiteral(runtime[0].mInteger);
|
2010-07-03 20:35:59 +02:00
|
|
|
runtime.pop();
|
2022-09-22 21:26:05 +03:00
|
|
|
|
2017-09-15 01:03:41 -07:00
|
|
|
MWBase::Environment::get().getSoundManager()->playSound(
|
|
|
|
sound, 1.0, 1.0, MWSound::Type::Sfx, MWSound::PlayMode::NoEnv);
|
2010-12-31 19:09:25 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-07-03 20:35:59 +02:00
|
|
|
class OpPlaySoundVP : 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
|
|
|
{
|
2022-05-21 01:21:55 +02:00
|
|
|
std::string_view sound = runtime.getStringLiteral(runtime[0].mInteger);
|
2010-07-03 20:35:59 +02:00
|
|
|
runtime.pop();
|
2010-12-31 19:09:25 +01:00
|
|
|
|
2010-07-14 15:28:55 +02:00
|
|
|
Interpreter::Type_Float volume = runtime[0].mFloat;
|
2010-07-03 20:35:59 +02:00
|
|
|
runtime.pop();
|
|
|
|
|
2010-07-14 15:28:55 +02:00
|
|
|
Interpreter::Type_Float pitch = runtime[0].mFloat;
|
2010-07-03 20:35:59 +02:00
|
|
|
runtime.pop();
|
2010-12-31 19:09:25 +01:00
|
|
|
|
2017-09-15 01:03:41 -07:00
|
|
|
MWBase::Environment::get().getSoundManager()->playSound(
|
|
|
|
sound, volume, pitch, MWSound::Type::Sfx, MWSound::PlayMode::NoEnv);
|
2010-12-31 19:09:25 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-01-27 19:18:57 +00:00
|
|
|
template <class R, bool TLoop>
|
2010-07-03 20:35:59 +02:00
|
|
|
class OpPlaySound3D : public Interpreter::Opcode0
|
|
|
|
{
|
|
|
|
public:
|
2020-10-16 22:18:54 +04:00
|
|
|
void execute(Interpreter::Runtime& runtime) override
|
2010-07-03 20:35:59 +02:00
|
|
|
{
|
2010-12-31 19:09:25 +01:00
|
|
|
MWWorld::Ptr ptr = R()(runtime);
|
|
|
|
|
2022-05-21 01:21:55 +02:00
|
|
|
std::string_view sound = runtime.getStringLiteral(runtime[0].mInteger);
|
2010-07-03 20:35:59 +02:00
|
|
|
runtime.pop();
|
2010-12-31 19:09:25 +01:00
|
|
|
|
2013-07-18 19:01:13 -07:00
|
|
|
MWBase::Environment::get().getSoundManager()->playSound3D(ptr, sound, 1.0, 1.0, MWSound::Type::Sfx,
|
2022-01-27 19:18:57 +00:00
|
|
|
TLoop ? MWSound::PlayMode::LoopRemoveAtDistance : MWSound::PlayMode::Normal);
|
2010-12-31 19:09:25 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-01-27 19:18:57 +00:00
|
|
|
template <class R, bool TLoop>
|
2010-07-03 20:35:59 +02:00
|
|
|
class OpPlaySoundVP3D : public Interpreter::Opcode0
|
|
|
|
{
|
|
|
|
public:
|
2020-10-16 22:18:54 +04:00
|
|
|
void execute(Interpreter::Runtime& runtime) override
|
2010-07-03 20:35:59 +02:00
|
|
|
{
|
2010-12-31 19:09:25 +01:00
|
|
|
MWWorld::Ptr ptr = R()(runtime);
|
|
|
|
|
2022-05-21 01:21:55 +02:00
|
|
|
std::string_view sound = runtime.getStringLiteral(runtime[0].mInteger);
|
2010-07-03 20:35:59 +02:00
|
|
|
runtime.pop();
|
2010-12-31 19:09:25 +01:00
|
|
|
|
2010-07-14 15:28:55 +02:00
|
|
|
Interpreter::Type_Float volume = runtime[0].mFloat;
|
2010-07-03 20:35:59 +02:00
|
|
|
runtime.pop();
|
|
|
|
|
2010-07-14 15:28:55 +02:00
|
|
|
Interpreter::Type_Float pitch = runtime[0].mFloat;
|
2010-07-03 20:35:59 +02:00
|
|
|
runtime.pop();
|
|
|
|
|
2013-07-18 19:01:13 -07:00
|
|
|
MWBase::Environment::get().getSoundManager()->playSound3D(ptr, sound, volume, pitch, MWSound::Type::Sfx,
|
2022-01-27 19:18:57 +00:00
|
|
|
TLoop ? MWSound::PlayMode::LoopRemoveAtDistance : MWSound::PlayMode::Normal);
|
2010-12-31 19:09:25 +01:00
|
|
|
}
|
2010-07-03 15:04:00 +02:00
|
|
|
};
|
2010-07-10 12:24:41 +02:00
|
|
|
|
2010-12-31 19:09:25 +01:00
|
|
|
template <class R>
|
|
|
|
class OpStopSound : public Interpreter::Opcode0
|
2010-07-10 12:24:41 +02:00
|
|
|
{
|
|
|
|
public:
|
2020-10-16 22:18:54 +04:00
|
|
|
void execute(Interpreter::Runtime& runtime) override
|
2022-09-22 21:26:05 +03:00
|
|
|
{
|
2010-12-31 19:09:25 +01:00
|
|
|
MWWorld::Ptr ptr = R()(runtime);
|
2010-07-10 12:24:41 +02:00
|
|
|
|
2022-05-21 01:21:55 +02:00
|
|
|
std::string_view sound = runtime.getStringLiteral(runtime[0].mInteger);
|
2010-07-10 12:24:41 +02:00
|
|
|
runtime.pop();
|
|
|
|
|
2012-04-23 15:27:03 +02:00
|
|
|
MWBase::Environment::get().getSoundManager()->stopSound3D(ptr, sound);
|
2010-12-31 19:09:25 +01:00
|
|
|
}
|
|
|
|
};
|
2010-07-10 12:24:41 +02:00
|
|
|
|
2010-12-31 19:09:25 +01:00
|
|
|
template <class R>
|
|
|
|
class OpGetSoundPlaying : public Interpreter::Opcode0
|
2010-07-10 12:24:41 +02:00
|
|
|
{
|
|
|
|
public:
|
2020-10-16 22:18:54 +04:00
|
|
|
void execute(Interpreter::Runtime& runtime) override
|
2022-09-22 21:26:05 +03:00
|
|
|
{
|
2010-12-31 19:09:25 +01:00
|
|
|
MWWorld::Ptr ptr = R()(runtime);
|
2010-07-10 12:24:41 +02:00
|
|
|
|
2020-10-16 22:18:54 +04:00
|
|
|
int index = runtime[0].mInteger;
|
2010-12-31 19:09:25 +01:00
|
|
|
runtime.pop();
|
|
|
|
|
2010-07-14 15:28:55 +02:00
|
|
|
bool ret = MWBase::Environment::get().getSoundManager()->getSoundPlaying(
|
|
|
|
ptr, runtime.getStringLiteral(index));
|
2010-12-31 19:09:25 +01:00
|
|
|
|
2017-03-07 19:00:09 +01:00
|
|
|
// GetSoundPlaying called on an equipped item should also look for sounds played by the equipping actor.
|
|
|
|
if (!ret && ptr.getContainerStore())
|
2022-09-22 21:26:05 +03:00
|
|
|
{
|
2017-03-07 19:00:09 +01:00
|
|
|
MWWorld::Ptr cont = MWBase::Environment::get().getWorld()->findContainer(ptr);
|
|
|
|
|
|
|
|
if (!cont.isEmpty() && cont.getClass().hasInventoryStore(cont)
|
|
|
|
&& cont.getClass().getInventoryStore(cont).isEquipped(ptr))
|
|
|
|
{
|
|
|
|
ret = MWBase::Environment::get().getSoundManager()->getSoundPlaying(
|
|
|
|
cont, runtime.getStringLiteral(index));
|
|
|
|
}
|
2010-12-31 19:09:25 +01:00
|
|
|
}
|
|
|
|
|
2017-03-07 19:00:09 +01:00
|
|
|
runtime.push(ret);
|
2022-09-22 21:26:05 +03:00
|
|
|
}
|
|
|
|
};
|
2010-12-31 19:09:25 +01:00
|
|
|
|
2022-01-27 19:18:57 +00:00
|
|
|
void installOpcodes(Interpreter::Interpreter& interpreter)
|
2010-07-10 11:48:05 +02:00
|
|
|
{
|
2022-01-27 19:18:57 +00:00
|
|
|
interpreter.installSegment5<OpSay<ImplicitRef>>(Compiler::Sound::opcodeSay);
|
|
|
|
interpreter.installSegment5<OpSayDone<ImplicitRef>>(Compiler::Sound::opcodeSayDone);
|
|
|
|
interpreter.installSegment5<OpStreamMusic>(Compiler::Sound::opcodeStreamMusic);
|
|
|
|
interpreter.installSegment5<OpPlaySound>(Compiler::Sound::opcodePlaySound);
|
|
|
|
interpreter.installSegment5<OpPlaySoundVP>(Compiler::Sound::opcodePlaySoundVP);
|
|
|
|
interpreter.installSegment5<OpPlaySound3D<ImplicitRef, false>>(Compiler::Sound::opcodePlaySound3D);
|
|
|
|
interpreter.installSegment5<OpPlaySoundVP3D<ImplicitRef, false>>(Compiler::Sound::opcodePlaySound3DVP);
|
|
|
|
interpreter.installSegment5<OpPlaySound3D<ImplicitRef, true>>(Compiler::Sound::opcodePlayLoopSound3D);
|
|
|
|
interpreter.installSegment5<OpPlaySoundVP3D<ImplicitRef, true>>(Compiler::Sound::opcodePlayLoopSound3DVP);
|
|
|
|
interpreter.installSegment5<OpStopSound<ImplicitRef>>(Compiler::Sound::opcodeStopSound);
|
|
|
|
interpreter.installSegment5<OpGetSoundPlaying<ImplicitRef>>(Compiler::Sound::opcodeGetSoundPlaying);
|
|
|
|
|
|
|
|
interpreter.installSegment5<OpSay<ExplicitRef>>(Compiler::Sound::opcodeSayExplicit);
|
|
|
|
interpreter.installSegment5<OpSayDone<ExplicitRef>>(Compiler::Sound::opcodeSayDoneExplicit);
|
|
|
|
interpreter.installSegment5<OpPlaySound3D<ExplicitRef, false>>(Compiler::Sound::opcodePlaySound3DExplicit);
|
|
|
|
interpreter.installSegment5<OpPlaySoundVP3D<ExplicitRef, false>>(
|
|
|
|
Compiler::Sound::opcodePlaySound3DVPExplicit);
|
|
|
|
interpreter.installSegment5<OpPlaySound3D<ExplicitRef, true>>(
|
|
|
|
Compiler::Sound::opcodePlayLoopSound3DExplicit);
|
|
|
|
interpreter.installSegment5<OpPlaySoundVP3D<ExplicitRef, true>>(
|
|
|
|
Compiler::Sound::opcodePlayLoopSound3DVPExplicit);
|
|
|
|
interpreter.installSegment5<OpStopSound<ExplicitRef>>(Compiler::Sound::opcodeStopSoundExplicit);
|
|
|
|
interpreter.installSegment5<OpGetSoundPlaying<ExplicitRef>>(Compiler::Sound::opcodeGetSoundPlayingExplicit);
|
2010-07-10 11:48:05 +02:00
|
|
|
}
|
2010-12-31 19:09:25 +01:00
|
|
|
}
|
2010-07-03 15:04:00 +02:00
|
|
|
}
|