llhudeffecttrail.cpp

Go to the documentation of this file.
00001 
00032 #include "llviewerprecompiledheaders.h"
00033 
00034 #include "llhudeffecttrail.h"
00035 
00036 #include "llviewercontrol.h"
00037 #include "llimagegl.h"
00038 #include "message.h"
00039 
00040 #include "llagent.h"
00041 #include "llbox.h"
00042 #include "lldrawable.h"
00043 #include "llhudrender.h"
00044 #include "llviewerimagelist.h"
00045 #include "llviewerobjectlist.h"
00046 #include "llviewerpartsim.h"
00047 #include "llviewerpartsource.h"
00048 #include "llvoavatar.h"
00049 #include "llworld.h"
00050 
00051 
00052 const F32 PARTICLE_SPACING = 0.01f;
00053 const F32 MAX_SIZE = 0.025f;
00054 const F32 START_POS_MAG = 1.f;
00055 const F32 END_POS_MAG = 1.2f;
00056 
00057 
00058 LLHUDEffectSpiral::LLHUDEffectSpiral(const U8 type) : LLHUDEffect(type), mbInit(FALSE)
00059 {
00060         mKillTime = 10.f;
00061         mVMag = 1.f;
00062         mVOffset = 0.f;
00063         mInitialRadius = 1.f;
00064         mFinalRadius = 1.f;
00065         mSpinRate = 10.f;
00066         mFlickerRate = 50.f;
00067         mScaleBase = 0.1f;
00068         mScaleVar = 0.f;
00069 
00070         mFadeInterp.setStartTime(0.f);
00071         mFadeInterp.setEndTime(mKillTime);
00072         mFadeInterp.setStartVal(1.f);
00073         mFadeInterp.setEndVal(1.f);
00074 }
00075 
00076 LLHUDEffectSpiral::~LLHUDEffectSpiral()
00077 {
00078 }
00079 
00080 void LLHUDEffectSpiral::markDead()
00081 {
00082         if (mPartSourcep)
00083         {
00084                 mPartSourcep->setDead();
00085                 mPartSourcep = NULL;
00086         }
00087         LLHUDObject::markDead();
00088 }
00089 
00090 void LLHUDEffectSpiral::packData(LLMessageSystem *mesgsys)
00091 {
00092         if (!mSourceObject)
00093         {
00094                 //llwarns << "Missing object in trail pack!" << llendl;
00095         }
00096         LLHUDEffect::packData(mesgsys);
00097 
00098         U8 packed_data[56];
00099         memset(packed_data, 0, 56);
00100 
00101         if (mSourceObject)
00102         {
00103                 htonmemcpy(packed_data, mSourceObject->mID.mData, MVT_LLUUID, 16);
00104         }
00105         if (mTargetObject)
00106         {
00107                 htonmemcpy(packed_data + 16, mTargetObject->mID.mData, MVT_LLUUID, 16);
00108         }
00109         if (!mPositionGlobal.isExactlyZero())
00110         {
00111                 htonmemcpy(packed_data + 32, mPositionGlobal.mdV, MVT_LLVector3d, 24);
00112         }
00113         mesgsys->addBinaryDataFast(_PREHASH_TypeData, packed_data, 56);
00114 }
00115 
00116 void LLHUDEffectSpiral::unpackData(LLMessageSystem *mesgsys, S32 blocknum)
00117 {
00118         const size_t EFFECT_SIZE = 56;
00119         U8 packed_data[EFFECT_SIZE];
00120 
00121         LLHUDEffect::unpackData(mesgsys, blocknum);
00122         LLUUID object_id, target_object_id;
00123         S32 size = mesgsys->getSizeFast(_PREHASH_Effect, blocknum, _PREHASH_TypeData);
00124         if (size != EFFECT_SIZE)
00125         {
00126                 llwarns << "Spiral effect with bad size " << size << llendl;
00127                 return;
00128         }
00129         mesgsys->getBinaryDataFast(_PREHASH_Effect, _PREHASH_TypeData, 
00130                 packed_data, EFFECT_SIZE, blocknum, EFFECT_SIZE);
00131         
00132         htonmemcpy(object_id.mData, packed_data, MVT_LLUUID, 16);
00133         htonmemcpy(target_object_id.mData, packed_data + 16, MVT_LLUUID, 16);
00134         htonmemcpy(mPositionGlobal.mdV, packed_data + 32, MVT_LLVector3d, 24);
00135 
00136         LLViewerObject *objp = NULL;
00137 
00138         if (object_id.isNull())
00139         {
00140                 setSourceObject(NULL);
00141         }
00142         else
00143         {
00144                 LLViewerObject *objp = gObjectList.findObject(object_id);
00145                 if (objp)
00146                 {
00147                         setSourceObject(objp);
00148                 }
00149                 else
00150                 {
00151                         // We don't have this object, kill this effect
00152                         markDead();
00153                         return;
00154                 }
00155         }
00156 
00157         if (target_object_id.isNull())
00158         {
00159                 setTargetObject(NULL);
00160         }
00161         else
00162         {
00163                 objp = gObjectList.findObject(target_object_id);
00164                 if (objp)
00165                 {
00166                         setTargetObject(objp);
00167                 }
00168                 else
00169                 {
00170                         // We don't have this object, kill this effect
00171                         markDead();
00172                         return;
00173                 }
00174         }
00175 
00176         triggerLocal();
00177 }
00178 
00179 void LLHUDEffectSpiral::triggerLocal()
00180 {
00181         mKillTime = mTimer.getElapsedTimeF32() + mDuration;
00182 
00183         BOOL show_beam = gSavedSettings.getBOOL("ShowSelectionBeam");
00184 
00185         LLColor4 color;
00186         color.setVec(mColor);
00187 
00188         if (!mPartSourcep)
00189         {
00190                 if (!mTargetObject.isNull() && !mSourceObject.isNull())
00191                 {
00192                         if (show_beam)
00193                         {
00194                                 LLPointer<LLViewerPartSourceBeam> psb = new LLViewerPartSourceBeam;
00195                                 psb->setColor(color);
00196                                 psb->setSourceObject(mSourceObject);
00197                                 psb->setTargetObject(mTargetObject);
00198                                 psb->setOwnerUUID(gAgent.getID());
00199                                 gWorldPointer->mPartSim.addPartSource(psb);
00200                                 mPartSourcep = psb;
00201                         }
00202                 }
00203                 else
00204                 {
00205                         if (!mSourceObject.isNull() && !mPositionGlobal.isExactlyZero())
00206                         {
00207                                 if (show_beam)
00208                                 {
00209                                         LLPointer<LLViewerPartSourceBeam> psb = new LLViewerPartSourceBeam;
00210                                         psb->setSourceObject(mSourceObject);
00211                                         psb->setTargetObject(NULL);
00212                                         psb->setColor(color);
00213                                         psb->mLKGTargetPosGlobal = mPositionGlobal;
00214                                         psb->setOwnerUUID(gAgent.getID());
00215                                         gWorldPointer->mPartSim.addPartSource(psb);
00216                                         mPartSourcep = psb;
00217                                 }
00218                         }
00219                         else
00220                         {
00221                                 LLVector3 pos;
00222                                 if (mSourceObject)
00223                                 {
00224                                         pos = mSourceObject->getPositionAgent();
00225                                 }
00226                                 else
00227                                 {
00228                                         pos = gAgent.getPosAgentFromGlobal(mPositionGlobal);
00229                                 }
00230                                 LLPointer<LLViewerPartSourceSpiral> pss = new LLViewerPartSourceSpiral(pos);
00231                                 if (!mSourceObject.isNull())
00232                                 {
00233                                         pss->setSourceObject(mSourceObject);
00234                                 }
00235                                 pss->setColor(color);
00236                                 pss->setOwnerUUID(gAgent.getID());
00237                                 gWorldPointer->mPartSim.addPartSource(pss);
00238                                 mPartSourcep = pss;
00239                         }
00240                 }
00241         }
00242         else
00243         {
00244                 LLPointer<LLViewerPartSource>& ps = mPartSourcep;
00245                 if (mPartSourcep->getType() == LLViewerPartSource::LL_PART_SOURCE_BEAM)
00246                 {
00247                         LLViewerPartSourceBeam *psb = (LLViewerPartSourceBeam *)ps.get();
00248                         psb->setSourceObject(mSourceObject);
00249                         psb->setTargetObject(mTargetObject);
00250                         psb->setColor(color);
00251                         if (mTargetObject.isNull())
00252                         {
00253                                 psb->mLKGTargetPosGlobal = mPositionGlobal;                             
00254                         }
00255                 }
00256                 else
00257                 {
00258                         LLViewerPartSourceSpiral *pss = (LLViewerPartSourceSpiral *)ps.get();
00259                         pss->setSourceObject(mSourceObject);
00260                 }
00261         }
00262 
00263         mbInit = TRUE;
00264 }
00265 
00266 void LLHUDEffectSpiral::setTargetObject(LLViewerObject *objp)
00267 {
00268         if (objp == mTargetObject)
00269         {
00270                 return;
00271         }
00272 
00273         mTargetObject = objp;
00274 }
00275 
00276 void LLHUDEffectSpiral::render()
00277 {
00278         F32 time = mTimer.getElapsedTimeF32();
00279 
00280         if (!mSourceObject.isNull() && mSourceObject->isDead() ||
00281                 !mTargetObject.isNull() && mTargetObject->isDead() ||
00282                 mKillTime < time ||
00283                 !gSavedSettings.getBOOL("ShowSelectionBeam"))
00284         {
00285                 markDead();
00286                 return;
00287         }
00288 }

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