llhudobject.cpp

Go to the documentation of this file.
00001 
00032 // llhudobject.cpp
00033 // Copyright 2002, Linden Research, Inc.
00034 
00035 #include "llviewerprecompiledheaders.h"
00036 
00037 #include "llhudobject.h"
00038 #include "llviewerobject.h"
00039 
00040 #include "llhudtext.h"
00041 #include "llhudicon.h"
00042 #include "llhudconnector.h"
00043 #include "llhudeffectbeam.h"
00044 #include "llhudeffecttrail.h"
00045 #include "llhudeffectlookat.h"
00046 
00047 //Ventrella
00048 #include "llvoicevisualizer.h"
00049 #include "llanimalcontrols.h"
00050 #include "lllocalanimationobject.h"
00051 #include "llcape.h"
00052 // End Ventrella
00053 
00054 #include "llagent.h"
00055 
00056 // statics
00057 std::list<LLPointer<LLHUDObject> > LLHUDObject::sHUDObjects;
00058 
00059 struct hud_object_further_away
00060 {
00061         bool operator()(const LLPointer<LLHUDObject>& lhs, const LLPointer<LLHUDObject>& rhs) const;
00062 };
00063 
00064 
00065 bool hud_object_further_away::operator()(const LLPointer<LLHUDObject>& lhs, const LLPointer<LLHUDObject>& rhs) const
00066 {
00067         return (lhs->getDistance() > rhs->getDistance()) ? true : false;
00068 }
00069 
00070 
00071 LLHUDObject::LLHUDObject(const U8 type) : 
00072         mPositionGlobal(), 
00073         mSourceObject(NULL), 
00074         mTargetObject(NULL)
00075 {
00076         mVisible = TRUE;
00077         mType = type;
00078         mDead = FALSE;
00079         mOnHUDAttachment = FALSE;
00080 }
00081 
00082 LLHUDObject::~LLHUDObject()
00083 {
00084 }
00085 
00086 void LLHUDObject::markDead()
00087 {
00088         mVisible = FALSE;
00089         mDead = TRUE;
00090         mSourceObject = NULL;
00091         mTargetObject = NULL;
00092 }
00093 
00094 F32 LLHUDObject::getDistance() const
00095 {
00096         return 0.f;
00097 }
00098 
00099 void LLHUDObject::setSourceObject(LLViewerObject* objectp)
00100 {
00101         if (objectp == mSourceObject)
00102         {
00103                 return;
00104         }
00105 
00106         mSourceObject = objectp;
00107 }
00108 
00109 void LLHUDObject::setTargetObject(LLViewerObject* objectp)
00110 {
00111         if (objectp == mTargetObject)
00112         {
00113                 return;
00114         }
00115 
00116         mTargetObject = objectp;
00117 }
00118 
00119 void LLHUDObject::setPositionGlobal(const LLVector3d &position_global)
00120 {
00121         mPositionGlobal = position_global;
00122 }
00123 
00124 void LLHUDObject::setPositionAgent(const LLVector3 &position_agent)
00125 {
00126         mPositionGlobal = gAgent.getPosGlobalFromAgent(position_agent);
00127 }
00128 
00129 // static
00130 void LLHUDObject::cleanupHUDObjects()
00131 {
00132         LLHUDIcon::cleanupDeadIcons();
00133         hud_object_list_t::iterator object_it;
00134         for (object_it = sHUDObjects.begin(); object_it != sHUDObjects.end(); ++object_it)
00135         {
00136                 (*object_it)->markDead();
00137                 if ((*object_it)->getNumRefs() > 1)
00138                 {
00139                         llinfos << "LLHUDObject " << (LLHUDObject *)(*object_it) << " has " << (*object_it)->getNumRefs() << " refs!" << llendl;
00140                 }
00141         }
00142         sHUDObjects.clear();
00143 }
00144 
00145 // static
00146 LLHUDObject *LLHUDObject::addHUDObject(const U8 type)
00147 {
00148         LLHUDObject *hud_objectp = NULL;
00149         
00150         switch (type)
00151         {
00152         case LL_HUD_TEXT:
00153                 hud_objectp = new LLHUDText(type);
00154                 break;
00155         case LL_HUD_ICON:
00156                 hud_objectp = new LLHUDIcon(type);
00157                 break;
00158         case LL_HUD_CONNECTOR:
00159                 hud_objectp = new LLHUDConnector(type);
00160                 break;
00161         default:
00162                 llwarns << "Unknown type of hud object:" << (U32) type << llendl;
00163         }
00164         if (hud_objectp)
00165         {
00166                 sHUDObjects.push_back(hud_objectp);
00167         }
00168         return hud_objectp;
00169 }
00170 
00171 LLHUDEffect *LLHUDObject::addHUDEffect(const U8 type)
00172 {
00173         LLHUDEffect *hud_objectp = NULL;
00174         
00175         switch (type)
00176         {
00177         case LL_HUD_EFFECT_BEAM:
00178                 hud_objectp = new LLHUDEffectSpiral(type);
00179                 ((LLHUDEffectSpiral *)hud_objectp)->setDuration(0.7f);
00180                 ((LLHUDEffectSpiral *)hud_objectp)->setVMag(0.f);
00181                 ((LLHUDEffectSpiral *)hud_objectp)->setVOffset(0.f);
00182                 ((LLHUDEffectSpiral *)hud_objectp)->setInitialRadius(0.1f);
00183                 ((LLHUDEffectSpiral *)hud_objectp)->setFinalRadius(0.2f);
00184                 ((LLHUDEffectSpiral *)hud_objectp)->setSpinRate(10.f);
00185                 ((LLHUDEffectSpiral *)hud_objectp)->setFlickerRate(0.f);
00186                 ((LLHUDEffectSpiral *)hud_objectp)->setScaleBase(0.05f);
00187                 ((LLHUDEffectSpiral *)hud_objectp)->setScaleVar(0.02f);
00188                 ((LLHUDEffectSpiral *)hud_objectp)->setColor(LLColor4U(255, 255, 255, 255));
00189                 break;
00190         case LL_HUD_EFFECT_GLOW:
00191                 // deprecated
00192                 break;
00193         case LL_HUD_EFFECT_POINT:
00194                 hud_objectp = new LLHUDEffectSpiral(type);
00195                 ((LLHUDEffectSpiral *)hud_objectp)->setDuration(0.5f);
00196                 ((LLHUDEffectSpiral *)hud_objectp)->setVMag(1.f);
00197                 ((LLHUDEffectSpiral *)hud_objectp)->setVOffset(0.f);
00198                 ((LLHUDEffectSpiral *)hud_objectp)->setInitialRadius(0.5f);
00199                 ((LLHUDEffectSpiral *)hud_objectp)->setFinalRadius(1.f);
00200                 ((LLHUDEffectSpiral *)hud_objectp)->setSpinRate(10.f);
00201                 ((LLHUDEffectSpiral *)hud_objectp)->setFlickerRate(0.f);
00202                 ((LLHUDEffectSpiral *)hud_objectp)->setScaleBase(0.1f);
00203                 ((LLHUDEffectSpiral *)hud_objectp)->setScaleVar(0.1f);
00204                 ((LLHUDEffectSpiral *)hud_objectp)->setColor(LLColor4U(255, 255, 255, 255));
00205                 break;
00206         case LL_HUD_EFFECT_SPHERE:
00207                 hud_objectp = new LLHUDEffectSpiral(type);
00208                 ((LLHUDEffectSpiral *)hud_objectp)->setDuration(0.5f);
00209                 ((LLHUDEffectSpiral *)hud_objectp)->setVMag(1.f);
00210                 ((LLHUDEffectSpiral *)hud_objectp)->setVOffset(0.f);
00211                 ((LLHUDEffectSpiral *)hud_objectp)->setInitialRadius(0.5f);
00212                 ((LLHUDEffectSpiral *)hud_objectp)->setFinalRadius(0.5f);
00213                 ((LLHUDEffectSpiral *)hud_objectp)->setSpinRate(20.f);
00214                 ((LLHUDEffectSpiral *)hud_objectp)->setFlickerRate(0.f);
00215                 ((LLHUDEffectSpiral *)hud_objectp)->setScaleBase(0.1f);
00216                 ((LLHUDEffectSpiral *)hud_objectp)->setScaleVar(0.1f);
00217                 ((LLHUDEffectSpiral *)hud_objectp)->setColor(LLColor4U(255, 255, 255, 255));
00218                 break;
00219         case LL_HUD_EFFECT_SPIRAL:
00220                 hud_objectp = new LLHUDEffectSpiral(type);
00221                 ((LLHUDEffectSpiral *)hud_objectp)->setDuration(2.f);
00222                 ((LLHUDEffectSpiral *)hud_objectp)->setVMag(-2.f);
00223                 ((LLHUDEffectSpiral *)hud_objectp)->setVOffset(0.5f);
00224                 ((LLHUDEffectSpiral *)hud_objectp)->setInitialRadius(1.f);
00225                 ((LLHUDEffectSpiral *)hud_objectp)->setFinalRadius(0.5f);
00226                 ((LLHUDEffectSpiral *)hud_objectp)->setSpinRate(10.f);
00227                 ((LLHUDEffectSpiral *)hud_objectp)->setFlickerRate(20.f);
00228                 ((LLHUDEffectSpiral *)hud_objectp)->setScaleBase(0.02f);
00229                 ((LLHUDEffectSpiral *)hud_objectp)->setScaleVar(0.02f);
00230                 ((LLHUDEffectSpiral *)hud_objectp)->setColor(LLColor4U(255, 255, 255, 255));
00231                 break;
00232         case LL_HUD_EFFECT_EDIT:
00233                 hud_objectp = new LLHUDEffectSpiral(type);
00234                 ((LLHUDEffectSpiral *)hud_objectp)->setDuration(2.f);
00235                 ((LLHUDEffectSpiral *)hud_objectp)->setVMag(2.f);
00236                 ((LLHUDEffectSpiral *)hud_objectp)->setVOffset(-1.f);
00237                 ((LLHUDEffectSpiral *)hud_objectp)->setInitialRadius(1.5f);
00238                 ((LLHUDEffectSpiral *)hud_objectp)->setFinalRadius(1.f);
00239                 ((LLHUDEffectSpiral *)hud_objectp)->setSpinRate(4.f);
00240                 ((LLHUDEffectSpiral *)hud_objectp)->setFlickerRate(200.f);
00241                 ((LLHUDEffectSpiral *)hud_objectp)->setScaleBase(0.1f);
00242                 ((LLHUDEffectSpiral *)hud_objectp)->setScaleVar(0.1f);
00243                 ((LLHUDEffectSpiral *)hud_objectp)->setColor(LLColor4U(255, 255, 255, 255));
00244                 break;
00245         case LL_HUD_EFFECT_LOOKAT:
00246                 hud_objectp = new LLHUDEffectLookAt(type);
00247                 break;
00248         case LL_HUD_EFFECT_VOICE_VISUALIZER:
00249                 hud_objectp = new LLVoiceVisualizer(type);
00250                 break;
00251         case LL_HUD_EFFECT_POINTAT:
00252                 hud_objectp = new LLHUDEffectPointAt(type);
00253                 break;
00254         default:
00255                 llwarns << "Unknown type of hud effect:" << (U32) type << llendl;
00256         }
00257 
00258         if (hud_objectp)
00259         {
00260                 sHUDObjects.push_back(hud_objectp);
00261         }
00262         return hud_objectp;
00263 }
00264 
00265 // static
00266 void LLHUDObject::updateAll()
00267 {
00268         LLFastTimer ftm(LLFastTimer::FTM_HUD_UPDATE);
00269         LLHUDText::updateAll();
00270         LLHUDIcon::updateAll();
00271         sortObjects();
00272 }
00273 
00274 // static
00275 void LLHUDObject::renderAll()
00276 {
00277         LLHUDObject *hud_objp;
00278         
00279         hud_object_list_t::iterator object_it;
00280         for (object_it = sHUDObjects.begin(); object_it != sHUDObjects.end(); )
00281         {
00282                 hud_object_list_t::iterator cur_it = object_it++;
00283                 hud_objp = (*cur_it);
00284                 if (hud_objp->getNumRefs() == 1)
00285                 {
00286                         sHUDObjects.erase(cur_it);
00287                 }
00288                 else if (hud_objp->isVisible())
00289                 {
00290                         hud_objp->render();
00291                 }
00292         }
00293 }
00294 
00295 // static
00296 void LLHUDObject::renderAllForSelect()
00297 {
00298         LLHUDObject *hud_objp;
00299         
00300         hud_object_list_t::iterator object_it;
00301         for (object_it = sHUDObjects.begin(); object_it != sHUDObjects.end(); )
00302         {
00303                 hud_object_list_t::iterator cur_it = object_it++;
00304                 hud_objp = (*cur_it);
00305                 if (hud_objp->getNumRefs() == 1)
00306                 {
00307                         sHUDObjects.erase(cur_it);
00308                 }
00309                 else if (hud_objp->isVisible())
00310                 {
00311                         hud_objp->renderForSelect();
00312                 }
00313         }
00314 }
00315 
00316 // static
00317 void LLHUDObject::sortObjects()
00318 {
00319         sHUDObjects.sort(hud_object_further_away());    
00320 }

Generated on Thu Jul 1 06:08:42 2010 for Second Life Viewer by  doxygen 1.4.7