1 // environment-mgr.cxx -- manager for natural environment information.
3 // Written by David Megginson, started February 2002.
5 // Copyright (C) 2002 David Megginson - david@megginson.com
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include <simgear/debug/logstream.hxx>
25 #include <Main/fg_props.hxx>
26 #include <Aircraft/aircraft.hxx>
28 #include "environment.hxx"
29 #include "environment_ctrl.hxx"
30 #include "environment_mgr.hxx"
33 FGEnvironmentMgr::FGEnvironmentMgr ()
34 : _environment(new FGEnvironment),
35 _controller(new FGUserDefEnvironmentCtrl)
39 FGEnvironmentMgr::~FGEnvironmentMgr ()
46 FGEnvironmentMgr::init ()
48 SG_LOG( SG_GENERAL, SG_INFO, "Initializing environment subsystem");
49 _controller->setEnvironment(_environment);
54 FGEnvironmentMgr::bind ()
56 fgTie("/environment/visibility-m", _environment,
57 &FGEnvironment::get_visibility_m, &FGEnvironment::set_visibility_m);
58 fgSetArchivable("/environment/visibility-m");
59 fgTie("/environment/temperature-sea-level-degc", _environment,
60 &FGEnvironment::get_temperature_sea_level_degc,
61 &FGEnvironment::set_temperature_sea_level_degc);
62 fgSetArchivable("/environment/temperature-sea-level-degc");
63 fgTie("/environment/pressure-sea-level-inhg", _environment,
64 &FGEnvironment::get_pressure_sea_level_inhg,
65 &FGEnvironment::set_pressure_sea_level_inhg);
66 fgSetArchivable("/environment/pressure-sea-level-inhg");
67 fgTie("/environment/wind-from-heading-deg", _environment,
68 &FGEnvironment::get_wind_from_heading_deg,
69 &FGEnvironment::set_wind_from_heading_deg);
70 fgTie("/environment/wind-speed-kt", _environment,
71 &FGEnvironment::get_wind_speed_kt, &FGEnvironment::set_wind_speed_kt);
72 fgTie("/environment/wind-from-north-fps", _environment,
73 &FGEnvironment::get_wind_from_north_fps,
74 &FGEnvironment::set_wind_from_north_fps);
75 fgSetArchivable("/environment/wind-from-north-fps");
76 fgTie("/environment/wind-from-east-fps", _environment,
77 &FGEnvironment::get_wind_from_east_fps,
78 &FGEnvironment::set_wind_from_east_fps);
79 fgSetArchivable("/environment/wind-from-east-fps");
80 fgTie("/environment/wind-from-down-fps", _environment,
81 &FGEnvironment::get_wind_from_down_fps,
82 &FGEnvironment::set_wind_from_down_fps);
83 fgSetArchivable("/environment/wind-from-down-fps");
87 FGEnvironmentMgr::unbind ()
89 fgUntie("/environment/visibility-m");
90 fgUntie("/environment/wind-from-heading-deg");
91 fgUntie("/environment/wind-speed-kt");
92 fgUntie("/environment/wind-from-north-fps");
93 fgUntie("/environment/wind-from-east-fps");
94 fgUntie("/environment/wind-from-down-fps");
98 FGEnvironmentMgr::update (double dt)
100 _controller->update(dt);
101 // FIXME: the FDMs should update themselves
102 current_aircraft.fdm_state
103 ->set_Velocities_Local_Airmass(_environment->get_wind_from_north_fps(),
104 _environment->get_wind_from_east_fps(),
105 _environment->get_wind_from_down_fps());
108 const FGEnvironment *
109 FGEnvironmentMgr::getEnvironment () const
114 const FGEnvironment *
115 FGEnvironmentMgr::getEnvironment (double lat, double lon, double alt) const
117 // Always returns the same environment
118 // for now; we'll make it interesting
123 // end of environment-mgr.cxx