llhudeffectspiral.cpp 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. /**
  2. * @file llhudeffectspiral.cpp
  3. * @brief LLHUDEffectSpiral 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 <utility>
  34. #include "llhudeffectspiral.h"
  35. #include "llimagegl.h"
  36. #include "llmessage.h"
  37. #include "llagent.h"
  38. #include "lldrawable.h"
  39. //MK
  40. #include "mkrlinterface.h"
  41. //mk
  42. #include "llhudmanager.h"
  43. #include "llviewercontrol.h"
  44. #include "llviewerobjectlist.h"
  45. #include "llviewerpartsim.h"
  46. #include "llviewerpartsource.h"
  47. #include "llviewertexturelist.h"
  48. #include "llvoavatarself.h"
  49. #include "llworld.h"
  50. LLHUDEffectSpiral::LLHUDEffectSpiral(U8 type)
  51. : LLHUDEffect(type),
  52. mKillTime(10.f),
  53. mVMag(1.f),
  54. mVOffset(0.f),
  55. mInitialRadius(1.f),
  56. mFinalRadius(1.f),
  57. mSpinRate(10.f),
  58. mFlickerRate(50.f),
  59. mScaleBase(0.1f),
  60. mScaleVar(0.f)
  61. {
  62. mFadeInterp.setStartTime(0.f);
  63. mFadeInterp.setEndTime(mKillTime);
  64. mFadeInterp.setStartVal(1.f);
  65. mFadeInterp.setEndVal(1.f);
  66. }
  67. void LLHUDEffectSpiral::markDead()
  68. {
  69. if (mPartSourcep)
  70. {
  71. mPartSourcep->setDead();
  72. mPartSourcep = NULL;
  73. }
  74. LLHUDEffect::markDead();
  75. }
  76. void LLHUDEffectSpiral::packData(LLMessageSystem* mesgsys)
  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. constexpr S32 EFFECT_SIZE = 56;
  98. U8 packed_data[EFFECT_SIZE];
  99. LLHUDEffect::unpackData(mesgsys, blocknum);
  100. LLUUID object_id, target_object_id;
  101. S32 size = mesgsys->getSizeFast(_PREHASH_Effect, blocknum,
  102. _PREHASH_TypeData);
  103. if (size != EFFECT_SIZE)
  104. {
  105. llwarns << "Spiral effect with bad size " << size << llendl;
  106. return;
  107. }
  108. mesgsys->getBinaryDataFast(_PREHASH_Effect, _PREHASH_TypeData,
  109. packed_data, EFFECT_SIZE, blocknum,
  110. EFFECT_SIZE);
  111. htonmemcpy(object_id.mData, packed_data, MVT_LLUUID, 16);
  112. htonmemcpy(target_object_id.mData, packed_data + 16, MVT_LLUUID, 16);
  113. htonmemcpy(mPositionGlobal.mdV, packed_data + 32, MVT_LLVector3d, 24);
  114. if (object_id.isNull())
  115. {
  116. setSourceObject(NULL);
  117. }
  118. else
  119. {
  120. LLViewerObject* objp = gObjectList.findObject(object_id);
  121. if (objp)
  122. {
  123. setSourceObject(objp);
  124. }
  125. else
  126. {
  127. // We do not have this object, kill this effect
  128. markDead();
  129. return;
  130. }
  131. }
  132. if (target_object_id.isNull())
  133. {
  134. setTargetObject(NULL);
  135. }
  136. else
  137. {
  138. LLViewerObject* objp = gObjectList.findObject(target_object_id);
  139. if (objp)
  140. {
  141. setTargetObject(objp);
  142. }
  143. else
  144. {
  145. // We do not have this object, kill this effect
  146. markDead();
  147. return;
  148. }
  149. }
  150. triggerLocal();
  151. }
  152. void LLHUDEffectSpiral::triggerLocal()
  153. {
  154. //MK
  155. if (gRLenabled && gRLInterface.mVisionRestricted &&
  156. gRLInterface.mCamDistDrawAlphaMax >= 0.25f)
  157. {
  158. return;
  159. }
  160. //mk
  161. mKillTime = mTimer.getElapsedTimeF32() + mDuration;
  162. static LLCachedControl<bool> show_beam(gSavedSettings,
  163. "ShowSelectionBeam");
  164. LLColor4 color;
  165. color.set(mColor);
  166. if (!mPartSourcep)
  167. {
  168. if (mTargetObject.notNull() && mSourceObject.notNull())
  169. {
  170. if (show_beam)
  171. {
  172. mPartSourcep = new LLViewerPartSourceBeam;
  173. LLViewerPartSourceBeam* psb =
  174. (LLViewerPartSourceBeam*)mPartSourcep.get();
  175. psb->setColor(color);
  176. psb->setSourceObject(mSourceObject);
  177. psb->setTargetObject(mTargetObject);
  178. psb->setOwnerUUID(gAgentID);
  179. gViewerPartSim.addPartSource(mPartSourcep);
  180. }
  181. }
  182. else if (mSourceObject.notNull() && !mPositionGlobal.isExactlyZero())
  183. {
  184. if (show_beam)
  185. {
  186. mPartSourcep = new LLViewerPartSourceBeam;
  187. LLViewerPartSourceBeam* psb =
  188. (LLViewerPartSourceBeam*)mPartSourcep.get();
  189. psb->setSourceObject(mSourceObject);
  190. psb->setTargetObject(NULL);
  191. psb->setColor(color);
  192. psb->mLKGTargetPosGlobal = mPositionGlobal;
  193. psb->setOwnerUUID(gAgentID);
  194. gViewerPartSim.addPartSource(mPartSourcep);
  195. }
  196. }
  197. else
  198. {
  199. LLVector3 pos;
  200. if (mSourceObject)
  201. {
  202. pos = mSourceObject->getPositionAgent();
  203. }
  204. else
  205. {
  206. pos = gAgent.getPosAgentFromGlobal(mPositionGlobal);
  207. }
  208. mPartSourcep = new LLViewerPartSourceSpiral(pos);
  209. LLViewerPartSourceSpiral* pss =
  210. (LLViewerPartSourceSpiral*)mPartSourcep.get();
  211. if (mSourceObject.notNull())
  212. {
  213. pss->setSourceObject(mSourceObject);
  214. }
  215. pss->setColor(color);
  216. pss->setOwnerUUID(gAgentID);
  217. gViewerPartSim.addPartSource(mPartSourcep);
  218. }
  219. }
  220. else if (mPartSourcep->getType() == LLViewerPartSource::LL_PART_SOURCE_BEAM)
  221. {
  222. LLViewerPartSourceBeam* psb =
  223. (LLViewerPartSourceBeam*)mPartSourcep.get();
  224. psb->setSourceObject(mSourceObject);
  225. psb->setTargetObject(mTargetObject);
  226. psb->setColor(color);
  227. if (mTargetObject.isNull())
  228. {
  229. psb->mLKGTargetPosGlobal = mPositionGlobal;
  230. }
  231. }
  232. else
  233. {
  234. LLViewerPartSourceSpiral* pss =
  235. (LLViewerPartSourceSpiral*)mPartSourcep.get();
  236. pss->setSourceObject(mSourceObject);
  237. }
  238. }
  239. void LLHUDEffectSpiral::setTargetObject(LLViewerObject* objp)
  240. {
  241. if (objp == mTargetObject)
  242. {
  243. return;
  244. }
  245. mTargetObject = objp;
  246. }
  247. void LLHUDEffectSpiral::update()
  248. {
  249. F32 time = mTimer.getElapsedTimeF32();
  250. static LLCachedControl<bool> show_selection_beam(gSavedSettings,
  251. "ShowSelectionBeam");
  252. if (mKillTime < time ||
  253. (mSourceObject.notNull() && mSourceObject->isDead()) ||
  254. (mTargetObject.notNull() && mTargetObject->isDead()) ||
  255. (mPartSourcep.notNull() && !show_selection_beam))
  256. {
  257. markDead();
  258. }
  259. }
  260. //static
  261. void LLHUDEffectSpiral::agentBeamToObject(LLViewerObject* objectp)
  262. {
  263. if (!isAgentAvatarValid() || !objectp) return;
  264. LLHUDEffectSpiral* self =
  265. (LLHUDEffectSpiral*)LLHUDManager::createEffect(LL_HUD_EFFECT_BEAM);
  266. self->setSourceObject(gAgentAvatarp);
  267. self->setTargetObject(objectp);
  268. self->setDuration(LL_HUD_DUR_SHORT);
  269. self->setColor(LLColor4U(gAgent.getEffectColor()));
  270. }
  271. //static
  272. void LLHUDEffectSpiral::agentBeamToPosition(const LLVector3d& pos)
  273. {
  274. if (!isAgentAvatarValid()) return;
  275. LLHUDEffectSpiral* self =
  276. (LLHUDEffectSpiral*)LLHUDManager::createEffect(LL_HUD_EFFECT_BEAM);
  277. self->setSourceObject(gAgentAvatarp);
  278. self->setPositionGlobal(pos);
  279. self->setDuration(LL_HUD_DUR_SHORT);
  280. self->setColor(LLColor4U(gAgent.getEffectColor()));
  281. }
  282. //static
  283. void LLHUDEffectSpiral::swirlAtPosition(const LLVector3d& pos, F32 duration,
  284. bool send_now)
  285. {
  286. LLHUDEffectSpiral* self =
  287. (LLHUDEffectSpiral*)LLHUDManager::createEffect(LL_HUD_EFFECT_POINT);
  288. self->setPositionGlobal(pos);
  289. self->setColor(LLColor4U(gAgent.getEffectColor()));
  290. if (duration > 0.f)
  291. {
  292. self->setDuration(duration);
  293. }
  294. if (send_now)
  295. {
  296. LLHUDManager::sendEffects();
  297. }
  298. if (duration == 0.f)
  299. {
  300. self->markDead(); // Remove it.
  301. }
  302. }
  303. //static
  304. void LLHUDEffectSpiral::sphereAtPosition(const LLVector3d& pos)
  305. {
  306. LLHUDEffectSpiral* self =
  307. (LLHUDEffectSpiral*)LLHUDManager::createEffect(LL_HUD_EFFECT_SPHERE);
  308. self->setPositionGlobal(pos);
  309. self->setColor(LLColor4U(gAgent.getEffectColor()));
  310. self->setDuration(0.25f);
  311. }