llhudmanager.cpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. /**
  2. * @file llhudmanager.cpp
  3. * @brief LLHUDManager class implementation
  4. *
  5. * $LicenseInfo:firstyear=2002&license=viewergpl$
  6. *
  7. * Copyright (c) 2002-2009, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #include "llviewerprecompiledheaders.h"
  33. #include "llhudmanager.h"
  34. #include "llfasttimer.h"
  35. #include "llmessage.h"
  36. #include "object_flags.h"
  37. #include "llagent.h"
  38. #include "llhudeffect.h"
  39. #include "llpipeline.h"
  40. #include "llviewercontrol.h"
  41. #include "llviewerobjectlist.h"
  42. //static
  43. LLHUDManager::effects_list_t LLHUDManager::sHUDEffects;
  44. //static
  45. void LLHUDManager::updateEffects()
  46. {
  47. LL_FAST_TIMER(FTM_HUD_EFFECTS);
  48. for (S32 i = 0, count = sHUDEffects.size(); i < count; ++i)
  49. {
  50. LLHUDEffect* hep = sHUDEffects[i];
  51. if (!hep->isDead())
  52. {
  53. hep->update();
  54. }
  55. }
  56. }
  57. //static
  58. void LLHUDManager::sendEffects()
  59. {
  60. for (S32 i = 0, count = sHUDEffects.size(); i < count; ++i)
  61. {
  62. LLHUDEffect* hep = sHUDEffects[i];
  63. if (hep->isDead())
  64. {
  65. // It does happen (e.g. on TP or logout). Harmless: just ignore. HB
  66. continue;
  67. }
  68. if (hep->mType < LLHUDObject::LL_HUD_EFFECT_BEAM)
  69. {
  70. llwarns << "Trying to send effect of unknown type: " << hep->mType
  71. << llendl;
  72. llassert(false);
  73. continue;
  74. }
  75. if (hep->getNeedsSendToSim() && hep->getOriginatedHere())
  76. {
  77. LLMessageSystem* msg = gMessageSystemp;
  78. msg->newMessageFast(_PREHASH_ViewerEffect);
  79. msg->nextBlockFast(_PREHASH_AgentData);
  80. msg->addUUIDFast(_PREHASH_AgentID, gAgentID);
  81. msg->addUUIDFast(_PREHASH_SessionID, gAgentSessionID);
  82. msg->nextBlockFast(_PREHASH_Effect);
  83. hep->packData(msg);
  84. hep->setNeedsSendToSim(false);
  85. gAgent.sendMessage();
  86. }
  87. }
  88. }
  89. //static
  90. void LLHUDManager::cleanupClass()
  91. {
  92. sHUDEffects.clear();
  93. }
  94. //static
  95. void LLHUDManager::cleanupEffects()
  96. {
  97. effects_list_t::iterator iter = sHUDEffects.begin();
  98. while (iter != sHUDEffects.end())
  99. {
  100. LLHUDEffect* effect = (*iter).get();
  101. if (!effect || effect->isDead())
  102. {
  103. if (iter + 1 != sHUDEffects.end())
  104. {
  105. *iter = sHUDEffects.back();
  106. }
  107. sHUDEffects.pop_back();
  108. }
  109. else
  110. {
  111. ++iter;
  112. }
  113. }
  114. }
  115. //static
  116. LLHUDEffect* LLHUDManager::createEffect(U8 type, bool send_to_sim,
  117. bool originated_here)
  118. {
  119. // SJB: DO NOT USE addHUDObject ! Not all LLHUDObjects are LLHUDEffects !
  120. LLHUDEffect* effectp = LLHUDObject::addHUDEffect(type);
  121. if (effectp)
  122. {
  123. LLUUID tmp;
  124. tmp.generate();
  125. effectp->setID(tmp);
  126. effectp->setNeedsSendToSim(send_to_sim);
  127. effectp->setOriginatedHere(originated_here);
  128. sHUDEffects.push_back(effectp);
  129. }
  130. return effectp;
  131. }
  132. //static
  133. void LLHUDManager::processViewerEffect(LLMessageSystem* mesgsys, void**)
  134. {
  135. LLUUID effect_id;
  136. U8 effect_type = 0;
  137. S32 number_blocks = mesgsys->getNumberOfBlocksFast(_PREHASH_Effect);
  138. for (S32 k = 0; k < number_blocks; ++k)
  139. {
  140. LLHUDEffect* effectp = NULL;
  141. LLHUDEffect::getIDType(mesgsys, k, effect_id, effect_type);
  142. effects_list_t::iterator iter = sHUDEffects.begin();
  143. while (iter != sHUDEffects.end())
  144. {
  145. LLHUDEffect* cur_effectp = (*iter).get();
  146. if (!cur_effectp || cur_effectp->isDead())
  147. {
  148. LL_DEBUGS("HudManager") << (cur_effectp ? "Dead" : "NULL")
  149. << " effect in manager list; removed."
  150. << LL_ENDL;
  151. if (iter + 1 != sHUDEffects.end())
  152. {
  153. *iter = sHUDEffects.back();
  154. }
  155. sHUDEffects.pop_back();
  156. continue;
  157. }
  158. if (cur_effectp->getID() == effect_id)
  159. {
  160. if (cur_effectp->getType() != effect_type)
  161. {
  162. llwarns << "Viewer effect " << effect_id
  163. << " update does not match effect type (effect type: "
  164. << cur_effectp->getType() << " - update type: "
  165. << effect_type << ")" << llendl;
  166. }
  167. effectp = cur_effectp;
  168. break;
  169. }
  170. ++iter;
  171. }
  172. if (effect_type)
  173. {
  174. if (!effectp)
  175. {
  176. effectp = LLHUDManager::createEffect(effect_type, false,
  177. false);
  178. }
  179. if (effectp)
  180. {
  181. effectp->unpackData(mesgsys, k);
  182. }
  183. }
  184. else
  185. {
  186. llwarns << "Received viewer effect " << effect_id
  187. << " without type; skipped." << llendl;
  188. }
  189. }
  190. }