PageRenderTime 34ms CodeModel.GetById 18ms RepoModel.GetById 1ms 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
Possible License(s): LGPL-2.1
  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. #include "llviewerprecompiledheaders.h"
  28. #include "llaudiosourcevo.h"
  29. #include "llagentcamera.h"
  30. #include "llmutelist.h"
  31. #include "llviewerparcelmgr.h"
  32. LLAudioSourceVO::LLAudioSourceVO(const LLUUID &sound_id, const LLUUID& owner_id, const F32 gain, LLViewerObject *objectp)
  33. : LLAudioSource(sound_id, owner_id, gain, LLAudioEngine::AUDIO_TYPE_SFX),
  34. mObjectp(objectp)
  35. {
  36. update();
  37. }
  38. LLAudioSourceVO::~LLAudioSourceVO()
  39. {
  40. if (mObjectp)
  41. {
  42. mObjectp->clearAttachedSound();
  43. }
  44. mObjectp = NULL;
  45. }
  46. void LLAudioSourceVO::setGain(const F32 gain)
  47. {
  48. mGain = llclamp(gain, 0.f, 1.f);
  49. }
  50. void LLAudioSourceVO::updateMute()
  51. {
  52. if (!mObjectp || mObjectp->isDead())
  53. {
  54. mSourceMuted = true;
  55. return;
  56. }
  57. bool mute = false;
  58. LLVector3d pos_global;
  59. if (mObjectp->isAttachment())
  60. {
  61. LLViewerObject* parent = mObjectp;
  62. while (parent && !parent->isAvatar())
  63. {
  64. parent = (LLViewerObject*)parent->getParent();
  65. }
  66. if (parent)
  67. {
  68. pos_global = parent->getPositionGlobal();
  69. }
  70. }
  71. else
  72. {
  73. pos_global = mObjectp->getPositionGlobal();
  74. }
  75. if (!LLViewerParcelMgr::getInstance()->canHearSound(pos_global))
  76. {
  77. mute = true;
  78. }
  79. if (!mute)
  80. {
  81. if (LLMuteList::getInstance()->isMuted(mObjectp->getID()))
  82. {
  83. mute = true;
  84. }
  85. else if (LLMuteList::getInstance()->isMuted(mOwnerID, LLMute::flagObjectSounds))
  86. {
  87. mute = true;
  88. }
  89. else if (mObjectp->isAttachment())
  90. {
  91. LLViewerObject* parent = mObjectp;
  92. while (parent && !parent->isAvatar())
  93. {
  94. parent = (LLViewerObject*)parent->getParent();
  95. }
  96. if (parent
  97. && LLMuteList::getInstance()->isMuted(parent->getID()))
  98. {
  99. mute = true;
  100. }
  101. }
  102. }
  103. if (mute != mSourceMuted)
  104. {
  105. mSourceMuted = mute;
  106. if (mSourceMuted)
  107. {
  108. // Stop the sound.
  109. this->play(LLUUID::null);
  110. }
  111. else
  112. {
  113. // Muted sounds keep there data at all times, because
  114. // it's the place where the audio UUID is stored.
  115. // However, it's possible that mCurrentDatap is
  116. // NULL when this source did only preload sounds.
  117. if (mCurrentDatap)
  118. {
  119. // Restart the sound.
  120. this->play(mCurrentDatap->getID());
  121. }
  122. }
  123. }
  124. }
  125. void LLAudioSourceVO::update()
  126. {
  127. updateMute();
  128. if (!mObjectp)
  129. {
  130. return;
  131. }
  132. if (mObjectp->isDead())
  133. {
  134. mObjectp = NULL;
  135. return;
  136. }
  137. if (mSourceMuted)
  138. {
  139. return;
  140. }
  141. if (mObjectp->isHUDAttachment())
  142. {
  143. mPositionGlobal = gAgentCamera.getCameraPositionGlobal();
  144. }
  145. else
  146. {
  147. mPositionGlobal = mObjectp->getPositionGlobal();
  148. }
  149. if (mObjectp->getSubParent())
  150. {
  151. mVelocity = mObjectp->getSubParent()->getVelocity();
  152. }
  153. else
  154. {
  155. mVelocity = mObjectp->getVelocity();
  156. }
  157. LLAudioSource::update();
  158. }