llaudiosourcevo.cpp

Go to the documentation of this file.
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         LLVector3d pos_global;
00075 
00076         if (mObjectp->isAttachment())
00077         {
00078                 LLViewerObject* parent = mObjectp;
00079                 while (parent && !parent->isAvatar())
00080                 {
00081                         parent = (LLViewerObject*)parent->getParent();
00082                 }
00083                 if (parent)
00084                 {
00085                         pos_global = parent->getPositionGlobal();
00086                 }
00087         }
00088         else
00089         {
00090                 pos_global = mObjectp->getPositionGlobal();
00091         }
00092         
00093         if (!LLViewerParcelMgr::getInstance()->canHearSound(pos_global))
00094         {
00095                 mute = TRUE;
00096         }
00097 
00098         if (!mute)
00099         {
00100                 if (LLMuteList::getInstance()->isMuted(mObjectp->getID()))
00101                 {
00102                         mute = TRUE;
00103                 }
00104                 else if (LLMuteList::getInstance()->isMuted(mOwnerID, LLMute::flagObjectSounds))
00105                 {
00106                         mute = TRUE;
00107                 }
00108                 else if (mObjectp->isAttachment())
00109                 {
00110                         LLViewerObject* parent = mObjectp;
00111                         while (parent && !parent->isAvatar())
00112                         {
00113                                 parent = (LLViewerObject*)parent->getParent();
00114                         }
00115                         if (parent 
00116                                 && LLMuteList::getInstance()->isMuted(parent->getID()))
00117                         {
00118                                 mute = TRUE;
00119                         }
00120                 }
00121         }
00122 
00123         if (!mute)
00124         {
00125                 mGain = mActualGain;
00126         }
00127         else
00128         {
00129                 mGain = 0.f;
00130         }
00131 }
00132 
00133 
00134 void LLAudioSourceVO::update()
00135 {
00136         if (!mObjectp)
00137         {
00138                 return;
00139         }
00140 
00141         if (mObjectp->isDead())
00142         {
00143                 mObjectp = NULL;
00144                 return;
00145         }
00146 
00147         updateGain();
00148         if (mObjectp->isHUDAttachment())
00149         {
00150                 mPositionGlobal = gAgent.getCameraPositionGlobal();
00151         }
00152         else
00153         {
00154                 mPositionGlobal = mObjectp->getPositionGlobal();
00155         }
00156         if (mObjectp->getSubParent())
00157         {
00158                 mVelocity = mObjectp->getSubParent()->getVelocity();
00159         }
00160         else
00161         {
00162                 mVelocity = mObjectp->getVelocity();
00163         }
00164 
00165         LLAudioSource::update();
00166 }

Generated on Fri May 16 08:33:15 2008 for SecondLife by  doxygen 1.5.5