summaryrefslogtreecommitdiff
path: root/indra/newview/llaudiosourcevo.cpp
blob: 9d83e5d80eb9b57c3a43722a1e4bb04e7f2931f4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
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, LLMute::flagObjectSounds))
		{
			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();
}