1 // globals.hxx -- Global state that needs to be shared among the sim modules
3 // Written by Curtis Olson, started July 2000.
5 // Copyright (C) 2000 Curtis L. Olson - http://www.flightgear.org/~curt
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
27 #include <simgear/compiler.h>
28 #include <simgear/props/props.hxx>
29 #include <simgear/structure/subsystem_mgr.hxx>
30 #include <simgear/misc/sg_path.hxx>
35 typedef std::vector<std::string> string_list;
37 // Forward declarations
39 // This file is included, directly or indirectly, almost everywhere in
40 // FlightGear, so if any of its dependencies changes, most of the sim
41 // has to be recompiled. Using these forward declarations helps us to
42 // avoid including a lot of header files (and thus, a lot of
43 // dependencies). Since Most of the methods simply set or return
44 // pointers, we don't need to know anything about the class details
71 * Bucket for subsystem pointers representing the sim's state.
79 // properties, destroy last
80 SGPropertyNode_ptr props;
81 SGPropertyNode_ptr initial_state;
87 SGSubsystemMgr *subsystem_mgr;
88 SGEventMgr *event_mgr;
90 // Number of milliseconds elapsed since the start of the program.
93 // Root of FlightGear data tree
96 // Users home directory for data
99 // Roots of FlightGear scenery tree
100 string_list fg_scenery;
110 // Material properties library
111 SGMaterialLib *matlib;
113 // Global autopilot "route"
114 FGRouteMgr *route_mgr;
119 // control input state
120 FGControls *controls;
125 SGCommandMgr *commands;
127 // list of serial port-like configurations
128 string_list *channel_options_list;
130 // A list of initial waypoints that are read from the command line
131 // and or flight-plan file during initialization
132 string_list *initial_waypoints;
134 // FlightGear scenery manager
140 FGFontCache *fontcache;
143 FGTACANList *channellist;
145 /// roots of Aircraft trees
146 string_list fg_aircraft_dirs;
148 bool haveUserSettings;
150 SGPropertyNode_ptr positionLon, positionLat, positionAlt;
151 SGPropertyNode_ptr orientHeading, orientPitch, orientRoll;
155 virtual ~FGGlobals();
157 virtual FGRenderer *get_renderer () const;
159 virtual SGSubsystemMgr *get_subsystem_mgr () const;
161 virtual SGSubsystem *get_subsystem (const char * name);
163 virtual void add_subsystem (const char * name,
164 SGSubsystem * subsystem,
165 SGSubsystemMgr::GroupType
166 type = SGSubsystemMgr::GENERAL,
167 double min_time_sec = 0);
169 virtual SGEventMgr *get_event_mgr () const;
171 virtual SGSoundMgr *get_soundmgr () const;
173 inline double get_sim_time_sec () const { return sim_time_sec; }
174 inline void inc_sim_time_sec (double dt) { sim_time_sec += dt; }
175 inline void set_sim_time_sec (double t) { sim_time_sec = t; }
177 inline const std::string &get_fg_root () const { return fg_root; }
178 void set_fg_root (const std::string &root);
180 inline const std::string &get_fg_home () const { return fg_home; }
181 void set_fg_home (const std::string &home);
183 inline const string_list &get_fg_scenery () const { return fg_scenery; }
184 void append_fg_scenery (const std::string &scenery);
186 const string_list& get_aircraft_paths() const { return fg_aircraft_dirs; }
187 void append_aircraft_path(const std::string& path);
188 void append_aircraft_paths(const std::string& path);
191 * Given a path to an aircraft-related resource file, resolve it
192 * against the appropriate root. This means looking at the location
193 * defined by /sim/aircraft-dir, and then aircraft_path in turn,
194 * finishing with fg_root/Aircraft.
196 * if the path could not be resolved, an empty path is returned.
198 SGPath resolve_aircraft_path(const std::string& branch) const;
201 * Same as above, but test for non 'Aircraft/' branch paths, and
202 * always resolve them against fg_root.
204 SGPath resolve_maybe_aircraft_path(const std::string& branch) const;
207 * Search in the following directories:
209 * 1. Root directory of current aircraft (defined by /sim/aircraft-dir)
210 * 2. All aircraft directories if branch starts with Aircraft/
211 * 3. fg_data directory
213 SGPath resolve_ressource_path(const std::string& branch) const;
215 inline const std::string &get_browser () const { return browser; }
216 void set_browser (const std::string &b) { browser = b; }
218 long int get_warp() const;
219 void set_warp( long int w );
221 long int get_warp_delta() const;
222 void set_warp_delta( long int d );
224 inline SGTime *get_time_params() const { return time_params; }
225 inline void set_time_params( SGTime *t ) { time_params = t; }
227 inline SGEphemeris *get_ephem() const { return ephem; }
228 inline void set_ephem( SGEphemeris *e ) { ephem = e; }
230 inline SGMaterialLib *get_matlib() const { return matlib; }
231 inline void set_matlib( SGMaterialLib *m ) { matlib = m; }
233 inline FGATISMgr *get_ATIS_mgr() const { return ATIS_mgr; }
234 inline void set_ATIS_mgr( FGATISMgr *a ) {ATIS_mgr = a; }
236 inline FGControls *get_controls() const { return controls; }
237 inline void set_controls( FGControls *c ) { controls = c; }
239 inline FGViewMgr *get_viewmgr() const { return viewmgr; }
240 inline void set_viewmgr( FGViewMgr *vm ) { viewmgr = vm; }
241 FGViewer *get_current_view() const;
243 inline SGPropertyNode *get_props () { return props; }
244 inline void set_props( SGPropertyNode *n ) { props = n; }
246 inline FGLocale* get_locale () { return locale; }
248 inline SGCommandMgr *get_commands () { return commands; }
250 SGGeod get_aircraft_position() const;
252 SGVec3d get_aircraft_positon_cart() const;
254 void get_aircraft_orientation(double& heading, double& pitch, double& roll);
256 inline string_list *get_channel_options_list () {
257 return channel_options_list;
259 inline void set_channel_options_list( string_list *l ) {
260 channel_options_list = l;
263 inline string_list *get_initial_waypoints () {
264 return initial_waypoints;
267 inline void set_initial_waypoints (string_list *list) {
268 initial_waypoints = list;
271 inline FGScenery * get_scenery () const { return scenery; }
272 inline void set_scenery ( FGScenery *s ) { scenery = s; }
274 inline FGTileMgr * get_tile_mgr () const { return tile_mgr; }
275 inline void set_tile_mgr ( FGTileMgr *t ) { tile_mgr = t; }
277 inline FGFontCache *get_fontcache() const { return fontcache; }
279 inline FGTACANList *get_channellist() const { return channellist; }
280 inline void set_channellist( FGTACANList *c ) { channellist = c; }
283 * Save the current state as the initial state.
285 void saveInitialState ();
289 * Restore the saved initial state, if any.
291 void restoreInitialState ();
294 * Load user settings from autosave.xml
296 void loadUserSettings(const SGPath& datapath);
299 * Save user settings in autosave.xml
301 void saveUserSettings();
305 extern FGGlobals *globals;
308 #endif // _GLOBALS_HXX