OpenMW
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
weather.hpp
Go to the documentation of this file.
1 #ifndef GAME_MWWORLD_WEATHER_H
2 #define GAME_MWWORLD_WEATHER_H
3 
4 #include <stdint.h>
5 #include <string>
6 #include <map>
7 
8 #include <osg/Vec4f>
9 
11 
12 #include "../mwbase/soundmanager.hpp"
13 
14 #include "../mwrender/sky.hpp"
15 
16 namespace ESM
17 {
18  struct Region;
19  struct RegionWeatherState;
20  class ESMWriter;
21  class ESMReader;
22 }
23 
24 namespace MWRender
25 {
26  class RenderingManager;
27 }
28 
29 namespace Loading
30 {
31  class Listener;
32 }
33 
34 namespace Fallback
35 {
36  class Map;
37 }
38 
39 namespace MWWorld
40 {
41  class TimeStamp;
42 
44  {
49  };
50 
52  {
53  float mNightStart;
54  float mNightEnd;
55  float mDayStart;
56  float mDayEnd;
57 
58  std::map<std::string, WeatherSetting> mSunriseTransitions;
59 
63 
64  WeatherSetting getSetting(const std::string& type) const
65  {
66  std::map<std::string, WeatherSetting>::const_iterator it = mSunriseTransitions.find(type);
67  if (it != mSunriseTransitions.end())
68  {
69  return it->second;
70  }
71  else
72  {
73  return { 1.f, 1.f, 1.f, 1.f };
74  }
75  }
76 
77  void addSetting(const Fallback::Map& fallback, const std::string& type)
78  {
79  WeatherSetting setting = {
80  fallback.getFallbackFloat("Weather_" + type + "_Pre-Sunrise_Time"),
81  fallback.getFallbackFloat("Weather_" + type + "_Post-Sunrise_Time"),
82  fallback.getFallbackFloat("Weather_" + type + "_Pre-Sunset_Time"),
83  fallback.getFallbackFloat("Weather_" + type + "_Post-Sunset_Time")
84  };
85 
86  mSunriseTransitions[type] = setting;
87  }
88  };
89 
92  template <typename T>
94  {
95  public:
96  TimeOfDayInterpolator(const T& sunrise, const T& day, const T& sunset, const T& night)
97  : mSunriseValue(sunrise), mDayValue(day), mSunsetValue(sunset), mNightValue(night)
98  {
99  }
100 
101  T getValue (const float gameHour, const TimeOfDaySettings& timeSettings, const std::string& prefix) const;
102 
103  private:
105  };
106 
108  class Weather
109  {
110  public:
111  Weather(const std::string& name,
112  const Fallback::Map& fallback,
113  float stormWindSpeed,
114  float rainSpeed,
115  float dlFactor,
116  float dlOffset,
117  const std::string& particleEffect);
118 
119  std::string mCloudTexture;
120 
121  // Sky (atmosphere) color
123  // Fog color
125  // Ambient lighting color
127  // Sun (directional) lighting color
129 
130  // Fog depth/density
132 
133  // Color modulation for the sun itself during sunset
135 
136  // Used by scripts to animate signs, etc based on the wind (GetWindSpeed)
137  float mWindSpeed;
138 
139  // Cloud animation speed multiplier
140  float mCloudSpeed;
141 
142  // Value between 0 and 1, defines the strength of the sun glare effect.
143  // Also appears to modify how visible the sun, moons, and stars are for various weather effects.
144  float mGlareView;
145 
146  // Fog factor and offset used with distant land rendering.
147  struct {
148  float FogFactor;
149  float FogOffset;
150  } mDL;
151 
152  // Sound effect
153  // This is used for Blight, Ashstorm and Blizzard (Bloodmoon)
154  std::string mAmbientLoopSoundID;
155 
156  // Is this an ash storm / blight storm? If so, the following will happen:
157  // - The particles and clouds will be oriented so they appear to come from the Red Mountain.
158  // - Characters will animate their hand to protect eyes from the storm when looking in its direction (idlestorm animation)
159  // - Slower movement when walking against the storm (fStromWalkMult)
160  bool mIsStorm;
161 
162  // How fast does rain travel down?
163  // In Morrowind.ini this is set globally, but we may want to change it per weather later.
164  float mRainSpeed;
165 
166  // How often does a new rain mesh spawn?
168 
169  std::string mParticleEffect;
170 
171  std::string mRainEffect;
172 
173  // Note: For Weather Blight, there is a "Disease Chance" (=0.1) setting. But according to MWSFD this feature
174  // is broken in the vanilla game and was disabled.
175 
176  float transitionDelta() const;
177  float cloudBlendFactor(const float transitionRatio) const;
178 
179  float calculateThunder(const float transitionRatio, const float elapsedSeconds, const bool isPaused);
180 
181  private:
184 
185  // Note: In MW, only thunderstorms support these attributes, but in the interest of making weather more
186  // flexible, these settings are imported for all weather types. Only thunderstorms will normally have any
187  // non-zero values.
190  std::string mThunderSoundID[4];
192 
194 
195  void flashDecrement(const float elapsedSeconds);
196  float thunderChance(const float transitionRatio, const float elapsedSeconds) const;
197  void lightningAndThunder(void);
198  };
199 
202  {
203  public:
204  explicit RegionWeather(const ESM::Region& region);
205  explicit RegionWeather(const ESM::RegionWeatherState& state);
206 
207  operator ESM::RegionWeatherState() const;
208 
209  void setChances(const std::vector<char>& chances);
210 
211  void setWeather(int weatherID);
212 
213  int getWeather();
214 
215  private:
216  int mWeather;
217  std::vector<char> mChances;
218 
219  void chooseNewWeather();
220  };
221 
223  class MoonModel
224  {
225  public:
226  MoonModel(const std::string& name, const Fallback::Map& fallback);
227 
228  MWRender::MoonState calculateState(const TimeStamp& gameTime) const;
229 
230  private:
235  float mAxisOffset;
236  float mSpeed;
241 
242  float angle(const TimeStamp& gameTime) const;
243  float moonRiseHour(unsigned int daysPassed) const;
244  float rotation(float hours) const;
245  unsigned int phase(const TimeStamp& gameTime) const;
246  float shadowBlend(float angle) const;
247  float hourlyAlpha(float gameHour) const;
248  float earlyMoonShadowAlpha(float angle) const;
249  };
250 
253  {
254  public:
255  // Have to pass fallback and Store, can't use singleton since World isn't fully constructed yet at the time
257  const Fallback::Map& fallback,
258  MWWorld::ESMStore& store);
259  ~WeatherManager();
260 
266  void changeWeather(const std::string& regionID, const unsigned int weatherID);
267  void modRegion(const std::string& regionID, const std::vector<char>& chances);
268  void playerTeleported(const std::string& playerRegion, bool isExterior);
269 
275  void update(float duration, bool paused, const TimeStamp& time, bool isExterior);
276 
277  void stopSounds();
278 
279  float getWindSpeed() const;
280 
282  bool isInStorm() const;
283 
284  osg::Vec3f getStormDirection() const;
285 
286  void advanceTime(double hours, bool incremental);
287 
288  unsigned int getWeatherID() const;
289 
290  bool useTorches(float hour) const;
291 
292  void write(ESM::ESMWriter& writer, Loading::Listener& progress);
293 
294  bool readRecord(ESM::ESMReader& reader, uint32_t type);
295 
296  void clear();
297 
298  private:
302  float mSunsetTime;
306 
308 
309  // fading of night skydome
311 
313  float mRainSpeed;
314 
315  // underwater fog not really related to weather, but we handle it here because it's convenient
317 
318  std::vector<Weather> mWeatherSettings;
321 
322  float mWindSpeed;
323  bool mIsStorm;
325  osg::Vec3f mStormDirection;
326 
327  std::string mCurrentRegion;
328  float mTimePassed;
335  std::map<std::string, RegionWeather> mRegions;
337 
339  std::string mPlayingSoundID;
340 
341  void addWeather(const std::string& name,
342  const Fallback::Map& fallback,
343  float dlFactor, float dlOffset,
344  const std::string& particleEffect = "");
345 
346  void importRegions();
347 
348  void regionalWeatherChanged(const std::string& regionID, RegionWeather& region);
349  bool updateWeatherTime();
350  bool updateWeatherRegion(const std::string& playerRegion);
351  void updateWeatherTransitions(const float elapsedRealSeconds);
352  void forceWeather(const int weatherID);
353 
354  bool inTransition();
355  void addWeatherTransition(const int weatherID);
356 
357  void calculateWeatherResult(const float gameHour, const float elapsedSeconds, const bool isPaused);
358  void calculateResult(const int weatherID, const float gameHour);
359  void calculateTransitionResult(const float factor, const float gameHour);
360  };
361 }
362 
363 #endif // GAME_MWWORLD_WEATHER_H
float mStarsFadingDuration
Definition: weather.hpp:62
void addWeather(const std::string &name, const Fallback::Map &fallback, float dlFactor, float dlOffset, const std::string &particleEffect="")
Definition: weather.cpp:912
void calculateTransitionResult(const float factor, const float gameHour)
Definition: weather.cpp:1153
void calculateWeatherResult(const float gameHour, const float elapsedSeconds, const bool isPaused)
Definition: weather.cpp:1055
float mTransitionDelta
Definition: weather.hpp:182
TimeOfDayInterpolator< float > mNightFade
Definition: weather.hpp:310
float mMoonShadowEarlyFadeAngle
Definition: weather.hpp:240
osg::Vec4f mSunDiscSunsetColor
Definition: weather.hpp:134
void stopSounds()
Definition: weather.cpp:790
float mStarsPostSunsetStart
Definition: weather.hpp:60
float mFadeInStart
Definition: weather.hpp:231
float mPreSunriseTime
Definition: weather.hpp:45
float mWindSpeed
Definition: weather.hpp:322
float angle(const TimeStamp &gameTime) const
Definition: weather.cpp:386
TimeOfDayInterpolator< osg::Vec4f > mFogColor
Definition: weather.hpp:124
void setWeather(int weatherID)
Definition: weather.cpp:315
float mThunderThreshold
Definition: weather.hpp:189
void changeWeather(const std::string &regionID, const unsigned int weatherID)
Definition: weather.cpp:611
float mRainSpeed
Definition: weather.hpp:164
std::vector< char > mChances
Definition: weather.hpp:217
float shadowBlend(float angle) const
Definition: weather.cpp:460
Definition: weather.hpp:43
float mRainSpeed
Definition: weather.hpp:313
Definition: renderingmanager.hpp:72
Definition: sky.hpp:48
MoonModel mMasser
Definition: weather.hpp:319
T mNightValue
Definition: weather.hpp:104
Definition: esmreader.hpp:21
TimeOfDaySettings mTimeSettings
Definition: weather.hpp:307
WeatherSetting getSetting(const std::string &type) const
Definition: weather.hpp:64
void update(float duration, bool paused, const TimeStamp &time, bool isExterior)
Definition: weather.cpp:666
int mNextWeather
Definition: weather.hpp:333
unsigned int phase(const TimeStamp &gameTime) const
Definition: weather.cpp:447
osg::Vec3f getStormDirection() const
Definition: weather.cpp:808
float mGlareView
Definition: weather.hpp:144
MWWorld::ESMStore & mStore
Definition: weather.hpp:299
float mPostSunsetTime
Definition: weather.hpp:48
contains settings imported from the Morrowind INI file.
Definition: fallback.hpp:12
unsigned int getWeatherID() const
Definition: weather.cpp:821
TimeOfDayInterpolator< float > mUnderwaterFog
Definition: weather.hpp:316
float mDayStart
Definition: weather.hpp:55
Definition: weather.hpp:93
MWRender::RenderingManager & mRendering
Definition: weather.hpp:300
TimeOfDayInterpolator< osg::Vec4f > mSkyColor
Definition: weather.hpp:122
float rotation(float hours) const
Definition: weather.cpp:439
Definition: sound.hpp:95
MWRender::MoonState calculateState(const TimeStamp &gameTime) const
Definition: weather.cpp:371
osg::Vec3f mStormDirection
Definition: weather.hpp:325
float getFallbackFloat(const std::string &fall) const
Definition: fallback.cpp:25
Definition: loadregn.hpp:19
bool readRecord(ESM::ESMReader &reader, uint32_t type)
Definition: weather.cpp:856
MoonModel mSecunda
Definition: weather.hpp:320
float mSunsetTime
Definition: weather.hpp:302
Definition: loadinglistener.hpp:8
void clear()
Definition: weather.cpp:900
float mSunsetDuration
Definition: weather.hpp:304
bool useTorches(float hour) const
Definition: weather.cpp:826
void lightningAndThunder(void)
Definition: weather.cpp:249
float mNightStart
Definition: weather.hpp:53
bool mIsStorm
Definition: weather.hpp:323
bool inTransition()
Definition: weather.cpp:1032
int mCurrentWeather
Definition: weather.hpp:332
std::map< std::string, RegionWeather > mRegions
Definition: weather.hpp:335
std::string mPlayingSoundID
Definition: weather.hpp:339
void playerTeleported(const std::string &playerRegion, bool isExterior)
Definition: weather.cpp:652
Definition: esmwriter.hpp:17
int mWeather
Definition: weather.hpp:216
float FogOffset
Definition: weather.hpp:149
Definition: sky.hpp:93
int getWeather()
Definition: weather.cpp:320
float FogFactor
Definition: weather.hpp:148
float mFlashBrightness
Definition: weather.hpp:193
float earlyMoonShadowAlpha(float angle) const
Definition: weather.cpp:502
Definition: esmstore.hpp:17
float mWeatherUpdateTime
Definition: weather.hpp:330
void updateWeatherTransitions(const float elapsedRealSeconds)
Definition: weather.cpp:980
int mQueuedWeather
Definition: weather.hpp:334
float mPostSunriseTime
Definition: weather.hpp:46
std::vector< Weather > mWeatherSettings
Definition: weather.hpp:318
Weather(const std::string &name, const Fallback::Map &fallback, float stormWindSpeed, float rainSpeed, float dlFactor, float dlOffset, const std::string &particleEffect)
Definition: weather.cpp:118
TimeOfDayInterpolator(const T &sunrise, const T &day, const T &sunset, const T &night)
Definition: weather.hpp:96
std::string mAmbientLoopSoundID
Definition: weather.hpp:154
float mFadeOutStart
Definition: weather.hpp:233
float hourlyAlpha(float gameHour) const
Definition: weather.cpp:483
std::map< std::string, WeatherSetting > mSunriseTransitions
Definition: weather.hpp:58
float mTransitionFactor
Definition: weather.hpp:331
struct MWWorld::Weather::@5 mDL
TimeOfDayInterpolator< osg::Vec4f > mSunColor
Definition: weather.hpp:128
float mWindSpeed
Definition: weather.hpp:137
void regionalWeatherChanged(const std::string &regionID, RegionWeather &region)
Definition: weather.cpp:934
bool mIsStorm
Definition: weather.hpp:160
float moonRiseHour(unsigned int daysPassed) const
Definition: weather.cpp:425
MoonModel(const std::string &name, const Fallback::Map &fallback)
Definition: weather.cpp:354
float mFadeStartAngle
Definition: weather.hpp:238
T mDayValue
Definition: weather.hpp:104
A class that acts as a model for the moons.
Definition: weather.hpp:223
float mNightEnd
Definition: weather.hpp:54
float mDayEnd
Definition: weather.hpp:56
void calculateResult(const int weatherID, const float gameHour)
Definition: weather.cpp:1083
bool updateWeatherTime()
Definition: weather.cpp:947
void addSetting(const Fallback::Map &fallback, const std::string &type)
Definition: weather.hpp:77
In-game time stamp.
Definition: timestamp.hpp:14
float getWindSpeed() const
Definition: weather.cpp:798
std::string mCurrentRegion
Definition: weather.hpp:327
bool mFastForward
Definition: weather.hpp:329
T getValue(const float gameHour, const TimeOfDaySettings &timeSettings, const std::string &prefix) const
Definition: weather.cpp:45
float calculateThunder(const float transitionRatio, const float elapsedSeconds, const bool isPaused)
Definition: weather.cpp:207
bool updateWeatherRegion(const std::string &playerRegion)
Definition: weather.cpp:968
float mTimePassed
Definition: weather.hpp:328
Defines a single weather setting (according to INI)
Definition: weather.hpp:108
float mSpeed
Definition: weather.hpp:236
float mThunderFrequency
Definition: weather.hpp:188
float mPreSunsetTime
Definition: weather.hpp:47
float mFadeInFinish
Definition: weather.hpp:232
Definition: weatherstate.hpp:13
void addWeatherTransition(const int weatherID)
Definition: weather.cpp:1037
float mFlashDecrement
Definition: weather.hpp:191
float mSunriseDuration
Definition: weather.hpp:303
bool isInStorm() const
Are we in an ash or blight storm?
Definition: weather.cpp:803
Interface for weather settings.
Definition: weather.hpp:252
MWBase::Sound * mAmbientSound
Definition: weather.hpp:338
float mFadeEndAngle
Definition: weather.hpp:239
~WeatherManager()
Definition: weather.cpp:606
std::string mThunderSoundID[4]
Definition: weather.hpp:190
float mDailyIncrement
Definition: weather.hpp:237
void write(ESM::ESMWriter &writer, Loading::Listener &progress)
Definition: weather.cpp:833
WeatherManager(MWRender::RenderingManager &rendering, const Fallback::Map &fallback, MWWorld::ESMStore &store)
Definition: weather.cpp:523
void advanceTime(double hours, bool incremental)
Definition: weather.cpp:813
T mSunsetValue
Definition: weather.hpp:104
float mCloudSpeed
Definition: weather.hpp:140
float cloudBlendFactor(const float transitionRatio) const
Definition: weather.cpp:201
float transitionDelta() const
Definition: weather.cpp:194
bool mPrecipitation
Definition: weather.hpp:324
void importRegions()
Definition: weather.cpp:924
float mStarsPreSunriseFinish
Definition: weather.hpp:61
float mSunPreSunsetTime
Definition: weather.hpp:305
Definition: weather.hpp:51
RegionWeather(const ESM::Region &region)
Definition: weather.cpp:261
float thunderChance(const float transitionRatio, const float elapsedSeconds) const
Definition: weather.cpp:239
float mFadeOutFinish
Definition: weather.hpp:234
std::string mCloudTexture
Definition: weather.hpp:119
TimeOfDayInterpolator< osg::Vec4f > mAmbientColor
Definition: weather.hpp:126
std::string mRainEffect
Definition: weather.hpp:171
float mHoursBetweenWeatherChanges
Definition: weather.hpp:312
float mAxisOffset
Definition: weather.hpp:235
void chooseNewWeather()
Definition: weather.cpp:332
float mSunriseTime
Definition: weather.hpp:301
void flashDecrement(const float elapsedSeconds)
Definition: weather.cpp:231
std::string mParticleEffect
Definition: weather.hpp:169
void modRegion(const std::string &regionID, const std::vector< char > &chances)
Definition: weather.cpp:633
float mCloudsMaximumPercent
Definition: weather.hpp:183
T mSunriseValue
Definition: weather.hpp:104
MWRender::WeatherResult mResult
Definition: weather.hpp:336
float mRainFrequency
Definition: weather.hpp:167
TimeOfDayInterpolator< float > mLandFogDepth
Definition: weather.hpp:131
A class for storing a region's weather.
Definition: weather.hpp:201
const char * name
Definition: crashcatcher.cpp:67
void setChances(const std::vector< char > &chances)
Definition: weather.cpp:295
void forceWeather(const int weatherID)
Definition: weather.cpp:1024