added sound manager skeleton and sound script functions
parent
f0c492ae22
commit
c12752df4d
@ -0,0 +1,76 @@
|
||||
|
||||
#include "extensions.hpp"
|
||||
|
||||
#include <components/compiler/extensions.hpp>
|
||||
|
||||
#include <components/interpreter/interpreter.hpp>
|
||||
#include <components/interpreter/runtime.hpp>
|
||||
#include <components/interpreter/opcodes.hpp>
|
||||
|
||||
#include "../mwscript/interpretercontext.hpp"
|
||||
|
||||
#include "../world.hpp"
|
||||
|
||||
namespace MWSound
|
||||
{
|
||||
namespace Script
|
||||
{
|
||||
class OpSayDone : public Interpreter::Opcode0
|
||||
{
|
||||
public:
|
||||
|
||||
virtual void execute (Interpreter::Runtime& runtime)
|
||||
{
|
||||
MWScript::InterpreterContext& context
|
||||
= static_cast<MWScript::InterpreterContext&> (runtime.getContext());
|
||||
|
||||
runtime.push (context.getWorld().getSoundManager().sayDone ("", context));
|
||||
}
|
||||
};
|
||||
|
||||
class OpGetSoundPlaying : public Interpreter::Opcode0
|
||||
{
|
||||
public:
|
||||
|
||||
virtual void execute (Interpreter::Runtime& runtime)
|
||||
{
|
||||
MWScript::InterpreterContext& context
|
||||
= static_cast<MWScript::InterpreterContext&> (runtime.getContext());
|
||||
|
||||
int index = runtime[0];
|
||||
runtime.pop();
|
||||
|
||||
runtime.push (context.getWorld().getSoundManager().getSoundPlaying (
|
||||
"", runtime.getStringLiteral (index), context));
|
||||
}
|
||||
};
|
||||
|
||||
const int opcodeSay = 0x2000001;
|
||||
const int opcodeSayDone = 0x2000002;
|
||||
const int opcodeStreamMusic = 0x2000003;
|
||||
const int opcodePlaySound = 0x2000004;
|
||||
const int opcodePlaySoundVP = 0x2000005;
|
||||
const int opcodePlaySound3D = 0x2000006;
|
||||
const int opcodePlaySound3DVP = 0x2000007;
|
||||
const int opcodeStopSound = 0x2000008;
|
||||
const int opcodeGetSoundPlaying = 0x2000009;
|
||||
}
|
||||
|
||||
// TODO opcodeSay, opcodeStreamMusic, opcodePlaySound, opcodePlaySoundVP,
|
||||
// opcodePlaySound, opcodePlaySound, opcodeStopSound
|
||||
|
||||
void registerExtensions (Compiler::Extensions& extensions)
|
||||
{
|
||||
extensions.registerFunction ("saydone", 'l', "", Script::opcodeSayDone);
|
||||
|
||||
extensions.registerFunction ("getsoundplaying", 'l', "S", Script::opcodeGetSoundPlaying);
|
||||
|
||||
}
|
||||
|
||||
void installOpcodes (Interpreter::Interpreter& interpreter)
|
||||
{
|
||||
interpreter.installSegment5 (Script::opcodeSayDone, new Script::OpSayDone);
|
||||
|
||||
interpreter.installSegment5 (Script::opcodeGetSoundPlaying, new Script::OpGetSoundPlaying);
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
#ifndef GAME_SOUND_EXTENSIONS_H
|
||||
#define GAME_SOUND_EXTENSIONS_H
|
||||
|
||||
namespace Compiler
|
||||
{
|
||||
class Extensions;
|
||||
}
|
||||
|
||||
namespace Interpreter
|
||||
{
|
||||
class Interpreter;
|
||||
}
|
||||
|
||||
namespace MWSound
|
||||
{
|
||||
// Script-extensions related to sound
|
||||
|
||||
void registerExtensions (Compiler::Extensions& extensions);
|
||||
|
||||
void installOpcodes (Interpreter::Interpreter& interpreter);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -0,0 +1,70 @@
|
||||
|
||||
#include "soundmanager.hpp"
|
||||
|
||||
#include <iostream> // TODO remove this line, once the real code is in place.
|
||||
|
||||
#include <components/interpreter/context.hpp>
|
||||
|
||||
namespace MWSound
|
||||
{
|
||||
void SoundManager::say (const std::string& handle, const std::string& filename,
|
||||
const std::string& text, Interpreter::Context& context)
|
||||
{
|
||||
std::cout << "sound effect: " << handle << " is speaking" << std::endl;
|
||||
|
||||
context.messageBox (text);
|
||||
}
|
||||
|
||||
bool SoundManager::sayDone (const std::string& handle, Interpreter::Context& context) const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void SoundManager::streamMusic (const std::string& filename, Interpreter::Context& context)
|
||||
{
|
||||
std::cout << "sound effect: playing music" << filename << std::endl;
|
||||
}
|
||||
|
||||
void SoundManager::playSound (const std::string& soundId, float volume, float pitch,
|
||||
Interpreter::Context& context)
|
||||
{
|
||||
std::cout
|
||||
<< "sound effect: playing sound " << soundId
|
||||
<< " at volume " << volume << ", at pitch " << pitch
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
void SoundManager::playSound3D (const std::string& handle, const std::string& soundId,
|
||||
float volume, float pitch, Interpreter::Context& context)
|
||||
{
|
||||
std::cout
|
||||
<< "sound effect: playing sound " << soundId
|
||||
<< " from " << handle
|
||||
<< " at volume " << volume << ", at pitch " << pitch
|
||||
<< std::endl;
|
||||
|
||||
mSounds[handle] = soundId;
|
||||
}
|
||||
|
||||
void SoundManager::stopSound3D (const std::string& handle, const std::string& soundId,
|
||||
Interpreter::Context& context)
|
||||
{
|
||||
std::cout
|
||||
<< "sound effect : stop playing sound " << soundId
|
||||
<< " from " << handle << std::endl;
|
||||
|
||||
mSounds[handle] = "";
|
||||
}
|
||||
|
||||
bool SoundManager::getSoundPlaying (const std::string& handle, const std::string& soundId,
|
||||
Interpreter::Context& context) const
|
||||
{
|
||||
std::map<std::string, std::string>::const_iterator iter = mSounds.find (handle);
|
||||
|
||||
if (iter==mSounds.end())
|
||||
return false;
|
||||
|
||||
return iter->second==soundId;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,76 @@
|
||||
#ifndef GAME_SOUND_SOUNDMANAGER_H
|
||||
#define GAME_SOUND_SOUNDMANAGER_H
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
namespace Interpreter
|
||||
{
|
||||
class Context;
|
||||
}
|
||||
|
||||
namespace MWSound
|
||||
{
|
||||
// Note to the sound implementor (can be removed once the implementation is complete):
|
||||
//
|
||||
// - the dummy implementation allows only one sound effect per object at a time. I am
|
||||
// not sure, if that is what Morrowind does. Beyond the dummy code in this class the script
|
||||
// system does not make any assumption about the number of sound effects.
|
||||
//
|
||||
// - the handle argument below is the ogre handle. Since we can assume, that all objects
|
||||
// that play a sound are in an active cell, they must have a handle. Sound script instructions
|
||||
// that reference objects not in an active cell will be taken care of long before the flow
|
||||
// of control reached this class.
|
||||
//
|
||||
// - all text-output (error messages and such) must be directed through the
|
||||
// context.messageBox interface.
|
||||
//
|
||||
// - the -> script syntax is not implemented yet ( script instructions of the type
|
||||
// npc_x -> say "file", "text"
|
||||
// aren't working)
|
||||
|
||||
class SoundManager
|
||||
{
|
||||
std::map<std::string, std::string> mSounds; // object, sound (for testing only)
|
||||
|
||||
public:
|
||||
|
||||
void say (const std::string& handle, const std::string& filename,
|
||||
const std::string& text, Interpreter::Context& context);
|
||||
///< Make an actor say some text.
|
||||
/// \param handle Handle as returned from render-subsystem
|
||||
/// \param filename name of a sound file in "Sound/Vo/" in the data directory.
|
||||
/// \param text Subtitle
|
||||
|
||||
bool sayDone (const std::string& handle, Interpreter::Context& context) const;
|
||||
///< Is actor not speaking?
|
||||
/// \param handle Handle as returned from render-subsystem
|
||||
|
||||
void streamMusic (const std::string& filename, Interpreter::Context& context);
|
||||
///< Play a soundifle
|
||||
/// \param filename name of a sound file in "Music/" in the data directory.
|
||||
|
||||
void playSound (const std::string& soundId, float volume, float pitch,
|
||||
Interpreter::Context& context);
|
||||
///< Play a sound, independently of 3D-position
|
||||
|
||||
void playSound3D (const std::string& handle, const std::string& soundId,
|
||||
float volume, float pitch, Interpreter::Context& context);
|
||||
///< Play a sound from an object
|
||||
/// \param handle Handle as returned from render-subsystem
|
||||
|
||||
void stopSound3D (const std::string& handle, const std::string& soundId,
|
||||
Interpreter::Context& context);
|
||||
///< Stop the given object from playing the given sound.
|
||||
/// \param handle Handle as returned from render-subsystem
|
||||
|
||||
bool getSoundPlaying (const std::string& handle, const std::string& soundId,
|
||||
Interpreter::Context& context) const;
|
||||
///< Is the given sound currently playing on the given object?
|
||||
/// \param handle Handle as returned from render-subsystem
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
Loading…
Reference in New Issue