PageRenderTime 36ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/newview/llhudmanager.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 210 lines | 153 code | 24 blank | 33 comment | 21 complexity | bbb34853c7a68c9e16fa65ec2ece0c0e MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llhudmanager.cpp
  3. * @brief LLHUDManager class implementation
  4. *
  5. * $LicenseInfo:firstyear=2002&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #include "llviewerprecompiledheaders.h"
  27. #include "llhudmanager.h"
  28. #include "message.h"
  29. #include "object_flags.h"
  30. #include "llagent.h"
  31. #include "llhudeffect.h"
  32. #include "pipeline.h"
  33. #include "llui.h"
  34. #include "llviewercontrol.h"
  35. #include "llviewerobjectlist.h"
  36. // These are loaded from saved settings.
  37. LLColor4 LLHUDManager::sParentColor;
  38. LLColor4 LLHUDManager::sChildColor;
  39. LLHUDManager::LLHUDManager()
  40. {
  41. LLHUDManager::sParentColor = LLUIColorTable::instance().getColor("FocusColor");
  42. // rdw commented out since it's not used. Also removed from colors_base.xml
  43. //LLHUDManager::sChildColor =LLUIColorTable::instance().getColor("FocusSecondaryColor");
  44. }
  45. LLHUDManager::~LLHUDManager()
  46. {
  47. }
  48. static LLFastTimer::DeclareTimer FTM_HUD_EFFECTS("Hud Effects");
  49. void LLHUDManager::updateEffects()
  50. {
  51. LLFastTimer ftm(FTM_HUD_EFFECTS);
  52. S32 i;
  53. for (i = 0; i < mHUDEffects.count(); i++)
  54. {
  55. LLHUDEffect *hep = mHUDEffects[i];
  56. if (hep->isDead())
  57. {
  58. continue;
  59. }
  60. hep->update();
  61. }
  62. }
  63. void LLHUDManager::sendEffects()
  64. {
  65. S32 i;
  66. for (i = 0; i < mHUDEffects.count(); i++)
  67. {
  68. LLHUDEffect *hep = mHUDEffects[i];
  69. if (hep->isDead())
  70. {
  71. llwarns << "Trying to send dead effect!" << llendl;
  72. continue;
  73. }
  74. if (hep->mType < LLHUDObject::LL_HUD_EFFECT_BEAM)
  75. {
  76. llwarns << "Trying to send effect of type " << hep->mType << " which isn't really an effect and shouldn't be in this list!" << llendl;
  77. continue;
  78. }
  79. if (hep->getNeedsSendToSim() && hep->getOriginatedHere())
  80. {
  81. LLMessageSystem* msg = gMessageSystem;
  82. msg->newMessageFast(_PREHASH_ViewerEffect);
  83. msg->nextBlockFast(_PREHASH_AgentData);
  84. msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
  85. msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
  86. msg->nextBlockFast(_PREHASH_Effect);
  87. hep->packData(msg);
  88. hep->setNeedsSendToSim(FALSE);
  89. gAgent.sendMessage();
  90. }
  91. }
  92. }
  93. //static
  94. void LLHUDManager::shutdownClass()
  95. {
  96. getInstance()->mHUDEffects.reset();
  97. }
  98. void LLHUDManager::cleanupEffects()
  99. {
  100. S32 i = 0;
  101. while (i < mHUDEffects.count())
  102. {
  103. if (mHUDEffects[i]->isDead())
  104. {
  105. mHUDEffects.remove(i);
  106. }
  107. else
  108. {
  109. i++;
  110. }
  111. }
  112. }
  113. LLHUDEffect *LLHUDManager::createViewerEffect(const U8 type, BOOL send_to_sim, BOOL originated_here)
  114. {
  115. // SJB: DO NOT USE addHUDObject!!! Not all LLHUDObjects are LLHUDEffects!
  116. LLHUDEffect *hep = LLHUDObject::addHUDEffect(type);
  117. if (!hep)
  118. {
  119. return NULL;
  120. }
  121. LLUUID tmp;
  122. tmp.generate();
  123. hep->setID(tmp);
  124. hep->setNeedsSendToSim(send_to_sim);
  125. hep->setOriginatedHere(originated_here);
  126. mHUDEffects.put(hep);
  127. return hep;
  128. }
  129. //static
  130. void LLHUDManager::processViewerEffect(LLMessageSystem *mesgsys, void **user_data)
  131. {
  132. LLHUDEffect *effectp = NULL;
  133. LLUUID effect_id;
  134. U8 effect_type = 0;
  135. S32 number_blocks = mesgsys->getNumberOfBlocksFast(_PREHASH_Effect);
  136. S32 k;
  137. for (k = 0; k < number_blocks; k++)
  138. {
  139. effectp = NULL;
  140. LLHUDEffect::getIDType(mesgsys, k, effect_id, effect_type);
  141. S32 i;
  142. for (i = 0; i < LLHUDManager::getInstance()->mHUDEffects.count(); i++)
  143. {
  144. LLHUDEffect *cur_effectp = LLHUDManager::getInstance()->mHUDEffects[i];
  145. if (!cur_effectp)
  146. {
  147. llwarns << "Null effect in effect manager, skipping" << llendl;
  148. LLHUDManager::getInstance()->mHUDEffects.remove(i);
  149. i--;
  150. continue;
  151. }
  152. if (cur_effectp->isDead())
  153. {
  154. // llwarns << "Dead effect in effect manager, removing" << llendl;
  155. LLHUDManager::getInstance()->mHUDEffects.remove(i);
  156. i--;
  157. continue;
  158. }
  159. if (cur_effectp->getID() == effect_id)
  160. {
  161. if (cur_effectp->getType() != effect_type)
  162. {
  163. llwarns << "Viewer effect update doesn't match old type!" << llendl;
  164. }
  165. effectp = cur_effectp;
  166. break;
  167. }
  168. }
  169. if (effect_type)
  170. {
  171. if (!effectp)
  172. {
  173. effectp = LLHUDManager::getInstance()->createViewerEffect(effect_type, FALSE, FALSE);
  174. }
  175. if (effectp)
  176. {
  177. effectp->unpackData(mesgsys, k);
  178. }
  179. }
  180. else
  181. {
  182. llwarns << "Received viewer effect of type " << effect_type << " which isn't really an effect!" << llendl;
  183. }
  184. }
  185. //llinfos << "Got viewer effect: " << effect_id << llendl;
  186. }