PageRenderTime 433ms CodeModel.GetById 171ms app.highlight 15ms RepoModel.GetById 187ms app.codeStats 0ms

/indra/newview/llviewerpartsim.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 203 lines | 123 code | 49 blank | 31 comment | 2 complexity | 7c0c5e6bb84f653f9250c7d2299fbf9c MD5 | raw file
  1/** 
  2 * @file llviewerpartsim.h
  3 * @brief LLViewerPart class header file
  4 *
  5 * $LicenseInfo:firstyear=2003&license=viewerlgpl$
  6 * Second Life Viewer Source Code
  7 * Copyright (C) 2010, Linden Research, Inc.
  8 * 
  9 * This library is free software; you can redistribute it and/or
 10 * modify it under the terms of the GNU Lesser General Public
 11 * License as published by the Free Software Foundation;
 12 * version 2.1 of the License only.
 13 * 
 14 * This library is distributed in the hope that it will be useful,
 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 17 * Lesser General Public License for more details.
 18 * 
 19 * You should have received a copy of the GNU Lesser General Public
 20 * License along with this library; if not, write to the Free Software
 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 22 * 
 23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 24 * $/LicenseInfo$
 25 */
 26
 27#ifndef LL_LLVIEWERPARTSIM_H
 28#define LL_LLVIEWERPARTSIM_H
 29
 30#include "lldarrayptr.h"
 31#include "llframetimer.h"
 32#include "llpointer.h"
 33#include "llpartdata.h"
 34#include "llviewerpartsource.h"
 35
 36class LLViewerTexture;
 37class LLViewerPart;
 38class LLViewerRegion;
 39class LLViewerTexture;
 40class LLVOPartGroup;
 41
 42typedef void (*LLVPCallback)(LLViewerPart &part, const F32 dt);
 43
 44///////////////////
 45//
 46// An individual particle
 47//
 48
 49
 50class LLViewerPart : public LLPartData
 51{
 52public:
 53	~LLViewerPart();
 54public:
 55	LLViewerPart();
 56
 57	void init(LLPointer<LLViewerPartSource> sourcep, LLViewerTexture *imagep, LLVPCallback cb);
 58
 59
 60	U32					mPartID;					// Particle ID used primarily for moving between groups
 61	F32					mLastUpdateTime;			// Last time the particle was updated
 62	F32					mSkipOffset;				// Offset against current group mSkippedTime
 63
 64	LLVPCallback		mVPCallback;				// Callback function for more complicated behaviors
 65	LLPointer<LLViewerPartSource> mPartSourcep;		// Particle source used for this object
 66	
 67
 68	// Current particle state (possibly used for rendering)
 69	LLPointer<LLViewerTexture>	mImagep;
 70	LLVector3		mPosAgent;
 71	LLVector3		mVelocity;
 72	LLVector3		mAccel;
 73	LLColor4		mColor;
 74	LLVector2		mScale;
 75
 76	static U32		sNextPartID;
 77};
 78
 79
 80
 81class LLViewerPartGroup
 82{
 83public:
 84	LLViewerPartGroup(const LLVector3 &center,
 85					  const F32 box_radius,
 86					  bool hud);
 87	virtual ~LLViewerPartGroup();
 88
 89	void cleanup();
 90
 91	BOOL addPart(LLViewerPart* part, const F32 desired_size = -1.f);
 92	
 93	void updateParticles(const F32 lastdt);
 94
 95	BOOL posInGroup(const LLVector3 &pos, const F32 desired_size = -1.f);
 96
 97	void shift(const LLVector3 &offset);
 98
 99	typedef std::vector<LLViewerPart*>  part_list_t;
100	part_list_t mParticles;
101
102	const LLVector3 &getCenterAgent() const		{ return mCenterAgent; }
103	S32 getCount() const					{ return (S32) mParticles.size(); }
104	LLViewerRegion *getRegion() const		{ return mRegionp; }
105
106	void removeParticlesByID(const U32 source_id);
107	
108	LLPointer<LLVOPartGroup> mVOPartGroupp;
109
110	BOOL mUniformParticles;
111	U32 mID;
112
113	F32 mSkippedTime;
114	bool mHud;
115
116protected:
117	LLVector3 mCenterAgent;
118	F32 mBoxRadius;
119	LLVector3 mMinObjPos;
120	LLVector3 mMaxObjPos;
121
122	LLViewerRegion *mRegionp;
123};
124
125class LLViewerPartSim : public LLSingleton<LLViewerPartSim>
126{
127public:
128	LLViewerPartSim();
129	virtual ~LLViewerPartSim(){}
130	void destroyClass();
131
132	typedef std::vector<LLViewerPartGroup *> group_list_t;
133	typedef std::vector<LLPointer<LLViewerPartSource> > source_list_t;
134
135	void shift(const LLVector3 &offset);
136
137	void updateSimulation();
138
139	void addPartSource(LLPointer<LLViewerPartSource> sourcep);
140
141	void cleanupRegion(LLViewerRegion *regionp);
142
143	BOOL shouldAddPart(); // Just decides whether this particle should be added or not (for particle count capping)
144	F32 maxRate() // Return maximum particle generation rate
145	{
146		if (sParticleCount >= MAX_PART_COUNT)
147		{
148			return 1.f;
149		}
150		if (sParticleCount > PART_THROTTLE_THRESHOLD*sMaxParticleCount)
151		{
152			return (((F32)sParticleCount/(F32)sMaxParticleCount)-PART_THROTTLE_THRESHOLD)*PART_THROTTLE_RESCALE;
153		}
154		return 0.f;
155	}
156	F32 getRefRate() { return sParticleAdaptiveRate; }
157	F32 getBurstRate() {return sParticleBurstRate; }
158	void addPart(LLViewerPart* part);
159	void updatePartBurstRate() ;
160	void clearParticlesByID(const U32 system_id);
161	void clearParticlesByOwnerID(const LLUUID& task_id);
162	void removeLastCreatedSource();
163
164	const source_list_t* getParticleSystemList() const { return &mViewerPartSources; }
165
166	friend class LLViewerPartGroup;
167
168	BOOL aboveParticleLimit() const { return sParticleCount > sMaxParticleCount; }
169
170	static void setMaxPartCount(const S32 max_parts)	{ sMaxParticleCount = max_parts; }
171	static S32  getMaxPartCount()						{ return sMaxParticleCount; }
172	static void incPartCount(const S32 count)			{ sParticleCount += count; }
173	static void decPartCount(const S32 count)			{ sParticleCount -= count; }
174	
175	U32 mID;
176
177protected:
178	LLViewerPartGroup *createViewerPartGroup(const LLVector3 &pos_agent, const F32 desired_size, bool hud);
179	LLViewerPartGroup *put(LLViewerPart* part);
180
181	group_list_t mViewerPartGroups;
182	source_list_t mViewerPartSources;
183	LLFrameTimer mSimulationTimer;
184
185	static S32 sMaxParticleCount;
186	static S32 sParticleCount;
187	static F32 sParticleAdaptiveRate;
188	static F32 sParticleBurstRate;
189
190	static const S32 MAX_PART_COUNT;
191	static const F32 PART_THROTTLE_THRESHOLD;
192	static const F32 PART_THROTTLE_RESCALE;
193	static const F32 PART_ADAPT_RATE_MULT;
194	static const F32 PART_ADAPT_RATE_MULT_RECIP;
195
196//debug use only
197public:
198	static S32 sParticleCount2;
199
200	static void checkParticleCount(U32 size = 0) ;
201};
202
203#endif // LL_LLVIEWERPARTSIM_H