Use configured resolution for login/outgame/ingame
[ryzomcore.git] / ryzom / client / src / precipitation.h
blob164519a2946367ab25f9145eeec1b669a22d3b9e
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/>.
21 #ifndef CL_PRECIPITATION_H
22 #define CL_PRECIPITATION_H
24 #include "precipitation_clip_grid.h"
25 #include "nel/misc/vector_2f.h"
26 #include "nel/3d/u_particle_system_instance.h"
27 #include <vector>
28 #include <map>
30 namespace NL3D
32 class UScene;
33 class UDriver;
35 namespace NLPACS
37 class UGlobalRetriever;
39 namespace NLMISC
41 class CMatrix;
44 ///////////////////////////////////////////////////////////
45 // class to describe precipitations //
46 // Several instances of the same shared FX are displayed //
47 ///////////////////////////////////////////////////////////
48 struct CPrecipitationDesc
50 std::string FxName; // name of the FX used for precipitations
51 uint GridSize; // Size of the grid used to display FXs.
52 bool UseBBoxSize; // The size of each block of the grid is taken from the x & y coordinates of the bbox.
53 // When set to false, 'Size' is used instead
54 float Size; // Size of the blocks, it is used only if UseBBoxSize is set to false.
55 bool ReleasableModel; // Models are allocated only if particles are needed. This avoid useless models traversal during the render when thare are no precipitations.
56 CPrecipitationDesc()
58 GridSize = 7;
59 UseBBoxSize = true;
60 Size = 0;
61 ReleasableModel = true;
66 ///////////////////////////////////
67 // class to manage Precipitations //
68 ///////////////////////////////////
70 class CPrecipitation
72 public:
73 // ctor
74 CPrecipitation();
75 // Init the precipitations, and load associated fx
76 void init(const CPrecipitationDesc &desc);
77 // Release datas. Should call this if the scene is still present.
78 void release();
79 // Update precipitations depending on the camera position & orientation
80 void update(const NLMISC::CMatrix &camMat, NLPACS::UGlobalRetriever *retriever);
81 /** Set strenght for rain. Should go from 0 to 1 (clamped).
82 * 0 stops the rains
84 void setStrenght(float strenght);
85 /// After strenght has been set to 0, it may need some time before there are no more particle in the fx. This allow to now if the fx i still running
86 bool isRunning() const;
88 // For clip grid : Draw the clip grid associated with taht precipitation
89 void drawClipGrid(NL3D::UDriver &drv) const;
91 // get description of precipitation
92 const CPrecipitationDesc &getDesc() const { return _Desc; }
94 /////////////////////////////////////////////////////////
95 /////////////////////////////////////////////////////////
96 private:
97 typedef std::map<NLMISC::CVector2f, CPrecipitationClipGrid> TClipGridMap;
98 private:
99 CPrecipitationClipGrid *_ClipGrid;
100 std::vector<NL3D::UParticleSystemInstance> _Blocks;
101 float _Strenght;
102 float _TimeOut;
103 float _XSize;
104 float _YSize;
105 sint _OldX;
106 sint _OldY;
107 bool _Touched; // when set to true, force the next grid update
108 CPrecipitationDesc _Desc;
109 // the precipitation clip girds, sorted by size
110 static TClipGridMap _PrecipitationClipGripMap;
111 private:
112 // helper to view the vector as a 2D tab
113 NL3D::UParticleSystemInstance getBlock(uint x, uint y)
115 nlassert(x < _Desc.GridSize && y < _Desc.GridSize);
116 return _Blocks[x + y * _Desc.GridSize];
118 // allocate the FXs
119 void allocateFXs();
120 // deallocate the FXs
121 void deallocateFXs();
123 bool areFXsAllocated() const { return !_Blocks.empty(); }
124 // Force the setup of strenght with no check for previous value
125 void forceSetStrenght(float strenght);
131 #endif