PageRenderTime 50ms CodeModel.GetById 19ms app.highlight 28ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/newview/llhudobject.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 323 lines | 254 code | 34 blank | 35 comment | 23 complexity | 4a692777acc8f36349d474a52efc6ac9 MD5 | raw file
  1/** 
  2 * @file llhudobject.cpp
  3 * @brief LLHUDObject class implementation
  4 *
  5 * $LicenseInfo:firstyear=2002&license=viewerlgpl$
  6 * Second Life Viewer Source Code
  7 * Copyright (C) 2002-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 "llhudobject.h"
 30#include "llviewerobject.h"
 31
 32#include "llhudtext.h"
 33#include "llhudicon.h"
 34#include "llhudeffectbeam.h"
 35#include "llhudeffectblob.h"
 36#include "llhudeffecttrail.h"
 37#include "llhudeffectlookat.h"
 38#include "llhudeffectpointat.h"
 39#include "llhudnametag.h"
 40#include "llvoicevisualizer.h"
 41
 42#include "llagent.h"
 43
 44// statics
 45std::list<LLPointer<LLHUDObject> > LLHUDObject::sHUDObjects;
 46
 47struct hud_object_further_away
 48{
 49	bool operator()(const LLPointer<LLHUDObject>& lhs, const LLPointer<LLHUDObject>& rhs) const;
 50};
 51
 52
 53bool hud_object_further_away::operator()(const LLPointer<LLHUDObject>& lhs, const LLPointer<LLHUDObject>& rhs) const
 54{
 55	return (lhs->getDistance() > rhs->getDistance()) ? true : false;
 56}
 57
 58
 59LLHUDObject::LLHUDObject(const U8 type) : 
 60	mPositionGlobal(), 
 61	mSourceObject(NULL), 
 62	mTargetObject(NULL)
 63{
 64	mVisible = TRUE;
 65	mType = type;
 66	mDead = FALSE;
 67}
 68
 69LLHUDObject::~LLHUDObject()
 70{
 71}
 72
 73void LLHUDObject::markDead()
 74{
 75	mVisible = FALSE;
 76	mDead = TRUE;
 77	mSourceObject = NULL;
 78	mTargetObject = NULL;
 79}
 80
 81F32 LLHUDObject::getDistance() const
 82{
 83	return 0.f;
 84}
 85
 86void LLHUDObject::setSourceObject(LLViewerObject* objectp)
 87{
 88	if (objectp == mSourceObject)
 89	{
 90		return;
 91	}
 92
 93	mSourceObject = objectp;
 94}
 95
 96void LLHUDObject::setTargetObject(LLViewerObject* objectp)
 97{
 98	if (objectp == mTargetObject)
 99	{
100		return;
101	}
102
103	mTargetObject = objectp;
104}
105
106void LLHUDObject::setPositionGlobal(const LLVector3d &position_global)
107{
108	mPositionGlobal = position_global;
109}
110
111void LLHUDObject::setPositionAgent(const LLVector3 &position_agent)
112{
113	mPositionGlobal = gAgent.getPosGlobalFromAgent(position_agent);
114}
115
116// static
117void LLHUDObject::cleanupHUDObjects()
118{
119	LLHUDIcon::cleanupDeadIcons();
120	hud_object_list_t::iterator object_it;
121	for (object_it = sHUDObjects.begin(); object_it != sHUDObjects.end(); ++object_it)
122	{
123		(*object_it)->markDead();
124		if ((*object_it)->getNumRefs() > 1)
125		{
126			llinfos << "LLHUDObject " << (LLHUDObject *)(*object_it) << " type " << (S32)(*object_it)->getType() << " has " << (*object_it)->getNumRefs() << " refs!" << llendl;			
127		}
128	}
129	sHUDObjects.clear();
130}
131
132// static
133LLHUDObject *LLHUDObject::addHUDObject(const U8 type)
134{
135	LLHUDObject *hud_objectp = NULL;
136	
137	switch (type)
138	{
139	case LL_HUD_TEXT:
140		hud_objectp = new LLHUDText(type);
141		break;
142	case LL_HUD_ICON:
143		hud_objectp = new LLHUDIcon(type);
144		break;
145	case LL_HUD_NAME_TAG:
146		hud_objectp = new LLHUDNameTag(type);
147		break;
148	default:
149		llwarns << "Unknown type of hud object:" << (U32) type << llendl;
150	}
151	if (hud_objectp)
152	{
153		sHUDObjects.push_back(hud_objectp);
154	}
155	return hud_objectp;
156}
157
158LLHUDEffect *LLHUDObject::addHUDEffect(const U8 type)
159{
160	LLHUDEffect *hud_objectp = NULL;
161	
162	switch (type)
163	{
164	case LL_HUD_EFFECT_BEAM:
165		hud_objectp = new LLHUDEffectSpiral(type);
166		((LLHUDEffectSpiral *)hud_objectp)->setDuration(0.7f);
167		((LLHUDEffectSpiral *)hud_objectp)->setVMag(0.f);
168		((LLHUDEffectSpiral *)hud_objectp)->setVOffset(0.f);
169		((LLHUDEffectSpiral *)hud_objectp)->setInitialRadius(0.1f);
170		((LLHUDEffectSpiral *)hud_objectp)->setFinalRadius(0.2f);
171		((LLHUDEffectSpiral *)hud_objectp)->setSpinRate(10.f);
172		((LLHUDEffectSpiral *)hud_objectp)->setFlickerRate(0.f);
173		((LLHUDEffectSpiral *)hud_objectp)->setScaleBase(0.05f);
174		((LLHUDEffectSpiral *)hud_objectp)->setScaleVar(0.02f);
175		((LLHUDEffectSpiral *)hud_objectp)->setColor(LLColor4U(255, 255, 255, 255));
176		break;
177	case LL_HUD_EFFECT_GLOW:
178		// deprecated
179		break;
180	case LL_HUD_EFFECT_POINT:
181		hud_objectp = new LLHUDEffectSpiral(type);
182		((LLHUDEffectSpiral *)hud_objectp)->setDuration(0.5f);
183		((LLHUDEffectSpiral *)hud_objectp)->setVMag(1.f);
184		((LLHUDEffectSpiral *)hud_objectp)->setVOffset(0.f);
185		((LLHUDEffectSpiral *)hud_objectp)->setInitialRadius(0.5f);
186		((LLHUDEffectSpiral *)hud_objectp)->setFinalRadius(1.f);
187		((LLHUDEffectSpiral *)hud_objectp)->setSpinRate(10.f);
188		((LLHUDEffectSpiral *)hud_objectp)->setFlickerRate(0.f);
189		((LLHUDEffectSpiral *)hud_objectp)->setScaleBase(0.1f);
190		((LLHUDEffectSpiral *)hud_objectp)->setScaleVar(0.1f);
191		((LLHUDEffectSpiral *)hud_objectp)->setColor(LLColor4U(255, 255, 255, 255));
192		break;
193	case LL_HUD_EFFECT_SPHERE:
194		hud_objectp = new LLHUDEffectSpiral(type);
195		((LLHUDEffectSpiral *)hud_objectp)->setDuration(0.5f);
196		((LLHUDEffectSpiral *)hud_objectp)->setVMag(1.f);
197		((LLHUDEffectSpiral *)hud_objectp)->setVOffset(0.f);
198		((LLHUDEffectSpiral *)hud_objectp)->setInitialRadius(0.5f);
199		((LLHUDEffectSpiral *)hud_objectp)->setFinalRadius(0.5f);
200		((LLHUDEffectSpiral *)hud_objectp)->setSpinRate(20.f);
201		((LLHUDEffectSpiral *)hud_objectp)->setFlickerRate(0.f);
202		((LLHUDEffectSpiral *)hud_objectp)->setScaleBase(0.1f);
203		((LLHUDEffectSpiral *)hud_objectp)->setScaleVar(0.1f);
204		((LLHUDEffectSpiral *)hud_objectp)->setColor(LLColor4U(255, 255, 255, 255));
205		break;
206	case LL_HUD_EFFECT_SPIRAL:
207		hud_objectp = new LLHUDEffectSpiral(type);
208		((LLHUDEffectSpiral *)hud_objectp)->setDuration(2.f);
209		((LLHUDEffectSpiral *)hud_objectp)->setVMag(-2.f);
210		((LLHUDEffectSpiral *)hud_objectp)->setVOffset(0.5f);
211		((LLHUDEffectSpiral *)hud_objectp)->setInitialRadius(1.f);
212		((LLHUDEffectSpiral *)hud_objectp)->setFinalRadius(0.5f);
213		((LLHUDEffectSpiral *)hud_objectp)->setSpinRate(10.f);
214		((LLHUDEffectSpiral *)hud_objectp)->setFlickerRate(20.f);
215		((LLHUDEffectSpiral *)hud_objectp)->setScaleBase(0.02f);
216		((LLHUDEffectSpiral *)hud_objectp)->setScaleVar(0.02f);
217		((LLHUDEffectSpiral *)hud_objectp)->setColor(LLColor4U(255, 255, 255, 255));
218		break;
219	case LL_HUD_EFFECT_EDIT:
220		hud_objectp = new LLHUDEffectSpiral(type);
221		((LLHUDEffectSpiral *)hud_objectp)->setDuration(2.f);
222		((LLHUDEffectSpiral *)hud_objectp)->setVMag(2.f);
223		((LLHUDEffectSpiral *)hud_objectp)->setVOffset(-1.f);
224		((LLHUDEffectSpiral *)hud_objectp)->setInitialRadius(1.5f);
225		((LLHUDEffectSpiral *)hud_objectp)->setFinalRadius(1.f);
226		((LLHUDEffectSpiral *)hud_objectp)->setSpinRate(4.f);
227		((LLHUDEffectSpiral *)hud_objectp)->setFlickerRate(200.f);
228		((LLHUDEffectSpiral *)hud_objectp)->setScaleBase(0.1f);
229		((LLHUDEffectSpiral *)hud_objectp)->setScaleVar(0.1f);
230		((LLHUDEffectSpiral *)hud_objectp)->setColor(LLColor4U(255, 255, 255, 255));
231		break;
232	case LL_HUD_EFFECT_LOOKAT:
233		hud_objectp = new LLHUDEffectLookAt(type);
234		break;
235	case LL_HUD_EFFECT_VOICE_VISUALIZER:
236		hud_objectp = new LLVoiceVisualizer(type);
237		break;
238	case LL_HUD_EFFECT_POINTAT:
239		hud_objectp = new LLHUDEffectPointAt(type);
240		break;
241	case LL_HUD_EFFECT_BLOB:
242		hud_objectp = new LLHUDEffectBlob(type);
243		break;
244	default:
245		llwarns << "Unknown type of hud effect:" << (U32) type << llendl;
246	}
247
248	if (hud_objectp)
249	{
250		sHUDObjects.push_back(hud_objectp);
251	}
252	return hud_objectp;
253}
254
255static LLFastTimer::DeclareTimer FTM_HUD_UPDATE("Update Hud");
256
257// static
258void LLHUDObject::updateAll()
259{
260	LLFastTimer ftm(FTM_HUD_UPDATE);
261	LLHUDText::updateAll();
262	LLHUDIcon::updateAll();
263	LLHUDNameTag::updateAll();
264	sortObjects();
265}
266
267// static
268void LLHUDObject::renderAll()
269{
270	LLHUDObject *hud_objp;
271	
272	hud_object_list_t::iterator object_it;
273	for (object_it = sHUDObjects.begin(); object_it != sHUDObjects.end(); )
274	{
275		hud_object_list_t::iterator cur_it = object_it++;
276		hud_objp = (*cur_it);
277		if (hud_objp->getNumRefs() == 1)
278		{
279			sHUDObjects.erase(cur_it);
280		}
281		else if (hud_objp->isVisible())
282		{
283			hud_objp->render();
284		}
285	}
286
287	LLVertexBuffer::unbind();
288}
289
290// static
291void LLHUDObject::renderAllForTimer()
292{
293	LLHUDObject *hud_objp;
294	
295	hud_object_list_t::iterator object_it;
296	for (object_it = sHUDObjects.begin(); object_it != sHUDObjects.end(); )
297	{
298		hud_object_list_t::iterator cur_it = object_it++;
299		hud_objp = (*cur_it);
300		if (hud_objp->getNumRefs() == 1)
301		{
302			sHUDObjects.erase(cur_it);
303		}
304		else if (hud_objp->isVisible())
305		{
306			hud_objp->renderForTimer();
307		}
308	}
309}
310
311// static
312void LLHUDObject::reshapeAll()
313{
314	// only hud objects that use fonts care about window size/scale changes
315	LLHUDText::reshape();
316	LLHUDNameTag::reshape();
317}
318
319// static
320void LLHUDObject::sortObjects()
321{
322	sHUDObjects.sort(hud_object_further_away());	
323}