diff options
Diffstat (limited to 'indra/newview/llaudiosourcevo.cpp')
-rw-r--r-- | indra/newview/llaudiosourcevo.cpp | 129 |
1 files changed, 129 insertions, 0 deletions
diff --git a/indra/newview/llaudiosourcevo.cpp b/indra/newview/llaudiosourcevo.cpp new file mode 100644 index 0000000000..86cc1e206e --- /dev/null +++ b/indra/newview/llaudiosourcevo.cpp @@ -0,0 +1,129 @@ +/** + * @file llaudiosourcevo.cpp + * @author Douglas Soo, James Cook + * @brief Audio sources attached to viewer objects + * + * Copyright (c) 2006-$CurrentYear$, Linden Research, Inc. + * $License$ + */ + +#include "llviewerprecompiledheaders.h" + +#include "llaudiosourcevo.h" + +#include "llagent.h" +#include "llmutelist.h" +#include "llviewerparcelmgr.h" + +LLAudioSourceVO::LLAudioSourceVO(const LLUUID &sound_id, const LLUUID& owner_id, const F32 gain, LLViewerObject *objectp) +: LLAudioSource(sound_id, owner_id, gain), + mObjectp(objectp), + mActualGain(gain) +{ + setAmbient(FALSE); + updateGain(); + update(); +} + +LLAudioSourceVO::~LLAudioSourceVO() +{ + if (mObjectp) + { + mObjectp->clearAttachedSound(); + } + mObjectp = NULL; +} + +void LLAudioSourceVO::setGain(const F32 gain) +{ + mActualGain = llclamp(gain, 0.f, 1.f); + updateGain(); +} + +void LLAudioSourceVO::updateGain() +{ + if (!mObjectp) + { + return; + } + + BOOL mute = FALSE; + if (gParcelMgr) + { + LLVector3d pos_global = mObjectp->getPositionGlobal(); + if (!gParcelMgr->canHearSound(pos_global)) + { + mute = TRUE; + } + } + + if (!mute && gMuteListp) + { + if (gMuteListp->isMuted(mObjectp->getID())) + { + mute = TRUE; + } + else if (gMuteListp->isMuted(mOwnerID)) + { + mute = TRUE; + } + else if (mObjectp->isAttachment()) + { + LLViewerObject* parent = mObjectp; + while (parent + && !parent->isAvatar()) + { + parent = (LLViewerObject*)parent->getParent(); + } + if (parent + && gMuteListp->isMuted(parent->getID())) + { + mute = TRUE; + } + } + } + + if (!mute) + { + mGain = mActualGain; + } + else + { + mGain = 0.f; + } +} + + +void LLAudioSourceVO::update() +{ + if (!mObjectp) + { + return; + } + + if (mObjectp->isDead()) + { + mObjectp = NULL; + return; + } + + updateGain(); + if (mObjectp->isHUDAttachment()) + { + mPositionGlobal = gAgent.getCameraPositionGlobal(); + } + else + { + mPositionGlobal = mObjectp->getPositionGlobal(); + } + if (mObjectp->getSubParent()) + { + mVelocity = mObjectp->getSubParent()->getVelocity(); + } + else + { + mVelocity = mObjectp->getVelocity(); + } + + LLAudioSource::update(); +} |