1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010-2017 Winch Gate Property Limited
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2016 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Affero General Public License as
9 // published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Affero General Public License for more details.
17 // You should have received a copy of the GNU Affero General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #ifndef CL_WEATHER_MANAGER_CLIENT_H
25 #define CL_WEATHER_MANAGER_CLIENT_H
27 #include "game_share/time_weather_season/weather_setup.h"
28 #include "game_share/time_weather_season/weather_function.h"
29 #include "game_share/season.h"
30 #include "game_share/time_weather_season/weather_manager.h"
31 #include "weather_setup_client.h"
32 #include "nel/misc/vector.h"
47 class UGlobalRetriever
;
50 class CWeatherFunctionParamsSheet
;
53 // a context to pass to the weather manager methods
54 struct CWeatherContext
57 const CWeatherFunction
*WF
;
58 const CWeatherFunctionParamsSheet
*WFP
;
59 const CLightCycle
*LC
;
60 NLPACS::UGlobalRetriever
*GR
;
63 class CWeatherManagerClient
: public CWeatherManager
67 CWeatherManagerClient();
70 /// From CWeatherManager : Loads all the weather setups
71 virtual void init(const std::vector
<const CWeatherSetupSheetBase
*> &sheets
, const std::vector
<std::string
> &sheetNames
);
72 /// From CWeatherManager : Release all datas (fx models..). Should be called before deleting the scene
73 virtual void release();
74 /// Set the global direction of the wind. Only XY direction is kept
75 void setWindDir(const NLMISC::CVector
&dir
);
76 /// Update the weather, small update, only to update current weather state
77 void update(uint64 day
, float hour
, const CWeatherContext
&wc
);
78 /// Update the weather, full update, with 3d FX thunder update
79 void update(uint64 day
, float hour
, const CWeatherContext
&wc
, const NLMISC::CMatrix
&camMat
, const class CContinent
&continent
);
80 /// Get the current weather value. Updated after each call to 'update'
81 float getWeatherValue() const { return _WeatherValue
; }
82 /// Get the weather value for next cycle
83 float getNextWeatherValue() const { return _NextWeatherValue
; }
84 /// Get the hour for next weather cycle
85 uint32
getNextWeatherHour() const { return _NextWeatherHour
; }
86 /** Does the same than 'update', but let the user choose the weather value. The weather value ranges from 0 to 1.
87 * The day and hour are needed only to manage phenomena like thunder (need a clock to know when there are thunder strikes)
88 * Small update, only to update current weather state
90 void manualUpdate(uint64 day
, float hour
, const CWeatherContext
&wc
, float weatherValue
, EGSPD::CSeason::TSeason season
);
91 /** Does the same than 'update', but let the user choose the weather value. The weather value ranges from 0 to 1.
92 * The day and hour are needed only to manage phenomena like thunder (need a clock to know when there are thunder strikes)
93 * Full update, with 3d FX thunder update
95 void manualUpdate(uint64 day
, float hour
, const CWeatherContext
&wc
, float weatherValue
, EGSPD::CSeason::TSeason season
, const NLMISC::CMatrix
&camMat
, const class CContinent
&continent
);
96 // get the current weather setup. It is updated at each call to 'update'
97 const CWeatherState
&getCurrWeatherState() const { return _CurrWeatherState
; }
98 // Compute the state of clouds at the given date.
99 void computeCloudState(uint64 day
, float hour
, const CWeatherContext
&wc
, CCloudState
&dest
) const;
100 // Compute the cloud state for the given weather value.
101 void computeCloudState(float weatherValue
, EGSPD::CSeason::TSeason season
, CCloudState
&dest
, const CWeatherFunction wf
[EGSPD::CSeason::Invalid
]) const;
102 // For debug : draw the clip grids of currently active precipitations
103 void drawPrecipitationClipGrids(NL3D::UDriver
&drv
) const;
104 // Get the 'thunder level', that is how bright the thunder lighting is. It ranges from 0 (no thunder) to 1 (thunder impact)
105 float getThunderLevel() const { return _ThunderLevel
; }
106 // To avoid rain in town, There's a Noprecipitation map that give a factor to stop rain at some places
107 float getLocalPrecipitationFactor() const { return _LocalPrecipitationFactor
; }
108 /////////////////////////////////////////////////////////////////
110 // from CWeatherManager
111 virtual CWeatherSetup
*newWeatherSetup() const;
112 // from CWeatherManager
113 virtual void setupLoaded(CWeatherSetup
*setup
);
115 void manualUpdateImpl(uint64 day
, float hour
, const CWeatherContext
&wc
, float weatherValue
, EGSPD::CSeason::TSeason season
);
116 void manualUpdateImpl(uint64 day
, float hour
, const CWeatherContext
&wc
, float weatherValue
, EGSPD::CSeason::TSeason season
, const NLMISC::CMatrix
&camMat
, const class CContinent
&continent
);
117 typedef std::map
<std::string
, CPrecipitation
> TPrecipitationMap
;
118 // A vector of precipitation pointers
119 typedef std::vector
<CPrecipitation
*> TPrecipitationVect
;
121 CWeatherState _CurrWeatherState
;
122 CWeatherStateClient _CurrWeatherStateClient
;
123 TPrecipitationMap _PrecipitationMap
;
124 TPrecipitationVect _ActivePrecipitations
;
125 TPrecipitationVect _WaitingPrecipitations
;
126 NLMISC::CVector _WindDir
;
129 bool _ThunderStrike
; // true if a thunder strike is currently happening
132 float _LocalPrecipitationFactor
;
133 uint32 _NextWeatherHour
;
134 float _NextWeatherValue
;
136 void initPrecipitationFXs();
137 void setupFXs(const NLMISC::CMatrix
&camMat
, NLPACS::UGlobalRetriever
*gr
, const class CContinent
&continent
);
138 void setupWind(const CWeatherFunction
*wf
);
140 /** A time measurment for thunder function. Each cycle of thunder last a period like 0.5 s. One thunder
141 * strike can happen only each 2 cycles
142 * PRIVATE use by implementation
144 struct CThunderTimeMeasure
148 CThunderTimeMeasure() : Cycle(~0), SubCycle(0)
152 CThunderTimeMeasure _ThunderStrikeDate
;
154 // Use the curr weather state to update the thunder.
155 void updateThunder(uint64 day
, float hour
, const CWeatherContext
&wc
, bool manual
= false, float manualWeatherValue
= 0.f
, EGSPD::CSeason::TSeason manualSeason
= EGSPD::CSeason::Spring
);
156 // The thunder intensity at the given day and hour (value of the 'ThunderIntensity' field in the weather setups)
157 float getThunderIntensity(uint64 day
, float hour
, const CWeatherContext
&wc
);
158 // Compute the minimum threshold that must be reached to create a thunder strike
159 float getThunderThreshold(uint64 thunderCycle
, const CWeatherContext
&wc
);
160 // update the thunder state between 2 times between which the thunder function is linear
161 bool updateThunderState(CThunderTimeMeasure
&t0
, CThunderTimeMeasure
&t1
, float thunderThreshold
);