particle_system.h

Go to the documentation of this file.
00001 
00005 /* Copyright, 2001 Nevrax Ltd.
00006  *
00007  * This file is part of NEVRAX NEL.
00008  * NEVRAX NEL is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation; either version 2, or (at your option)
00011  * any later version.
00012 
00013  * NEVRAX NEL is distributed in the hope that it will be useful, but
00014  * WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00016  * General Public License for more details.
00017 
00018  * You should have received a copy of the GNU General Public License
00019  * along with NEVRAX NEL; see the file COPYING. If not, write to the
00020  * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00021  * MA 02111-1307, USA.
00022  */
00023 
00024 #ifndef NL_PARTICLE_SYSTEM_H
00025 #define NL_PARTICLE_SYSTEM_H
00026 
00027 #include "nel/misc/types_nl.h"
00028 #include "nel/misc/matrix.h"
00029 #include "nel/misc/aabbox.h"
00030 #include "nel/misc/smart_ptr.h"
00031 #include "nel/misc/rgba.h"
00032 #include "nel/misc/object_arena_allocator.h"
00033 #include "nel/3d/animation_time.h"
00034 #include "nel/3d/animation_time.h"
00035 #include "nel/3d/animated_value.h"
00036 #include "nel/3d/particle_system_process.h"
00037 #include "nel/3d/ps_lod.h"
00038 #include "nel/3d/ps_attrib_maker.h"
00039 #include "nel/3d/ps_spawn_info.h"
00040 
00041 #include <map>
00042 
00043 
00044 
00045 namespace NL3D
00046 {
00047 
00048 class CParticleSystemShape;
00049 class CParticleSystemModel;
00050 class CPSLocated;
00051 class CPSLocatedBindable;
00052 class CFontGenerator;
00053 class CFontManager;
00054 class CPSCopyHelper;
00055 class CScene;
00056 class CPSLocated;
00057 class IDriver;
00058 struct UPSSoundServer;
00059 
00060 
00061 
00062 
00064 const uint MaxPSUserParam = 4;
00065 
00066 
00078 class CParticleSystem : public NLMISC::CRefCount
00079 {
00080 public:
00081     PS_FAST_OBJ_ALLOC
00082     // the pass that is applied on particles
00083     enum TPass { Anim, SolidRender, BlendRender, ToolRender };
00084 public:
00085     //*****************************************************************************************************
00086 
00088 
00089 
00090             CParticleSystem();
00092             virtual ~CParticleSystem();
00094             void serial(NLMISC::IStream &f)  throw(NLMISC::EStream);
00100             bool merge(CParticleSystemShape *toMerge);
00101 
00102             /*** duplication method NOT SUPPORTED for now (duplication is using streams, but it may not last)
00103              * \param ch for private use, set to null by default
00104              */
00105             //  CParticleSystem *clone(CPSCopyHelper *ch = NULL) ;
00107 
00108     //*****************************************************************************************************
00109 
00111 
00112 
00120             void    enableSharing(bool enabled = true) { _Sharing = enabled; }
00121 
00123             bool    isSharingEnabled() const { return _Sharing; }
00125 
00126     //*****************************************************************************************************
00127 
00129 
00130 
00131         void setDriver(IDriver *driver) { _Driver = driver; }
00132 
00134         IDriver *getDriver(void) { return _Driver; }
00136     //*****************************************************************************************************
00137 
00139 
00140 
00143         void setScene(CScene *scene) { _Scene = scene; }
00144 
00146         CScene *getScene() const { return _Scene; }
00148 
00149     //*****************************************************************************************************
00150 
00152 
00153 
00157             void    hide(bool hidden) { _HiddenAtCurrentFrame = hidden; }
00161             void onShow(bool shown);
00167             void setSysMat(const NLMISC::CMatrix *m);
00168 
00172             void setUserMatrix(const NLMISC::CMatrix *m);
00173 
00175             const NLMISC::CMatrix &getSysMat() const
00176             {
00177                 return _CoordSystemInfo.Matrix ? *_CoordSystemInfo.Matrix : NLMISC::CMatrix::Identity;
00178             }
00179 
00181             const NLMISC::CMatrix &getInvertedSysMat() const { return _CoordSystemInfo.InvMatrix; }
00182 
00188             const NLMISC::CMatrix &getUserMatrix() const
00189             {
00190                 NL_PS_FUNC_MAIN(getUserMatrix)
00191                 return (_UserCoordSystemInfo && _UserCoordSystemInfo->CoordSystemInfo.Matrix) ? *(_UserCoordSystemInfo->CoordSystemInfo.Matrix) : getSysMat();
00192             }
00193 
00199             const NLMISC::CMatrix &getInvertedUserMatrix() const { return (_UserCoordSystemInfo && _UserCoordSystemInfo->CoordSystemInfo.Matrix) ? _UserCoordSystemInfo->CoordSystemInfo.InvMatrix : getInvertedSysMat(); }
00200 
00201             // conversion matrix (from user matrix to fx matrix)
00202             const NLMISC::CMatrix &getUserToFXMatrix() const { return (_UserCoordSystemInfo && _UserCoordSystemInfo->CoordSystemInfo.Matrix) ? _UserCoordSystemInfo->UserBasisToFXBasis : NLMISC::CMatrix::Identity; }
00203             // conversion matrix (from fx matrix to user matrix)
00204             const NLMISC::CMatrix &getFXToUserMatrix() const { return (_UserCoordSystemInfo && _UserCoordSystemInfo->CoordSystemInfo.Matrix) ? _UserCoordSystemInfo->FXBasisToUserBasis : NLMISC::CMatrix::Identity; }
00205 
00209             void setViewMat(const NLMISC::CMatrix &m);
00210 
00212             const NLMISC::CMatrix &getViewMat(void) const { return _ViewMat; }
00213 
00215             const NLMISC::CMatrix &getInvertedViewMat(void) const { return _InvertedViewMat; }
00217 
00218 
00219     //*****************************************************************************************************
00220 
00222 
00223 
00230         virtual void step(TPass pass, TAnimationTime ellapsedTime, CParticleSystemShape &shape, CParticleSystemModel &model);
00232 
00233 
00234 
00236         static uint32 NbParticlesDrawn;
00237 
00238     //*****************************************************************************************************
00239 
00251         bool                        attach(CParticleSystemProcess *process);
00252 
00255         CParticleSystemProcess      *detach(uint index);
00256 
00259         bool                        isProcess(const CParticleSystemProcess *process) const;
00260 
00264         uint                        getIndexOf(const CParticleSystemProcess &process) const;
00265 
00270         void                        remove(CParticleSystemProcess *process);
00271 
00273         uint32                      getNbProcess(void) const { return _ProcessVect.size(); }
00274 
00279         CParticleSystemProcess      *getProcess(uint32 index)
00280         {
00281             nlassert(index < _ProcessVect.size());
00282             return _ProcessVect[index];
00283         }
00284 
00289         const CParticleSystemProcess *getProcess(uint32 index) const
00290         {
00291             nlassert(index < _ProcessVect.size());
00292             return _ProcessVect[index];
00293         }
00294 
00296 
00297     //*****************************************************************************************************
00298 
00300 
00301 
00303         TAnimationTime getSystemDate(void) const { return _SystemDate; }
00304 
00306         void setSystemDate(float date);
00307 
00312         uint64 getDate(void) const
00313         {
00314             NL_PS_FUNC_MAIN(getDate)
00315             return _Date;
00316         }
00318 
00319     //*****************************************************************************************************
00320 
00329         void setUserParam(uint userParamIndex, float value)
00330         {
00331             NL_PS_FUNC_MAIN(setUserParam)
00332             nlassert(userParamIndex < MaxPSUserParam);
00333             NLMISC::clamp(value, 0, MaxInputValue);
00334             _UserParam[userParamIndex] = value;
00335         }
00336 
00340         float getUserParam(uint userParamIndex) const
00341         {
00342             NL_PS_FUNC_MAIN(getUserParam)
00343             nlassert(userParamIndex < MaxPSUserParam);
00344             return _UserParam[userParamIndex];
00345         }
00346 
00352         void  bindGlobalValueToUserParam(const std::string &globalValueName, uint userParamIndex);
00353         // Get name of a global value, or NULL if no global value is bound to that user param
00354         std::string getGlobalValueName(uint userParamIndex) const;
00355         // Set a global value
00356         static void  setGlobalValue(const std::string &name, float value);
00357         // Get a global value
00358         static float getGlobalValue(const std::string &name);
00362         static void                  setGlobalVectorValue(const std::string &name, const NLMISC::CVector &value);
00363         // Get a global vector value
00364         static NLMISC::CVector       getGlobalVectorValue(const std::string &name);
00365         // define a handle to a global value
00366         class CGlobalVectorValueHandle
00367         {
00368         public:
00369             CGlobalVectorValueHandle() { reset(); }
00370             const NLMISC::CVector &get() const                       { nlassert(_Value); return *_Value; }
00371             void                   set(const NLMISC::CVector &value) { nlassert(_Value); *_Value = value; }
00372             const std::string     &getName() const                   { nlassert(_Name); return *_Name; }
00373             bool                   isValid() const { return _Name != NULL && _Value != NULL; }
00374             void                   reset() { _Name = NULL; _Value = NULL; }
00376         private:
00377             friend class CParticleSystem;
00378             const std::string *_Name;
00379             NLMISC::CVector   *_Value;
00380         };
00381         // Get a handle on a global value that provide a quick access on it (no map lookup)
00382         static CGlobalVectorValueHandle     getGlobalVectorValueHandle(const std::string &name);
00384 
00385 
00386 
00387     //*****************************************************************************************************
00388 
00390         // @{
00396          void setCurrentEditedElement(CPSLocated *loc = NULL , uint32 index = 0, class CPSLocatedBindable *bd = NULL )
00397          {
00398             NL_PS_FUNC_MAIN(setCurrentEditedElement)
00399             _CurrEditedElementLocated = loc;
00400             _CurrEditedElementLocatedBindable = bd;
00401             _CurrEditedElementIndex = index;
00402          }
00403 
00407          void getCurrentEditedElement(CPSLocated *&loc , uint32 &index, CPSLocatedBindable *&lb)
00408          {
00409             NL_PS_FUNC_MAIN(getCurrentEditedElement)
00410             loc = _CurrEditedElementLocated;
00411             index = _CurrEditedElementIndex;
00412             lb = _CurrEditedElementLocatedBindable;
00413          }
00414 
00416         void setFontGenerator(CFontGenerator *fg) { _FontGenerator = fg; }
00417 
00419         CFontGenerator *getFontGenerator(void) { return _FontGenerator; }
00420 
00422         const CFontGenerator *getFontGenerator(void) const { return _FontGenerator; }
00423 
00425         void setFontManager(CFontManager *fg) { _FontManager = fg; }
00426 
00428         CFontManager *getFontManager(void) { return _FontManager; }
00429 
00431         const CFontManager *getFontManager(void) const { return _FontManager; }
00432         // @}
00433 
00435         void setName(const std::string &s) { _Name = s; }
00436 
00438         std::string getName(void) const { return _Name; }
00439 
00440     //*****************************************************************************************************
00441 
00443     // @{
00445         bool hasOpaqueObjects(void) const;
00446 
00448         bool hasTransparentObjects(void) const;
00449     // @}
00450 
00451     //*****************************************************************************************************
00452 
00454     // @{
00456         bool hasLightableObjects() const;
00457     // @}
00458 
00459     //*****************************************************************************************************
00460 
00462     // @{
00466         void enableAccurateIntegration(bool enable = true) { _AccurateIntegration = enable; }
00467         bool isAccurateIntegrationEnabled(void) const { return _AccurateIntegration; }
00468 
00474         void setAccurateIntegrationParams(TAnimationTime threshold,
00475                                           uint32 maxNbIntegrations,
00476                                           bool canSlowDown,
00477                                           bool keepEllapsedTimeForLifeUpdate
00478                                          )
00479         {
00480             NL_PS_FUNC_MAIN(setAccurateIntegrationParams)
00481             _TimeThreshold = threshold;
00482             _MaxNbIntegrations = maxNbIntegrations;
00483             _CanSlowDown = canSlowDown;
00484             if (_KeepEllapsedTimeForLifeUpdate != keepEllapsedTimeForLifeUpdate)
00485             {
00486                 _KeepEllapsedTimeForLifeUpdate = keepEllapsedTimeForLifeUpdate;
00487                 _PresetBehaviour = UserBehaviour;
00488             }
00489         }
00490 
00494         void getAccurateIntegrationParams(TAnimationTime &threshold,
00495                                           uint32 &maxNbIntegrations,
00496                                           bool &canSlowDown,
00497                                           bool &keepEllapsedTimeForLifeUpdate
00498                                          )
00499         {
00500             NL_PS_FUNC_MAIN(getAccurateIntegrationParams)
00501             threshold = _TimeThreshold;
00502             maxNbIntegrations = _MaxNbIntegrations;
00503             canSlowDown = _CanSlowDown;
00504             keepEllapsedTimeForLifeUpdate = _KeepEllapsedTimeForLifeUpdate;
00505         }
00506 
00507         // get time thrhsold / integration time
00508         float getTimeTheshold() const { return _TimeThreshold; }
00512         uint  getMaxNbIntegrations() const { return _MaxNbIntegrations; }
00513 
00520         void    setBypassMaxNumIntegrationSteps(bool bypass = true)
00521         {
00522             NL_PS_FUNC_MAIN(setBypassMaxNumIntegrationSteps)
00523             if (_BypassIntegrationStepLimit != bypass)
00524             {
00525                 if (bypass)
00526                 {
00527                     if (!canFinish())
00528                     {
00529                         nlwarning("<CParticleSystem::setBypassMaxNumIntegrationSteps> Can't set flag to true. The system must have a finite duration");
00530                         nlassert(0); // the system can't stop!
00531                         return;
00532                     }
00533                 }
00534                 _BypassIntegrationStepLimit = bypass;
00535                 _PresetBehaviour = UserBehaviour;
00536             }
00537         }
00538         bool    getBypassMaxNumIntegrationSteps() const { return _BypassIntegrationStepLimit; }
00539 
00545         bool canFinish(CPSLocatedBindable **lastingForeverObj = NULL) const;
00546 
00551         bool hasLoop(CPSLocatedBindable **loopingObj = NULL) const;
00552 
00553 
00554     // @}
00555 
00556     //*****************************************************************************************************
00557 
00566         // @{
00567 
00569         void setMaxViewDist(float maxDist)
00570         {
00571             NL_PS_FUNC_MAIN(setMaxViewDist)
00572             nlassert(maxDist > 0.f);
00573             _MaxViewDist = maxDist;
00574             _InvCurrentViewDist = _InvMaxViewDist = 1.f / maxDist;
00575         }
00576 
00578         float getMaxViewDist(void) const { return _MaxViewDist; }
00579 
00581         void setLODRatio(float ratio) { nlassert(ratio > 0 && ratio <= 1.f); _LODRatio =  ratio; }
00582 
00584         float getLODRatio(void) const  { return _LODRatio; }
00585 
00586 
00591         void getLODVect(NLMISC::CVector &v, float &offset, TPSMatrixMode matrixMode);
00592 
00594         TPSLod getLOD(void) const;
00595 
00597         float getOneMinusCurrentLODRatio(void) const { return _OneMinusCurrentLODRatio; }
00598 
00604         void    enableAutoLOD(bool enabled = true) { _AutoLOD = enabled; }
00605 
00607         bool    isAutoLODEnabled() const { return _AutoLOD; }
00608 
00613         void    setupAutoLOD(float startDistPercent, uint8 degradationExponent)
00614         {
00615             NL_PS_FUNC_MAIN(setupAutoLOD)
00616             nlassert(startDistPercent < 1.f);
00617             nlassert(degradationExponent > 0);
00618             _AutoLODStartDistPercent    =   startDistPercent;
00619             _AutoLODDegradationExponent =   degradationExponent;
00620         }
00621 
00627         void    setMaxDistLODBias(float lodBias);
00628         float   getMaxDistLODBias() const { return _MaxDistLODBias; }
00629 
00630 
00631 
00632         float   getAutoLODStartDistPercent() const { return _AutoLODStartDistPercent; }
00633         uint8   getAutoLODDegradationExponent() const { return _AutoLODDegradationExponent; }
00634 
00639         void    setAutoLODMode(bool skipParticles) { _AutoLODSkipParticles = skipParticles; }
00640         bool    getAutoLODMode() const { return _AutoLODSkipParticles; }
00641 
00648           void  setColorAttenuationScheme(CPSAttribMaker<NLMISC::CRGBA> *colScheme)
00649           {
00650             NL_PS_FUNC_MAIN(setColorAttenuationScheme)
00651             delete _ColorAttenuationScheme;
00652             _ColorAttenuationScheme = colScheme;
00653             if (!colScheme)
00654             {
00655                 _GlobalColor = NLMISC::CRGBA::White;
00656             }
00657           }
00658 
00660           CPSAttribMaker<NLMISC::CRGBA> *getColorAttenuationScheme() { return _ColorAttenuationScheme; }
00661           const CPSAttribMaker<NLMISC::CRGBA> *getColorAttenuationScheme() const { return _ColorAttenuationScheme; }
00662 
00668           void              setUserColor(NLMISC::CRGBA userColor) { _UserColor = userColor; }
00669           NLMISC::CRGBA     getUserColor() const { return _UserColor; }
00670 
00671           // shortcut : test il global color is used (not white)
00672           bool              isUserColorUsed() const { return _UserColor != NLMISC::CRGBA::White; }
00673 
00677           NLMISC::CRGBA     getGlobalColor() const { return _GlobalColor; }
00680           NLMISC::CRGBA     getGlobalColorLighted() const { return _GlobalColorLighted; }
00681           // test if all objects should use global color lighting
00682           bool              getForceGlobalColorLightingFlag() { return _ForceGlobalColorLighting; }
00683           // force global color lighting
00684           void              setForceGlobalColorLightingFlag(bool enable) { _ForceGlobalColorLighting = enable; }
00685           // set lighting color (used by look at, and object that don't have normals)
00686           void              setLightingColor(NLMISC::CRGBA col) { _LightingColor = col; }
00687           NLMISC::CRGBA     getLightingColor() const { return _LightingColor; }
00688         // @}
00689 
00690     //*****************************************************************************************************
00691 
00692         // \name Load balancing
00693         // @{
00694             // get an evaluation of how many tris are needed with the system for the given distance
00695             float getWantedNumTris(float dist);
00696 
00698             void setNumTris(uint numFaces);
00699 
00703             //void notifyMaxNumFacesChanged(void);
00704 
00706             bool isLoadBalancingEnabled() const { return _EnableLoadBalancing; }
00707 
00709             void enableLoadBalancing(bool enabled = true);
00710         // @}
00711 
00712     //*****************************************************************************************************
00713 
00715         // @{
00720         void computeBBox(NLMISC::CAABBox &aabbox);
00721 
00724         void forceComputeBBox(NLMISC::CAABBox &aabbox);
00725 
00729         void setAutoComputeBBox(bool enable = true) { _ComputeBBox = enable; }
00730 
00731 
00733         bool getAutoComputeBBox(void) const { return _ComputeBBox; }
00734 
00735 
00740         void setPrecomputedBBox(const NLMISC::CAABBox &precompBBox)
00741         {
00742             NL_PS_FUNC_MAIN(setPrecomputedBBox)
00743             nlassert(!_ComputeBBox);
00744             _PreComputedBBox = precompBBox;
00745         }
00746 
00748         void getLastComputedBBox(NLMISC::CAABBox &dest) { dest = _PreComputedBBox; }
00749         // @}
00750 
00751     //*****************************************************************************************************
00752 
00754         // @{
00758         void                setDestroyModelWhenOutOfRange(bool enable = true)
00759         {
00760             NL_PS_FUNC_MAIN(setDestroyModelWhenOutOfRange)
00761             _DestroyModelWhenOutOfRange  = enable;
00762             _PresetBehaviour = UserBehaviour;
00763         }
00764 
00766         bool                getDestroyModelWhenOutOfRange(void) const { return _DestroyModelWhenOutOfRange; }
00767 
00768 
00770         enum TDieCondition { none, noMoreParticles, noMoreParticlesAndEmitters   };
00771 
00772 
00779         void                setDestroyCondition(TDieCondition dieCondition)
00780         {
00781             NL_PS_FUNC_MAIN(setDestroyCondition)
00782             _DieCondition = dieCondition;
00783             _PresetBehaviour = UserBehaviour;
00784         }
00785 
00786         // test if the destroy condition is currently verified
00787         bool                isDestroyConditionVerified() const;
00788 
00790         TDieCondition       getDestroyCondition(void) const { return _DieCondition; }
00791 
00803         void setDelayBeforeDeathConditionTest(TAnimationTime delay)
00804         {
00805             NL_PS_FUNC_MAIN(setDelayBeforeDeathConditionTest)
00806 
00807             _DelayBeforeDieTest  = delay;
00808         }
00809 
00817         void systemDurationChanged();
00818 
00822         TAnimationTime      getDelayBeforeDeathConditionTest() const;
00823 
00830         void                setAutoComputeDelayBeforeDeathConditionTest(bool computeAuto);
00831         bool                getAutoComputeDelayBeforeDeathConditionTest() const { return _AutoComputeDelayBeforeDeathTest; }
00832 
00838         void                destroyWhenOutOfFrustum(bool enable = true)
00839         {
00840             _DestroyWhenOutOfFrustum = enable;
00841             _PresetBehaviour = UserBehaviour;
00842         }
00843 
00847         bool                doesDestroyWhenOutOfFrustum(void) const { return _DestroyWhenOutOfFrustum; }
00848 
00849 
00851         bool                hasEmitters(void) const;
00852 
00854         bool                hasParticles() const;
00855 
00857         bool                hasTemporaryParticles() const;
00858 
00860         enum TAnimType
00861         {  AnimVisible = 0,   /* visible systems only are animated */
00862            AnimInCluster, /* systems that are in cluster are animated */
00863            AnimAlways,    /* animate always when not too far */
00864            LastValue
00865         };
00866 
00870         void                performMotionWhenOutOfFrustum(bool enable = true)
00871         {
00872             NL_PS_FUNC_MAIN(performMotionWhenOutOfFrustum)
00873             _AnimType = enable ? AnimInCluster : AnimVisible;
00874             _PresetBehaviour = UserBehaviour;
00875         }
00876 
00880         bool                doesPerformMotionWhenOutOfFrustum(void) const { return _AnimType == AnimInCluster; }
00881 
00883         void                setAnimType(TAnimType animType)
00884         {
00885             NL_PS_FUNC_MAIN(setAnimType)
00886             nlassert(animType < LastValue);
00887             _AnimType = animType;
00888             _PresetBehaviour = UserBehaviour;
00889         }
00890 
00892         TAnimType           getAnimType() const { return _AnimType; }
00893 
00905         enum TPresetBehaviour
00906         {
00907             EnvironmentFX = 0,    // environment FX, not animated when not visible, persistent.
00908             RunningEnvironmentFX, /* an environment fx that should
00909                                    * run when in parsed cluster : cascade for example,
00910                                    * so that it doesn't start when the player first see
00911                                    * it
00912                                    */
00913             SpellFX,              // always animated, not persistent, garanteed to match the good frame even if framerate is low
00914             LoopingSpellFX,       // alway animated, persistent until emitter are stopped
00915             MinorFX,              // animated when visible, discarded when not visible
00916             UserBehaviour,
00917             MovingLoopingFX,       // persistent, moving fx
00918             SpawnedEnvironmentFX,  // environment fx, not animated when not visible, not persistent
00919             GroundFX,              
00922             Projectile,            // like moving looping fx, but not persistent
00923             PresetLast
00924         };
00925 
00926         void activatePresetBehaviour(TPresetBehaviour behaviour);
00927 
00928         TPresetBehaviour getBehaviourType() const
00929         {
00930             NL_PS_FUNC_MAIN(getBehaviourType)
00931             return _PresetBehaviour;
00932         }
00933 
00934 
00935 
00936 
00937         // @}
00938 
00939     //*****************************************************************************************************
00941         // @{
00943         static void                 registerSoundServer(UPSSoundServer *soundServer);
00944 
00946         static UPSSoundServer *     getSoundServer(void)
00947         {
00948             NL_PS_FUNC(getSoundServer)
00949             return _SoundServer;
00950         }
00951 
00953         void stopSound();
00954 
00955         // reactivate all sound in this system
00956         void reactivateSound();
00957 
00958         // @}
00959 
00960     //*****************************************************************************************************
00962         // @{
00967             void registerLocatedBindableExternID(uint32 id, CPSLocatedBindable *lb);
00968 
00970             void unregisterLocatedBindableExternID(CPSLocatedBindable *lb);
00971         // @}
00972 
00973     //*****************************************************************************************************
00975         // @{
00977                 uint               getNumLocatedBindableByExternID(uint32 id) const;
00981                 CPSLocatedBindable       *getLocatedBindableByExternID(uint32 id, uint index);
00982                 const CPSLocatedBindable *getLocatedBindableByExternID(uint32 id, uint index) const;
00984                 uint   getNumID() const;
00986                 uint32 getID(uint index) const;
00990                 void getIDs(std::vector<uint32> &dest) const;
00991         // @}
00992 
00993     //*****************************************************************************************************
00995         // @{
01002                 void enableEmitThreshold(bool enabled = true) { _EmitThreshold = enabled; }
01003                 bool isEmitThresholdEnabled() const { return _EmitThreshold; }
01004 
01005             // activate // deactivate all emitters in the system
01006             void activateEmitters(bool active);
01007             // test is there are active emitters in the system
01008             bool hasActiveEmitters() const;
01009             // test if there are emitters in the system (e.g. derivers of CPSEmitter bound to the system)
01010             bool hasEmittersTemplates() const;
01017             float evalDuration() const;
01026             void setAutoCountFlag(bool enabled) { _AutoCount = enabled; }
01027             bool getAutoCountFlag() const { return _AutoCount; }
01032             void matchArraySize();
01033             // get max number of individual particles in the system
01034             uint getMaxNumParticles() const;
01035             // get current number of particles in the system
01036             uint getCurrNumParticles() const;
01037             // tool fct : get the list of located that target another located
01038             void getTargeters(const CPSLocated *target, std::vector<CPSTargetLocatedBindable *> &targeters);
01039             // allow to serialize identifiers. The default is false (to speedup instanciation of ps by not creating unecessary strings)
01040             static void setSerializeIdentifierFlag(bool on) { _SerialIdentifiers = on; }
01041             static bool getSerializeIdentifierFlag() { return _SerialIdentifiers; }
01042             // list all textures used by the ps, and append them in the given vector
01043             void enumTexs(std::vector<NLMISC::CSmartPtr<ITexture> > &dest, IDriver &drv);
01044             // Change z-bias of all materials. The z-bias value is given in world coordinates
01045             void setZBias(float value);
01046             // debug : force to display bbox of all particle systems
01047             static void forceDisplayBBox(bool on) { _ForceDisplayBBox = on; }
01051             void        getSortingByEmitterPrecedence(std::vector<uint> &result) const;
01052         // @}
01053 
01054 
01055 
01056 private:
01057     typedef std::map<std::string, float> TGlobalValuesMap;
01058     typedef std::map<std::string, NLMISC::CVector> TGlobalVectorValuesMap;
01059 private:
01060     friend class CParticleSystemModel;
01062     void                    stepLocated(TPSProcessPass pass);
01063     // update the lod & return the distance from viewer
01064     float                   updateLODRatio();
01065     float                   getDistFromViewer() const;
01066     void                    updateColor(float distFromViewer);
01067     void                    updateNumWantedTris();
01068     // update index of all the process
01069     void                    updateProcessIndices();
01070     // for debug only
01071     void                    checkIntegrity();
01072     // map that contain global value that can be affected to user param
01073     static TGlobalValuesMap       _GlobalValuesMap;
01074     // map that contain global vector values
01075     static TGlobalVectorValuesMap _GlobalVectorValuesMap;
01076     // A bbox that has been specified by the user
01077     NLMISC::CAABBox          _PreComputedBBox;
01078     // the driver used for rendering
01079     IDriver                  *_Driver;
01080 
01081     typedef CPSVector<CParticleSystemProcess *>::V TProcessVect;
01082     TProcessVect             _ProcessVect;
01083     CFontGenerator           *_FontGenerator;
01084     CFontManager             *_FontManager;
01085 
01086     // Infos about a coordinate system (current matrix, previous pos...)
01087     class CCoordSystemInfo
01088     {
01089     public:
01090         const NLMISC::CMatrix *Matrix;          // gives the matrix to use
01091         NLMISC::CMatrix        InvMatrix;       // inverted matrix for that coord system
01092         NLMISC::CVector        OldPos;          // translation part of matrix at previous frame
01093         NLMISC::CVector        CurrentDeltaPos; // current pos (for integration step) of the coord system relative to its final pos
01094     public:
01095         CCoordSystemInfo()
01096         {
01097             Matrix = NULL;
01098         }
01099     };
01100 
01101 
01102     class CUserCoordSystemInfo
01103     {
01104     public:
01105         CCoordSystemInfo    CoordSystemInfo;
01106         NLMISC::CMatrix     UserBasisToFXBasis; // conversion matrix : from user basis to FX Basis
01107         NLMISC::CMatrix     FXBasisToUserBasis; // conversion matrix : from FX basis to user Basis
01108         uint16              NumRef; // number of objects in the system that use position of the user matrix
01109                                     // because this is used rarely, we allocate memory to track the user matrix position only when needed
01110     public:
01111         CUserCoordSystemInfo()
01112         {
01113             NumRef = 0;
01114         }
01115     };
01116 
01117     CCoordSystemInfo           _CoordSystemInfo;                // coordinate system infos for this fx
01118     CUserCoordSystemInfo       *_UserCoordSystemInfo;           // coordinate system infos for an hypothetic user matrix
01119 
01120 
01121 
01122 
01123 
01124 
01125     // the view matrix (TODO : this is duplcated from CScene)
01126     NLMISC::CMatrix          _ViewMat;
01127 
01128     // the inverted view matrix (TODO : this is duplcated from CScene)
01129     NLMISC::CMatrix          _InvertedViewMat;
01130 
01131 
01132     // number of rendered pass on the system, incremented each time the system is redrawn
01133     uint64                   _Date;
01134 
01136     sint64                   _LastUpdateDate;
01137 
01138     // current edited element located (edition purpose only)
01139     CPSLocated               *_CurrEditedElementLocated;
01140     // current edited located bindable, NULL means all binadable of a located. (edition purpose only)
01141     CPSLocatedBindable       *_CurrEditedElementLocatedBindable;
01142     // current edited element index in its located (edition purpose only)
01143     uint32                   _CurrEditedElementIndex;
01144 
01145 
01150     CScene                  *_Scene;
01151 
01152 
01153     // contains the name of the system. (VERSION >= 2 only)
01154     std::string _Name;
01155 
01156     TAnimationTime                              _TimeThreshold;
01157     TAnimationTime                              _SystemDate;
01158     uint32                                      _MaxNbIntegrations;
01159 
01160 
01161     float                                       _LODRatio;
01162     float                                       _OneMinusCurrentLODRatio;
01163     float                                       _MaxViewDist;
01164     float                                       _MaxDistLODBias;
01165     float                                       _InvMaxViewDist;
01166     float                                       _InvCurrentViewDist; // inverse of the current view dist. It can be the same than _InvMaxViewDist
01167                                                                 // but when there's LOD, the view distance may be reduced
01168     float                                       _AutoLODEmitRatio;
01169 
01170     TDieCondition                               _DieCondition;
01171     mutable TAnimationTime                      _DelayBeforeDieTest;
01172     uint                                        _NumWantedTris;
01173     TAnimType                                   _AnimType;
01174 
01175     static UPSSoundServer                      *_SoundServer;
01176 
01177     float                                       _UserParam[MaxPSUserParam];
01178     const TGlobalValuesMap::value_type          **_UserParamGlobalValue; // usually set to NULL unless some user params mirror a global value,
01179                                                                          // in this case this contains as many pointer into the global map as there are user params
01180     uint8                                       _BypassGlobalUserParam;  // mask to bypass a global user param. This state is not serialized
01181 
01182     TPresetBehaviour                            _PresetBehaviour;
01183 
01184     typedef
01185         CPSMultiMap<uint32, CPSLocatedBindable *>::M TLBMap;
01186     TLBMap                                          _LBMap;
01187 
01188     float                                       _AutoLODStartDistPercent;
01189     uint8                                       _AutoLODDegradationExponent;
01190 
01191     CPSAttribMaker<NLMISC::CRGBA>               *_ColorAttenuationScheme;
01192     NLMISC::CRGBA                               _GlobalColor;
01193     NLMISC::CRGBA                               _GlobalColorLighted;
01194     NLMISC::CRGBA                               _LightingColor;
01195     NLMISC::CRGBA                               _UserColor;
01196 
01197     bool                                        _ComputeBBox                         : 1;   
01198     bool                                        _BBoxTouched                         : 1;
01199     bool                                        _AccurateIntegration                 : 1;
01200     bool                                        _CanSlowDown                         : 1;
01201     bool                                        _DestroyModelWhenOutOfRange          : 1;
01202     bool                                        _DestroyWhenOutOfFrustum             : 1;
01203     bool                                        _Sharing                             : 1;
01204     bool                                        _AutoLOD                             : 1;
01205     bool                                        _KeepEllapsedTimeForLifeUpdate       : 1;
01206     bool                                        _AutoLODSkipParticles                : 1;
01207     bool                                        _EnableLoadBalancing                 : 1;
01208     bool                                        _EmitThreshold                       : 1;
01209     bool                                        _BypassIntegrationStepLimit          : 1;
01210     bool                                        _ForceGlobalColorLighting            : 1;
01211     bool                                        _AutoComputeDelayBeforeDeathTest     : 1;
01212     bool                                        _AutoCount                           : 1;
01213     bool                                        _HiddenAtCurrentFrame                : 1;
01214     bool                                        _HiddenAtPreviousFrame               : 1;
01215 
01216     static bool                                 _SerialIdentifiers;
01217     static bool                                 _ForceDisplayBBox;
01218 
01219 
01220     #ifdef NL_DEBUG
01221         static uint                                 _NumInstances;
01222     #endif
01223 public:
01224     // For use by emitters only : This compute a delta of position of the fx matrix to ensure that spawning position are correct when the system moves
01225     void        interpolateFXPosDelta(NLMISC::CVector &dest, TAnimationTime deltaT);
01226     // For use by emitters only : This compute a delta of position of the user matrix to ensure that spawning position are correct when the system moves
01227     void        interpolateUserPosDelta(NLMISC::CVector &dest, TAnimationTime deltaT);
01228     // For use by emitters only : Get the current emit ratio when auto-LOD is used. Valid only during the 'Emit' pass
01229     float       getAutoLODEmitRatio() const { return _AutoLODEmitRatio; }
01230     // For private used by CPSLocated instances : should be called when the matrix mode of a located has changed
01231     void        matrixModeChanged(CParticleSystemProcess *proc, TPSMatrixMode oldMode, TPSMatrixMode newMode);
01232     // FOR PRIVATE USE : called when one more object of the system needs the _UserCoordSystemInfo field => so allocate it if needed.
01233     void        addRefForUserSysCoordInfo(uint numRefs = 1);
01234     // FOR PRIVATE USE : called when one less object of the system needs the _UserCoordSystemInfo field => deallocate it when there are no references left
01235     void        releaseRefForUserSysCoordInfo(uint numRefs = 1);
01236     // tmp for debug : dump hierarchy of fx
01237     void        dumpHierarchy();
01238 public:
01239     // spawn info. They are shared by all PS ! This is because there can be only one PS processed at a time in the lib, so no need to store that per instance
01240     typedef std::vector<CPSSpawnInfo> TSpawnInfoVect;
01241     struct CSpawnVect : public NLMISC::CRefCount
01242     {
01243         TSpawnInfoVect SpawnInfos;
01244         uint           MaxNumSpawns;
01245     };
01246     static std::vector<NLMISC::CSmartPtr<CSpawnVect> > _Spawns; // for each process of the system (the array is ordered as CParticleSystem::_ProcessVect is) , store a list of particles to spawn. We can't spawn them directly,
01247                                                                 // because ageing particle must be processed and removed first to make room
01248                                                                 // for new particles and thus avoid a 'pulse' effect when framerate is low or when spawning is fast  (see the update loop CParticleSystem::step for details)
01249                                                                 // NB : we use a smart pointer to avoid resize of a vector of vector, which is baaad...
01250                                                                 // This is public but intended to be used by CPSLocated only.
01251     static std::vector<uint>                           _ParticleToRemove;           // used during the update step, contains the indices of the particles to remove
01252     static std::vector<sint>                           _ParticleRemoveListIndex;    // for each particle, -1 if it hasn't been removed, or else give the insertion number in _ParticleToRemove
01253     static std::vector<uint>                           _CollidingParticles; // index of particle that collided
01254     static std::vector<NLMISC::CVector>                _SpawnPos;           // spawn position of newly created particles
01255 public:
01256     // current sim steps infos
01257     static TAnimationTime                               EllapsedTime;
01258     static TAnimationTime                               InverseTotalEllapsedTime;
01259     static TAnimationTime                               RealEllapsedTime;
01260     static float                                        RealEllapsedTimeRatio;
01261     static bool                                         InsideSimLoop;
01262     static bool                                         InsideRemoveLoop;
01263     static bool                                         InsideNewElementsLoop;
01264     static CParticleSystemModel                         *OwnerModel; // owner model for that system
01265 };
01266 
01267 // NOT USED FOR NOW
01275 /*
01276 class CPSCopyHelper
01277 {
01278     public:
01279         // duplicate an object using the copy ctor, if it has not been before
01280         template <class T> T *ctorCopy(const T &src)
01281         {
01282             TCopiedIt it = _Alreadycopied.find(src);
01283             if (it  != _AlreadyCopied.end())
01284             {
01285                 return (T *) it;
01286             }
01287             else
01288             {
01289                 T *result = new T(src);
01290                 _AlreadyCopied.insert((void *) result);
01291                 return result;
01292             }
01293         }
01294         // duplicate an object using its clone method, if it has not been before
01295 
01296         template <class T> T *clone(const T &src)
01297         {
01298             TCopiedIt it = _AlreadyCopied.find(src);
01299             if (it  != _AlreadyCopied.end())
01300             {
01301                 return (T *) *it;
01302             }
01303             else
01304             {
01305                 T *result = src.clone(this);
01306                 _AlreadyCopied.insert((void *) result);
01307                 return result;
01308             }
01309         }
01310 
01311 
01312         // insert a value that has been copied by other means
01313         void insert(void *ptr)
01314         {
01315             std::pair<TCopiedIt, bool> result = _AlreadyCopied.insert(ptr);
01316             nlassert(result.second);
01317         }
01318 
01319     private:
01320         typedef std::set<void *> TAlreadyCopied;
01321         typedef TAlreadyCopied::iterator TCopiedIt;
01322         TAlreadyCopied _AlreadyCopied;
01323 };
01324 
01325 */
01326 
01327 
01328 
01329 } // NL3D
01330 
01331 
01332 #endif // NL_PARTICLE_SYSTEM_H
01333 
01334 /* End of particle_system.h */

Generated on Thu Jan 7 08:26:19 2010 for NeL by  doxygen 1.6.1