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
59 class FGAircraftModel;
61 class FGFlightPlanDispatcher;
77 * Bucket for subsystem pointers representing the sim's state.
85 // properties, destroy last
86 SGPropertyNode_ptr props;
87 SGPropertyNode_ptr initial_state;
93 SGSubsystemMgr *subsystem_mgr;
94 SGEventMgr *event_mgr;
96 // Number of milliseconds elapsed since the start of the program.
99 // Root of FlightGear data tree
102 // Roots of FlightGear scenery tree
103 string_list fg_scenery;
113 // Magnetic Variation
116 // Material properties library
117 SGMaterialLib *matlib;
119 // Global autopilot "route"
120 FGRouteMgr *route_mgr;
123 SGSharedPtr<FGPanel> current_panel;
128 // control input state
129 FGControls *controls;
134 SGCommandMgr *commands;
136 //FGFlightPlanDispatcher *fpDispatcher;
138 FGAircraftModel *acmodel;
140 FGModelMgr * model_mgr;
142 // list of serial port-like configurations
143 string_list *channel_options_list;
145 // A list of initial waypoints that are read from the command line
146 // and or flight-plan file during initialization
147 string_list *initial_waypoints;
149 // FlightGear scenery manager
155 FGFontCache *fontcache;
162 FGNavList *tacanlist;
163 FGNavList *carrierlist;
164 FGTACANList *channellist;
166 /// roots of Aircraft trees
167 string_list fg_aircraft_dirs;
169 bool haveUserSettings;
174 virtual ~FGGlobals();
176 virtual FGRenderer *get_renderer () const;
178 virtual SGSubsystemMgr *get_subsystem_mgr () const;
180 virtual SGSubsystem *get_subsystem (const char * name);
182 virtual void add_subsystem (const char * name,
183 SGSubsystem * subsystem,
184 SGSubsystemMgr::GroupType
185 type = SGSubsystemMgr::GENERAL,
186 double min_time_sec = 0);
188 virtual SGEventMgr *get_event_mgr () const;
190 virtual SGSoundMgr *get_soundmgr () const;
192 inline double get_sim_time_sec () const { return sim_time_sec; }
193 inline void inc_sim_time_sec (double dt) { sim_time_sec += dt; }
194 inline void set_sim_time_sec (double t) { sim_time_sec = t; }
196 inline const std::string &get_fg_root () const { return fg_root; }
197 void set_fg_root (const std::string &root);
199 inline const string_list &get_fg_scenery () const { return fg_scenery; }
200 void append_fg_scenery (const std::string &scenery);
202 const string_list& get_aircraft_paths() const { return fg_aircraft_dirs; }
203 void append_aircraft_path(const std::string& path);
204 void append_aircraft_paths(const std::string& path);
207 * Given a path to an aircraft-related resource file, resolve it
208 * against the appropriate root. This means looking at the location
209 * defined by /sim/aircraft-dir, and then aircraft_path in turn,
210 * finishing with fg_root/Aircraft.
212 * if the path could not be resolved, an empty path is returned.
214 SGPath resolve_aircraft_path(const std::string& branch) const;
217 * Same as above, but test for non 'Aircraft/' branch paths, and
218 * always resolve them against fg_root.
220 SGPath resolve_maybe_aircraft_path(const std::string& branch) const;
222 inline const std::string &get_browser () const { return browser; }
223 void set_browser (const std::string &b) { browser = b; }
225 long int get_warp() const;
226 void set_warp( long int w );
228 long int get_warp_delta() const;
229 void set_warp_delta( long int d );
231 inline SGTime *get_time_params() const { return time_params; }
232 inline void set_time_params( SGTime *t ) { time_params = t; }
234 inline SGEphemeris *get_ephem() const { return ephem; }
235 inline void set_ephem( SGEphemeris *e ) { ephem = e; }
237 inline SGMagVar *get_mag() const { return mag; }
238 inline void set_mag( SGMagVar *m ) { mag = m; }
240 inline SGMaterialLib *get_matlib() const { return matlib; }
241 inline void set_matlib( SGMaterialLib *m ) { matlib = m; }
243 inline FGATCMgr *get_ATC_mgr() const { return ATC_mgr; }
244 inline void set_ATC_mgr( FGATCMgr *a ) {ATC_mgr = a; }
246 inline FGPanel *get_current_panel() const { return current_panel; }
247 void set_current_panel( FGPanel *cp );
249 inline FGControls *get_controls() const { return controls; }
250 inline void set_controls( FGControls *c ) { controls = c; }
252 inline FGViewMgr *get_viewmgr() const { return viewmgr; }
253 inline void set_viewmgr( FGViewMgr *vm ) { viewmgr = vm; }
254 FGViewer *get_current_view() const;
256 inline SGPropertyNode *get_props () { return props; }
257 inline void set_props( SGPropertyNode *n ) { props = n; }
259 inline FGLocale* get_locale () { return locale; }
261 inline SGCommandMgr *get_commands () { return commands; }
263 inline FGAircraftModel *get_aircraft_model () { return acmodel; }
265 inline void set_aircraft_model (FGAircraftModel * model)
270 const SGGeod & get_aircraft_position() const;
272 SGVec3d get_aircraft_positon_cart() const;
274 inline FGModelMgr *get_model_mgr () { return model_mgr; }
276 inline void set_model_mgr (FGModelMgr * mgr)
281 inline string_list *get_channel_options_list () {
282 return channel_options_list;
284 inline void set_channel_options_list( string_list *l ) {
285 channel_options_list = l;
288 inline string_list *get_initial_waypoints () {
289 return initial_waypoints;
292 inline void set_initial_waypoints (string_list *list) {
293 initial_waypoints = list;
296 inline FGScenery * get_scenery () const { return scenery; }
297 inline void set_scenery ( FGScenery *s ) { scenery = s; }
299 inline FGTileMgr * get_tile_mgr () const { return tile_mgr; }
300 inline void set_tile_mgr ( FGTileMgr *t ) { tile_mgr = t; }
302 inline FGFontCache *get_fontcache() const { return fontcache; }
304 inline FGNavList *get_navlist() const { return navlist; }
305 inline void set_navlist( FGNavList *n ) { navlist = n; }
306 inline FGNavList *get_loclist() const { return loclist; }
307 inline void set_loclist( FGNavList *n ) { loclist = n; }
308 inline FGNavList *get_gslist() const { return gslist; }
309 inline void set_gslist( FGNavList *n ) { gslist = n; }
310 inline FGNavList *get_dmelist() const { return dmelist; }
311 inline void set_dmelist( FGNavList *n ) { dmelist = n; }
312 inline FGNavList *get_tacanlist() const { return tacanlist; }
313 inline void set_tacanlist( FGNavList *n ) { tacanlist = n; }
314 inline FGNavList *get_carrierlist() const { return carrierlist; }
315 inline void set_carrierlist( FGNavList *n ) { carrierlist = n; }
316 inline FGTACANList *get_channellist() const { return channellist; }
317 inline void set_channellist( FGTACANList *c ) { channellist = c; }
320 * Save the current state as the initial state.
322 void saveInitialState ();
326 * Restore the saved initial state, if any.
328 void restoreInitialState ();
331 * Load user settings from autosave.xml
333 void loadUserSettings(const SGPath& datapath);
336 * Save user settings in autosave.xml
338 void saveUserSettings();
342 extern FGGlobals *globals;
345 #endif // _GLOBALS_HXX