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