00001
00032 #include "llviewerprecompiledheaders.h"
00033
00034 #include "llhudmanager.h"
00035
00036 #include "message.h"
00037 #include "object_flags.h"
00038
00039 #include "llagent.h"
00040 #include "llhudconnector.h"
00041 #include "llhudeffect.h"
00042 #include "pipeline.h"
00043 #include "llviewercontrol.h"
00044 #include "llviewerobjectlist.h"
00045
00046 LLHUDManager *gHUDManager = NULL;
00047
00048 extern BOOL gNoRender;
00049
00050
00051 LLColor4 LLHUDManager::sParentColor;
00052 LLColor4 LLHUDManager::sChildColor;
00053
00054 LLHUDManager::LLHUDManager()
00055 {
00056
00057 LLHUDManager::sParentColor = gColors.getColor("FocusColor");
00058
00059
00060 }
00061
00062 LLHUDManager::~LLHUDManager()
00063 {
00064 mHUDEffects.reset();
00065 }
00066
00067
00068 void LLHUDManager::updateEffects()
00069 {
00070 LLFastTimer ftm(LLFastTimer::FTM_HUD_EFFECTS);
00071 S32 i;
00072 for (i = 0; i < mHUDEffects.count(); i++)
00073 {
00074 LLHUDEffect *hep = mHUDEffects[i];
00075 if (hep->isDead())
00076 {
00077 continue;
00078 }
00079 hep->update();
00080 }
00081 }
00082
00083 void LLHUDManager::sendEffects()
00084 {
00085 S32 i;
00086 for (i = 0; i < mHUDEffects.count(); i++)
00087 {
00088 LLHUDEffect *hep = mHUDEffects[i];
00089 if (hep->isDead())
00090 {
00091 llwarns << "Trying to send dead effect!" << llendl;
00092 continue;
00093 }
00094 if (hep->mType <= LLHUDObject::LL_HUD_CONNECTOR)
00095 {
00096 llwarns << "Trying to send effect of type " << hep->mType << " which isn't really an effect and shouldn't be in this list!" << llendl;
00097 continue;
00098 }
00099 if (hep->getNeedsSendToSim() && hep->getOriginatedHere())
00100 {
00101 LLMessageSystem* msg = gMessageSystem;
00102 msg->newMessageFast(_PREHASH_ViewerEffect);
00103 msg->nextBlockFast(_PREHASH_AgentData);
00104 msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
00105 msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
00106 msg->nextBlockFast(_PREHASH_Effect);
00107 hep->packData(msg);
00108 hep->setNeedsSendToSim(FALSE);
00109 gAgent.sendMessage();
00110 }
00111 }
00112 }
00113
00114 void LLHUDManager::cleanupEffects()
00115 {
00116 S32 i = 0;
00117
00118 while (i < mHUDEffects.count())
00119 {
00120 if (mHUDEffects[i]->isDead())
00121 {
00122 mHUDEffects.remove(i);
00123 }
00124 else
00125 {
00126 i++;
00127 }
00128 }
00129 }
00130
00131 LLHUDEffect *LLHUDManager::createViewerEffect(const U8 type, BOOL send_to_sim, BOOL originated_here)
00132 {
00133
00134 LLHUDEffect *hep = LLHUDObject::addHUDEffect(type);
00135 if (!hep)
00136 {
00137 return NULL;
00138 }
00139
00140 LLUUID tmp;
00141 tmp.generate();
00142 hep->setID(tmp);
00143 hep->setNeedsSendToSim(send_to_sim);
00144 hep->setOriginatedHere(originated_here);
00145
00146 mHUDEffects.put(hep);
00147 return hep;
00148 }
00149
00150
00151
00152 void LLHUDManager::processViewerEffect(LLMessageSystem *mesgsys, void **user_data)
00153 {
00154 if (gNoRender)
00155 {
00156 return;
00157 }
00158
00159 if (!gHUDManager)
00160 {
00161 llwarns << "No gHUDManager!" << llendl;
00162 return;
00163 }
00164
00165 LLHUDEffect *effectp = NULL;
00166 LLUUID effect_id;
00167 U8 effect_type = 0;
00168 S32 number_blocks = mesgsys->getNumberOfBlocksFast(_PREHASH_Effect);
00169 S32 k;
00170
00171 for (k = 0; k < number_blocks; k++)
00172 {
00173 effectp = NULL;
00174 LLHUDEffect::getIDType(mesgsys, k, effect_id, effect_type);
00175 S32 i;
00176 for (i = 0; i < gHUDManager->mHUDEffects.count(); i++)
00177 {
00178 LLHUDEffect *cur_effectp = gHUDManager->mHUDEffects[i];
00179 if (!cur_effectp)
00180 {
00181 llwarns << "Null effect in effect manager, skipping" << llendl;
00182 gHUDManager->mHUDEffects.remove(i);
00183 i--;
00184 continue;
00185 }
00186 if (cur_effectp->isDead())
00187 {
00188
00189 gHUDManager->mHUDEffects.remove(i);
00190 i--;
00191 continue;
00192 }
00193 if (cur_effectp->getID() == effect_id)
00194 {
00195 if (cur_effectp->getType() != effect_type)
00196 {
00197 llwarns << "Viewer effect update doesn't match old type!" << llendl;
00198 }
00199 effectp = cur_effectp;
00200 break;
00201 }
00202 }
00203
00204 if (effect_type)
00205 {
00206 if (!effectp)
00207 {
00208 effectp = gHUDManager->createViewerEffect(effect_type, FALSE, FALSE);
00209 }
00210
00211 if (effectp)
00212 {
00213 effectp->unpackData(mesgsys, k);
00214 }
00215 }
00216 else
00217 {
00218 llwarns << "Received viewer effect of type " << effect_type << " which isn't really an effect!" << llendl;
00219 }
00220 }
00221
00222
00223 }
00224