Skip to content

Commit

Permalink
Move some code from core to landscapeMgr
Browse files Browse the repository at this point in the history
This is the code that automatically changes the landscape when the
location planet changes.  It's better to keep this in the landscape
manager and just react when the core signal a location change.
  • Loading branch information
guillaumechereau committed Dec 4, 2017
1 parent a02a901 commit 4ba8544
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 60 deletions.
55 changes: 0 additions & 55 deletions src/core/StelCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1163,38 +1163,6 @@ void StelCore::moveObserverToSelected()
loc = results.value(results.firstKey()); // ...and use it!

moveObserverTo(loc);

LandscapeMgr* landscapeMgr = GETSTELMODULE(LandscapeMgr);
Q_ASSERT(landscapeMgr);

bool landscapeSetsLocation=landscapeMgr->getFlagLandscapeSetsLocation();
landscapeMgr->setFlagLandscapeSetsLocation(false);
if (landscapeMgr->getFlagLandscapeAutoSelection())
{
// If we have a landscape for selected planet then set it, otherwise use zero horizon landscape
if (landscapeMgr->getAllLandscapeNames().indexOf(loc.planetName)>0)
landscapeMgr->setCurrentLandscapeName(loc.planetName);
else
landscapeMgr->setCurrentLandscapeID("zero");
}
landscapeMgr->setFlagLandscapeSetsLocation(landscapeSetsLocation);

if (pl->getEnglishName().contains("Observer", Qt::CaseInsensitive))
{
landscapeMgr->setFlagAtmosphere(false);
landscapeMgr->setFlagFog(false);
landscapeMgr->setFlagLandscape(false);
}
else
{
if (landscapeMgr->getFlagAtmosphereAutoEnable())
{
QSettings* conf = StelApp::getInstance().getSettings();
landscapeMgr->setFlagAtmosphere(pl->hasAtmosphere() & conf->value("landscape/flag_atmosphere", true).toBool());
landscapeMgr->setFlagFog(pl->hasAtmosphere() & conf->value("landscape/flag_fog", true).toBool());
}
landscapeMgr->setFlagLandscape(true);
}
}
}
else
Expand All @@ -1213,29 +1181,6 @@ void StelCore::moveObserverToSelected()

moveObserverTo(loc);
objmgr->unSelect(); // no use to keep it: Marker will flicker around the screen.

LandscapeMgr* landscapeMgr = GETSTELMODULE(LandscapeMgr);
Q_ASSERT(landscapeMgr);

bool landscapeSetsLocation=landscapeMgr->getFlagLandscapeSetsLocation();
landscapeMgr->setFlagLandscapeSetsLocation(false);
if (landscapeMgr->getFlagLandscapeAutoSelection())
{
// If we have a landscape for selected planet then set it, otherwise use zero horizon landscape
if (landscapeMgr->getAllLandscapeNames().indexOf(loc.planetName)>0)
landscapeMgr->setCurrentLandscapeName(loc.planetName);
else
landscapeMgr->setCurrentLandscapeID("zero");

if (landscapeMgr->getFlagAtmosphereAutoEnable())
{
QSettings* conf = StelApp::getInstance().getSettings();
landscapeMgr->setFlagAtmosphere(ni->getPlanet()->hasAtmosphere() & conf->value("landscape/flag_atmosphere", true).toBool());
landscapeMgr->setFlagFog(ni->getPlanet()->hasAtmosphere() & conf->value("landscape/flag_fog", true).toBool());
}
}
landscapeMgr->setFlagLandscapeSetsLocation(landscapeSetsLocation);
landscapeMgr->setFlagLandscape(true);
}
}
}
Expand Down
46 changes: 43 additions & 3 deletions src/core/modules/LandscapeMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,10 +412,12 @@ void LandscapeMgr::init()
setColorCardinalPoints(StelUtils::strToVec3f(conf->value("color/cardinal_color", defaultColor).toString()));

StelApp *app = &StelApp::getInstance();
currentPlanetName = app->getCore()->getCurrentLocation().planetName;
//Bortle scale is managed by SkyDrawer
StelSkyDrawer* drawer = app->getCore()->getSkyDrawer();
setAtmosphereBortleLightPollution(drawer->getBortleScaleIndex());
connect(app->getCore(), SIGNAL(locationChanged(StelLocation)), this, SLOT(updateLocationBasedPollution(StelLocation)));
connect(app->getCore(), SIGNAL(locationChanged(StelLocation)), this, SLOT(onLocationChanged(StelLocation)));
connect(app->getCore(), SIGNAL(targetLocationChanged(StelLocation)), this, SLOT(onTargetLocationChanged(StelLocation)));
connect(drawer, SIGNAL(bortleScaleIndexChanged(int)), this, SLOT(setAtmosphereBortleLightPollution(int)));
connect(app, SIGNAL(languageChanged()), this, SLOT(updateI18n()));

Expand Down Expand Up @@ -660,14 +662,14 @@ void LandscapeMgr::setFlagUseLightPollutionFromDatabase(const bool usage)
if (usage)
{
StelLocation loc = core->getCurrentLocation();
updateLocationBasedPollution(loc);
onLocationChanged(loc);
}

emit flagUseLightPollutionFromDatabaseChanged(usage);
}
}

void LandscapeMgr::updateLocationBasedPollution(StelLocation loc)
void LandscapeMgr::onLocationChanged(StelLocation loc)
{
if(flagLightPollutionFromDatabase)
{
Expand All @@ -683,6 +685,44 @@ void LandscapeMgr::updateLocationBasedPollution(StelLocation loc)
}
}

void LandscapeMgr::onTargetLocationChanged(StelLocation loc)
{
if (loc.planetName != currentPlanetName)
{
currentPlanetName = loc.planetName;
if (flagLandscapeAutoSelection)
{
// If we have a landscape for selected planet then set it, otherwise use zero horizon landscape
bool landscapeSetsLocation = getFlagLandscapeSetsLocation();
setFlagLandscapeSetsLocation(false);
if (getAllLandscapeNames().indexOf(loc.planetName)>0)
setCurrentLandscapeName(loc.planetName);
else
setCurrentLandscapeID("zero");
setFlagLandscapeSetsLocation(landscapeSetsLocation);
}

if (loc.planetName.contains("Observer", Qt::CaseInsensitive))
{
setFlagAtmosphere(false);
setFlagFog(false);
setFlagLandscape(false);
}
else
{
SolarSystem* ssystem = (SolarSystem*)StelApp::getInstance().getModuleMgr().getModule("SolarSystem");
PlanetP pl = ssystem->searchByEnglishName(loc.planetName);
if (pl && flagAtmosphereAutoEnabling)
{
QSettings* conf = StelApp::getInstance().getSettings();
setFlagAtmosphere(pl->hasAtmosphere() & conf->value("landscape/flag_atmosphere", true).toBool());
setFlagFog(pl->hasAtmosphere() & conf->value("landscape/flag_fog", true).toBool());
}
setFlagLandscape(true);
}
}
}

void LandscapeMgr::setFlagFog(const bool displayed)
{
if (landscape->getFlagShowFog() != displayed) {
Expand Down
8 changes: 6 additions & 2 deletions src/core/modules/LandscapeMgr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -505,8 +505,9 @@ private slots:
//! This should not be called from script code, use StelMainScriptAPI::setBortleScaleIndex if you want to change the light pollution.
void setAtmosphereBortleLightPollution(const int bIndex);

//! Reacts to StelCore::locationChanged, and changes the light pollution if the flagLightPollutionFromDatabase is true
void updateLocationBasedPollution(StelLocation loc);
//! Reacts to StelCore::locationChanged.
void onLocationChanged(StelLocation loc);
void onTargetLocationChanged(StelLocation loc);

//! Translate labels to new language settings.
void updateI18n();
Expand Down Expand Up @@ -568,6 +569,9 @@ private slots:
//! at system start (e.g. in the startup.ssc script) and then retrieved while script is running.
//! The key is just the LandscapeID.
QCache<QString,Landscape> landscapeCache;

//! Core current planet name, used to react to planet change.
QString currentPlanetName;
};

#endif // _LANDSCAPEMGR_HPP_

0 comments on commit 4ba8544

Please sign in to comment.