From 8da3494d74c783574c850c691d3efcc7bb732cef Mon Sep 17 00:00:00 2001 From: Miroslav Puda Date: Thu, 20 Jun 2013 21:44:28 +0200 Subject: [PATCH] Revert "Type of weather changed from string to enum." This reverts commit 04d90b4c47e140cec53750d523378d2cf9938387. Conflicts: apps/openmw/mwworld/weather.cpp apps/openmw/mwworld/weather.hpp --- apps/openmw/mwbase/world.hpp | 2 +- apps/openmw/mwworld/weather.cpp | 225 ++++++++++++++++++------------- apps/openmw/mwworld/weather.hpp | 36 ++--- apps/openmw/mwworld/worldimp.cpp | 2 +- apps/openmw/mwworld/worldimp.hpp | 2 +- 5 files changed, 144 insertions(+), 123 deletions(-) diff --git a/apps/openmw/mwbase/world.hpp b/apps/openmw/mwbase/world.hpp index 8a83aaf862..86a6a89d21 100644 --- a/apps/openmw/mwbase/world.hpp +++ b/apps/openmw/mwbase/world.hpp @@ -191,7 +191,7 @@ namespace MWBase virtual bool toggleSky() = 0; ///< \return Resulting mode - virtual void changeWeather(const std::string& region, int id) = 0; + virtual void changeWeather(const std::string& region, unsigned int id) = 0; virtual int getCurrentWeather() const = 0; diff --git a/apps/openmw/mwworld/weather.cpp b/apps/openmw/mwworld/weather.cpp index 4a2a2f8039..68a46ec124 100644 --- a/apps/openmw/mwworld/weather.cpp +++ b/apps/openmw/mwworld/weather.cpp @@ -31,62 +31,35 @@ namespace } } -std::string Weather::weatherTypeToStr(Weather::Type type) +void WeatherManager::setFallbackWeather(Weather& weather,const std::string& name) { - switch (type) { - case Type_Clear: - return "Clear"; - case Type_Cloudy: - return "Cloudy"; - case Type_Foggy: - return "Foggy"; - case Type_Overcast: - return "Overcast"; - case Type_Rain: - return "Rain"; - case Type_Thunderstorm: - return "Thunderstorm"; - case Type_Ashstorm: - return "Ashstorm"; - case Type_Blight: - return "Blight"; - case Type_Snow: - return "Snow"; - case Type_Blizzard: - return "Blizzard"; - default: // Type_Unknown - return ""; - } -} - -void WeatherManager::setFallbackWeather(Weather& weather, Weather::Type type) -{ - const std::string weatherName = Weather::weatherTypeToStr(type); - weather.mCloudsMaximumPercent = mFallback->getFallbackFloat("Weather_"+weatherName+"_Clouds_Maximum_Percent"); - weather.mTransitionDelta = mFallback->getFallbackFloat("Weather_"+weatherName+"_Transition_Delta"); - weather.mSkySunriseColor= mFallback->getFallbackColour("Weather_"+weatherName+"_Sky_Sunrise_Color"); - weather.mSkyDayColor = mFallback->getFallbackColour("Weather_"+weatherName+"_Sky_Day_Color"); - weather.mSkySunsetColor = mFallback->getFallbackColour("Weather_"+weatherName+"_Sky_Sunset_Color"); - weather.mSkyNightColor = mFallback->getFallbackColour("Weather_"+weatherName+"_Sky_Night_Color"); - weather.mFogSunriseColor = mFallback->getFallbackColour("Weather_"+weatherName+"_Fog_Sunrise_Color"); - weather.mFogDayColor = mFallback->getFallbackColour("Weather_"+weatherName+"_Fog_Day_Color"); - weather.mFogSunsetColor = mFallback->getFallbackColour("Weather_"+weatherName+"_Fog_Sunset_Color"); - weather.mFogNightColor = mFallback->getFallbackColour("Weather_"+weatherName+"_Fog_Night_Color"); - weather.mAmbientSunriseColor = mFallback->getFallbackColour("Weather_"+weatherName+"_Ambient_Sunrise_Color"); - weather.mAmbientDayColor = mFallback->getFallbackColour("Weather_"+weatherName+"_Ambient_Day_Color"); - weather.mAmbientSunsetColor = mFallback->getFallbackColour("Weather_"+weatherName+"_Ambient_Sunset_Color"); - weather.mAmbientNightColor = mFallback->getFallbackColour("Weather_"+weatherName+"_Ambient_Night_Color"); - weather.mSunSunriseColor = mFallback->getFallbackColour("Weather_"+weatherName+"_Sun_Sunrise_Color"); - weather.mSunDayColor = mFallback->getFallbackColour("Weather_"+weatherName+"_Sun_Day_Color"); - weather.mSunSunsetColor = mFallback->getFallbackColour("Weather_"+weatherName+"_Sun_Sunset_Color"); - weather.mSunNightColor = mFallback->getFallbackColour("Weather_"+weatherName+"_Sun_Night_Color"); - weather.mSunDiscSunsetColor = mFallback->getFallbackColour("Weather_"+weatherName+"_Sun_Disc_Sunset_Color"); - weather.mLandFogDayDepth = mFallback->getFallbackFloat("Weather_"+weatherName+"_Land_Fog_Day_Depth"); - weather.mLandFogNightDepth = mFallback->getFallbackFloat("Weather_"+weatherName+"_Land_Fog_Night_Depth"); - weather.mWindSpeed = mFallback->getFallbackFloat("Weather_"+weatherName+"_Wind_Speed"); - weather.mCloudSpeed = mFallback->getFallbackFloat("Weather_"+weatherName+"_Cloud_Speed"); - weather.mGlareView = mFallback->getFallbackFloat("Weather_"+weatherName+"_Glare_View"); - mWeatherSettings[type] = weather; + std::string upper=name; + upper[0]=toupper(name[0]); + weather.mCloudsMaximumPercent = mFallback->getFallbackFloat("Weather_"+upper+"_Clouds_Maximum_Percent"); + weather.mTransitionDelta = mFallback->getFallbackFloat("Weather_"+upper+"_Transition_Delta"); + weather.mSkySunriseColor=mFallback->getFallbackColour("Weather_"+upper+"_Sky_Sunrise_Color"); + weather.mSkyDayColor = mFallback->getFallbackColour("Weather_"+upper+"_Sky_Day_Color"); + weather.mSkySunsetColor = mFallback->getFallbackColour("Weather_"+upper+"_Sky_Sunset_Color"); + weather.mSkyNightColor = mFallback->getFallbackColour("Weather_"+upper+"_Sky_Night_Color"); + weather.mFogSunriseColor = mFallback->getFallbackColour("Weather_"+upper+"_Fog_Sunrise_Color"); + weather.mFogDayColor = mFallback->getFallbackColour("Weather_"+upper+"_Fog_Day_Color"); + weather.mFogSunsetColor = mFallback->getFallbackColour("Weather_"+upper+"_Fog_Sunset_Color"); + weather.mFogNightColor = mFallback->getFallbackColour("Weather_"+upper+"_Fog_Night_Color"); + weather.mAmbientSunriseColor = mFallback->getFallbackColour("Weather_"+upper+"_Ambient_Sunrise_Color"); + weather.mAmbientDayColor = mFallback->getFallbackColour("Weather_"+upper+"_Ambient_Day_Color"); + weather.mAmbientSunsetColor = mFallback->getFallbackColour("Weather_"+upper+"_Ambient_Sunset_Color"); + weather.mAmbientNightColor = mFallback->getFallbackColour("Weather_"+upper+"_Ambient_Night_Color"); + weather.mSunSunriseColor = mFallback->getFallbackColour("Weather_"+upper+"_Sun_Sunrise_Color"); + weather.mSunDayColor = mFallback->getFallbackColour("Weather_"+upper+"_Sun_Day_Color"); + weather.mSunSunsetColor = mFallback->getFallbackColour("Weather_"+upper+"_Sun_Sunset_Color"); + weather.mSunNightColor = mFallback->getFallbackColour("Weather_"+upper+"_Sun_Night_Color"); + weather.mSunDiscSunsetColor = mFallback->getFallbackColour("Weather_"+upper+"_Sun_Disc_Sunset_Color"); + weather.mLandFogDayDepth = mFallback->getFallbackFloat("Weather_"+upper+"_Land_Fog_Day_Depth"); + weather.mLandFogNightDepth = mFallback->getFallbackFloat("Weather_"+upper+"_Land_Fog_Night_Depth"); + weather.mWindSpeed = mFallback->getFallbackFloat("Weather_"+upper+"_Wind_Speed"); + weather.mCloudSpeed = mFallback->getFallbackFloat("Weather_"+upper+"_Cloud_Speed"); + weather.mGlareView = mFallback->getFallbackFloat("Weather_"+upper+"_Glare_View"); + mWeatherSettings[name] = weather; } @@ -118,10 +91,11 @@ float WeatherManager::calculateAngleFade (const std::string& moonName, float ang } WeatherManager::WeatherManager(MWRender::RenderingManager* rendering,MWWorld::Fallback* fallback) : - mHour(14), mCurrentWeather(Weather::Type_Clear), mNextWeather(Weather::Type_Unknown), - mFirstUpdate(true), mWeatherUpdateTime(0), mThunderFlash(0), mThunderChance(0), - mThunderChanceNeeded(50), mThunderSoundDelay(0), mRemainingTransitionTime(0), mMonth(0), mDay(0), - mTimePassed(0), mFallback(fallback), mWindSpeed(0.f), mRendering(rendering) + mHour(14), mCurrentWeather("clear"), mNextWeather(""), mFirstUpdate(true), + mWeatherUpdateTime(0), mThunderFlash(0), mThunderChance(0), + mThunderChanceNeeded(50), mThunderSoundDelay(0), mRemainingTransitionTime(0), + mMonth(0), mDay(0), mTimePassed(0), mFallback(fallback), mWindSpeed(0.f), + mRendering(rendering) { //Globals mThunderSoundID0 = mFallback->getFallbackString("Weather_Thunderstorm_Thunder_Sound_ID_0"); @@ -152,53 +126,53 @@ WeatherManager::WeatherManager(MWRender::RenderingManager* rendering,MWWorld::Fa //Weather Weather clear; clear.mCloudTexture = "tx_sky_clear.dds"; - setFallbackWeather(clear, Weather::Type_Clear); + setFallbackWeather(clear,"clear"); Weather cloudy; cloudy.mCloudTexture = "tx_sky_cloudy.dds"; - setFallbackWeather(cloudy, Weather::Type_Cloudy); + setFallbackWeather(cloudy,"cloudy"); Weather foggy; foggy.mCloudTexture = "tx_sky_foggy.dds"; - setFallbackWeather(foggy, Weather::Type_Foggy); + setFallbackWeather(foggy,"foggy"); Weather thunderstorm; thunderstorm.mCloudTexture = "tx_sky_thunder.dds"; thunderstorm.mRainLoopSoundID = "rain heavy"; - setFallbackWeather(thunderstorm, Weather::Type_Thunderstorm); + setFallbackWeather(thunderstorm,"thunderstorm"); Weather rain; rain.mCloudTexture = "tx_sky_rainy.dds"; rain.mRainLoopSoundID = "rain"; - setFallbackWeather(rain, Weather::Type_Rain); + setFallbackWeather(rain,"rain"); Weather overcast; overcast.mCloudTexture = "tx_sky_overcast.dds"; - setFallbackWeather(overcast, Weather::Type_Overcast); + setFallbackWeather(overcast,"overcast"); Weather ashstorm; ashstorm.mCloudTexture = "tx_sky_ashstorm.dds"; ashstorm.mAmbientLoopSoundID = "ashstorm"; - setFallbackWeather(ashstorm, Weather::Type_Ashstorm); + setFallbackWeather(ashstorm,"ashstorm"); Weather blight; blight.mCloudTexture = "tx_sky_blight.dds"; blight.mAmbientLoopSoundID = "blight"; - setFallbackWeather(blight, Weather::Type_Blight); + setFallbackWeather(blight,"blight"); Weather snow; snow.mCloudTexture = "tx_bm_sky_snow.dds"; - setFallbackWeather(snow, Weather::Type_Snow); + setFallbackWeather(snow, "snow"); Weather blizzard; blizzard.mCloudTexture = "tx_bm_sky_blizzard.dds"; blizzard.mAmbientLoopSoundID = "BM Blizzard"; - setFallbackWeather(blizzard, Weather::Type_Blizzard); + setFallbackWeather(blizzard,"blizzard"); } -void WeatherManager::setWeather(Weather::Type weatherType, bool instant) +void WeatherManager::setWeather(const String& weather, bool instant) { - if (weatherType == mCurrentWeather && mNextWeather == Weather::Type_Unknown) + if (weather == mCurrentWeather && mNextWeather == "") { mFirstUpdate = false; return; @@ -206,25 +180,25 @@ void WeatherManager::setWeather(Weather::Type weatherType, bool instant) if (instant || mFirstUpdate) { - mNextWeather = Weather::Type_Unknown; - mCurrentWeather = weatherType; + mNextWeather = ""; + mCurrentWeather = weather; } else { - if (mNextWeather != Weather::Type_Unknown) + if (mNextWeather != "") { // transition more than 50% finished? if (mRemainingTransitionTime/(mWeatherSettings[mCurrentWeather].mTransitionDelta * 24.f * 3600) <= 0.5) mCurrentWeather = mNextWeather; } - mNextWeather = weatherType; + mNextWeather = weather; mRemainingTransitionTime = mWeatherSettings[mCurrentWeather].mTransitionDelta * 24.f * 3600; } mFirstUpdate = false; } -void WeatherManager::setResult(Weather::Type weatherType) +void WeatherManager::setResult(const String& weatherType) { const Weather& current = mWeatherSettings[weatherType]; @@ -366,7 +340,7 @@ void WeatherManager::update(float duration) mCurrentRegion = regionstr; mWeatherUpdateTime = mHoursBetweenWeatherChanges * 3600; - Weather::Type weatherType = Weather::Type_Clear; + std::string weatherType = "clear"; if (mRegionOverrides.find(regionstr) != mRegionOverrides.end()) weatherType = mRegionOverrides[regionstr]; @@ -385,17 +359,17 @@ void WeatherManager::update(float duration) setWeather(weatherType, false); } - if (mNextWeather != Weather::Type_Unknown) + if (mNextWeather != "") { mRemainingTransitionTime -= timePassed; if (mRemainingTransitionTime < 0) { mCurrentWeather = mNextWeather; - mNextWeather = Weather::Type_Unknown; + mNextWeather = ""; } } - if (mNextWeather != Weather::Type_Unknown) + if (mNextWeather != "") transition(1 - (mRemainingTransitionTime / (mWeatherSettings[mCurrentWeather].mTransitionDelta * 24.f * 3600))); else setResult(mCurrentWeather); @@ -487,7 +461,7 @@ void WeatherManager::update(float duration) mRendering->getSkyManager()->secundaDisable(); } - if (mCurrentWeather == Weather::Type_Thunderstorm && mNextWeather == Weather::Type_Unknown) + if (mCurrentWeather == "thunderstorm" && mNextWeather == "") { if (mThunderFlash > 0) { @@ -542,7 +516,7 @@ void WeatherManager::update(float duration) // Play sounds - if (mNextWeather == Weather::Type_Unknown) + if (mNextWeather == "") { std::string ambientSnd = mWeatherSettings[mCurrentWeather].mAmbientLoopSoundID; if (!ambientSnd.empty() && std::find(mSoundsPlaying.begin(), mSoundsPlaying.end(), ambientSnd) == mSoundsPlaying.end()) @@ -579,7 +553,7 @@ void WeatherManager::stopSounds(bool stopAll) } } -Weather::Type WeatherManager::nextWeather(const ESM::Region* region) const +Ogre::String WeatherManager::nextWeather(const ESM::Region* region) const { /* * All probabilities must add to 100 (responsibility of the user). @@ -602,16 +576,36 @@ Weather::Type WeatherManager::nextWeather(const ESM::Region* region) const int chance = (rand() % 100) + 1; // 1..100 int sum = 0; - int i = 0; - for (; i < 10; ++i) + for (int i = 0; i < 10; ++i) { sum += probability[i]; if (chance < sum) { - break; + switch (i) + { + case 1: + return "cloudy"; + case 2: + return "foggy"; + case 3: + return "overcast"; + case 4: + return "rain"; + case 5: + return "thunderstorm"; + case 6: + return "ashstorm"; + case 7: + return "blight"; + case 8: + return "snow"; + case 9: + return "blizzard"; + default: // case 0 + return "clear"; + } } } - return (Weather::Type) i; } void WeatherManager::setHour(const float hour) @@ -628,23 +622,66 @@ void WeatherManager::setDate(const int day, const int month) unsigned int WeatherManager::getWeatherID() const { // Source: http://www.uesp.net/wiki/Tes3Mod:GetCurrentWeather - return mCurrentWeather; + + if (mCurrentWeather == "clear") + return 0; + else if (mCurrentWeather == "cloudy") + return 1; + else if (mCurrentWeather == "foggy") + return 2; + else if (mCurrentWeather == "overcast") + return 3; + else if (mCurrentWeather == "rain") + return 4; + else if (mCurrentWeather == "thunderstorm") + return 5; + else if (mCurrentWeather == "ashstorm") + return 6; + else if (mCurrentWeather == "blight") + return 7; + else if (mCurrentWeather == "snow") + return 8; + else if (mCurrentWeather == "blizzard") + return 9; + + else + return 0; } -void WeatherManager::changeWeather(const std::string& region, const int id) +void WeatherManager::changeWeather(const std::string& region, const unsigned int id) { // make sure this region exists MWBase::Environment::get().getWorld()->getStore().get().find(region); - Weather::Type weatherType = Weather::Type_Clear; - if (id >= Weather::Type_Clear && id < Weather::Type_Unknown) - weatherType = (Weather::Type)id; + std::string weather; + if (id==0) + weather = "clear"; + else if (id==1) + weather = "cloudy"; + else if (id==2) + weather = "foggy"; + else if (id==3) + weather = "overcast"; + else if (id==4) + weather = "rain"; + else if (id==5) + weather = "thunderstorm"; + else if (id==6) + weather = "ashstorm"; + else if (id==7) + weather = "blight"; + else if (id==8) + weather = "snow"; + else if (id==9) + weather = "blizzard"; + else + weather = "clear"; - mRegionOverrides[Misc::StringUtils::lowerCase(region)] = weatherType; + mRegionOverrides[Misc::StringUtils::lowerCase(region)] = weather; std::string playerRegion = MWBase::Environment::get().getWorld()->getPlayer().getPlayer().getCell()->mCell->mRegion; if (Misc::StringUtils::ciEqual(region, playerRegion)) - setWeather(weatherType); + setWeather(weather); } float WeatherManager::getWindSpeed() const diff --git a/apps/openmw/mwworld/weather.hpp b/apps/openmw/mwworld/weather.hpp index 90b0a2dc5e..1a787aae8f 100644 --- a/apps/openmw/mwworld/weather.hpp +++ b/apps/openmw/mwworld/weather.hpp @@ -55,21 +55,6 @@ namespace MWWorld /// Defines a single weather setting (according to INI) struct Weather { - enum Type - { - Type_Clear = 0, - Type_Cloudy, - Type_Foggy, - Type_Overcast, - Type_Rain, - Type_Thunderstorm, - Type_Ashstorm, - Type_Blight, - Type_Snow, - Type_Blizzard, - Type_Unknown - }; - Ogre::String mCloudTexture; // Sky (atmosphere) colors @@ -126,8 +111,6 @@ namespace MWWorld Ogre::String mRainLoopSoundID; /// \todo disease chance - - static std::string weatherTypeToStr(Weather::Type type); }; /// @@ -143,7 +126,7 @@ namespace MWWorld * @param region that should be changed * @param ID of the weather setting to shift to */ - void changeWeather(const std::string& region, const int id); + void changeWeather(const std::string& region, const unsigned int id); /** * Per-frame update @@ -171,17 +154,17 @@ namespace MWWorld int mDay, mMonth; float mWindSpeed; MWWorld::Fallback* mFallback; - void setFallbackWeather(Weather& weather, Weather::Type type); + void setFallbackWeather(Weather& weather,const std::string& name); MWRender::RenderingManager* mRendering; - std::map mWeatherSettings; + std::map mWeatherSettings; - std::map mRegionOverrides; + std::map mRegionOverrides; std::vector mSoundsPlaying; - Weather::Type mCurrentWeather; - Weather::Type mNextWeather; + Ogre::String mCurrentWeather; + Ogre::String mNextWeather; std::string mCurrentRegion; @@ -196,14 +179,15 @@ namespace MWWorld double mTimePassed; // time passed since last update void transition(const float factor); - void setResult(Weather::Type weatherType); + void setResult(const Ogre::String& weatherType); float calculateHourFade (const std::string& moonName) const; float calculateAngleFade (const std::string& moonName, float angle) const; - void setWeather(Weather::Type weatherType, bool instant=false); - Weather::Type nextWeather(const ESM::Region* region) const; + void setWeather(const Ogre::String& weatherType, bool instant=false); + Ogre::String nextWeather(const ESM::Region* region) const; WeatherResult mResult; + float mSunriseTime; float mSunsetTime; float mSunriseDuration; diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index ee642f869b..16cba2ea8e 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -1371,7 +1371,7 @@ namespace MWWorld return mWeatherManager->getWeatherID(); } - void World::changeWeather(const std::string& region, const int id) + void World::changeWeather(const std::string& region, const unsigned int id) { mWeatherManager->changeWeather(region, id); } diff --git a/apps/openmw/mwworld/worldimp.hpp b/apps/openmw/mwworld/worldimp.hpp index 35eba979f7..12438efd42 100644 --- a/apps/openmw/mwworld/worldimp.hpp +++ b/apps/openmw/mwworld/worldimp.hpp @@ -225,7 +225,7 @@ namespace MWWorld virtual bool toggleSky(); ///< \return Resulting mode - virtual void changeWeather (const std::string& region, int id); + virtual void changeWeather (const std::string& region, unsigned int id); virtual int getCurrentWeather() const;