#include <simgear/structure/event_mgr.hxx>
#include <Main/main.hxx>
-#include <Main/renderer.hxx>
#include <Main/fg_props.hxx>
+#include <Viewer/renderer.hxx>
#include <FDM/flight.hxx>
#include "environment.hxx"
#include "precipitation_mgr.hxx"
#include "ridge_lift.hxx"
#include "terrainsampler.hxx"
-#include "Airports/simple.hxx"
+#include "Airports/airport.hxx"
#include "gravity.hxx"
+#include "magvarmanager.hxx"
class FG3DCloudsListener : public SGPropertyChangeListener {
public:
_environment(new FGEnvironment()),
fgClouds(new FGClouds()),
_cloudLayersDirty(true),
- _altitude_n(fgGetNode("/position/altitude-ft", true)),
- _longitude_n(fgGetNode( "/position/longitude-deg", true )),
- _latitude_n( fgGetNode( "/position/latitude-deg", true )),
_3dCloudsEnableListener(new FG3DCloudsListener(fgClouds) ),
_sky(globals->get_renderer()->getSky())
{
set_subsystem("precipitation", new FGPrecipitationMgr);
set_subsystem("terrainsampler", Environment::TerrainSampler::createInstance( fgGetNode("/environment/terrain", true ) ));
set_subsystem("ridgelift", new FGRidgeLift);
+
+ set_subsystem("magvar", new FGMagVarManager);
}
FGEnvironmentMgr::~FGEnvironmentMgr ()
{
- SGSubsystem * subsys;
-
- subsys = get_subsystem( "ridgelift" );
remove_subsystem( "ridgelift" );
- delete subsys;
-
- subsys = get_subsystem( "terrainsampler" );
remove_subsystem( "terrainsampler" );
- delete subsys;
-
- subsys = get_subsystem( "precipitation" );
remove_subsystem("precipitation");
- delete subsys;
-
- subsys = get_subsystem("realwx");
remove_subsystem("realwx");
- delete subsys;
-
- subsys = get_subsystem("controller");
remove_subsystem("controller");
- delete subsys;
-
+ remove_subsystem("magvar");
+
delete fgClouds;
delete _environment;
delete _3dCloudsEnableListener;
}
-void
-FGEnvironmentMgr::init ()
+SGSubsystem::InitStatus FGEnvironmentMgr::incrementalInit()
{
- SG_LOG( SG_ENVIRONMENT, SG_INFO, "Initializing environment subsystem");
- SGSubsystemGroup::init();
- fgClouds->Init();
-
- // FIXME: is this really part of the environment_mgr?
- // Initialize the longitude, latitude and altitude to the initial position
- // of the aircraft so that the atmospheric properties (pressure, temperature
- // and density) can be initialized accordingly.
- _altitude_n->setDoubleValue(fgGetDouble("/sim/presets/altitude-ft"));
- _longitude_n->setDoubleValue(fgGetDouble("/sim/presets/longitude-deg"));
- _latitude_n->setDoubleValue(fgGetDouble("/sim/presets/latitude-deg"));
- globals->get_event_mgr()->addTask("updateClosestAirport", this,
- &FGEnvironmentMgr::updateClosestAirport, 30 );
+ InitStatus r = SGSubsystemGroup::incrementalInit();
+ if (r == INIT_DONE) {
+ fgClouds->Init();
+ globals->get_event_mgr()->addTask("updateClosestAirport", this,
+ &FGEnvironmentMgr::updateClosestAirport, 30 );
+ }
+
+ return r;
}
void
FGEnvironmentMgr::shutdown()
{
globals->get_event_mgr()->removeTask("updateClosestAirport");
+ SGSubsystemGroup::shutdown();
}
void
&SGSky::get_3dCloudUseImpostors,
&SGSky::set_3dCloudUseImpostors);
- _tiedProperties.Tie("minimum-sky-visibility", _sky,
- &SGSky::get_minimum_sky_visibility,
- &SGSky::set_minimum_sky_visibility);
-
-// _tiedProperties.Tie("lightning-enable", &sgEnviro,
-// &SGEnviro::get_lightning_enable_state,
-// &SGEnviro::set_lightning_enable_state);
-
}
void
{
SGSubsystemGroup::update(dt);
- _environment->set_elevation_ft( _altitude_n->getDoubleValue() );
+ SGGeod aircraftPos(globals->get_aircraft_position());
+ _environment->set_elevation_ft( aircraftPos.getElevationFt() );
simgear::Particles::setWindFrom( _environment->get_wind_from_heading_deg(),
_environment->get_wind_speed_kt() );
fgSetDouble( "/environment/gravitational-acceleration-mps2",
- Environment::Gravity::instance()->getGravity(SGGeod::fromDegFt(
- _longitude_n->getDoubleValue(),
- _latitude_n->getDoubleValue(),
- _altitude_n->getDoubleValue()
- )));
+ Environment::Gravity::instance()->getGravity(aircraftPos));
}
void