PageRenderTime 81ms CodeModel.GetById 41ms app.highlight 18ms RepoModel.GetById 12ms app.codeStats 0ms

/indra/newview/llhudmanager.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 210 lines | 153 code | 24 blank | 33 comment | 21 complexity | bbb34853c7a68c9e16fa65ec2ece0c0e MD5 | raw file
  1/** 
  2 * @file llhudmanager.cpp
  3 * @brief LLHUDManager 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 "llhudmanager.h"
 30
 31#include "message.h"
 32#include "object_flags.h"
 33
 34#include "llagent.h"
 35#include "llhudeffect.h"
 36#include "pipeline.h"
 37#include "llui.h"
 38#include "llviewercontrol.h"
 39#include "llviewerobjectlist.h"
 40
 41// These are loaded from saved settings.
 42LLColor4 LLHUDManager::sParentColor;
 43LLColor4 LLHUDManager::sChildColor;
 44
 45LLHUDManager::LLHUDManager()
 46{
 47
 48	LLHUDManager::sParentColor = LLUIColorTable::instance().getColor("FocusColor");
 49	// rdw commented out since it's not used.  Also removed from colors_base.xml
 50	//LLHUDManager::sChildColor =LLUIColorTable::instance().getColor("FocusSecondaryColor");
 51}
 52
 53LLHUDManager::~LLHUDManager()
 54{
 55}
 56
 57static LLFastTimer::DeclareTimer FTM_HUD_EFFECTS("Hud Effects");
 58
 59void LLHUDManager::updateEffects()
 60{
 61	LLFastTimer ftm(FTM_HUD_EFFECTS);
 62	S32 i;
 63	for (i = 0; i < mHUDEffects.count(); i++)
 64	{
 65		LLHUDEffect *hep = mHUDEffects[i];
 66		if (hep->isDead())
 67		{
 68			continue;
 69		}
 70		hep->update();
 71	}
 72}
 73
 74void LLHUDManager::sendEffects()
 75{
 76	S32 i;
 77	for (i = 0; i < mHUDEffects.count(); i++)
 78	{
 79		LLHUDEffect *hep = mHUDEffects[i];
 80		if (hep->isDead())
 81		{
 82			llwarns << "Trying to send dead effect!" << llendl;
 83			continue;
 84		}
 85		if (hep->mType < LLHUDObject::LL_HUD_EFFECT_BEAM)
 86		{
 87			llwarns << "Trying to send effect of type " << hep->mType << " which isn't really an effect and shouldn't be in this list!" << llendl;
 88			continue;
 89		}
 90		if (hep->getNeedsSendToSim() && hep->getOriginatedHere())
 91		{
 92			LLMessageSystem* msg = gMessageSystem;
 93			msg->newMessageFast(_PREHASH_ViewerEffect);
 94			msg->nextBlockFast(_PREHASH_AgentData);
 95			msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
 96			msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
 97			msg->nextBlockFast(_PREHASH_Effect);
 98			hep->packData(msg);
 99			hep->setNeedsSendToSim(FALSE);
100			gAgent.sendMessage();
101		}
102	}
103}
104
105//static
106void LLHUDManager::shutdownClass()
107{
108	getInstance()->mHUDEffects.reset();
109}
110
111void LLHUDManager::cleanupEffects()
112{
113	S32 i = 0;
114
115	while (i < mHUDEffects.count())
116	{
117		if (mHUDEffects[i]->isDead())
118		{
119			mHUDEffects.remove(i);
120		}
121		else
122		{
123			i++;
124		}
125	}
126}
127
128LLHUDEffect *LLHUDManager::createViewerEffect(const U8 type, BOOL send_to_sim, BOOL originated_here)
129{
130	// SJB: DO NOT USE addHUDObject!!! Not all LLHUDObjects are LLHUDEffects!
131	LLHUDEffect *hep = LLHUDObject::addHUDEffect(type);
132	if (!hep)
133	{
134		return NULL;
135	}
136
137	LLUUID tmp;
138	tmp.generate();
139	hep->setID(tmp);
140	hep->setNeedsSendToSim(send_to_sim);
141	hep->setOriginatedHere(originated_here);
142
143	mHUDEffects.put(hep);
144	return hep;
145}
146
147
148//static
149void LLHUDManager::processViewerEffect(LLMessageSystem *mesgsys, void **user_data)
150{
151	LLHUDEffect *effectp = NULL;
152	LLUUID effect_id;
153	U8 effect_type = 0;
154	S32 number_blocks = mesgsys->getNumberOfBlocksFast(_PREHASH_Effect);
155	S32 k;
156
157	for (k = 0; k < number_blocks; k++)
158	{
159		effectp = NULL;
160		LLHUDEffect::getIDType(mesgsys, k, effect_id, effect_type);
161		S32 i;
162		for (i = 0; i < LLHUDManager::getInstance()->mHUDEffects.count(); i++)
163		{
164			LLHUDEffect *cur_effectp = LLHUDManager::getInstance()->mHUDEffects[i];
165			if (!cur_effectp)
166			{
167				llwarns << "Null effect in effect manager, skipping" << llendl;
168				LLHUDManager::getInstance()->mHUDEffects.remove(i);
169				i--;
170				continue;
171			}
172			if (cur_effectp->isDead())
173			{
174	//			llwarns << "Dead effect in effect manager, removing" << llendl;
175				LLHUDManager::getInstance()->mHUDEffects.remove(i);
176				i--;
177				continue;
178			}
179			if (cur_effectp->getID() == effect_id)
180			{
181				if (cur_effectp->getType() != effect_type)
182				{
183					llwarns << "Viewer effect update doesn't match old type!" << llendl;
184				}
185				effectp = cur_effectp;
186				break;
187			}
188		}
189
190		if (effect_type)
191		{
192			if (!effectp)
193			{
194				effectp = LLHUDManager::getInstance()->createViewerEffect(effect_type, FALSE, FALSE);
195			}
196
197			if (effectp)
198			{
199				effectp->unpackData(mesgsys, k);
200			}
201		}
202		else
203		{
204			llwarns << "Received viewer effect of type " << effect_type << " which isn't really an effect!" << llendl;
205		}
206	}
207
208	//llinfos << "Got viewer effect: " << effect_id << llendl;
209}
210