Fix css style order when using external css files
[ryzomcore.git] / ryzom / client / src / ground_fx_manager.h
blob85dd179e34506ab988ffe87c706ae1f6e993a73f
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
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.
8 //
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"
26 namespace NL3D
28 class UParticleSystemInstance;
29 class UScene;
32 namespace NLMISC
34 class CVectorD;
37 class CEntityCL;
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
42 * \date 2003
44 class CGroundFXManager
46 private:
47 struct CGroundFX
49 NL3D::UParticleSystemInstance FX;
50 NL3D::UParticleSystemInstance FXUnderWater; // underwater part of fx
51 std::string FXName;
53 typedef std::list<CGroundFX> TGroundFXList;
54 typedef std::list<CGroundFX>::iterator TGroundFXHandle;
55 class CInstance
57 public:
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
61 public:
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 ?
70 TMode Mode;
71 float WaterHeight; // if entity is in water, give its height
72 bool Idle;
73 public:
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;
80 public:
82 typedef TInstanceList::iterator TEntityHandle;
83 typedef std::vector<TEntityHandle> TInstancePtrVect;
85 // ctor
86 CGroundFXManager();
87 // dtor
88 ~CGroundFXManager();
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.
109 void reset();
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);
118 private:
119 float _MinSpeed;
120 float _MaxSpeed;
121 float _SpeedWaterWalkFast;
122 float _SpeedWaterSwimFast;
123 float _MaxDist;
124 TGroundFXList _ActiveFXs;
125 TGroundFXList _InactiveFXs; // Shutting down FXs
126 TGroundFXList _CachedFXs; // Cached fxs FXs
127 uint _MaxNumFX; // max number of fxs ( active fxs)
128 uint _NumFX;
129 uint _MaxNumCachedFX;
130 uint _NumCachedFX;
132 TInstanceList _InstancesList;
133 uint _NumInstances;
134 TInstancePtrVect _SortedInstances; // sorted entities by distance
135 NL3D::UScene *_Scene;
136 private:
137 void invalidateFX(TEntityHandle handle);
138 void moveFXInCache(TGroundFXList &ownerList, TGroundFXHandle fx);
139 // for debug only
140 void checkIntegrity();
145 /////////////////////////////////////////
146 // tmp : test class to test ground fxs //
147 /////////////////////////////////////////
149 #if 1
151 /** temp class to test ground fxs
153 struct CTestGroundFX
155 struct CEntity
157 CEntityCL *Entity;
158 uint Slot;
159 bool Move;
160 NLMISC::CVector Dir;
161 NLMISC::CVector StartPos;
162 float Duration;
164 std::vector<CEntity> Entities;
165 bool MoveAll;
166 void update();
167 void displayFXBoxes() const;
168 CTestGroundFX() : MoveAll(false) {}
171 extern CTestGroundFX TestGroundFX;
173 #endif
175 #endif