00001
00033 #include "llviewerprecompiledheaders.h"
00034
00035 #include "llaudiosourcevo.h"
00036
00037 #include "llagent.h"
00038 #include "llmutelist.h"
00039 #include "llviewerparcelmgr.h"
00040
00041 LLAudioSourceVO::LLAudioSourceVO(const LLUUID &sound_id, const LLUUID& owner_id, const F32 gain, LLViewerObject *objectp)
00042 : LLAudioSource(sound_id, owner_id, gain),
00043 mObjectp(objectp),
00044 mActualGain(gain)
00045 {
00046 setAmbient(FALSE);
00047 updateGain();
00048 update();
00049 }
00050
00051 LLAudioSourceVO::~LLAudioSourceVO()
00052 {
00053 if (mObjectp)
00054 {
00055 mObjectp->clearAttachedSound();
00056 }
00057 mObjectp = NULL;
00058 }
00059
00060 void LLAudioSourceVO::setGain(const F32 gain)
00061 {
00062 mActualGain = llclamp(gain, 0.f, 1.f);
00063 updateGain();
00064 }
00065
00066 void LLAudioSourceVO::updateGain()
00067 {
00068 if (!mObjectp)
00069 {
00070 return;
00071 }
00072
00073 BOOL mute = FALSE;
00074 if (gParcelMgr)
00075 {
00076 LLVector3d pos_global;
00077
00078 if (mObjectp->isAttachment())
00079 {
00080 LLViewerObject* parent = mObjectp;
00081 while (parent
00082 && !parent->isAvatar())
00083 {
00084 parent = (LLViewerObject*)parent->getParent();
00085 }
00086 if (parent)
00087 pos_global = parent->getPositionGlobal();
00088 }
00089
00090 else
00091 pos_global = mObjectp->getPositionGlobal();
00092
00093 if (!gParcelMgr->canHearSound(pos_global))
00094 {
00095 mute = TRUE;
00096 }
00097 }
00098
00099 if (!mute && gMuteListp)
00100 {
00101 if (gMuteListp->isMuted(mObjectp->getID()))
00102 {
00103 mute = TRUE;
00104 }
00105 else if (gMuteListp->isMuted(mOwnerID, LLMute::flagObjectSounds))
00106 {
00107 mute = TRUE;
00108 }
00109 else if (mObjectp->isAttachment())
00110 {
00111 LLViewerObject* parent = mObjectp;
00112 while (parent
00113 && !parent->isAvatar())
00114 {
00115 parent = (LLViewerObject*)parent->getParent();
00116 }
00117 if (parent
00118 && gMuteListp->isMuted(parent->getID()))
00119 {
00120 mute = TRUE;
00121 }
00122 }
00123 }
00124
00125 if (!mute)
00126 {
00127 mGain = mActualGain;
00128 }
00129 else
00130 {
00131 mGain = 0.f;
00132 }
00133 }
00134
00135
00136 void LLAudioSourceVO::update()
00137 {
00138 if (!mObjectp)
00139 {
00140 return;
00141 }
00142
00143 if (mObjectp->isDead())
00144 {
00145 mObjectp = NULL;
00146 return;
00147 }
00148
00149 updateGain();
00150 if (mObjectp->isHUDAttachment())
00151 {
00152 mPositionGlobal = gAgent.getCameraPositionGlobal();
00153 }
00154 else
00155 {
00156 mPositionGlobal = mObjectp->getPositionGlobal();
00157 }
00158 if (mObjectp->getSubParent())
00159 {
00160 mVelocity = mObjectp->getSubParent()->getVelocity();
00161 }
00162 else
00163 {
00164 mVelocity = mObjectp->getVelocity();
00165 }
00166
00167 LLAudioSource::update();
00168 }