Weather manager: get rid of World dependency

0.6.3
Andrei Kortunov 7 years ago
parent a0a30cdbf5
commit fed3e56fc1

@ -9,7 +9,6 @@
#include <components/fallback/fallback.hpp> #include <components/fallback/fallback.hpp>
#include "../mwbase/environment.hpp" #include "../mwbase/environment.hpp"
#include "../mwbase/world.hpp"
#include "../mwbase/soundmanager.hpp" #include "../mwbase/soundmanager.hpp"
#include "../mwmechanics/actorutil.hpp" #include "../mwmechanics/actorutil.hpp"
@ -609,14 +608,11 @@ void WeatherManager::modRegion(const std::string& regionID, const std::vector<ch
} }
} }
void WeatherManager::playerTeleported() void WeatherManager::playerTeleported(const std::string& playerRegion, bool isExterior)
{ {
// If the player teleports to an outdoors cell in a new region (for instance, by travelling), the weather needs to // If the player teleports to an outdoors cell in a new region (for instance, by travelling), the weather needs to
// be changed immediately, and any transitions for the previous region discarded. // be changed immediately, and any transitions for the previous region discarded.
MWBase::World* world = MWBase::Environment::get().getWorld();
if(world->isCellExterior() || world->isCellQuasiExterior())
{ {
std::string playerRegion = Misc::StringUtils::lowerCase(world->getPlayerPtr().getCell()->getCell()->mRegion);
std::map<std::string, RegionWeather>::iterator it = mRegions.find(playerRegion); std::map<std::string, RegionWeather>::iterator it = mRegions.find(playerRegion);
if(it != mRegions.end() && playerRegion != mCurrentRegion) if(it != mRegions.end() && playerRegion != mCurrentRegion)
{ {
@ -626,11 +622,9 @@ void WeatherManager::playerTeleported()
} }
} }
void WeatherManager::update(float duration, bool paused) void WeatherManager::update(float duration, bool paused, const TimeStamp& time, bool isExterior)
{ {
MWWorld::ConstPtr player = MWMechanics::getPlayer(); MWWorld::ConstPtr player = MWMechanics::getPlayer();
MWBase::World& world = *MWBase::Environment::get().getWorld();
TimeStamp time = world.getTimeStamp();
if(!paused || mFastForward) if(!paused || mFastForward)
{ {
@ -648,8 +642,7 @@ void WeatherManager::update(float duration, bool paused)
updateWeatherTransitions(duration); updateWeatherTransitions(duration);
} }
const bool exterior = (world.isCellExterior() || world.isCellQuasiExterior()); if(!isExterior)
if(!exterior)
{ {
mRendering.setSkyEnabled(false); mRendering.setSkyEnabled(false);
stopSounds(); stopSounds();
@ -782,10 +775,9 @@ unsigned int WeatherManager::getWeatherID() const
return mCurrentWeather; return mCurrentWeather;
} }
bool WeatherManager::useTorches() const bool WeatherManager::useTorches(float hour) const
{ {
TimeStamp time = MWBase::Environment::get().getWorld()->getTimeStamp(); bool isDark = hour < mSunriseTime || hour > mTimeSettings.mNightStart - 1;
bool isDark = time.getHour() < mSunriseTime || time.getHour() > mTimeSettings.mNightStart - 1;
return isDark && !mPrecipitation; return isDark && !mPrecipitation;
} }

@ -218,14 +218,14 @@ namespace MWWorld
*/ */
void changeWeather(const std::string& regionID, const unsigned int weatherID); void changeWeather(const std::string& regionID, const unsigned int weatherID);
void modRegion(const std::string& regionID, const std::vector<char>& chances); void modRegion(const std::string& regionID, const std::vector<char>& chances);
void playerTeleported(); void playerTeleported(const std::string& playerRegion, bool isExterior);
/** /**
* Per-frame update * Per-frame update
* @param duration * @param duration
* @param paused * @param paused
*/ */
void update(float duration, bool paused = false); void update(float duration, bool paused, const TimeStamp& time, bool isExterior);
void stopSounds(); void stopSounds();
@ -240,7 +240,7 @@ namespace MWWorld
unsigned int getWeatherID() const; unsigned int getWeatherID() const;
bool useTorches() const; bool useTorches(float hour) const;
void write(ESM::ESMWriter& writer, Loading::Listener& progress); void write(ESM::ESMWriter& writer, Loading::Listener& progress);

@ -2851,9 +2851,13 @@ namespace MWWorld
{ {
// If we are in exterior, check the weather manager. // If we are in exterior, check the weather manager.
// In interiors there are no precipitations and sun, so check the ambient // In interiors there are no precipitations and sun, so check the ambient
// Looks like pseudo-exteriors considered as interiors in this case
MWWorld::CellStore* cell = mPlayer->getPlayer().getCell(); MWWorld::CellStore* cell = mPlayer->getPlayer().getCell();
if (cell->isExterior()) if (cell->isExterior())
return mWeatherManager->useTorches(); {
float hour = getTimeStamp().getHour();
return mWeatherManager->useTorches(hour);
}
else else
{ {
uint32_t ambient = cell->getCell()->mAmbi.mAmbient; uint32_t ambient = cell->getCell()->mAmbi.mAmbient;
@ -3014,13 +3018,17 @@ namespace MWWorld
void World::updateWeather(float duration, bool paused) void World::updateWeather(float duration, bool paused)
{ {
bool isExterior = isCellExterior() || isCellQuasiExterior();
if (mPlayer->wasTeleported()) if (mPlayer->wasTeleported())
{ {
mPlayer->setTeleported(false); mPlayer->setTeleported(false);
mWeatherManager->playerTeleported();
const std::string playerRegion = Misc::StringUtils::lowerCase(getPlayerPtr().getCell()->getCell()->mRegion);
mWeatherManager->playerTeleported(playerRegion, isExterior);
} }
mWeatherManager->update(duration, paused); const TimeStamp time = getTimeStamp();
mWeatherManager->update(duration, paused, time, isExterior);
} }
struct AddDetectedReferenceVisitor struct AddDetectedReferenceVisitor

Loading…
Cancel
Save