particle_system_model.h
Go to the documentation of this file.00001
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef NL_PARTICLE_SYSTEM_MODEL_H
00025 #define NL_PARTICLE_SYSTEM_MODEL_H
00026
00027 #include "nel/misc/types_nl.h"
00028 #include "nel/misc/plane.h"
00029 #include "nel/misc/contiguous_block_allocator.h"
00030 #include "nel/3d/transform_shape.h"
00031 #include "nel/3d/particle_system.h"
00032 #include "nel/3d/particle_system_manager.h"
00033 #include "nel/3d/clip_trav.h"
00034 #include "nel/3d/anim_detail_trav.h"
00035 #include "nel/3d/load_balancing_trav.h"
00036 #include "nel/3d/scene.h"
00037
00038
00039 #include "nel/misc/hierarchical_timer.h"
00040
00041 #include <vector>
00042
00043 namespace NL3D {
00044
00046
00047
00048
00050
00051 class CParticleSystem;
00052 class CScene;
00053 class CParticleSystemShape;
00054
00055
00061 class CParticleSystemModel : public CTransformShape
00062 {
00063 public:
00065
00066
00067 CParticleSystemModel();
00069 ~CParticleSystemModel();
00070
00072 static void registerBasic();
00074
00076
00077
00082 CParticleSystem *getPS(void)
00083 {
00084 return _ParticleSystem;
00085 }
00086
00090 const CParticleSystem *getPS(void) const
00091 {
00092 return _ParticleSystem;
00093 }
00094
00098 void setParticleSystem(CParticleSystem *ps)
00099 {
00100 nlassert(!_ParticleSystem);
00101 _ParticleSystem = ps;
00102 updateOpacityInfos();
00103 }
00105
00107
00108
00112 bool isInvalid(void) const { return _Invalidated; }
00113
00115 struct IPSModelObserver
00116 {
00117 virtual ~IPSModelObserver() {}
00119 virtual void invalidPS(CParticleSystemModel *psm) = 0;
00120 };
00121
00123 void registerPSModelObserver(IPSModelObserver *obs);
00124
00128 void removePSModelObserver(IPSModelObserver *obs);
00130 bool isPSModelObserver(IPSModelObserver *obs);
00132
00133
00134
00136
00140 void enableAutoGetEllapsedTime(bool enable = true)
00141 {
00142 _AutoGetEllapsedTime = enable;
00143 }
00148 void setEllapsedTimeRatio(float value)
00149 {
00150 nlassert(value >= 0);
00151 _EllapsedTimeRatio = value;
00152 }
00153
00154 float getEllapsedTimeRatio() const { return _EllapsedTimeRatio; }
00156 bool isAutoGetEllapsedTimeEnabled(void) const
00157 {
00158 return _AutoGetEllapsedTime;
00159 }
00161 void setEllapsedTime(TAnimationTime ellapsedTime)
00162 {
00163 _EllapsedTime = ellapsedTime;
00164 }
00166 TAnimationTime getEllapsedTime(void) const
00167 {
00168 return _EllapsedTime;
00169 }
00171
00173
00174
00175 void enableDisplayTools(bool enable = true);
00176
00177
00178 bool isToolDisplayEnabled(void) const
00179 {
00180 return _ToolDisplayEnabled;
00181 }
00188 void setEditionMode(bool enable = true) ;
00190 bool getEditionMode(void) const
00191 {
00192 return _EditionMode;
00193 }
00195 void touchTransparencyState(void)
00196 {
00197 _TransparencyStateTouched = true;
00198 }
00200 void touchLightableState(void)
00201 {
00202 _LightableStateTouched = true;
00203 }
00205
00207
00208
00209 enum TAnimValues
00210 {
00211 OwnerBit= CTransformShape::AnimValueLast,
00212 PSParam0,
00213 PSParam1,
00214 PSParam2,
00215 PSParam3,
00216 PSTrigger,
00217 AnimValueLast,
00218 };
00219 virtual IAnimatedValue *getValue (uint valueId);
00220 virtual const char *getValueName (uint valueId) const;
00221 static const char *getPSParamName (uint valueId);
00222 virtual ITrack *getDefaultTrack (uint valueId);
00223 virtual void registerToChannelMixer(CChannelMixer *chanMixer,
00224 const std::string &prefix = "");
00225
00226 void bypassGlobalUserParamValue(uint userParamIndex, bool byPass = true);
00227 bool isGlobalUserParamValueBypassed(uint userParamIndex) const;
00229
00233 void updateOpacityInfos(void);
00234
00235 void updateLightingInfos(void);
00236
00237 virtual void getAABBox(NLMISC::CAABBox &bbox) const;
00239 virtual float getNumTriangles (float distance);
00241 static CTransform *creator()
00242 {
00243 return new CParticleSystemModel;
00244 }
00245
00246
00248
00251 virtual void traverseClip();
00252
00253 virtual bool clip();
00259 virtual void traverseAnimDetail();
00260 virtual void traverseRender();
00261
00262
00263
00264 void activateEmitters(bool active);
00265
00266 bool hasActiveEmitters() const;
00267
00268
00269 void setUserColor(NLMISC::CRGBA userColor);
00270 NLMISC::CRGBA getUserColor() const { return _UserColor; }
00271
00280 void setUserMatrix(const NLMISC::CMatrix &userMatrix) { _UserMatrix = userMatrix; }
00281
00282 void forceSetUserMatrix(const NLMISC::CMatrix &userMatrix);
00283 const NLMISC::CMatrix &getUserMatrix() const { return _UserMatrix; }
00284
00285 void forceInstanciate();
00286
00287
00288 void setZBias(float value);
00289
00290
00291 void stopSound();
00292 void reactivateSound();
00293
00294
00295 virtual void update();
00296
00299 private:
00300 friend class CParticleSystemShape;
00301 friend class CParticleSystemManager;
00302
00303
00305 void reallocRsc();
00307 void refreshRscDeletion(const std::vector<CPlane> &worldFrustumPyramid, const NLMISC::CVector &viewerPos);
00308
00309 void releaseRsc();
00310
00311 void releaseRscAndInvalidate();
00313 bool checkAgainstPyramid(const std::vector<CPlane> &worldFrustumPyramid) const;
00314
00315 void releasePSPointer();
00316
00317 void invalidateAutoAnimatedHandle();
00318
00319
00320
00321 void insertInVisibleList()
00322 {
00323
00324 if (!_InsertedInVisibleList)
00325 {
00326 _Visible = true;
00327 _InsertedInVisibleList = true;
00328
00329 getOwnerScene()->getClipTrav().addVisibleModel(this);
00330 getOwnerScene()->getLoadBalancingTrav().addVisibleModel(this);
00331
00332
00333 if( _AncestorSkeletonModel==NULL )
00334 {
00335
00336
00337
00338 if( isLightable() )
00339 getOwnerScene()->getLightTrav().addLightedModel(this);
00340
00341
00342
00343 getOwnerScene()->getAnimDetailTrav().addVisibleModel(this);
00344 }
00345 }
00346 }
00347 bool checkDestroyCondition(CParticleSystem *ps);
00348
00349 void doAnimate();
00350
00351 private:
00352 CParticleSystemManager::TModelHandle _ModelHandle;
00355 CParticleSystemManager::TAlwaysAnimatedModelHandle _AnimatedModelHandle;
00356 NLMISC::CSmartPtr<CParticleSystem> _ParticleSystem;
00357 CScene *_Scene;
00358 TAnimationTime _EllapsedTime;
00359 float _EllapsedTimeRatio;
00360
00361
00362 CParticleSystem::TAnimType _AnimType;
00363
00364 bool _AutoGetEllapsedTime : 1;
00365 bool _ToolDisplayEnabled : 1;
00366 bool _TransparencyStateTouched : 1;
00367 bool _LightableStateTouched : 1;
00368 bool _EditionMode : 1;
00369 bool _Invalidated : 1;
00370 bool _InsertedInVisibleList : 1;
00371 bool _InClusterAndVisible : 1;
00372 bool _EmitterActive : 1;
00373 bool _SoundActive : 1;
00374
00375 std::vector<IPSModelObserver *> _Observers;
00376 CAnimatedValueBool _TriggerAnimatedValue;
00378 CAnimatedValueFloat _UserParam[MaxPSUserParam];
00379 uint8 _BypassGlobalUserParam;
00380 NLMISC::CRGBA _UserColor;
00381 NLMISC::CMatrix _UserMatrix;
00382 float _ZBias;
00383 CHrcTrav::TVisibility _LastVisibility;
00384
00385 #ifdef PS_FAST_ALLOC
00386
00387 NLMISC::CContiguousBlockAllocator _Allocator;
00388 #endif
00389 };
00390
00391
00392
00393 class CMiniTimer
00394 {
00395 public:
00396 NLMISC::CSimpleClock SC;
00397 uint64 &Target;
00398 uint64 StartDate;
00399 CMiniTimer(uint64 &target) : Target(target)
00400 {
00401 SC.start();
00402 }
00403 ~CMiniTimer()
00404 {
00405 SC.stop();
00406 Target += SC.getNumTicks();
00407 }
00408 };
00409
00410 #define MINI_TIMER(name)
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478 }
00479
00480
00481
00482
00483
00484
00485 #endif // NL_PARTICLE_SYSTEM_MODEL_H
00486
00487
00488
00489
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508