1
0
Fork 0

Adjust EnvironmentMgr API to avoid copying

getEnvironment encouraged pass-by-value of FGEnvironment
which is heavy and mostly unnecessary.
This commit is contained in:
James Turner 2021-12-25 12:31:13 +00:00
parent a12a7e9bec
commit 5b537a176e
4 changed files with 13 additions and 21 deletions

View file

@ -413,11 +413,13 @@ FGRunwayRef FGAirport::getActiveRunwayForUsage() const
double hdg = 270;
if (envMgr) {
FGEnvironment stationWeather(envMgr->getEnvironment(geod()));
// FIXME : this should use the weather at the airport, not the player's
// location.
const auto stationWeather = envMgr->getAircraftEnvironment();
double windSpeed = stationWeather.get_wind_speed_kt();
double windSpeed = stationWeather->get_wind_speed_kt();
if (windSpeed > 0.0) {
hdg = stationWeather.get_wind_from_heading_deg();
hdg = stationWeather->get_wind_from_heading_deg();
}
}

View file

@ -440,19 +440,13 @@ FGEnvironmentMgr::getEnvironment () const
return *_environment;
}
FGEnvironment
FGEnvironmentMgr::getEnvironment (double lat, double lon, double alt) const
const FGEnvironment* FGEnvironmentMgr::getAircraftEnvironment() const
{
// Always returns the same environment
// for now; we'll make it interesting
// later.
FGEnvironment env = *_environment;
env.set_elevation_ft(alt);
return env;
return _environment;
}
FGEnvironment
FGEnvironmentMgr::getEnvironment(const SGGeod& aPos) const
FGEnvironmentMgr::getEnvironmentAtPosition(const SGGeod& aPos) const
{
// Always returns the same environment
// for now; we'll make it interesting

View file

@ -65,13 +65,9 @@ public:
*/
virtual FGEnvironment getEnvironment () const;
/**
* Get the environment information for another location.
*/
virtual FGEnvironment getEnvironment (double lat, double lon,
double alt) const;
virtual FGEnvironment getEnvironment(const SGGeod& aPos) const;
const FGEnvironment* getAircraftEnvironment() const;
virtual FGEnvironment getEnvironmentAtPosition(const SGGeod& aPos) const;
private:
friend FGEnvironmentMgrMultiplayerListener;

View file

@ -137,9 +137,9 @@ AirspeedIndicator::computeMach()
return;
}
FGEnvironment env(_environmentManager->getEnvironment());
const auto env = _environmentManager->getAircraftEnvironment();
double oatK = env.get_temperature_degc() + SG_T0_K - 15.0 ; // OAT in Kelvin
double oatK = env->get_temperature_degc() + SG_T0_K - 15.0 ; // OAT in Kelvin
oatK = std::max( oatK , 0.001 ); // should never happen, but just in case someone flies into space...
double c = sqrt(SG_gamma * SG_R_m2_p_s2_p_K * oatK); // speed-of-sound in m/s at aircraft position
double pt = _total_pressure_node->getDoubleValue() * SG_INHG_TO_PA; // total pressure in Pa