forked from mirror/openmw-tes3mp
Use a set of flags instead of separate booleans
This commit is contained in:
parent
e48d125a84
commit
ae308b9b5f
17 changed files with 44 additions and 30 deletions
|
@ -56,7 +56,7 @@ namespace MWClass
|
|||
boost::shared_ptr<MWWorld::Action> Apparatus::activate (const MWWorld::Ptr& ptr,
|
||||
const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const
|
||||
{
|
||||
environment.mSoundManager->playSound3D (ptr, getUpSoundId(ptr), 1.0, 1.0, false, true);
|
||||
environment.mSoundManager->playSound3D (ptr, getUpSoundId(ptr), 1.0, 1.0, MWSound::Play_NoTrack);
|
||||
|
||||
return boost::shared_ptr<MWWorld::Action> (
|
||||
new MWWorld::ActionTake (ptr));
|
||||
|
|
|
@ -60,7 +60,7 @@ namespace MWClass
|
|||
boost::shared_ptr<MWWorld::Action> Armor::activate (const MWWorld::Ptr& ptr,
|
||||
const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const
|
||||
{
|
||||
environment.mSoundManager->playSound3D (ptr, getUpSoundId(ptr, environment), 1.0, 1.0, false, true);
|
||||
environment.mSoundManager->playSound3D (ptr, getUpSoundId(ptr, environment), 1.0, 1.0, MWSound::Play_NoTrack);
|
||||
|
||||
return boost::shared_ptr<MWWorld::Action> (
|
||||
new MWWorld::ActionTake (ptr));
|
||||
|
|
|
@ -58,7 +58,7 @@ namespace MWClass
|
|||
{
|
||||
// TODO implement reading
|
||||
|
||||
environment.mSoundManager->playSound3D (ptr, getUpSoundId(ptr, environment), 1.0, 1.0, false, true);
|
||||
environment.mSoundManager->playSound3D (ptr, getUpSoundId(ptr, environment), 1.0, 1.0, MWSound::Play_NoTrack);
|
||||
|
||||
return boost::shared_ptr<MWWorld::Action> (
|
||||
new MWWorld::ActionTake (ptr));
|
||||
|
|
|
@ -57,7 +57,7 @@ namespace MWClass
|
|||
boost::shared_ptr<MWWorld::Action> Clothing::activate (const MWWorld::Ptr& ptr,
|
||||
const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const
|
||||
{
|
||||
environment.mSoundManager->playSound3D (ptr, getUpSoundId(ptr, environment), 1.0, 1.0, false, true);
|
||||
environment.mSoundManager->playSound3D (ptr, getUpSoundId(ptr, environment), 1.0, 1.0, MWSound::Play_NoTrack);
|
||||
|
||||
return boost::shared_ptr<MWWorld::Action> (
|
||||
new MWWorld::ActionTake (ptr));
|
||||
|
|
|
@ -85,7 +85,7 @@ namespace MWClass
|
|||
{
|
||||
// TODO check for key
|
||||
std::cout << "Locked container" << std::endl;
|
||||
environment.mSoundManager->playSound3D (ptr, lockedSound, 1.0, 1.0, false);
|
||||
environment.mSoundManager->playSound3D (ptr, lockedSound, 1.0, 1.0);
|
||||
return boost::shared_ptr<MWWorld::Action> (new MWWorld::NullAction);
|
||||
}
|
||||
else
|
||||
|
@ -100,7 +100,7 @@ namespace MWClass
|
|||
{
|
||||
// Trap activation goes here
|
||||
std::cout << "Activated trap: " << ptr.getCellRef().trap << std::endl;
|
||||
environment.mSoundManager->playSound3D (ptr, trapActivationSound, 1.0, 1.0, false);
|
||||
environment.mSoundManager->playSound3D (ptr, trapActivationSound, 1.0, 1.0);
|
||||
ptr.getCellRef().trap = "";
|
||||
return boost::shared_ptr<MWWorld::Action> (new MWWorld::NullAction);
|
||||
}
|
||||
|
|
|
@ -73,7 +73,7 @@ namespace MWClass
|
|||
// TODO check for key
|
||||
// TODO report failure to player (message, sound?). Look up behaviour of original MW.
|
||||
std::cout << "Locked!" << std::endl;
|
||||
environment.mSoundManager->playSound3D (ptr, lockedSound, 1.0, 1.0, false);
|
||||
environment.mSoundManager->playSound3D (ptr, lockedSound, 1.0, 1.0);
|
||||
return boost::shared_ptr<MWWorld::Action> (new MWWorld::NullAction);
|
||||
}
|
||||
|
||||
|
@ -81,7 +81,7 @@ namespace MWClass
|
|||
{
|
||||
// Trap activation
|
||||
std::cout << "Activated trap: " << ptr.getCellRef().trap << std::endl;
|
||||
environment.mSoundManager->playSound3D(ptr, trapActivationSound, 1.0, 1.0, false);
|
||||
environment.mSoundManager->playSound3D(ptr, trapActivationSound, 1.0, 1.0);
|
||||
ptr.getCellRef().trap = "";
|
||||
return boost::shared_ptr<MWWorld::Action> (new MWWorld::NullAction);
|
||||
}
|
||||
|
@ -110,7 +110,7 @@ namespace MWClass
|
|||
// TODO return action for rotating the door
|
||||
|
||||
// This is a little pointless, but helps with testing
|
||||
environment.mSoundManager->playSound3D (ptr, openSound, 1.0, 1.0, false);
|
||||
environment.mSoundManager->playSound3D (ptr, openSound, 1.0, 1.0);
|
||||
return boost::shared_ptr<MWWorld::Action> (new MWWorld::NullAction);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,7 +54,7 @@ namespace MWClass
|
|||
boost::shared_ptr<MWWorld::Action> Ingredient::activate (const MWWorld::Ptr& ptr,
|
||||
const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const
|
||||
{
|
||||
environment.mSoundManager->playSound3D (ptr, getUpSoundId(ptr, environment), 1.0, 1.0, false, true);
|
||||
environment.mSoundManager->playSound3D (ptr, getUpSoundId(ptr, environment), 1.0, 1.0, MWSound::Play_NoTrack);
|
||||
|
||||
return boost::shared_ptr<MWWorld::Action> (
|
||||
new MWWorld::ActionTake (ptr));
|
||||
|
|
|
@ -59,7 +59,7 @@ namespace MWClass
|
|||
|
||||
if (!ref->base->sound.empty())
|
||||
{
|
||||
environment.mSoundManager->playSound3D (ptr, ref->base->sound, 1.0, 1.0, true);
|
||||
environment.mSoundManager->playSound3D (ptr, ref->base->sound, 1.0, 1.0, MWSound::Play_Loop);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -83,7 +83,7 @@ namespace MWClass
|
|||
if (!(ref->base->data.flags & ESM::Light::Carry))
|
||||
return boost::shared_ptr<MWWorld::Action> (new MWWorld::NullAction);
|
||||
|
||||
environment.mSoundManager->playSound3D (ptr, getUpSoundId(ptr, environment), 1.0, 1.0, false, true);
|
||||
environment.mSoundManager->playSound3D (ptr, getUpSoundId(ptr, environment), 1.0, 1.0, MWSound::Play_NoTrack);
|
||||
|
||||
return boost::shared_ptr<MWWorld::Action> (
|
||||
new MWWorld::ActionTake (ptr));
|
||||
|
|
|
@ -58,7 +58,7 @@ namespace MWClass
|
|||
boost::shared_ptr<MWWorld::Action> Lockpick::activate (const MWWorld::Ptr& ptr,
|
||||
const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const
|
||||
{
|
||||
environment.mSoundManager->playSound3D (ptr, getUpSoundId(ptr, environment), 1.0, 1.0, false, true);
|
||||
environment.mSoundManager->playSound3D (ptr, getUpSoundId(ptr, environment), 1.0, 1.0, MWSound::Play_NoTrack);
|
||||
|
||||
return boost::shared_ptr<MWWorld::Action> (
|
||||
new MWWorld::ActionTake (ptr));
|
||||
|
|
|
@ -56,7 +56,7 @@ namespace MWClass
|
|||
boost::shared_ptr<MWWorld::Action> Miscellaneous::activate (const MWWorld::Ptr& ptr,
|
||||
const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const
|
||||
{
|
||||
environment.mSoundManager->playSound3D (ptr, getUpSoundId(ptr, environment), 1.0, 1.0, false, true);
|
||||
environment.mSoundManager->playSound3D (ptr, getUpSoundId(ptr, environment), 1.0, 1.0, MWSound::Play_NoTrack);
|
||||
|
||||
return boost::shared_ptr<MWWorld::Action> (
|
||||
new MWWorld::ActionTake (ptr));
|
||||
|
|
|
@ -56,7 +56,7 @@ namespace MWClass
|
|||
boost::shared_ptr<MWWorld::Action> Potion::activate (const MWWorld::Ptr& ptr,
|
||||
const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const
|
||||
{
|
||||
environment.mSoundManager->playSound3D (ptr, getUpSoundId(ptr, environment), 1.0, 1.0, false, true);
|
||||
environment.mSoundManager->playSound3D (ptr, getUpSoundId(ptr, environment), 1.0, 1.0, MWSound::Play_NoTrack);
|
||||
|
||||
return boost::shared_ptr<MWWorld::Action> (
|
||||
new MWWorld::ActionTake (ptr));
|
||||
|
|
|
@ -57,7 +57,7 @@ namespace MWClass
|
|||
boost::shared_ptr<MWWorld::Action> Probe::activate (const MWWorld::Ptr& ptr,
|
||||
const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const
|
||||
{
|
||||
environment.mSoundManager->playSound3D (ptr, getUpSoundId(ptr, environment), 1.0, 1.0, false, true);
|
||||
environment.mSoundManager->playSound3D (ptr, getUpSoundId(ptr, environment), 1.0, 1.0, MWSound::Play_NoTrack);
|
||||
|
||||
return boost::shared_ptr<MWWorld::Action> (
|
||||
new MWWorld::ActionTake (ptr));
|
||||
|
|
|
@ -56,7 +56,7 @@ namespace MWClass
|
|||
boost::shared_ptr<MWWorld::Action> Repair::activate (const MWWorld::Ptr& ptr,
|
||||
const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const
|
||||
{
|
||||
environment.mSoundManager->playSound3D (ptr, getUpSoundId(ptr, environment), 1.0, 1.0, false, true);
|
||||
environment.mSoundManager->playSound3D (ptr, getUpSoundId(ptr, environment), 1.0, 1.0, MWSound::Play_NoTrack);
|
||||
|
||||
return boost::shared_ptr<MWWorld::Action> (
|
||||
new MWWorld::ActionTake (ptr));
|
||||
|
|
|
@ -57,7 +57,7 @@ namespace MWClass
|
|||
boost::shared_ptr<MWWorld::Action> Weapon::activate (const MWWorld::Ptr& ptr,
|
||||
const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const
|
||||
{
|
||||
environment.mSoundManager->playSound3D (ptr, getUpSoundId(ptr, environment), 1.0, 1.0, false, true);
|
||||
environment.mSoundManager->playSound3D (ptr, getUpSoundId(ptr, environment), 1.0, 1.0, MWSound::Play_NoTrack);
|
||||
|
||||
return boost::shared_ptr<MWWorld::Action> (
|
||||
new MWWorld::ActionTake (ptr));
|
||||
|
|
|
@ -130,7 +130,7 @@ namespace MWScript
|
|||
std::string sound = runtime.getStringLiteral (runtime[0].mInteger);
|
||||
runtime.pop();
|
||||
|
||||
context.getSoundManager().playSound3D (ptr, sound, 1.0, 1.0, mLoop);
|
||||
context.getSoundManager().playSound3D (ptr, sound, 1.0, 1.0, MWSound::Play_Single | (mLoop ? MWSound::Play_Loop : 0));
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -159,7 +159,7 @@ namespace MWScript
|
|||
Interpreter::Type_Float pitch = runtime[0].mFloat;
|
||||
runtime.pop();
|
||||
|
||||
context.getSoundManager().playSound3D (ptr, sound, volume, pitch, mLoop);
|
||||
context.getSoundManager().playSound3D (ptr, sound, volume, pitch, MWSound::Play_Single | (mLoop ? MWSound::Play_Loop : 0));
|
||||
|
||||
}
|
||||
};
|
||||
|
|
|
@ -204,7 +204,7 @@ namespace MWSound
|
|||
}
|
||||
|
||||
|
||||
SoundPtr SoundManager::playSound(const std::string& soundId, float volume, float pitch, bool loop)
|
||||
SoundPtr SoundManager::playSound(const std::string& soundId, float volume, float pitch, int mode)
|
||||
{
|
||||
SoundPtr sound;
|
||||
try
|
||||
|
@ -213,7 +213,7 @@ namespace MWSound
|
|||
float min, max;
|
||||
std::string file = lookup(soundId, basevol, min, max);
|
||||
|
||||
sound = mOutput->playSound(file, volume*basevol, pitch, loop);
|
||||
sound = mOutput->playSound(file, volume*basevol, pitch, mode&Play_Loop);
|
||||
sound->mVolume = volume;
|
||||
sound->mBaseVolume = basevol;
|
||||
sound->mMinDistance = min;
|
||||
|
@ -229,14 +229,13 @@ namespace MWSound
|
|||
}
|
||||
|
||||
SoundPtr SoundManager::playSound3D(MWWorld::Ptr ptr, const std::string& soundId,
|
||||
float volume, float pitch, bool loop,
|
||||
bool untracked)
|
||||
float volume, float pitch, int mode)
|
||||
{
|
||||
const ESM::Position &pos = ptr.getCellRef().pos;
|
||||
const Ogre::Vector3 objpos(pos.pos[0], pos.pos[1], pos.pos[2]);
|
||||
SoundPtr sound;
|
||||
|
||||
if(!untracked)
|
||||
if((mode&Play_Single))
|
||||
{
|
||||
IDSoundMap::iterator inviter = mSingleSounds.find(soundId);
|
||||
if(inviter != mSingleSounds.end())
|
||||
|
@ -256,14 +255,14 @@ namespace MWSound
|
|||
float min, max;
|
||||
std::string file = lookup(soundId, basevol, min, max);
|
||||
|
||||
sound = mOutput->playSound3D(file, objpos, volume*basevol, pitch, min, max, loop);
|
||||
sound = mOutput->playSound3D(file, objpos, volume*basevol, pitch, min, max, mode&Play_Loop);
|
||||
sound->mPos = objpos;
|
||||
sound->mVolume = volume;
|
||||
sound->mBaseVolume = basevol;
|
||||
sound->mMinDistance = min;
|
||||
sound->mMaxDistance = max;
|
||||
|
||||
if(untracked)
|
||||
if((mode&Play_NoTrack))
|
||||
mActiveSounds[sound] = std::make_pair(MWWorld::Ptr(), soundId);
|
||||
else
|
||||
{
|
||||
|
|
|
@ -30,6 +30,22 @@ namespace MWSound
|
|||
typedef boost::shared_ptr<Sound_Decoder> DecoderPtr;
|
||||
typedef boost::shared_ptr<Sound> SoundPtr;
|
||||
|
||||
enum PlayMode {
|
||||
Play_Normal = 0, /* tracked, non-looping, multi-instance, environment */
|
||||
Play_Loop = 1<<0, /* Sound will continually loop until explicitly stopped */
|
||||
Play_NoEnv = 1<<1, /* Do not apply environment effects (eg, underwater filters) */
|
||||
Play_NoTrack = 1<<2, /* (3D only) Play the sound at the given object's position
|
||||
* but do not keep it updated (the sound will not move with
|
||||
* the object and will not stop when the object is deleted. */
|
||||
Play_Single = 1<<3, /* (3D only) Play only a single instance of the given sound id.
|
||||
* Sounds not marked as Single will not count, and all but the
|
||||
* closest to the listener's position will be stopped. */
|
||||
};
|
||||
static inline int operator|(const PlayMode &a, const PlayMode &b)
|
||||
{ return (int)a | (int)b; }
|
||||
static inline int operator&(const PlayMode &a, const PlayMode &b)
|
||||
{ return (int)a & (int)b; }
|
||||
|
||||
class SoundManager
|
||||
{
|
||||
Ogre::ResourceGroupManager& mResourceMgr;
|
||||
|
@ -90,12 +106,11 @@ namespace MWSound
|
|||
bool sayDone(MWWorld::Ptr reference) const;
|
||||
///< Is actor not speaking?
|
||||
|
||||
SoundPtr playSound(const std::string& soundId, float volume, float pitch, bool loop=false);
|
||||
SoundPtr playSound(const std::string& soundId, float volume, float pitch, int mode=Play_Normal);
|
||||
///< Play a sound, independently of 3D-position
|
||||
|
||||
SoundPtr playSound3D(MWWorld::Ptr reference, const std::string& soundId,
|
||||
float volume, float pitch, bool loop,
|
||||
bool untracked=false);
|
||||
float volume, float pitch, int mode=Play_Normal);
|
||||
///< Play a sound from an object
|
||||
|
||||
void stopSound3D(MWWorld::Ptr reference, const std::string& soundId);
|
||||
|
|
Loading…
Reference in a new issue