1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #ifndef CL_GROUND_FX_MANAGER_H
20 #define CL_GROUND_FX_MANAGER_H
23 #include "nel/misc/vectord.h"
24 #include "nel/3d/u_particle_system_instance.h"
28 class UParticleSystemInstance
;
39 /** Manager of 'ground fxs' : fx that are displayed when character walk over sand (actually sawdust), or grass.
40 * \author Nicolas Vizerie
41 * \author Nevrax France
44 class CGroundFXManager
49 NL3D::UParticleSystemInstance FX
;
50 NL3D::UParticleSystemInstance FXUnderWater
; // underwater part of fx
53 typedef std::list
<CGroundFX
> TGroundFXList
;
54 typedef std::list
<CGroundFX
>::iterator TGroundFXHandle
;
58 enum TMode
{ Ground
= 0, Water
, Swim
}; // if the entity is on the ground, then fx is created whn it moves
59 // if the entity is in water, then fx is played even if it doesn't move
60 // the same goes if entity is swimming
62 CEntityCL
*Entity
; // the managed entity
63 float Dist2
; // square dist to the camera
64 TGroundFXHandle FXHandle
; // the FX that is played by that entity
65 uint32 GroundID
; // ground type of current fx
66 uint InstanciateDelay
; // delay before to instanciate the fx
67 bool HasFX
; // is the FXHandle valid ?
68 bool EmittersActive
; // are the emitters active ?
69 bool EmittersUnderWaterActive
; // are the emitters active ?
71 float WaterHeight
; // if entity is in water, give its height
74 // get name of ground fx associated with a ground material id, or empty
75 void getFXNameFromGroundType(uint32 groundID
, std::string
&fxName
) const;
78 typedef std::list
<CInstance
> TInstanceList
;
79 friend struct CSortInstancePred
;
82 typedef TInstanceList::iterator TEntityHandle
;
83 typedef std::vector
<TEntityHandle
> TInstancePtrVect
;
89 /** Init the manager to work with the given scene.
90 * \param scene The scene from which instance are created
91 * \param maxDist The max dist at which ground fxs are generated
92 * \param maxActiveFX The max number of fxs that are holded by an entity
93 * \param maxInactiveFX The max number of inactive FXs (shuting down fxs & fx ready to use)
95 void init(NL3D::UScene
*scene
, float maxDist
, uint maxNumFX
, uint fxCacheSize
);
96 // get the max number of fxs.
97 uint
getMaxNumFX() const { return _MaxNumFX
; }
98 // Get size of cache for FXs
99 uint
getFXCacheSize() const { return _MaxNumCachedFX
; }
100 // get the max dist at which ground FXs are played
101 float getMaxDist() const { return _MaxDist
; }
102 // register an entity to be managed
103 TEntityHandle
add(CEntityCL
*entity
);
104 // remove a managed entity from its handle
105 void remove(TEntityHandle handle
);
106 // update current manager state
107 void update(const NLMISC::CVectorD
&camPos
);
108 // reset the manager (must call init again for reuse). All handle allocated from add(CEntityCL *entity) becomes invalid after the call.
110 // set min speed for walk/run (speed at which fx starts)
111 void setMinSpeed(float minSpeed
);
112 // set max speed for walk/run (speed at which fx is at its max intensity)
113 void setMaxSpeed(float maxSpeed
);
114 // set speed for fast walk in water
115 void setSpeedWaterWalkFast(float speed
);
116 // set speed for fast swim in water
117 void setSpeedWaterSwimFast(float speed
);
121 float _SpeedWaterWalkFast
;
122 float _SpeedWaterSwimFast
;
124 TGroundFXList _ActiveFXs
;
125 TGroundFXList _InactiveFXs
; // Shutting down FXs
126 TGroundFXList _CachedFXs
; // Cached fxs FXs
127 uint _MaxNumFX
; // max number of fxs ( active fxs)
129 uint _MaxNumCachedFX
;
132 TInstanceList _InstancesList
;
134 TInstancePtrVect _SortedInstances
; // sorted entities by distance
135 NL3D::UScene
*_Scene
;
137 void invalidateFX(TEntityHandle handle
);
138 void moveFXInCache(TGroundFXList
&ownerList
, TGroundFXHandle fx
);
140 void checkIntegrity();
145 /////////////////////////////////////////
146 // tmp : test class to test ground fxs //
147 /////////////////////////////////////////
151 /** temp class to test ground fxs
161 NLMISC::CVector StartPos
;
164 std::vector
<CEntity
> Entities
;
167 void displayFXBoxes() const;
168 CTestGroundFX() : MoveAll(false) {}
171 extern CTestGroundFX TestGroundFX
;