Use configured resolution for login/outgame/ingame
[ryzomcore.git] / ryzom / client / src / weather_setup_client.cpp
blob519b29d3a16113af782cabec1d02b2a0c596fc84
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/>.
20 #include "stdpch.h"
21 #include "weather_setup_client.h"
22 #include "precipitation.h"
23 #include "nel/georges/u_form_elm.h"
24 #include "nel/3d/u_particle_system_instance.h"
26 using namespace NLMISC;
28 #ifdef DEBUG_NEW
29 #define new DEBUG_NEW
30 #endif
32 H_AUTO_DECL(RZ_WeatherSetupClient)
34 //==================================================================================
35 /** Tool fct to blend 2 floats
37 static inline void blendValue(float &dest, float f1, float f2, float blendFactor)
39 H_AUTO_USE(RZ_WeatherSetupClient)
40 dest = blendFactor * f2 + (1.f - blendFactor) * f1;
44 //==================================================================================
45 void CWeatherStateClient::setup(const CWeatherState &ws, std::map<std::string, CPrecipitation> &precipitationMap)
47 FXs.resize(ws.FXInfos.size());
48 for(uint k = 0; k < FXs.size(); ++k)
50 if (!ws.FXInfos[k].Name.empty())
52 FXs[k].Precipitation = &(precipitationMap[ws.FXInfos[k].Name]);
53 FXs[k].Ratio = ws.FXInfos[k].Ratio;
55 else
57 FXs[k].Precipitation = NULL;
58 FXs[k].Ratio = 0.f;
63 //==================================================================================
64 void CWeatherStateClient::blend(CWeatherStateClient &dest, const CWeatherStateClient &s1, const CWeatherStateClient &s2, float blendFactor)
66 H_AUTO_USE(RZ_WeatherSetupClient)
67 // FXs. Blend FXs ofthe 2 vectors togethers
68 dest.FXs.resize(s1.FXs.size());
70 uint numCommonFXs = 0; // number of fx in array 1 that are also in array 2
71 // Add / Blend FXs that are only in array 1, or in both arrays
72 uint l;
73 uint k;
74 for(k = 0; k < s1.FXs.size(); ++k)
76 dest.FXs[k].Precipitation = s1.FXs[k].Precipitation;
77 bool found = false;
78 // see if FX is in both vectors
79 for(l = 0; l < s2.FXs.size(); ++l)
81 if (s1.FXs[k].Precipitation == s2.FXs[l].Precipitation)
83 // yes, so blend the ratios
84 blendValue(dest.FXs[k].Ratio, s1.FXs[k].Ratio, s2.FXs[k].Ratio, blendFactor);
85 found = true;
86 ++ numCommonFXs;
87 break;
90 if (!found)
92 // this FX is only in array 1
93 blendValue(dest.FXs[k].Ratio, s1.FXs[k].Ratio, 0, blendFactor);
97 // Add FXs that are only in array 2
98 dest.FXs.reserve(dest.FXs.size() + s2.FXs.size() - numCommonFXs);
99 for(k = 0; k < s2.FXs.size(); ++k)
101 bool inBothArrays = false;
102 // see if FX is in both vectors
103 for(l = 0; l < s1.FXs.size(); ++l)
105 if (s1.FXs[k].Precipitation == s2.FXs[l].Precipitation)
107 inBothArrays = true;
108 break;
111 if (!inBothArrays)
113 dest.FXs.push_back(s2.FXs[k]);
114 // this FX is only in array 2
115 blendValue(dest.FXs.back().Ratio, 0.f, s2.FXs[k].Ratio, blendFactor);