Adjust EnvironmentMgr API to avoid copying
getEnvironment encouraged pass-by-value of FGEnvironment which is heavy and mostly unnecessary.
This commit is contained in:
parent
a12a7e9bec
commit
5b537a176e
4 changed files with 13 additions and 21 deletions
|
@ -413,11 +413,13 @@ FGRunwayRef FGAirport::getActiveRunwayForUsage() const
|
||||||
double hdg = 270;
|
double hdg = 270;
|
||||||
|
|
||||||
if (envMgr) {
|
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) {
|
if (windSpeed > 0.0) {
|
||||||
hdg = stationWeather.get_wind_from_heading_deg();
|
hdg = stationWeather->get_wind_from_heading_deg();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -440,19 +440,13 @@ FGEnvironmentMgr::getEnvironment () const
|
||||||
return *_environment;
|
return *_environment;
|
||||||
}
|
}
|
||||||
|
|
||||||
FGEnvironment
|
const FGEnvironment* FGEnvironmentMgr::getAircraftEnvironment() const
|
||||||
FGEnvironmentMgr::getEnvironment (double lat, double lon, double alt) const
|
|
||||||
{
|
{
|
||||||
// Always returns the same environment
|
return _environment;
|
||||||
// for now; we'll make it interesting
|
|
||||||
// later.
|
|
||||||
FGEnvironment env = *_environment;
|
|
||||||
env.set_elevation_ft(alt);
|
|
||||||
return env;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FGEnvironment
|
FGEnvironment
|
||||||
FGEnvironmentMgr::getEnvironment(const SGGeod& aPos) const
|
FGEnvironmentMgr::getEnvironmentAtPosition(const SGGeod& aPos) const
|
||||||
{
|
{
|
||||||
// Always returns the same environment
|
// Always returns the same environment
|
||||||
// for now; we'll make it interesting
|
// for now; we'll make it interesting
|
||||||
|
|
|
@ -65,13 +65,9 @@ public:
|
||||||
*/
|
*/
|
||||||
virtual FGEnvironment getEnvironment () const;
|
virtual FGEnvironment getEnvironment () const;
|
||||||
|
|
||||||
/**
|
const FGEnvironment* getAircraftEnvironment() const;
|
||||||
* Get the environment information for another location.
|
|
||||||
*/
|
virtual FGEnvironment getEnvironmentAtPosition(const SGGeod& aPos) const;
|
||||||
virtual FGEnvironment getEnvironment (double lat, double lon,
|
|
||||||
double alt) const;
|
|
||||||
|
|
||||||
virtual FGEnvironment getEnvironment(const SGGeod& aPos) const;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend FGEnvironmentMgrMultiplayerListener;
|
friend FGEnvironmentMgrMultiplayerListener;
|
||||||
|
|
|
@ -137,9 +137,9 @@ AirspeedIndicator::computeMach()
|
||||||
return;
|
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...
|
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 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
|
double pt = _total_pressure_node->getDoubleValue() * SG_INHG_TO_PA; // total pressure in Pa
|
||||||
|
|
Loading…
Reference in a new issue