llhudmanager.cpp

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

Generated on Fri May 16 08:33:39 2008 for SecondLife by  doxygen 1.5.5