]> git.mxchange.org Git - flightgear.git/blob - src/Environment/environment_mgr.cxx
de8481269d665d3b780e179083ad48e98f28d65e
[flightgear.git] / src / Environment / environment_mgr.cxx
1 // environment-mgr.cxx -- manager for natural environment information.
2 //
3 // Written by David Megginson, started February 2002.
4 //
5 // Copyright (C) 2002  David Megginson - david@megginson.com
6 //
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.
11 //
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.
16 //
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.
20 //
21 // $Id$
22
23 #include <simgear/debug/logstream.hxx>
24
25 #include <Main/fg_props.hxx>
26 #include <Aircraft/aircraft.hxx>
27
28 #include "environment.hxx"
29 #include "environment_ctrl.hxx"
30 #include "environment_mgr.hxx"
31
32
33 FGEnvironmentMgr::FGEnvironmentMgr ()
34   : _environment(new FGEnvironment),
35     _controller(new FGUserDefEnvironmentCtrl)
36 {
37 }
38
39 FGEnvironmentMgr::~FGEnvironmentMgr ()
40 {
41   delete _environment;
42   delete _controller;
43 }
44
45 void
46 FGEnvironmentMgr::init ()
47 {
48   SG_LOG( SG_GENERAL, SG_INFO, "Initializing environment subsystem");
49   _controller->setEnvironment(_environment);
50   _controller->init();
51 }
52
53 void
54 FGEnvironmentMgr::bind ()
55 {
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/temperature-degc", _environment,
64         &FGEnvironment::get_temperature_degc,
65         &FGEnvironment::set_temperature_degc);
66   fgSetArchivable("/environment/temperature-degc");
67   fgTie("/environment/pressure-sea-level-inhg", _environment,
68         &FGEnvironment::get_pressure_sea_level_inhg,
69         &FGEnvironment::set_pressure_sea_level_inhg);
70   fgSetArchivable("/environment/pressure-sea-level-inhg");
71   fgTie("/environment/pressure-inhg", _environment,
72         &FGEnvironment::get_pressure_inhg,
73         &FGEnvironment::set_pressure_inhg);
74   fgSetArchivable("/environment/pressure-inhg");
75   fgTie("/environment/density-sea-level-slugft3", _environment,
76         &FGEnvironment::get_density_sea_level_slugft3,
77         &FGEnvironment::set_density_sea_level_slugft3);
78   fgSetArchivable("/environment/density-sea-level-slugft3");
79   fgTie("/environment/density-slugft3", _environment,
80         &FGEnvironment::get_density_slugft3,
81         &FGEnvironment::set_density_slugft3);
82   fgSetArchivable("/environment/density-inhg");
83   fgTie("/environment/wind-from-heading-deg", _environment,
84         &FGEnvironment::get_wind_from_heading_deg,
85         &FGEnvironment::set_wind_from_heading_deg);
86   fgTie("/environment/wind-speed-kt", _environment,
87         &FGEnvironment::get_wind_speed_kt, &FGEnvironment::set_wind_speed_kt);
88   fgTie("/environment/wind-from-north-fps", _environment,
89         &FGEnvironment::get_wind_from_north_fps,
90         &FGEnvironment::set_wind_from_north_fps);
91   fgSetArchivable("/environment/wind-from-north-fps");
92   fgTie("/environment/wind-from-east-fps", _environment,
93         &FGEnvironment::get_wind_from_east_fps,
94         &FGEnvironment::set_wind_from_east_fps);
95   fgSetArchivable("/environment/wind-from-east-fps");
96   fgTie("/environment/wind-from-down-fps", _environment,
97         &FGEnvironment::get_wind_from_down_fps,
98         &FGEnvironment::set_wind_from_down_fps);
99   fgSetArchivable("/environment/wind-from-down-fps");
100 }
101
102 void
103 FGEnvironmentMgr::unbind ()
104 {
105   fgUntie("/environment/visibility-m");
106   fgUntie("/environment/wind-from-heading-deg");
107   fgUntie("/environment/wind-speed-kt");
108   fgUntie("/environment/wind-from-north-fps");
109   fgUntie("/environment/wind-from-east-fps");
110   fgUntie("/environment/wind-from-down-fps");
111 }
112
113 void
114 FGEnvironmentMgr::update (double dt)
115 {
116   _controller->update(dt);
117                                 // FIXME: the FDMs should update themselves
118   current_aircraft.fdm_state
119     ->set_Velocities_Local_Airmass(_environment->get_wind_from_north_fps(),
120                                    _environment->get_wind_from_east_fps(),
121                                    _environment->get_wind_from_down_fps());
122   _environment->set_elevation_ft(fgGetDouble("/position/altitude-ft"));
123 }
124
125 FGEnvironment
126 FGEnvironmentMgr::getEnvironment () const
127 {
128   return *_environment;
129 }
130
131 FGEnvironment
132 FGEnvironmentMgr::getEnvironment (double lat, double lon, double alt) const
133 {
134                                 // Always returns the same environment
135                                 // for now; we'll make it interesting
136                                 // later.
137   FGEnvironment env = *_environment;
138   env.set_elevation_ft(alt);
139   return env;
140 }
141
142 // end of environment-mgr.cxx