llviewerpartsim.h

Go to the documentation of this file.
00001 
00032 #ifndef LL_LLVIEWERPARTSIM_H
00033 #define LL_LLVIEWERPARTSIM_H
00034 
00035 #include "lldarrayptr.h"
00036 #include "llskiplist.h"
00037 #include "llframetimer.h"
00038 #include "llmemory.h"
00039 
00040 #include "llpartdata.h"
00041 
00042 class LLViewerImage;
00043 class LLViewerPart;
00044 class LLViewerPartSource;
00045 class LLViewerRegion;
00046 class LLViewerImage;
00047 class LLVOPartGroup;
00048 
00049 typedef void (*LLVPCallback)(LLViewerPart &part, const F32 dt);
00050 
00052 //
00053 // An individual particle
00054 //
00055 
00056 
00057 class LLViewerPart : public LLPartData, public LLRefCount
00058 {
00059 protected:
00060         ~LLViewerPart();
00061 public:
00062         LLViewerPart();
00063 
00064         LLViewerPart &operator=(const LLViewerPart &part);
00065         void init(LLPointer<LLViewerPartSource> sourcep, LLViewerImage *imagep, LLVPCallback cb);
00066 
00067 
00068         U32                                     mPartID;                                        // Particle ID used primarily for moving between groups
00069         F32                                     mLastUpdateTime;                        // Last time the particle was updated
00070 
00071 
00072         LLVPCallback            mVPCallback;                            // Callback function for more complicated behaviors
00073         LLPointer<LLViewerPartSource> mPartSourcep;             // Particle source used for this object
00074         
00075 
00076         // Current particle state (possibly used for rendering)
00077         LLPointer<LLViewerImage>        mImagep;
00078         LLVector3               mPosAgent;
00079         LLVector3               mVelocity;
00080         LLVector3               mAccel;
00081         LLColor4                mColor;
00082         LLVector2               mScale;
00083 
00084         static U32              sNextPartID;
00085 };
00086 
00087 
00088 
00089 class LLViewerPartGroup
00090 {
00091 public:
00092         LLViewerPartGroup(const LLVector3 &center,
00093                                           const F32 box_radius);
00094         virtual ~LLViewerPartGroup();
00095 
00096         void cleanup();
00097 
00098         BOOL addPart(LLViewerPart* part, const F32 desired_size = -1.f);
00099         
00100         void updateParticles(const F32 dt);
00101 
00102         BOOL posInGroup(const LLVector3 &pos, const F32 desired_size = -1.f);
00103 
00104         void shift(const LLVector3 &offset);
00105 
00106         typedef std::vector<LLPointer<LLViewerPart> > part_list_t;
00107         part_list_t mParticles;
00108 
00109         const LLVector3 &getCenterAgent() const         { return mCenterAgent; }
00110         S32 getCount() const                                    { return (S32) mParticles.size(); }
00111         LLViewerRegion *getRegion() const               { return mRegionp; }
00112 
00113         void removeParticlesByID(const U32 source_id);
00114         
00115         LLPointer<LLVOPartGroup> mVOPartGroupp;
00116 
00117         BOOL mUniformParticles;
00118         U32 mID;
00119 
00120 protected:
00121         void removePart(const S32 part_num);
00122 
00123 protected:
00124         LLVector3 mCenterAgent;
00125         F32 mBoxRadius;
00126         LLVector3 mMinObjPos;
00127         LLVector3 mMaxObjPos;
00128 
00129         LLViewerRegion *mRegionp;
00130 };
00131 
00132 class LLViewerPartSim
00133 {
00134 
00135 public:
00136         LLViewerPartSim();
00137         virtual ~LLViewerPartSim();
00138 
00139         typedef std::vector<LLViewerPartGroup *> group_list_t;
00140         typedef std::vector<LLPointer<LLViewerPartSource> > source_list_t;
00141 
00142         void shift(const LLVector3 &offset);
00143 
00144         void updateSimulation();
00145 
00146         void addPartSource(LLPointer<LLViewerPartSource> sourcep);
00147 
00148         void cleanupRegion(LLViewerRegion *regionp);
00149 
00150         BOOL shouldAddPart(); // Just decides whether this particle should be added or not (for particle count capping)
00151         void addPart(LLViewerPart* part);
00152         void clearParticlesByID(const U32 system_id);
00153         void clearParticlesByOwnerID(const LLUUID& task_id);
00154         void removeLastCreatedSource();
00155 
00156         const source_list_t* getParticleSystemList() const { return &mViewerPartSources; }
00157 
00158         friend class LLViewerPartGroup;
00159 
00160         BOOL aboveParticleLimit() const { return sParticleCount > sMaxParticleCount; }
00161 
00162         static void setMaxPartCount(const S32 max_parts)        { sMaxParticleCount = max_parts; }
00163         static S32  getMaxPartCount()                                           { return sMaxParticleCount; }
00164         static void incPartCount(const S32 count)                       { sParticleCount += count; }
00165         static void decPartCount(const S32 count)                       { sParticleCount -= count; }
00166         
00167         U32 mID;
00168 
00169 protected:
00170         LLViewerPartGroup *createViewerPartGroup(const LLVector3 &pos_agent, const F32 desired_size);
00171         LLViewerPartGroup *put(LLViewerPart* part);
00172 
00173 protected:
00174         group_list_t mViewerPartGroups;
00175         source_list_t mViewerPartSources;
00176         LLFrameTimer mSimulationTimer;
00177         static S32 sMaxParticleCount;
00178         static S32 sParticleCount;
00179 };
00180 
00181 #endif // LL_LLVIEWERPARTSIM_H

Generated on Thu Jul 1 06:09:33 2010 for Second Life Viewer by  doxygen 1.4.7