PageRenderTime 322ms CodeModel.GetById 121ms app.highlight 12ms RepoModel.GetById 129ms app.codeStats 0ms

/indra/newview/llaudiosourcevo.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 176 lines | 126 code | 18 blank | 32 comment | 27 complexity | 98905039195ab10a30815accd3cf389b MD5 | raw file
  1/** 
  2 * @file llaudiosourcevo.cpp
  3 * @author Douglas Soo, James Cook
  4 * @brief Audio sources attached to viewer objects
  5 *
  6 * $LicenseInfo:firstyear=2006&license=viewerlgpl$
  7 * Second Life Viewer Source Code
  8 * Copyright (C) 2010, Linden Research, Inc.
  9 * 
 10 * This library is free software; you can redistribute it and/or
 11 * modify it under the terms of the GNU Lesser General Public
 12 * License as published by the Free Software Foundation;
 13 * version 2.1 of the License only.
 14 * 
 15 * This library is distributed in the hope that it will be useful,
 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 18 * Lesser General Public License for more details.
 19 * 
 20 * You should have received a copy of the GNU Lesser General Public
 21 * License along with this library; if not, write to the Free Software
 22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 23 * 
 24 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 25 * $/LicenseInfo$
 26 */
 27
 28#include "llviewerprecompiledheaders.h"
 29
 30#include "llaudiosourcevo.h"
 31
 32#include "llagentcamera.h"
 33#include "llmutelist.h"
 34#include "llviewerparcelmgr.h"
 35
 36LLAudioSourceVO::LLAudioSourceVO(const LLUUID &sound_id, const LLUUID& owner_id, const F32 gain, LLViewerObject *objectp)
 37	:	LLAudioSource(sound_id, owner_id, gain, LLAudioEngine::AUDIO_TYPE_SFX), 
 38	mObjectp(objectp)
 39{
 40	update();
 41}
 42
 43LLAudioSourceVO::~LLAudioSourceVO()
 44{
 45	if (mObjectp)
 46	{
 47		mObjectp->clearAttachedSound();
 48	}
 49	mObjectp = NULL;
 50}
 51
 52void LLAudioSourceVO::setGain(const F32 gain)
 53{
 54	mGain = llclamp(gain, 0.f, 1.f);
 55}
 56
 57void LLAudioSourceVO::updateMute()
 58{
 59	if (!mObjectp || mObjectp->isDead())
 60	{
 61	  	mSourceMuted = true;
 62		return;
 63	}
 64
 65	bool mute = false;
 66	LLVector3d pos_global;
 67
 68	if (mObjectp->isAttachment())
 69	{
 70		LLViewerObject* parent = mObjectp;
 71		while (parent && !parent->isAvatar())
 72		{
 73			parent = (LLViewerObject*)parent->getParent();
 74		}
 75		if (parent)
 76		{
 77			pos_global = parent->getPositionGlobal();
 78		}
 79	}
 80	else
 81	{
 82		pos_global = mObjectp->getPositionGlobal();
 83	}
 84
 85	if (!LLViewerParcelMgr::getInstance()->canHearSound(pos_global))
 86	{
 87		mute = true;
 88	}
 89
 90	if (!mute)
 91	{
 92		if (LLMuteList::getInstance()->isMuted(mObjectp->getID()))
 93		{
 94			mute = true;
 95		}
 96		else if (LLMuteList::getInstance()->isMuted(mOwnerID, LLMute::flagObjectSounds))
 97		{
 98			mute = true;
 99		}
100		else if (mObjectp->isAttachment())
101		{
102			LLViewerObject* parent = mObjectp;
103			while (parent && !parent->isAvatar())
104			{
105				parent = (LLViewerObject*)parent->getParent();
106			}
107			if (parent 
108				&& LLMuteList::getInstance()->isMuted(parent->getID()))
109			{
110				mute = true;
111			}
112		}
113	}
114
115	if (mute != mSourceMuted)
116	{
117		mSourceMuted = mute;
118		if (mSourceMuted)
119		{
120		  	// Stop the sound.
121			this->play(LLUUID::null);
122		}
123		else
124		{
125		  	// Muted sounds keep there data at all times, because
126			// it's the place where the audio UUID is stored.
127			// However, it's possible that mCurrentDatap is
128			// NULL when this source did only preload sounds.
129			if (mCurrentDatap)
130			{
131		  		// Restart the sound.
132				this->play(mCurrentDatap->getID());
133			}
134		}
135	}
136}
137
138void LLAudioSourceVO::update()
139{
140	updateMute();
141
142	if (!mObjectp)
143	{
144		return;
145	}
146
147	if (mObjectp->isDead())
148	{
149		mObjectp = NULL;
150		return;
151	}
152
153	if (mSourceMuted)
154	{
155	  	return;
156	}
157
158	if (mObjectp->isHUDAttachment())
159	{
160		mPositionGlobal = gAgentCamera.getCameraPositionGlobal();
161	}
162	else
163	{
164		mPositionGlobal = mObjectp->getPositionGlobal();
165	}
166	if (mObjectp->getSubParent())
167	{
168		mVelocity = mObjectp->getSubParent()->getVelocity();
169	}
170	else
171	{
172		mVelocity = mObjectp->getVelocity();
173	}
174
175	LLAudioSource::update();
176}