PageRenderTime 40ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/newview/llhudeffecttrail.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 287 lines | 228 code | 31 blank | 28 comment | 29 complexity | f06a91db6989ca58dc5672a6561c8056 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llhudeffecttrail.cpp
  3. * @brief LLHUDEffectSpiral 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 "llhudeffecttrail.h"
  28. #include "llviewercontrol.h"
  29. #include "message.h"
  30. #include "llagent.h"
  31. #include "llbox.h"
  32. #include "lldrawable.h"
  33. #include "llhudrender.h"
  34. #include "llviewertexturelist.h"
  35. #include "llviewerobjectlist.h"
  36. #include "llviewerpartsim.h"
  37. #include "llviewerpartsource.h"
  38. #include "llvoavatar.h"
  39. #include "llworld.h"
  40. const F32 PARTICLE_SPACING = 0.01f;
  41. const F32 MAX_SIZE = 0.025f;
  42. const F32 START_POS_MAG = 1.f;
  43. const F32 END_POS_MAG = 1.2f;
  44. LLHUDEffectSpiral::LLHUDEffectSpiral(const U8 type) : LLHUDEffect(type), mbInit(FALSE)
  45. {
  46. mKillTime = 10.f;
  47. mVMag = 1.f;
  48. mVOffset = 0.f;
  49. mInitialRadius = 1.f;
  50. mFinalRadius = 1.f;
  51. mSpinRate = 10.f;
  52. mFlickerRate = 50.f;
  53. mScaleBase = 0.1f;
  54. mScaleVar = 0.f;
  55. mFadeInterp.setStartTime(0.f);
  56. mFadeInterp.setEndTime(mKillTime);
  57. mFadeInterp.setStartVal(1.f);
  58. mFadeInterp.setEndVal(1.f);
  59. }
  60. LLHUDEffectSpiral::~LLHUDEffectSpiral()
  61. {
  62. }
  63. void LLHUDEffectSpiral::markDead()
  64. {
  65. if (mPartSourcep)
  66. {
  67. mPartSourcep->setDead();
  68. mPartSourcep = NULL;
  69. }
  70. LLHUDEffect::markDead();
  71. }
  72. void LLHUDEffectSpiral::packData(LLMessageSystem *mesgsys)
  73. {
  74. if (!mSourceObject)
  75. {
  76. //llwarns << "Missing object in trail pack!" << llendl;
  77. }
  78. LLHUDEffect::packData(mesgsys);
  79. U8 packed_data[56];
  80. memset(packed_data, 0, 56);
  81. if (mSourceObject)
  82. {
  83. htonmemcpy(packed_data, mSourceObject->mID.mData, MVT_LLUUID, 16);
  84. }
  85. if (mTargetObject)
  86. {
  87. htonmemcpy(packed_data + 16, mTargetObject->mID.mData, MVT_LLUUID, 16);
  88. }
  89. if (!mPositionGlobal.isExactlyZero())
  90. {
  91. htonmemcpy(packed_data + 32, mPositionGlobal.mdV, MVT_LLVector3d, 24);
  92. }
  93. mesgsys->addBinaryDataFast(_PREHASH_TypeData, packed_data, 56);
  94. }
  95. void LLHUDEffectSpiral::unpackData(LLMessageSystem *mesgsys, S32 blocknum)
  96. {
  97. const size_t EFFECT_SIZE = 56;
  98. U8 packed_data[EFFECT_SIZE];
  99. LLHUDEffect::unpackData(mesgsys, blocknum);
  100. LLUUID object_id, target_object_id;
  101. size_t size = mesgsys->getSizeFast(_PREHASH_Effect, blocknum, _PREHASH_TypeData);
  102. if (size != EFFECT_SIZE)
  103. {
  104. llwarns << "Spiral effect with bad size " << size << llendl;
  105. return;
  106. }
  107. mesgsys->getBinaryDataFast(_PREHASH_Effect, _PREHASH_TypeData,
  108. packed_data, EFFECT_SIZE, blocknum, EFFECT_SIZE);
  109. htonmemcpy(object_id.mData, packed_data, MVT_LLUUID, 16);
  110. htonmemcpy(target_object_id.mData, packed_data + 16, MVT_LLUUID, 16);
  111. htonmemcpy(mPositionGlobal.mdV, packed_data + 32, MVT_LLVector3d, 24);
  112. LLViewerObject *objp = NULL;
  113. if (object_id.isNull())
  114. {
  115. setSourceObject(NULL);
  116. }
  117. else
  118. {
  119. LLViewerObject *objp = gObjectList.findObject(object_id);
  120. if (objp)
  121. {
  122. setSourceObject(objp);
  123. }
  124. else
  125. {
  126. // We don't have this object, kill this effect
  127. markDead();
  128. return;
  129. }
  130. }
  131. if (target_object_id.isNull())
  132. {
  133. setTargetObject(NULL);
  134. }
  135. else
  136. {
  137. objp = gObjectList.findObject(target_object_id);
  138. if (objp)
  139. {
  140. setTargetObject(objp);
  141. }
  142. else
  143. {
  144. // We don't have this object, kill this effect
  145. markDead();
  146. return;
  147. }
  148. }
  149. triggerLocal();
  150. }
  151. void LLHUDEffectSpiral::triggerLocal()
  152. {
  153. mKillTime = mTimer.getElapsedTimeF32() + mDuration;
  154. BOOL show_beam = gSavedSettings.getBOOL("ShowSelectionBeam");
  155. LLColor4 color;
  156. color.setVec(mColor);
  157. if (!mPartSourcep)
  158. {
  159. if (!mTargetObject.isNull() && !mSourceObject.isNull())
  160. {
  161. if (show_beam)
  162. {
  163. LLPointer<LLViewerPartSourceBeam> psb = new LLViewerPartSourceBeam;
  164. psb->setColor(color);
  165. psb->setSourceObject(mSourceObject);
  166. psb->setTargetObject(mTargetObject);
  167. psb->setOwnerUUID(gAgent.getID());
  168. LLViewerPartSim::getInstance()->addPartSource(psb);
  169. mPartSourcep = psb;
  170. }
  171. }
  172. else
  173. {
  174. if (!mSourceObject.isNull() && !mPositionGlobal.isExactlyZero())
  175. {
  176. if (show_beam)
  177. {
  178. LLPointer<LLViewerPartSourceBeam> psb = new LLViewerPartSourceBeam;
  179. psb->setSourceObject(mSourceObject);
  180. psb->setTargetObject(NULL);
  181. psb->setColor(color);
  182. psb->mLKGTargetPosGlobal = mPositionGlobal;
  183. psb->setOwnerUUID(gAgent.getID());
  184. LLViewerPartSim::getInstance()->addPartSource(psb);
  185. mPartSourcep = psb;
  186. }
  187. }
  188. else
  189. {
  190. LLVector3 pos;
  191. if (mSourceObject)
  192. {
  193. pos = mSourceObject->getPositionAgent();
  194. }
  195. else
  196. {
  197. pos = gAgent.getPosAgentFromGlobal(mPositionGlobal);
  198. }
  199. LLPointer<LLViewerPartSourceSpiral> pss = new LLViewerPartSourceSpiral(pos);
  200. if (!mSourceObject.isNull())
  201. {
  202. pss->setSourceObject(mSourceObject);
  203. }
  204. pss->setColor(color);
  205. pss->setOwnerUUID(gAgent.getID());
  206. LLViewerPartSim::getInstance()->addPartSource(pss);
  207. mPartSourcep = pss;
  208. }
  209. }
  210. }
  211. else
  212. {
  213. LLPointer<LLViewerPartSource>& ps = mPartSourcep;
  214. if (mPartSourcep->getType() == LLViewerPartSource::LL_PART_SOURCE_BEAM)
  215. {
  216. LLViewerPartSourceBeam *psb = (LLViewerPartSourceBeam *)ps.get();
  217. psb->setSourceObject(mSourceObject);
  218. psb->setTargetObject(mTargetObject);
  219. psb->setColor(color);
  220. if (mTargetObject.isNull())
  221. {
  222. psb->mLKGTargetPosGlobal = mPositionGlobal;
  223. }
  224. }
  225. else
  226. {
  227. LLViewerPartSourceSpiral *pss = (LLViewerPartSourceSpiral *)ps.get();
  228. pss->setSourceObject(mSourceObject);
  229. }
  230. }
  231. mbInit = TRUE;
  232. }
  233. void LLHUDEffectSpiral::setTargetObject(LLViewerObject *objp)
  234. {
  235. if (objp == mTargetObject)
  236. {
  237. return;
  238. }
  239. mTargetObject = objp;
  240. }
  241. void LLHUDEffectSpiral::render()
  242. {
  243. F32 time = mTimer.getElapsedTimeF32();
  244. if ((!mSourceObject.isNull() && mSourceObject->isDead()) ||
  245. (!mTargetObject.isNull() && mTargetObject->isDead()) ||
  246. mKillTime < time ||
  247. (!mPartSourcep.isNull() && !gSavedSettings.getBOOL("ShowSelectionBeam")) )
  248. {
  249. markDead();
  250. return;
  251. }
  252. }
  253. void LLHUDEffectSpiral::renderForTimer()
  254. {
  255. render();
  256. }