From 4e8e048968c5c20b0b4e71c66449f37f28bd177e Mon Sep 17 00:00:00 2001 From: vorenon Date: Wed, 19 Jun 2013 01:46:38 +0200 Subject: [PATCH 01/16] Added missing click sounds to dialogue --- apps/openmw/mwgui/dialogue.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/apps/openmw/mwgui/dialogue.cpp b/apps/openmw/mwgui/dialogue.cpp index 8a57234b8f..c9a7806918 100644 --- a/apps/openmw/mwgui/dialogue.cpp +++ b/apps/openmw/mwgui/dialogue.cpp @@ -7,6 +7,7 @@ #include "../mwbase/windowmanager.hpp" #include "../mwbase/mechanicsmanager.hpp" #include "../mwbase/world.hpp" +#include "../mwbase/soundmanager.hpp" #include "../mwmechanics/npcstats.hpp" @@ -224,16 +225,22 @@ namespace MWGui void Choice::activated() { + + MWBase::Environment::get().getSoundManager()->playSound("Menu Click", 1.0, 1.0); MWBase::Environment::get().getDialogueManager()->questionAnswered(mChoiceId); } void Topic::activated() { + + MWBase::Environment::get().getSoundManager()->playSound("Menu Click", 1.f, 1.f); MWBase::Environment::get().getDialogueManager()->keywordSelected(Misc::StringUtils::lowerCase(mTopicId)); } void Goodbye::activated() { + + MWBase::Environment::get().getSoundManager()->playSound("Menu Click", 1.f, 1.f); MWBase::Environment::get().getDialogueManager()->goodbyeSelected(); } From 04d90b4c47e140cec53750d523378d2cf9938387 Mon Sep 17 00:00:00 2001 From: Miroslav Puda Date: Wed, 19 Jun 2013 03:24:30 +0200 Subject: [PATCH 02/16] Type of weather changed from string to enum. --- apps/openmw/mwbase/world.hpp | 2 +- apps/openmw/mwworld/weather.cpp | 216 ++++++++++++++----------------- apps/openmw/mwworld/weather.hpp | 33 +++-- apps/openmw/mwworld/worldimp.cpp | 2 +- apps/openmw/mwworld/worldimp.hpp | 2 +- 5 files changed, 128 insertions(+), 127 deletions(-) diff --git a/apps/openmw/mwbase/world.hpp b/apps/openmw/mwbase/world.hpp index 86a6a89d21..8a83aaf862 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, unsigned int id) = 0; + virtual void changeWeather(const std::string& region, int id) = 0; virtual int getCurrentWeather() const = 0; diff --git a/apps/openmw/mwworld/weather.cpp b/apps/openmw/mwworld/weather.cpp index 8b3c5f6ffa..c09d706234 100644 --- a/apps/openmw/mwworld/weather.cpp +++ b/apps/openmw/mwworld/weather.cpp @@ -31,35 +31,62 @@ namespace } } -void WeatherManager::setFallbackWeather(Weather& weather,const std::string& name) +std::string Weather::weatherTypeToStr(Weather::Type type) { - 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; + 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; } @@ -91,7 +118,7 @@ float WeatherManager::calculateAngleFade (const std::string& moonName, float ang } WeatherManager::WeatherManager(MWRender::RenderingManager* rendering,MWWorld::Fallback* fallback) : - mHour(14), mCurrentWeather("clear"), mFirstUpdate(true), mWeatherUpdateTime(0), + mHour(14), mCurrentWeather(Weather::Type_Clear), 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) @@ -125,53 +152,53 @@ WeatherManager::WeatherManager(MWRender::RenderingManager* rendering,MWWorld::Fa //Weather Weather clear; clear.mCloudTexture = "tx_sky_clear.dds"; - setFallbackWeather(clear,"clear"); + setFallbackWeather(clear, Weather::Type_Clear); Weather cloudy; cloudy.mCloudTexture = "tx_sky_cloudy.dds"; - setFallbackWeather(cloudy,"cloudy"); + setFallbackWeather(cloudy, Weather::Type_Cloudy); Weather foggy; foggy.mCloudTexture = "tx_sky_foggy.dds"; - setFallbackWeather(foggy,"foggy"); + setFallbackWeather(foggy, Weather::Type_Foggy); Weather thunderstorm; thunderstorm.mCloudTexture = "tx_sky_thunder.dds"; thunderstorm.mRainLoopSoundID = "rain heavy"; - setFallbackWeather(thunderstorm,"thunderstorm"); + setFallbackWeather(thunderstorm, Weather::Type_Thunderstorm); Weather rain; rain.mCloudTexture = "tx_sky_rainy.dds"; rain.mRainLoopSoundID = "rain"; - setFallbackWeather(rain,"rain"); + setFallbackWeather(rain, Weather::Type_Rain); Weather overcast; overcast.mCloudTexture = "tx_sky_overcast.dds"; - setFallbackWeather(overcast,"overcast"); + setFallbackWeather(overcast, Weather::Type_Overcast); Weather ashstorm; ashstorm.mCloudTexture = "tx_sky_ashstorm.dds"; ashstorm.mAmbientLoopSoundID = "ashstorm"; - setFallbackWeather(ashstorm,"ashstorm"); + setFallbackWeather(ashstorm, Weather::Type_Ashstorm); Weather blight; blight.mCloudTexture = "tx_sky_blight.dds"; blight.mAmbientLoopSoundID = "blight"; - setFallbackWeather(blight,"blight"); + setFallbackWeather(blight, Weather::Type_Blight); Weather snow; snow.mCloudTexture = "tx_bm_sky_snow.dds"; - setFallbackWeather(snow, "snow"); + setFallbackWeather(snow, Weather::Type_Snow); Weather blizzard; blizzard.mCloudTexture = "tx_bm_sky_blizzard.dds"; blizzard.mAmbientLoopSoundID = "BM Blizzard"; - setFallbackWeather(blizzard,"blizzard"); + setFallbackWeather(blizzard, Weather::Type_Blizzard); } -void WeatherManager::setWeather(const String& weather, bool instant) +void WeatherManager::setWeather(Weather::Type weatherType, bool instant) { - if (weather == mCurrentWeather && mNextWeather == "") + if (weatherType == mCurrentWeather && mNextWeather == Weather::Type_Unknown) { mFirstUpdate = false; return; @@ -179,27 +206,27 @@ void WeatherManager::setWeather(const String& weather, bool instant) if (instant || mFirstUpdate) { - mNextWeather = ""; - mCurrentWeather = weather; + mNextWeather = Weather::Type_Unknown; + mCurrentWeather = weatherType; } else { - if (mNextWeather != "") + if (mNextWeather != Weather::Type_Unknown) { // transition more than 50% finished? if (mRemainingTransitionTime/(mWeatherSettings[mCurrentWeather].mTransitionDelta * 24.f * 3600) <= 0.5) mCurrentWeather = mNextWeather; } - mNextWeather = weather; + mNextWeather = weatherType; mRemainingTransitionTime = mWeatherSettings[mCurrentWeather].mTransitionDelta * 24.f * 3600; } mFirstUpdate = false; } -WeatherResult WeatherManager::getResult(const String& weather) +WeatherResult WeatherManager::getResult(Weather::Type weatherType) { - const Weather& current = mWeatherSettings[weather]; + const Weather& current = mWeatherSettings[weatherType]; WeatherResult result; result.mCloudTexture = current.mCloudTexture; @@ -336,10 +363,10 @@ void WeatherManager::update(float duration) mCurrentRegion = regionstr; mWeatherUpdateTime = mHoursBetweenWeatherChanges * 3600; - std::string weather = "clear"; + Weather::Type weatherType = Weather::Type_Clear; if (mRegionOverrides.find(regionstr) != mRegionOverrides.end()) - weather = mRegionOverrides[regionstr]; + weatherType = mRegionOverrides[regionstr]; else { // get weather probabilities for the current region @@ -365,44 +392,44 @@ void WeatherManager::update(float duration) float random = ((rand()%100)/100.f) * total; if (random >= snow+blight+ash+thunder+rain+overcast+foggy+cloudy+clear) - weather = "blizzard"; + weatherType = Weather::Type_Blizzard; else if (random >= blight+ash+thunder+rain+overcast+foggy+cloudy+clear) - weather = "snow"; + weatherType = Weather::Type_Snow; else if (random >= ash+thunder+rain+overcast+foggy+cloudy+clear) - weather = "blight"; + weatherType = Weather::Type_Blight; else if (random >= thunder+rain+overcast+foggy+cloudy+clear) - weather = "ashstorm"; + weatherType = Weather::Type_Ashstorm; else if (random >= rain+overcast+foggy+cloudy+clear) - weather = "thunderstorm"; + weatherType = Weather::Type_Thunderstorm; else if (random >= overcast+foggy+cloudy+clear) - weather = "rain"; + weatherType = Weather::Type_Rain; else if (random >= foggy+cloudy+clear) - weather = "overcast"; + weatherType = Weather::Type_Overcast; else if (random >= cloudy+clear) - weather = "foggy"; + weatherType = Weather::Type_Foggy; else if (random >= clear) - weather = "cloudy"; + weatherType = Weather::Type_Cloudy; else - weather = "clear"; + weatherType = Weather::Type_Clear; } } - setWeather(weather, false); + setWeather(weatherType, false); } WeatherResult result; - if (mNextWeather != "") + if (mNextWeather != Weather::Type_Unknown) { mRemainingTransitionTime -= timePassed; if (mRemainingTransitionTime < 0) { mCurrentWeather = mNextWeather; - mNextWeather = ""; + mNextWeather = Weather::Type_Unknown; } } - if (mNextWeather != "") + if (mNextWeather != Weather::Type_Unknown) result = transition(1 - (mRemainingTransitionTime / (mWeatherSettings[mCurrentWeather].mTransitionDelta * 24.f * 3600))); else result = getResult(mCurrentWeather); @@ -494,7 +521,7 @@ void WeatherManager::update(float duration) mRendering->getSkyManager()->secundaDisable(); } - if (mCurrentWeather == "thunderstorm" && mNextWeather == "" && exterior) + if (mCurrentWeather == Weather::Type_Thunderstorm && mNextWeather == Weather::Type_Unknown && exterior) { if (mThunderFlash > 0) { @@ -555,7 +582,7 @@ void WeatherManager::update(float duration) } // play sounds - std::string ambientSnd = (mNextWeather == "" ? mWeatherSettings[mCurrentWeather].mAmbientLoopSoundID : ""); + std::string ambientSnd = (mNextWeather == Weather::Type_Unknown ? mWeatherSettings[mCurrentWeather].mAmbientLoopSoundID : ""); if (!exterior) ambientSnd = ""; if (ambientSnd != "") { @@ -566,7 +593,7 @@ void WeatherManager::update(float duration) } } - std::string rainSnd = (mNextWeather == "" ? mWeatherSettings[mCurrentWeather].mRainLoopSoundID : ""); + std::string rainSnd = (mNextWeather == Weather::Type_Unknown ? mWeatherSettings[mCurrentWeather].mRainLoopSoundID : ""); if (!exterior) rainSnd = ""; if (rainSnd != "") { @@ -605,66 +632,23 @@ void WeatherManager::setDate(const int day, const int month) unsigned int WeatherManager::getWeatherID() const { // Source: http://www.uesp.net/wiki/Tes3Mod:GetCurrentWeather - - 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; + return mCurrentWeather; } -void WeatherManager::changeWeather(const std::string& region, const unsigned int id) +void WeatherManager::changeWeather(const std::string& region, const int id) { // make sure this region exists MWBase::Environment::get().getWorld()->getStore().get().find(region); - 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"; + Weather::Type weatherType = Weather::Type_Clear; + if (id >= Weather::Type_Clear && id < Weather::Type_Unknown) + weatherType = (Weather::Type)id; - mRegionOverrides[Misc::StringUtils::lowerCase(region)] = weather; + mRegionOverrides[Misc::StringUtils::lowerCase(region)] = weatherType; std::string playerRegion = MWBase::Environment::get().getWorld()->getPlayer().getPlayer().getCell()->mCell->mRegion; if (Misc::StringUtils::ciEqual(region, playerRegion)) - setWeather(weather); + setWeather(weatherType); } float WeatherManager::getWindSpeed() const diff --git a/apps/openmw/mwworld/weather.hpp b/apps/openmw/mwworld/weather.hpp index 081bd7f87d..08e9c017d9 100644 --- a/apps/openmw/mwworld/weather.hpp +++ b/apps/openmw/mwworld/weather.hpp @@ -50,6 +50,21 @@ 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 @@ -106,6 +121,8 @@ namespace MWWorld Ogre::String mRainLoopSoundID; /// \todo disease chance + + static std::string weatherTypeToStr(Weather::Type type); }; /// @@ -121,7 +138,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 unsigned int id); + void changeWeather(const std::string& region, const int id); /** * Per-frame update @@ -147,17 +164,17 @@ namespace MWWorld int mDay, mMonth; float mWindSpeed; MWWorld::Fallback* mFallback; - void setFallbackWeather(Weather& weather,const std::string& name); + void setFallbackWeather(Weather& weather, Weather::Type type); MWRender::RenderingManager* mRendering; - std::map mWeatherSettings; + std::map mWeatherSettings; - std::map mRegionOverrides; + std::map mRegionOverrides; std::vector mSoundsPlaying; - Ogre::String mCurrentWeather; - Ogre::String mNextWeather; + Weather::Type mCurrentWeather; + Weather::Type mNextWeather; std::string mCurrentRegion; @@ -172,12 +189,12 @@ namespace MWWorld double mTimePassed; // time passed since last update WeatherResult transition(const float factor); - WeatherResult getResult(const Ogre::String& weather); + WeatherResult getResult(Weather::Type weatherType); float calculateHourFade (const std::string& moonName) const; float calculateAngleFade (const std::string& moonName, float angle) const; - void setWeather(const Ogre::String& weather, bool instant=false); + void setWeather(Weather::Type weatherType, bool instant=false); float mSunriseTime; float mSunsetTime; float mSunriseDuration; diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 16cba2ea8e..ee642f869b 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 unsigned int id) + void World::changeWeather(const std::string& region, const int id) { mWeatherManager->changeWeather(region, id); } diff --git a/apps/openmw/mwworld/worldimp.hpp b/apps/openmw/mwworld/worldimp.hpp index 12438efd42..35eba979f7 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, unsigned int id); + virtual void changeWeather (const std::string& region, int id); virtual int getCurrentWeather() const; From f01aa8f55e76b3a6ada1ab81c009db66e648f933 Mon Sep 17 00:00:00 2001 From: Miroslav Puda Date: Wed, 19 Jun 2013 04:57:36 +0200 Subject: [PATCH 03/16] Simpler statistical calculation of next weather; minus before parens. --- apps/openmw/mwworld/weather.cpp | 68 +++++++++++++++------------------ 1 file changed, 31 insertions(+), 37 deletions(-) diff --git a/apps/openmw/mwworld/weather.cpp b/apps/openmw/mwworld/weather.cpp index c09d706234..bff52dfe80 100644 --- a/apps/openmw/mwworld/weather.cpp +++ b/apps/openmw/mwworld/weather.cpp @@ -375,42 +375,36 @@ void WeatherManager::update(float duration) if (region != 0) { - float clear = region->mData.mClear/255.f; - float cloudy = region->mData.mCloudy/255.f; - float foggy = region->mData.mFoggy/255.f; - float overcast = region->mData.mOvercast/255.f; - float rain = region->mData.mRain/255.f; - float thunder = region->mData.mThunder/255.f; - float ash = region->mData.mAsh/255.f; - float blight = region->mData.mBlight/255.f; - float snow = region->mData.mA/255.f; - float blizzard = region->mData.mB/255.f; + /* + * All probabilities must add to 100 (responsibility of the user). + * If chances A and B has values 30 and 70 then by generating + * 100 numbers 1..100, 30% will be lesser or equal 30 and + * 70% will be greater than 30 (in theory). + */ + const int probability[] = { + region->mData.mClear, + region->mData.mCloudy, + region->mData.mFoggy, + region->mData.mOvercast, + region->mData.mRain, + region->mData.mThunder, + region->mData.mAsh, + region->mData.mBlight, + region->mData.mA, + region->mData.mB + }; // 10 elements - // re-scale to 100 percent - const float total = clear+cloudy+foggy+overcast+rain+thunder+ash+blight+snow+blizzard; - - float random = ((rand()%100)/100.f) * total; - - if (random >= snow+blight+ash+thunder+rain+overcast+foggy+cloudy+clear) - weatherType = Weather::Type_Blizzard; - else if (random >= blight+ash+thunder+rain+overcast+foggy+cloudy+clear) - weatherType = Weather::Type_Snow; - else if (random >= ash+thunder+rain+overcast+foggy+cloudy+clear) - weatherType = Weather::Type_Blight; - else if (random >= thunder+rain+overcast+foggy+cloudy+clear) - weatherType = Weather::Type_Ashstorm; - else if (random >= rain+overcast+foggy+cloudy+clear) - weatherType = Weather::Type_Thunderstorm; - else if (random >= overcast+foggy+cloudy+clear) - weatherType = Weather::Type_Rain; - else if (random >= foggy+cloudy+clear) - weatherType = Weather::Type_Overcast; - else if (random >= cloudy+clear) - weatherType = Weather::Type_Foggy; - else if (random >= clear) - weatherType = Weather::Type_Cloudy; - else - weatherType = Weather::Type_Clear; + int chance = (rand() % 100) + 1; // 1..100 + int sum = 0; + for (int i = 0; i < 10; ++i) + { + sum += probability[i]; + if (chance < sum) + { + weatherType = (Weather::Type)i; + break; + } + } } } @@ -461,8 +455,8 @@ void WeatherManager::update(float duration) int facing = (mHour > 13.f) ? 1 : -1; Vector3 final( - -(1 - height) * facing, - -(1 - height) * facing, + (height - 1) * facing, + (height - 1) * facing, height); mRendering->setSunDirection(final); From 8a45686e0a98cf254fbd8b780d3016d196c9db89 Mon Sep 17 00:00:00 2001 From: Miroslav Puda Date: Wed, 19 Jun 2013 06:50:36 +0200 Subject: [PATCH 04/16] WeatherResult added as member variable. --- apps/openmw/mwworld/weather.cpp | 138 +++++++++++++++----------------- apps/openmw/mwworld/weather.hpp | 5 +- 2 files changed, 69 insertions(+), 74 deletions(-) diff --git a/apps/openmw/mwworld/weather.cpp b/apps/openmw/mwworld/weather.cpp index bff52dfe80..8cec967add 100644 --- a/apps/openmw/mwworld/weather.cpp +++ b/apps/openmw/mwworld/weather.cpp @@ -224,32 +224,31 @@ void WeatherManager::setWeather(Weather::Type weatherType, bool instant) mFirstUpdate = false; } -WeatherResult WeatherManager::getResult(Weather::Type weatherType) +void WeatherManager::setResult(Weather::Type weatherType) { const Weather& current = mWeatherSettings[weatherType]; - WeatherResult result; - result.mCloudTexture = current.mCloudTexture; - result.mCloudBlendFactor = 0; - result.mCloudOpacity = current.mCloudsMaximumPercent; - result.mWindSpeed = current.mWindSpeed; - result.mCloudSpeed = current.mCloudSpeed; - result.mGlareView = current.mGlareView; - result.mAmbientLoopSoundID = current.mAmbientLoopSoundID; - result.mSunColor = current.mSunDiscSunsetColor; + mResult.mCloudTexture = current.mCloudTexture; + mResult.mCloudBlendFactor = 0; + mResult.mCloudOpacity = current.mCloudsMaximumPercent; + mResult.mWindSpeed = current.mWindSpeed; + mResult.mCloudSpeed = current.mCloudSpeed; + mResult.mGlareView = current.mGlareView; + mResult.mAmbientLoopSoundID = current.mAmbientLoopSoundID; + mResult.mSunColor = current.mSunDiscSunsetColor; - result.mNight = (mHour < mSunriseTime || mHour > mNightStart - 1); + mResult.mNight = (mHour < mSunriseTime || mHour > mNightStart - 1); - result.mFogDepth = result.mNight ? current.mLandFogNightDepth : current.mLandFogDayDepth; + mResult.mFogDepth = mResult.mNight ? current.mLandFogNightDepth : current.mLandFogDayDepth; // night if (mHour <= mNightEnd || mHour >= mNightStart + 1) { - result.mFogColor = current.mFogNightColor; - result.mAmbientColor = current.mAmbientNightColor; - result.mSunColor = current.mSunNightColor; - result.mSkyColor = current.mSkyNightColor; - result.mNightFade = 1.f; + mResult.mFogColor = current.mFogNightColor; + mResult.mAmbientColor = current.mAmbientNightColor; + mResult.mSunColor = current.mSunNightColor; + mResult.mSkyColor = current.mSkyNightColor; + mResult.mNightFade = 1.f; } // sunrise @@ -260,31 +259,31 @@ WeatherResult WeatherManager::getResult(Weather::Type weatherType) // fade in float advance = mSunriseTime - mHour; float factor = advance / 0.5f; - result.mFogColor = lerp(current.mFogSunriseColor, current.mFogNightColor, factor); - result.mAmbientColor = lerp(current.mAmbientSunriseColor, current.mAmbientNightColor, factor); - result.mSunColor = lerp(current.mSunSunriseColor, current.mSunNightColor, factor); - result.mSkyColor = lerp(current.mSkySunriseColor, current.mSkyNightColor, factor); - result.mNightFade = factor; + mResult.mFogColor = lerp(current.mFogSunriseColor, current.mFogNightColor, factor); + mResult.mAmbientColor = lerp(current.mAmbientSunriseColor, current.mAmbientNightColor, factor); + mResult.mSunColor = lerp(current.mSunSunriseColor, current.mSunNightColor, factor); + mResult.mSkyColor = lerp(current.mSkySunriseColor, current.mSkyNightColor, factor); + mResult.mNightFade = factor; } else //if (mHour >= 6) { // fade out float advance = mHour - mSunriseTime; float factor = advance / 3.f; - result.mFogColor = lerp(current.mFogSunriseColor, current.mFogDayColor, factor); - result.mAmbientColor = lerp(current.mAmbientSunriseColor, current.mAmbientDayColor, factor); - result.mSunColor = lerp(current.mSunSunriseColor, current.mSunDayColor, factor); - result.mSkyColor = lerp(current.mSkySunriseColor, current.mSkyDayColor, factor); + mResult.mFogColor = lerp(current.mFogSunriseColor, current.mFogDayColor, factor); + mResult.mAmbientColor = lerp(current.mAmbientSunriseColor, current.mAmbientDayColor, factor); + mResult.mSunColor = lerp(current.mSunSunriseColor, current.mSunDayColor, factor); + mResult.mSkyColor = lerp(current.mSkySunriseColor, current.mSkyDayColor, factor); } } // day else if (mHour >= mDayStart + 1 && mHour <= mDayEnd - 1) { - result.mFogColor = current.mFogDayColor; - result.mAmbientColor = current.mAmbientDayColor; - result.mSunColor = current.mSunDayColor; - result.mSkyColor = current.mSkyDayColor; + mResult.mFogColor = current.mFogDayColor; + mResult.mAmbientColor = current.mAmbientDayColor; + mResult.mSunColor = current.mSunDayColor; + mResult.mSkyColor = current.mSkyDayColor; } // sunset @@ -295,54 +294,51 @@ WeatherResult WeatherManager::getResult(Weather::Type weatherType) // fade in float advance = (mDayEnd + 1) - mHour; float factor = (advance / 2); - result.mFogColor = lerp(current.mFogSunsetColor, current.mFogDayColor, factor); - result.mAmbientColor = lerp(current.mAmbientSunsetColor, current.mAmbientDayColor, factor); - result.mSunColor = lerp(current.mSunSunsetColor, current.mSunDayColor, factor); - result.mSkyColor = lerp(current.mSkySunsetColor, current.mSkyDayColor, factor); + mResult.mFogColor = lerp(current.mFogSunsetColor, current.mFogDayColor, factor); + mResult.mAmbientColor = lerp(current.mAmbientSunsetColor, current.mAmbientDayColor, factor); + mResult.mSunColor = lerp(current.mSunSunsetColor, current.mSunDayColor, factor); + mResult.mSkyColor = lerp(current.mSkySunsetColor, current.mSkyDayColor, factor); } else //if (mHour >= 19) { // fade out float advance = mHour - (mDayEnd + 1); float factor = advance / 2.f; - result.mFogColor = lerp(current.mFogSunsetColor, current.mFogNightColor, factor); - result.mAmbientColor = lerp(current.mAmbientSunsetColor, current.mAmbientNightColor, factor); - result.mSunColor = lerp(current.mSunSunsetColor, current.mSunNightColor, factor); - result.mSkyColor = lerp(current.mSkySunsetColor, current.mSkyNightColor, factor); - result.mNightFade = factor; + mResult.mFogColor = lerp(current.mFogSunsetColor, current.mFogNightColor, factor); + mResult.mAmbientColor = lerp(current.mAmbientSunsetColor, current.mAmbientNightColor, factor); + mResult.mSunColor = lerp(current.mSunSunsetColor, current.mSunNightColor, factor); + mResult.mSkyColor = lerp(current.mSkySunsetColor, current.mSkyNightColor, factor); + mResult.mNightFade = factor; } } - - return result; } -WeatherResult WeatherManager::transition(float factor) +void WeatherManager::transition(float factor) { - const WeatherResult& current = getResult(mCurrentWeather); - const WeatherResult& other = getResult(mNextWeather); - WeatherResult result; + setResult(mCurrentWeather); + const WeatherResult current = mResult; + setResult(mNextWeather); + const WeatherResult other = mResult; - result.mCloudTexture = current.mCloudTexture; - result.mNextCloudTexture = other.mCloudTexture; - result.mCloudBlendFactor = factor; + mResult.mCloudTexture = current.mCloudTexture; + mResult.mNextCloudTexture = other.mCloudTexture; + mResult.mCloudBlendFactor = factor; - result.mCloudOpacity = lerp(current.mCloudOpacity, other.mCloudOpacity, factor); - result.mFogColor = lerp(current.mFogColor, other.mFogColor, factor); - result.mSunColor = lerp(current.mSunColor, other.mSunColor, factor); - result.mSkyColor = lerp(current.mSkyColor, other.mSkyColor, factor); + mResult.mCloudOpacity = lerp(current.mCloudOpacity, other.mCloudOpacity, factor); + mResult.mFogColor = lerp(current.mFogColor, other.mFogColor, factor); + mResult.mSunColor = lerp(current.mSunColor, other.mSunColor, factor); + mResult.mSkyColor = lerp(current.mSkyColor, other.mSkyColor, factor); - result.mAmbientColor = lerp(current.mAmbientColor, other.mAmbientColor, factor); - result.mSunDiscColor = lerp(current.mSunDiscColor, other.mSunDiscColor, factor); - result.mFogDepth = lerp(current.mFogDepth, other.mFogDepth, factor); - result.mWindSpeed = lerp(current.mWindSpeed, other.mWindSpeed, factor); - result.mCloudSpeed = lerp(current.mCloudSpeed, other.mCloudSpeed, factor); - result.mCloudOpacity = lerp(current.mCloudOpacity, other.mCloudOpacity, factor); - result.mGlareView = lerp(current.mGlareView, other.mGlareView, factor); - result.mNightFade = lerp(current.mNightFade, other.mNightFade, factor); + mResult.mAmbientColor = lerp(current.mAmbientColor, other.mAmbientColor, factor); + mResult.mSunDiscColor = lerp(current.mSunDiscColor, other.mSunDiscColor, factor); + mResult.mFogDepth = lerp(current.mFogDepth, other.mFogDepth, factor); + mResult.mWindSpeed = lerp(current.mWindSpeed, other.mWindSpeed, factor); + mResult.mCloudSpeed = lerp(current.mCloudSpeed, other.mCloudSpeed, factor); + mResult.mCloudOpacity = lerp(current.mCloudOpacity, other.mCloudOpacity, factor); + mResult.mGlareView = lerp(current.mGlareView, other.mGlareView, factor); + mResult.mNightFade = lerp(current.mNightFade, other.mNightFade, factor); - result.mNight = current.mNight; - - return result; + mResult.mNight = current.mNight; } void WeatherManager::update(float duration) @@ -411,8 +407,6 @@ void WeatherManager::update(float duration) setWeather(weatherType, false); } - WeatherResult result; - if (mNextWeather != Weather::Type_Unknown) { mRemainingTransitionTime -= timePassed; @@ -424,13 +418,13 @@ void WeatherManager::update(float duration) } if (mNextWeather != Weather::Type_Unknown) - result = transition(1 - (mRemainingTransitionTime / (mWeatherSettings[mCurrentWeather].mTransitionDelta * 24.f * 3600))); + transition(1 - (mRemainingTransitionTime / (mWeatherSettings[mCurrentWeather].mTransitionDelta * 24.f * 3600))); else - result = getResult(mCurrentWeather); + setResult(mCurrentWeather); - mWindSpeed = result.mWindSpeed; + mWindSpeed = mResult.mWindSpeed; - mRendering->configureFog(result.mFogDepth, result.mFogColor); + mRendering->configureFog(mResult.mFogDepth, mResult.mFogColor); // disable sun during night if (mHour >= mNightStart || mHour <= mSunriseTime) @@ -562,11 +556,11 @@ void WeatherManager::update(float duration) else mRendering->getSkyManager()->setLightningStrength(0.f); - mRendering->setAmbientColour(result.mAmbientColor); + mRendering->setAmbientColour(mResult.mAmbientColor); mRendering->sunEnable(false); - mRendering->setSunColour(result.mSunColor); + mRendering->setSunColour(mResult.mSunColor); - mRendering->getSkyManager()->setWeather(result); + mRendering->getSkyManager()->setWeather(mResult); } else { diff --git a/apps/openmw/mwworld/weather.hpp b/apps/openmw/mwworld/weather.hpp index 08e9c017d9..f51a365c6d 100644 --- a/apps/openmw/mwworld/weather.hpp +++ b/apps/openmw/mwworld/weather.hpp @@ -188,13 +188,14 @@ namespace MWWorld double mTimePassed; // time passed since last update - WeatherResult transition(const float factor); - WeatherResult getResult(Weather::Type weatherType); + void transition(const float factor); + void setResult(Weather::Type 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); + WeatherResult mResult; float mSunriseTime; float mSunsetTime; float mSunriseDuration; From bf31e5385c041342f5633ee9db66120dd14e97e6 Mon Sep 17 00:00:00 2001 From: Miroslav Puda Date: Wed, 19 Jun 2013 16:18:43 +0200 Subject: [PATCH 05/16] Removal of duplicit exterior checking and unneded string copiing. --- apps/openmw/mwworld/weather.cpp | 466 ++++++++++++++++---------------- apps/openmw/mwworld/weather.hpp | 8 + 2 files changed, 245 insertions(+), 229 deletions(-) diff --git a/apps/openmw/mwworld/weather.cpp b/apps/openmw/mwworld/weather.cpp index 8cec967add..89c5892a9f 100644 --- a/apps/openmw/mwworld/weather.cpp +++ b/apps/openmw/mwworld/weather.cpp @@ -348,243 +348,210 @@ void WeatherManager::update(float duration) mWeatherUpdateTime -= timePassed; - bool exterior = (MWBase::Environment::get().getWorld()->isCellExterior() || MWBase::Environment::get().getWorld()->isCellQuasiExterior()); - - if (exterior) - { - std::string regionstr = Misc::StringUtils::lowerCase(MWBase::Environment::get().getWorld()->getPlayer().getPlayer().getCell()->mCell->mRegion); - - if (mWeatherUpdateTime <= 0 || regionstr != mCurrentRegion) - { - mCurrentRegion = regionstr; - mWeatherUpdateTime = mHoursBetweenWeatherChanges * 3600; - - Weather::Type weatherType = Weather::Type_Clear; - - if (mRegionOverrides.find(regionstr) != mRegionOverrides.end()) - weatherType = mRegionOverrides[regionstr]; - else - { - // get weather probabilities for the current region - const ESM::Region *region = - MWBase::Environment::get().getWorld()->getStore().get().search (regionstr); - - if (region != 0) - { - /* - * All probabilities must add to 100 (responsibility of the user). - * If chances A and B has values 30 and 70 then by generating - * 100 numbers 1..100, 30% will be lesser or equal 30 and - * 70% will be greater than 30 (in theory). - */ - const int probability[] = { - region->mData.mClear, - region->mData.mCloudy, - region->mData.mFoggy, - region->mData.mOvercast, - region->mData.mRain, - region->mData.mThunder, - region->mData.mAsh, - region->mData.mBlight, - region->mData.mA, - region->mData.mB - }; // 10 elements - - int chance = (rand() % 100) + 1; // 1..100 - int sum = 0; - for (int i = 0; i < 10; ++i) - { - sum += probability[i]; - if (chance < sum) - { - weatherType = (Weather::Type)i; - break; - } - } - } - } - - setWeather(weatherType, false); - } - - if (mNextWeather != Weather::Type_Unknown) - { - mRemainingTransitionTime -= timePassed; - if (mRemainingTransitionTime < 0) - { - mCurrentWeather = mNextWeather; - mNextWeather = Weather::Type_Unknown; - } - } - - if (mNextWeather != Weather::Type_Unknown) - transition(1 - (mRemainingTransitionTime / (mWeatherSettings[mCurrentWeather].mTransitionDelta * 24.f * 3600))); - else - setResult(mCurrentWeather); - - mWindSpeed = mResult.mWindSpeed; - - mRendering->configureFog(mResult.mFogDepth, mResult.mFogColor); - - // disable sun during night - if (mHour >= mNightStart || mHour <= mSunriseTime) - mRendering->getSkyManager()->sunDisable(); - else - mRendering->getSkyManager()->sunEnable(); - - // sun angle - float height; - - //Day duration - float dayDuration = (mNightStart - 1) - mSunriseTime; - - // rise at 6, set at 20 - if (mHour >= mSunriseTime && mHour <= mNightStart) - height = 1 - std::abs(((mHour - dayDuration) / 7.f)); - else if (mHour > mNightStart) - height = (mHour - mNightStart) / 4.f; - else //if (mHour > 0 && mHour < 6) - height = 1 - (mHour / mSunriseTime); - - int facing = (mHour > 13.f) ? 1 : -1; - - Vector3 final( - (height - 1) * facing, - (height - 1) * facing, - height); - mRendering->setSunDirection(final); - - /* - * TODO: import separated fadeInStart/Finish, fadeOutStart/Finish - * for masser and secunda - */ - - float fadeOutFinish=mFallback->getFallbackFloat("Moons_Masser_Fade_Out_Finish"); - float fadeInStart=mFallback->getFallbackFloat("Moons_Masser_Fade_In_Start"); - - //moon calculations - float moonHeight; - if (mHour >= fadeInStart) - moonHeight = mHour - fadeInStart; - else if (mHour <= fadeOutFinish) - moonHeight = mHour + fadeOutFinish; - else - moonHeight = 0; - - moonHeight /= (24.f - (fadeInStart - fadeOutFinish)); - - if (moonHeight != 0) - { - int facing = (moonHeight <= 1) ? 1 : -1; - Vector3 masser( - (moonHeight - 1) * facing, - (1 - moonHeight) * facing, - moonHeight); - - Vector3 secunda( - (moonHeight - 1) * facing * 1.25, - (1 - moonHeight) * facing * 0.8, - moonHeight); - - mRendering->getSkyManager()->setMasserDirection(masser); - mRendering->getSkyManager()->setSecundaDirection(secunda); - mRendering->getSkyManager()->masserEnable(); - mRendering->getSkyManager()->secundaEnable(); - - float angle = (1-moonHeight) * 90.f * facing; - float masserHourFade = calculateHourFade("Masser"); - float secundaHourFade = calculateHourFade("Secunda"); - float masserAngleFade = calculateAngleFade("Masser", angle); - float secundaAngleFade = calculateAngleFade("Secunda", angle); - - masserAngleFade *= masserHourFade; - secundaAngleFade *= secundaHourFade; - - mRendering->getSkyManager()->setMasserFade(masserAngleFade); - mRendering->getSkyManager()->setSecundaFade(secundaAngleFade); - } - else - { - mRendering->getSkyManager()->masserDisable(); - mRendering->getSkyManager()->secundaDisable(); - } - - if (mCurrentWeather == Weather::Type_Thunderstorm && mNextWeather == Weather::Type_Unknown && exterior) - { - if (mThunderFlash > 0) - { - // play the sound after a delay - mThunderSoundDelay -= duration; - if (mThunderSoundDelay <= 0) - { - // pick a random sound - int sound = rand() % 4; - std::string soundname; - if (sound == 0) soundname = mThunderSoundID0; - else if (sound == 1) soundname = mThunderSoundID1; - else if (sound == 2) soundname = mThunderSoundID2; - else if (sound == 3) soundname = mThunderSoundID3; - MWBase::Environment::get().getSoundManager()->playSound(soundname, 1.0, 1.0); - mThunderSoundDelay = 1000; - } - - mThunderFlash -= duration; - if (mThunderFlash > 0) - mRendering->getSkyManager()->setLightningStrength( mThunderFlash / mThunderThreshold ); - else - { - srand(time(NULL)); - mThunderChanceNeeded = rand() % 100; - mThunderChance = 0; - mRendering->getSkyManager()->setLightningStrength( 0.f ); - } - } - else - { - // no thunder active - mThunderChance += duration*4; // chance increases by 4 percent every second - if (mThunderChance >= mThunderChanceNeeded) - { - mThunderFlash = mThunderThreshold; - - mRendering->getSkyManager()->setLightningStrength( mThunderFlash / mThunderThreshold ); - - mThunderSoundDelay = 0.25; - } - } - } - else - mRendering->getSkyManager()->setLightningStrength(0.f); - - mRendering->setAmbientColour(mResult.mAmbientColor); - mRendering->sunEnable(false); - mRendering->setSunColour(mResult.mSunColor); - - mRendering->getSkyManager()->setWeather(mResult); - } - else + const bool exterior = (MWBase::Environment::get().getWorld()->isCellExterior() || MWBase::Environment::get().getWorld()->isCellQuasiExterior()); + if (!exterior) { mRendering->sunDisable(false); mRendering->skyDisable(); mRendering->getSkyManager()->setLightningStrength(0.f); + stopSounds(true); + return; } - // play sounds - std::string ambientSnd = (mNextWeather == Weather::Type_Unknown ? mWeatherSettings[mCurrentWeather].mAmbientLoopSoundID : ""); - if (!exterior) ambientSnd = ""; - if (ambientSnd != "") + // Exterior + std::string regionstr = Misc::StringUtils::lowerCase(MWBase::Environment::get().getWorld()->getPlayer().getPlayer().getCell()->mCell->mRegion); + + if (mWeatherUpdateTime <= 0 || regionstr != mCurrentRegion) { + mCurrentRegion = regionstr; + mWeatherUpdateTime = mHoursBetweenWeatherChanges * 3600; + + Weather::Type weatherType = Weather::Type_Clear; + + if (mRegionOverrides.find(regionstr) != mRegionOverrides.end()) + weatherType = mRegionOverrides[regionstr]; + else + { + // get weather probabilities for the current region + const ESM::Region *region = + MWBase::Environment::get().getWorld()->getStore().get().search (regionstr); + + if (region != 0) + { + weatherType = nextWeather(region); + } + } + + setWeather(weatherType, false); + } + + if (mNextWeather != Weather::Type_Unknown) + { + mRemainingTransitionTime -= timePassed; + if (mRemainingTransitionTime < 0) + { + mCurrentWeather = mNextWeather; + mNextWeather = Weather::Type_Unknown; + } + } + + if (mNextWeather != Weather::Type_Unknown) + transition(1 - (mRemainingTransitionTime / (mWeatherSettings[mCurrentWeather].mTransitionDelta * 24.f * 3600))); + else + setResult(mCurrentWeather); + + mWindSpeed = mResult.mWindSpeed; + + mRendering->configureFog(mResult.mFogDepth, mResult.mFogColor); + + // disable sun during night + if (mHour >= mNightStart || mHour <= mSunriseTime) + mRendering->getSkyManager()->sunDisable(); + else + mRendering->getSkyManager()->sunEnable(); + + // sun angle + float height; + + //Day duration + float dayDuration = (mNightStart - 1) - mSunriseTime; + + // rise at 6, set at 20 + if (mHour >= mSunriseTime && mHour <= mNightStart) + height = 1 - std::abs(((mHour - dayDuration) / 7.f)); + else if (mHour > mNightStart) + height = (mHour - mNightStart) / 4.f; + else //if (mHour > 0 && mHour < 6) + height = 1 - (mHour / mSunriseTime); + + int facing = (mHour > 13.f) ? 1 : -1; + + Vector3 final( + (height - 1) * facing, + (height - 1) * facing, + height); + mRendering->setSunDirection(final); + + /* + * TODO: import separated fadeInStart/Finish, fadeOutStart/Finish + * for masser and secunda + */ + + float fadeOutFinish=mFallback->getFallbackFloat("Moons_Masser_Fade_Out_Finish"); + float fadeInStart=mFallback->getFallbackFloat("Moons_Masser_Fade_In_Start"); + + //moon calculations + float moonHeight; + if (mHour >= fadeInStart) + moonHeight = mHour - fadeInStart; + else if (mHour <= fadeOutFinish) + moonHeight = mHour + fadeOutFinish; + else + moonHeight = 0; + + moonHeight /= (24.f - (fadeInStart - fadeOutFinish)); + + if (moonHeight != 0) + { + int facing = (moonHeight <= 1) ? 1 : -1; + Vector3 masser( + (moonHeight - 1) * facing, + (1 - moonHeight) * facing, + moonHeight); + + Vector3 secunda( + (moonHeight - 1) * facing * 1.25, + (1 - moonHeight) * facing * 0.8, + moonHeight); + + mRendering->getSkyManager()->setMasserDirection(masser); + mRendering->getSkyManager()->setSecundaDirection(secunda); + mRendering->getSkyManager()->masserEnable(); + mRendering->getSkyManager()->secundaEnable(); + + float angle = (1-moonHeight) * 90.f * facing; + float masserHourFade = calculateHourFade("Masser"); + float secundaHourFade = calculateHourFade("Secunda"); + float masserAngleFade = calculateAngleFade("Masser", angle); + float secundaAngleFade = calculateAngleFade("Secunda", angle); + + masserAngleFade *= masserHourFade; + secundaAngleFade *= secundaHourFade; + + mRendering->getSkyManager()->setMasserFade(masserAngleFade); + mRendering->getSkyManager()->setSecundaFade(secundaAngleFade); + } + else + { + mRendering->getSkyManager()->masserDisable(); + mRendering->getSkyManager()->secundaDisable(); + } + + if (mCurrentWeather == Weather::Type_Thunderstorm && mNextWeather == Weather::Type_Unknown) + { + if (mThunderFlash > 0) + { + // play the sound after a delay + mThunderSoundDelay -= duration; + if (mThunderSoundDelay <= 0) + { + // pick a random sound + int sound = rand() % 4; + std::string* soundName; + if (sound == 0) soundName = &mThunderSoundID0; + else if (sound == 1) soundName = &mThunderSoundID1; + else if (sound == 2) soundName = &mThunderSoundID2; + else if (sound == 3) soundName = &mThunderSoundID3; + MWBase::Environment::get().getSoundManager()->playSound(*soundName, 1.0, 1.0); + mThunderSoundDelay = 1000; + } + + mThunderFlash -= duration; + if (mThunderFlash > 0) + mRendering->getSkyManager()->setLightningStrength( mThunderFlash / mThunderThreshold ); + else + { + srand(time(NULL)); + mThunderChanceNeeded = rand() % 100; + mThunderChance = 0; + mRendering->getSkyManager()->setLightningStrength( 0.f ); + } + } + else + { + // no thunder active + mThunderChance += duration*4; // chance increases by 4 percent every second + if (mThunderChance >= mThunderChanceNeeded) + { + mThunderFlash = mThunderThreshold; + + mRendering->getSkyManager()->setLightningStrength( mThunderFlash / mThunderThreshold ); + + mThunderSoundDelay = 0.25; + } + } + } + else + mRendering->getSkyManager()->setLightningStrength(0.f); + + mRendering->setAmbientColour(mResult.mAmbientColor); + mRendering->sunEnable(false); + mRendering->setSunColour(mResult.mSunColor); + + mRendering->getSkyManager()->setWeather(mResult); + + + // Play sounds + if (mNextWeather == Weather::Type_Unknown) + { + std::string ambientSnd = mWeatherSettings[mCurrentWeather].mAmbientLoopSoundID; if (std::find(mSoundsPlaying.begin(), mSoundsPlaying.end(), ambientSnd) == mSoundsPlaying.end()) { mSoundsPlaying.push_back(ambientSnd); MWBase::Environment::get().getSoundManager()->playSound(ambientSnd, 1.0, 1.0, MWBase::SoundManager::Play_Loop); } - } - std::string rainSnd = (mNextWeather == Weather::Type_Unknown ? mWeatherSettings[mCurrentWeather].mRainLoopSoundID : ""); - if (!exterior) rainSnd = ""; - if (rainSnd != "") - { + std::string rainSnd = mWeatherSettings[mCurrentWeather].mRainLoopSoundID; if (std::find(mSoundsPlaying.begin(), mSoundsPlaying.end(), rainSnd) == mSoundsPlaying.end()) { mSoundsPlaying.push_back(rainSnd); @@ -592,20 +559,61 @@ void WeatherManager::update(float duration) } } - // stop sounds - std::vector::iterator it=mSoundsPlaying.begin(); + stopSounds(false); +} + +void WeatherManager::stopSounds(bool stopAll) +{ + std::vector::iterator it = mSoundsPlaying.begin(); while (it!=mSoundsPlaying.end()) { - if ( *it != ambientSnd && *it != rainSnd) + if (stopAll || \ + !(*it == mWeatherSettings[mCurrentWeather].mAmbientLoopSoundID || \ + *it == mWeatherSettings[mCurrentWeather].mRainLoopSoundID)) { MWBase::Environment::get().getSoundManager()->stopSound(*it); it = mSoundsPlaying.erase(it); } - else - ++it; + + ++it; } } +Weather::Type WeatherManager::nextWeather(const ESM::Region* region) +{ + /* + * All probabilities must add to 100 (responsibility of the user). + * If chances A and B has values 30 and 70 then by generating + * 100 numbers 1..100, 30% will be lesser or equal 30 and + * 70% will be greater than 30 (in theory). + */ + const int probability[] = { + region->mData.mClear, + region->mData.mCloudy, + region->mData.mFoggy, + region->mData.mOvercast, + region->mData.mRain, + region->mData.mThunder, + region->mData.mAsh, + region->mData.mBlight, + region->mData.mA, + region->mData.mB + }; // 10 elements + + int chance = (rand() % 100) + 1; // 1..100 + int sum = 0; + int i = 0; + for (; i < 10; ++i) + { + sum += probability[i]; + if (chance < sum) + { + break; + } + } + return (Weather::Type) i; +} + void WeatherManager::setHour(const float hour) { mHour = hour; diff --git a/apps/openmw/mwworld/weather.hpp b/apps/openmw/mwworld/weather.hpp index f51a365c6d..fa305dc3c6 100644 --- a/apps/openmw/mwworld/weather.hpp +++ b/apps/openmw/mwworld/weather.hpp @@ -4,6 +4,11 @@ #include #include +namespace ESM +{ + struct Region; +} + namespace MWRender { class RenderingManager; @@ -146,6 +151,8 @@ namespace MWWorld */ void update(float duration); + void stopSounds(bool stopAll); + void setHour(const float hour); float getWindSpeed() const; @@ -195,6 +202,7 @@ namespace MWWorld float calculateAngleFade (const std::string& moonName, float angle) const; void setWeather(Weather::Type weatherType, bool instant=false); + Weather::Type nextWeather(const ESM::Region* region); WeatherResult mResult; float mSunriseTime; float mSunsetTime; From f9940413fd611a2976e82be6e1413e3e484c5921 Mon Sep 17 00:00:00 2001 From: Miroslav Puda Date: Wed, 19 Jun 2013 16:49:43 +0200 Subject: [PATCH 06/16] Static for nextWeather() --- apps/openmw/mwworld/weather.cpp | 2 +- apps/openmw/mwworld/weather.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/openmw/mwworld/weather.cpp b/apps/openmw/mwworld/weather.cpp index 89c5892a9f..2d63dd6d55 100644 --- a/apps/openmw/mwworld/weather.cpp +++ b/apps/openmw/mwworld/weather.cpp @@ -579,7 +579,7 @@ void WeatherManager::stopSounds(bool stopAll) } } -Weather::Type WeatherManager::nextWeather(const ESM::Region* region) +Weather::Type WeatherManager::nextWeather(const ESM::Region* region) const { /* * All probabilities must add to 100 (responsibility of the user). diff --git a/apps/openmw/mwworld/weather.hpp b/apps/openmw/mwworld/weather.hpp index fa305dc3c6..90b0a2dc5e 100644 --- a/apps/openmw/mwworld/weather.hpp +++ b/apps/openmw/mwworld/weather.hpp @@ -202,7 +202,7 @@ namespace MWWorld float calculateAngleFade (const std::string& moonName, float angle) const; void setWeather(Weather::Type weatherType, bool instant=false); - Weather::Type nextWeather(const ESM::Region* region); + Weather::Type nextWeather(const ESM::Region* region) const; WeatherResult mResult; float mSunriseTime; float mSunsetTime; From 26a6bdb27dfec80bb71b3069d2acfda281e38d61 Mon Sep 17 00:00:00 2001 From: Miroslav Puda Date: Wed, 19 Jun 2013 19:37:35 +0200 Subject: [PATCH 07/16] Correction of sigsegv. --- apps/openmw/mwworld/weather.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/apps/openmw/mwworld/weather.cpp b/apps/openmw/mwworld/weather.cpp index 2d63dd6d55..4a2a2f8039 100644 --- a/apps/openmw/mwworld/weather.cpp +++ b/apps/openmw/mwworld/weather.cpp @@ -118,9 +118,9 @@ float WeatherManager::calculateAngleFade (const std::string& moonName, float ang } WeatherManager::WeatherManager(MWRender::RenderingManager* rendering,MWWorld::Fallback* fallback) : - mHour(14), mCurrentWeather(Weather::Type_Clear), mFirstUpdate(true), mWeatherUpdateTime(0), - mThunderFlash(0), mThunderChance(0), mThunderChanceNeeded(50), mThunderSoundDelay(0), - mRemainingTransitionTime(0), mMonth(0), mDay(0), + 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) { //Globals @@ -545,14 +545,14 @@ void WeatherManager::update(float duration) if (mNextWeather == Weather::Type_Unknown) { std::string ambientSnd = mWeatherSettings[mCurrentWeather].mAmbientLoopSoundID; - if (std::find(mSoundsPlaying.begin(), mSoundsPlaying.end(), ambientSnd) == mSoundsPlaying.end()) + if (!ambientSnd.empty() && std::find(mSoundsPlaying.begin(), mSoundsPlaying.end(), ambientSnd) == mSoundsPlaying.end()) { mSoundsPlaying.push_back(ambientSnd); MWBase::Environment::get().getSoundManager()->playSound(ambientSnd, 1.0, 1.0, MWBase::SoundManager::Play_Loop); } std::string rainSnd = mWeatherSettings[mCurrentWeather].mRainLoopSoundID; - if (std::find(mSoundsPlaying.begin(), mSoundsPlaying.end(), rainSnd) == mSoundsPlaying.end()) + if (!rainSnd.empty() && std::find(mSoundsPlaying.begin(), mSoundsPlaying.end(), rainSnd) == mSoundsPlaying.end()) { mSoundsPlaying.push_back(rainSnd); MWBase::Environment::get().getSoundManager()->playSound(rainSnd, 1.0, 1.0, MWBase::SoundManager::Play_Loop); @@ -568,14 +568,14 @@ void WeatherManager::stopSounds(bool stopAll) while (it!=mSoundsPlaying.end()) { if (stopAll || \ - !(*it == mWeatherSettings[mCurrentWeather].mAmbientLoopSoundID || \ - *it == mWeatherSettings[mCurrentWeather].mRainLoopSoundID)) + !((*it == mWeatherSettings[mCurrentWeather].mAmbientLoopSoundID) || \ + (*it == mWeatherSettings[mCurrentWeather].mRainLoopSoundID))) { MWBase::Environment::get().getSoundManager()->stopSound(*it); it = mSoundsPlaying.erase(it); } - - ++it; + else + ++it; } } From 8da3494d74c783574c850c691d3efcc7bb732cef Mon Sep 17 00:00:00 2001 From: Miroslav Puda Date: Thu, 20 Jun 2013 21:44:28 +0200 Subject: [PATCH 08/16] 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; From 8b909ff838fd04d41edb48e10375ab847617b491 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Fri, 21 Jun 2013 08:58:52 +0200 Subject: [PATCH 09/16] killed a stray srand --- apps/openmw/mwworld/weather.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/apps/openmw/mwworld/weather.cpp b/apps/openmw/mwworld/weather.cpp index 68a46ec124..10dbdae9bb 100644 --- a/apps/openmw/mwworld/weather.cpp +++ b/apps/openmw/mwworld/weather.cpp @@ -1,8 +1,5 @@ #include "weather.hpp" -#include -#include - #include #include "../mwbase/environment.hpp" #include "../mwbase/world.hpp" @@ -210,7 +207,7 @@ void WeatherManager::setResult(const String& weatherType) mResult.mGlareView = current.mGlareView; mResult.mAmbientLoopSoundID = current.mAmbientLoopSoundID; mResult.mSunColor = current.mSunDiscSunsetColor; - + mResult.mNight = (mHour < mSunriseTime || mHour > mNightStart - 1); mResult.mFogDepth = mResult.mNight ? current.mLandFogNightDepth : current.mLandFogDayDepth; @@ -485,7 +482,6 @@ void WeatherManager::update(float duration) mRendering->getSkyManager()->setLightningStrength( mThunderFlash / mThunderThreshold ); else { - srand(time(NULL)); mThunderChanceNeeded = rand() % 100; mThunderChance = 0; mRendering->getSkyManager()->setLightningStrength( 0.f ); From efdcd9649c29ed2c554365b26a561158db06276a Mon Sep 17 00:00:00 2001 From: vorenon Date: Fri, 21 Jun 2013 20:19:35 +0200 Subject: [PATCH 10/16] Fading for Exterior->Interior cell transitions --- apps/openmw/mwworld/scene.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/apps/openmw/mwworld/scene.cpp b/apps/openmw/mwworld/scene.cpp index aec00a8c6d..22facdcaf0 100644 --- a/apps/openmw/mwworld/scene.cpp +++ b/apps/openmw/mwworld/scene.cpp @@ -2,6 +2,8 @@ #include +#include + #include "../mwbase/environment.hpp" #include "../mwbase/world.hpp" /// FIXME #include "../mwbase/soundmanager.hpp" @@ -353,7 +355,7 @@ namespace MWWorld void Scene::changeToInteriorCell (const std::string& cellName, const ESM::Position& position) { - + MWBase::Environment::get().getWorld ()->getFader ()->fadeOut(0.5); const MWWorld::Store &gmst = MWBase::Environment::get().getWorld()->getStore().get(); @@ -422,6 +424,7 @@ namespace MWWorld MWBase::Environment::get().getWorld()->adjustSky(); mCellChanged = true; + MWBase::Environment::get().getWorld ()->getFader ()->fadeIn(0.5); MWBase::Environment::get().getWindowManager ()->loadingDone (); } From 0e29286856653bce1e73a1e409cfd422146d7808 Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Sat, 22 Jun 2013 19:15:13 +0200 Subject: [PATCH 11/16] fix custom resolution maximum --- apps/launcher/graphicspage.cpp | 17 ++++++++++++++++- apps/launcher/graphicspage.hpp | 1 + 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/apps/launcher/graphicspage.cpp b/apps/launcher/graphicspage.cpp index 700ba3db9c..d9e10e764a 100644 --- a/apps/launcher/graphicspage.cpp +++ b/apps/launcher/graphicspage.cpp @@ -35,7 +35,7 @@ GraphicsPage::GraphicsPage(Files::ConfigurationManager &cfg, GraphicsSettings &g setupUi(this); // Set the maximum res we can set in windowed mode - QRect res = QApplication::desktop()->screenGeometry(); + QRect res = getMaximumResolution(); customWidthSpinBox->setMaximum(res.width()); customHeightSpinBox->setMaximum(res.height()); @@ -289,6 +289,21 @@ QStringList GraphicsPage::getAvailableResolutions(Ogre::RenderSystem *renderer) return result; } +QRect GraphicsPage::getMaximumResolution() +{ + QRect max, res; + int i, screens = QApplication::desktop()->screenCount(); + for (i = 0; i < screens; i++) + { + res = QApplication::desktop()->screenGeometry(i); + if (res.width() > max.width()) + max.setWidth(res.width()); + if (res.height() > max.height()) + max.setHeight(res.height()); + } + return max; +} + void GraphicsPage::rendererChanged(const QString &renderer) { mSelectedRenderSystem = mOgre->getRenderSystemByName(renderer.toStdString()); diff --git a/apps/launcher/graphicspage.hpp b/apps/launcher/graphicspage.hpp index 21039af430..37f56d2bb6 100644 --- a/apps/launcher/graphicspage.hpp +++ b/apps/launcher/graphicspage.hpp @@ -56,6 +56,7 @@ private: QStringList getAvailableOptions(const QString &key, Ogre::RenderSystem *renderer); QStringList getAvailableResolutions(Ogre::RenderSystem *renderer); + QRect getMaximumResolution(); void loadSettings(); From d61c12ccfce9a464f38b645ae91ec79cb0071b85 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Sat, 22 Jun 2013 20:32:11 +0200 Subject: [PATCH 12/16] minor cleanup --- apps/launcher/graphicspage.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/apps/launcher/graphicspage.cpp b/apps/launcher/graphicspage.cpp index d9e10e764a..157702af4e 100644 --- a/apps/launcher/graphicspage.cpp +++ b/apps/launcher/graphicspage.cpp @@ -291,11 +291,11 @@ QStringList GraphicsPage::getAvailableResolutions(Ogre::RenderSystem *renderer) QRect GraphicsPage::getMaximumResolution() { - QRect max, res; - int i, screens = QApplication::desktop()->screenCount(); - for (i = 0; i < screens; i++) + QRect max; + int screens = QApplication::desktop()->screenCount(); + for (int i = 0; i < screens; ++i) { - res = QApplication::desktop()->screenGeometry(i); + QRect res = QApplication::desktop()->screenGeometry(i); if (res.width() > max.width()) max.setWidth(res.width()); if (res.height() > max.height()) From a1fea97c3ba175307bea2a85c8a2ef3a017c6625 Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Sun, 23 Jun 2013 03:49:30 +0200 Subject: [PATCH 13/16] use SDL for resolution -> multimonitor support --- apps/launcher/CMakeLists.txt | 1 + apps/launcher/graphicspage.cpp | 132 ++++++++++++++++++++++++++++++--- apps/launcher/graphicspage.hpp | 20 ++++- apps/launcher/main.cpp | 5 ++ apps/launcher/maindialog.cpp | 4 +- files/ui/graphicspage.ui | 10 +++ 6 files changed, 158 insertions(+), 14 deletions(-) diff --git a/apps/launcher/CMakeLists.txt b/apps/launcher/CMakeLists.txt index 0c93474da9..bff26b63c8 100644 --- a/apps/launcher/CMakeLists.txt +++ b/apps/launcher/CMakeLists.txt @@ -90,6 +90,7 @@ target_link_libraries(omwlauncher ${Boost_LIBRARIES} ${OGRE_LIBRARIES} ${OGRE_STATIC_PLUGINS} + ${SDL2_LIBRARY} ${QT_LIBRARIES} components ) diff --git a/apps/launcher/graphicspage.cpp b/apps/launcher/graphicspage.cpp index d9e10e764a..49f7ef7c46 100644 --- a/apps/launcher/graphicspage.cpp +++ b/apps/launcher/graphicspage.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include @@ -42,6 +43,7 @@ GraphicsPage::GraphicsPage(Files::ConfigurationManager &cfg, GraphicsSettings &g connect(rendererComboBox, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(rendererChanged(const QString&))); connect(fullScreenCheckBox, SIGNAL(stateChanged(int)), this, SLOT(slotFullScreenChanged(int))); connect(standardRadioButton, SIGNAL(toggled(bool)), this, SLOT(slotStandardToggled(bool))); + connect(screenComboBox, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(screenChanged(const QString&))); } @@ -144,17 +146,84 @@ bool GraphicsPage::setupOgre() } antiAliasingComboBox->clear(); - resolutionComboBox->clear(); antiAliasingComboBox->addItems(getAvailableOptions(QString("FSAA"), mSelectedRenderSystem)); - resolutionComboBox->addItems(getAvailableResolutions(mSelectedRenderSystem)); - // Load the rest of the values - loadSettings(); return true; } -void GraphicsPage::loadSettings() +bool GraphicsPage::setupSDL() { + // FIXME: do setupSDLWordaround here instead. + // seems like Qt, SDL and Ogre don't like each other + // results in a segfault if SDL is initialized after Qt + + QStringList screens; + for (int i = 0; i < mScreenCount; i++) + { + screens.append(QString("Screen ") + QString::number(i + 1)); + } + screenComboBox->addItems(screens); + + return true; +} + +std::vector GraphicsPage::mVideoModes; +int GraphicsPage::mScreenCount; + +bool GraphicsPage::setupSDLWordaround() { + if (SDL_Init(SDL_INIT_VIDEO) != 0) + { + std::cout << "SDL_Init failed: " << SDL_GetError() << std::endl; + return false; + } + + SDL_DisplayMode mode; + int displayIndex, modeIndex, displays = SDL_GetNumVideoDisplays(); + mScreenCount = displays; + + if(displays < 0) + { + std::cout << "SDL_GetNumVideoDisplays failed: " << SDL_GetError() << std::endl; + SDL_Quit(); + return false; + } + + for (displayIndex = 0; displayIndex < displays; displayIndex++) + { + int modes = SDL_GetNumDisplayModes(displayIndex); + if(modes < 0) + { + std::cout << "SDL_GetNumDisplayModes failed: " << SDL_GetError() << std::endl; + SDL_Quit(); + return false; + } + for (modeIndex = 0; modeIndex < modes; modeIndex++) + { + if (SDL_GetDisplayMode(displayIndex, modeIndex, &mode) < 0) + { + std::cout << "SDL_GetDisplayMode failed: " << SDL_GetError() << std::endl; + SDL_Quit(); + return false; + } + VideoMode vmode; + vmode.w = mode.w; + vmode.h = mode.h; + vmode.screen = displayIndex; + mVideoModes.push_back(vmode); + } + } + + SDL_Quit(); + return true; +} + +bool GraphicsPage::loadSettings() +{ + if (!setupSDL()) + return false; + if (!setupOgre()) + return false; + if (mGraphicsSettings.value(QString("Video/vsync")) == QLatin1String("true")) vSyncCheckBox->setCheckState(Qt::Checked); @@ -168,6 +237,9 @@ void GraphicsPage::loadSettings() QString width = mGraphicsSettings.value(QString("Video/resolution x")); QString height = mGraphicsSettings.value(QString("Video/resolution y")); QString resolution = width + QString(" x ") + height; + QString screen = mGraphicsSettings.value(QString("Video/screen")); + + screenComboBox->setCurrentIndex(screenComboBox->findText(QString("Screen ") + screen)); int resIndex = resolutionComboBox->findText(resolution, Qt::MatchStartsWith); @@ -180,6 +252,8 @@ void GraphicsPage::loadSettings() customHeightSpinBox->setValue(height.toInt()); } + + return true; } void GraphicsPage::saveSettings() @@ -205,6 +279,11 @@ void GraphicsPage::saveSettings() mGraphicsSettings.setValue(QString("Video/resolution x"), QString::number(customWidthSpinBox->value())); mGraphicsSettings.setValue(QString("Video/resolution y"), QString::number(customHeightSpinBox->value())); } + + QRegExp screenRe(QString(".*(\\d+)")); + if(screenRe.exactMatch(screenComboBox->currentText())) { + mGraphicsSettings.setValue(QString("Video/screen"), screenRe.cap(1)); + } } QStringList GraphicsPage::getAvailableOptions(const QString &key, Ogre::RenderSystem *renderer) @@ -240,6 +319,33 @@ QStringList GraphicsPage::getAvailableOptions(const QString &key, Ogre::RenderSy return result; } +#if 1 +QStringList GraphicsPage::getAvailableResolutions(int screen) +{ + QStringList result; + for (std::vector::iterator it = mVideoModes.begin(); it != mVideoModes.end(); it++) + { + VideoMode mode = *it; + if(mode.screen != screen) + continue; + + QString aspect = getAspect(mode.w, mode.h); + QString resolution = QString::number(mode.w) + QString(" x ") + QString::number(mode.h); + + if (aspect == QLatin1String("16:9") || aspect == QLatin1String("16:10")) { + resolution.append(tr("\t(Wide ") + aspect + ")"); + + } else if (aspect == QLatin1String("4:3")) { + resolution.append(tr("\t(Standard 4:3)")); + } + + result.append(resolution); + } + return result; +} +#endif + +#if 0 QStringList GraphicsPage::getAvailableResolutions(Ogre::RenderSystem *renderer) { QString key("Video Mode"); @@ -288,14 +394,15 @@ QStringList GraphicsPage::getAvailableResolutions(Ogre::RenderSystem *renderer) return result; } +#endif QRect GraphicsPage::getMaximumResolution() { - QRect max, res; + QRect max; int i, screens = QApplication::desktop()->screenCount(); for (i = 0; i < screens; i++) { - res = QApplication::desktop()->screenGeometry(i); + QRect res = QApplication::desktop()->screenGeometry(i); if (res.width() > max.width()) max.setWidth(res.width()); if (res.height() > max.height()) @@ -309,10 +416,17 @@ void GraphicsPage::rendererChanged(const QString &renderer) mSelectedRenderSystem = mOgre->getRenderSystemByName(renderer.toStdString()); antiAliasingComboBox->clear(); - resolutionComboBox->clear(); antiAliasingComboBox->addItems(getAvailableOptions(QString("FSAA"), mSelectedRenderSystem)); - resolutionComboBox->addItems(getAvailableResolutions(mSelectedRenderSystem)); +} + +void GraphicsPage::screenChanged(const QString &screen) +{ + QRegExp screenRe(QString(".*(\\d+)")); + if(screenRe.exactMatch(screen)) { + resolutionComboBox->clear(); + resolutionComboBox->addItems(getAvailableResolutions(screenRe.cap(1).toInt() - 1)); + } } void GraphicsPage::slotFullScreenChanged(int state) diff --git a/apps/launcher/graphicspage.hpp b/apps/launcher/graphicspage.hpp index 37f56d2bb6..5ed4e5632e 100644 --- a/apps/launcher/graphicspage.hpp +++ b/apps/launcher/graphicspage.hpp @@ -18,6 +18,13 @@ #include "ui_graphicspage.h" +struct VideoMode +{ + int w; + int h; + int screen; +}; + class GraphicsSettings; namespace Files { struct ConfigurationManager; } @@ -30,10 +37,14 @@ public: GraphicsPage(Files::ConfigurationManager &cfg, GraphicsSettings &graphicsSettings, QWidget *parent = 0); void saveSettings(); - bool setupOgre(); + bool loadSettings(); + + // SDL workaround + static bool setupSDLWordaround(); public slots: void rendererChanged(const QString &renderer); + void screenChanged(const QString &screen); private slots: void slotFullScreenChanged(int state); @@ -55,11 +66,14 @@ private: GraphicsSettings &mGraphicsSettings; QStringList getAvailableOptions(const QString &key, Ogre::RenderSystem *renderer); - QStringList getAvailableResolutions(Ogre::RenderSystem *renderer); + QStringList getAvailableResolutions(int screen); QRect getMaximumResolution(); - void loadSettings(); + static std::vector mVideoModes; + static int mScreenCount; + bool setupOgre(); + bool setupSDL(); }; #endif diff --git a/apps/launcher/main.cpp b/apps/launcher/main.cpp index 09da1d615f..e444bb9f2b 100644 --- a/apps/launcher/main.cpp +++ b/apps/launcher/main.cpp @@ -3,9 +3,14 @@ #include #include "maindialog.hpp" +// SDL workaround +#include "graphicspage.hpp" int main(int argc, char *argv[]) { + // SDL woraround + GraphicsPage::setupSDLWordaround(); + QApplication app(argc, argv); // Now we make sure the current dir is set to application path diff --git a/apps/launcher/maindialog.cpp b/apps/launcher/maindialog.cpp index 10a3f015a3..b75d09c51c 100644 --- a/apps/launcher/maindialog.cpp +++ b/apps/launcher/maindialog.cpp @@ -292,8 +292,8 @@ bool MainDialog::setup() // Now create the pages as they need the settings createPages(); - // Call this so we can exit on Ogre errors before mainwindow is shown - if (!mGraphicsPage->setupOgre()) + // Call this so we can exit on Ogre/SDL errors before mainwindow is shown + if (!mGraphicsPage->loadSettings()) return false; loadSettings(); diff --git a/files/ui/graphicspage.ui b/files/ui/graphicspage.ui index 5c330cebd5..7e9fe00d9e 100644 --- a/files/ui/graphicspage.ui +++ b/files/ui/graphicspage.ui @@ -58,6 +58,13 @@ + + + Screen: + + + + Resolution: @@ -71,6 +78,9 @@ + + + From 14d074e3e720343a6aa4a6e4b19d945f800576ab Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Sun, 23 Jun 2013 04:21:32 +0200 Subject: [PATCH 14/16] select first screen if none is in the setting --- apps/launcher/graphicspage.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/apps/launcher/graphicspage.cpp b/apps/launcher/graphicspage.cpp index 49f7ef7c46..17a2efc0b0 100644 --- a/apps/launcher/graphicspage.cpp +++ b/apps/launcher/graphicspage.cpp @@ -239,7 +239,9 @@ bool GraphicsPage::loadSettings() QString resolution = width + QString(" x ") + height; QString screen = mGraphicsSettings.value(QString("Video/screen")); - screenComboBox->setCurrentIndex(screenComboBox->findText(QString("Screen ") + screen)); + int screenIndex = screenComboBox->findText(QString("Screen ") + screen); + if (screenIndex != -1) + screenComboBox->setCurrentIndex(screenIndex); int resIndex = resolutionComboBox->findText(resolution, Qt::MatchStartsWith); From bb39a85f164adff8298290ce44fab015317b685b Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Sun, 23 Jun 2013 04:43:34 +0200 Subject: [PATCH 15/16] remove double entries --- apps/launcher/graphicspage.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/apps/launcher/graphicspage.cpp b/apps/launcher/graphicspage.cpp index 17a2efc0b0..3066a410cc 100644 --- a/apps/launcher/graphicspage.cpp +++ b/apps/launcher/graphicspage.cpp @@ -205,6 +205,19 @@ bool GraphicsPage::setupSDLWordaround() { SDL_Quit(); return false; } + + bool isDouble = false; + for (std::vector::iterator it = mVideoModes.begin(); it != mVideoModes.end(); it++) + { + if ((*it).w == mode.w && (*it).h == mode.h && (*it).screen == displayIndex) + { + isDouble = true; + break; + } + } + if (isDouble) + continue; + VideoMode vmode; vmode.w = mode.w; vmode.h = mode.h; From 6f7a7b4714144ed3a4487469e53e7e1d4be8f2b7 Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Sun, 23 Jun 2013 05:02:19 +0200 Subject: [PATCH 16/16] remove old code --- apps/launcher/graphicspage.cpp | 53 ---------------------------------- 1 file changed, 53 deletions(-) diff --git a/apps/launcher/graphicspage.cpp b/apps/launcher/graphicspage.cpp index 3066a410cc..4594fb4eb8 100644 --- a/apps/launcher/graphicspage.cpp +++ b/apps/launcher/graphicspage.cpp @@ -334,7 +334,6 @@ QStringList GraphicsPage::getAvailableOptions(const QString &key, Ogre::RenderSy return result; } -#if 1 QStringList GraphicsPage::getAvailableResolutions(int screen) { QStringList result; @@ -358,58 +357,6 @@ QStringList GraphicsPage::getAvailableResolutions(int screen) } return result; } -#endif - -#if 0 -QStringList GraphicsPage::getAvailableResolutions(Ogre::RenderSystem *renderer) -{ - QString key("Video Mode"); - QStringList result; - - uint row = 0; - Ogre::ConfigOptionMap options = renderer->getConfigOptions(); - - for (Ogre::ConfigOptionMap::iterator i = options.begin (); i != options.end (); i++, row++) - { - if (key.toStdString() != i->first) - continue; - - Ogre::StringVector::iterator opt_it; - uint idx = 0; - - for (opt_it = i->second.possibleValues.begin (); - opt_it != i->second.possibleValues.end (); opt_it++, idx++) - { - QRegExp resolutionRe(QString("(\\d+) x (\\d+).*")); - QString resolution = QString::fromStdString(*opt_it).simplified(); - - if (resolutionRe.exactMatch(resolution)) { - - int width = resolutionRe.cap(1).toInt(); - int height = resolutionRe.cap(2).toInt(); - - QString aspect = getAspect(width, height); - QString cleanRes = resolutionRe.cap(1) + QString(" x ") + resolutionRe.cap(2); - - if (aspect == QLatin1String("16:9") || aspect == QLatin1String("16:10")) { - cleanRes.append(tr("\t(Wide ") + aspect + ")"); - - } else if (aspect == QLatin1String("4:3")) { - cleanRes.append(tr("\t(Standard 4:3)")); - } - // do not add duplicate resolutions - if (!result.contains(cleanRes)) - result.append(cleanRes); - } - } - } - - // Sort the resolutions in descending order - qSort(result.begin(), result.end(), naturalSortGreaterThanCI); - - return result; -} -#endif QRect GraphicsPage::getMaximumResolution() {