]> git.mxchange.org Git - flightgear.git/blob - src/Main/globals.hxx
Support a --no-default-config option.
[flightgear.git] / src / Main / globals.hxx
1 // globals.hxx -- Global state that needs to be shared among the sim modules
2 //
3 // Written by Curtis Olson, started July 2000.
4 //
5 // Copyright (C) 2000  Curtis L. Olson - http://www.flightgear.org/~curt
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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20 //
21 // $Id$
22
23
24 #ifndef _GLOBALS_HXX
25 #define _GLOBALS_HXX
26
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>
31
32 #include <vector>
33 #include <string>
34
35 typedef std::vector<std::string> string_list;
36
37 // Forward declarations
38
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
45 // anyway.
46
47 class SGEphemeris;
48 class SGCommandMgr;
49 class SGMaterialLib;
50 class SGPropertyNode;
51 class SGTime;
52 class SGEventMgr;
53 class SGSubsystemMgr;
54 class SGSubsystem;
55 class SGSoundMgr;
56
57 class FGATISMgr;
58 class FGControls;
59 class FGTACANList;
60 class FGLocale;
61 class FGRouteMgr;
62 class FGScenery;
63 class FGTileMgr;
64 class FGViewMgr;
65 class FGViewer;
66 class FGRenderer;
67 class FGFontCache;
68
69
70 /**
71  * Bucket for subsystem pointers representing the sim's state.
72  */
73
74 class FGGlobals
75 {
76
77 private:
78
79     // properties, destroy last
80     SGPropertyNode_ptr props;
81     SGPropertyNode_ptr initial_state;
82
83     // localization
84     FGLocale* locale;
85
86     FGRenderer *renderer;
87     SGSubsystemMgr *subsystem_mgr;
88     SGEventMgr *event_mgr;
89
90     // Number of milliseconds elapsed since the start of the program.
91     double sim_time_sec;
92
93     // Root of FlightGear data tree
94     std::string fg_root;
95
96     // Users home directory for data
97     std::string fg_home;
98
99     // Roots of FlightGear scenery tree
100     string_list fg_scenery;
101
102     std::string browser;
103
104     // Time structure
105     SGTime *time_params;
106
107     // Sky structures
108     SGEphemeris *ephem;
109
110     // Material properties library
111     SGMaterialLib *matlib;
112
113     // Global autopilot "route"
114     FGRouteMgr *route_mgr;
115
116     // ATC manager
117     FGATISMgr *ATIS_mgr;
118
119     // control input state
120     FGControls *controls;
121
122     // viewer manager
123     FGViewMgr *viewmgr;
124
125     SGCommandMgr *commands;
126
127     // list of serial port-like configurations
128     string_list *channel_options_list;
129
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;
133
134     // FlightGear scenery manager
135     FGScenery *scenery;
136
137     // Tile manager
138     FGTileMgr *tile_mgr;
139
140     FGFontCache *fontcache;
141
142     // Navigational Aids
143     FGTACANList *channellist;
144
145     /// roots of Aircraft trees
146     string_list fg_aircraft_dirs;
147
148     bool haveUserSettings;
149
150     SGPropertyNode_ptr positionLon, positionLat, positionAlt;
151     SGPropertyNode_ptr viewLon, viewLat, viewAlt;
152     SGPropertyNode_ptr orientHeading, orientPitch, orientRoll;
153 public:
154
155     FGGlobals();
156     virtual ~FGGlobals();
157
158     virtual FGRenderer *get_renderer () const;
159
160     virtual SGSubsystemMgr *get_subsystem_mgr () const;
161
162     virtual SGSubsystem *get_subsystem (const char * name);
163
164     virtual void add_subsystem (const char * name,
165                                 SGSubsystem * subsystem,
166                                 SGSubsystemMgr::GroupType
167                                 type = SGSubsystemMgr::GENERAL,
168                                 double min_time_sec = 0);
169
170     virtual SGEventMgr *get_event_mgr () const;
171
172     virtual SGSoundMgr *get_soundmgr () const;
173
174     inline double get_sim_time_sec () const { return sim_time_sec; }
175     inline void inc_sim_time_sec (double dt) { sim_time_sec += dt; }
176     inline void set_sim_time_sec (double t) { sim_time_sec = t; }
177
178     inline const std::string &get_fg_root () const { return fg_root; }
179     void set_fg_root (const std::string &root);
180
181     inline const std::string &get_fg_home () const { return fg_home; }
182     void set_fg_home (const std::string &home);
183
184     inline const string_list &get_fg_scenery () const { return fg_scenery; }
185     void append_fg_scenery (const std::string &scenery);
186
187     const string_list& get_aircraft_paths() const { return fg_aircraft_dirs; }
188     void append_aircraft_path(const std::string& path);
189     void append_aircraft_paths(const std::string& path);
190     
191     /**
192      * Given a path to an aircraft-related resource file, resolve it
193      * against the appropriate root. This means looking at the location
194      * defined by /sim/aircraft-dir, and then aircraft_path in turn,
195      * finishing with fg_root/Aircraft.
196      *
197      * if the path could not be resolved, an empty path is returned.
198      */
199     SGPath resolve_aircraft_path(const std::string& branch) const;
200     
201     /**
202      * Same as above, but test for non 'Aircraft/' branch paths, and
203      * always resolve them against fg_root.
204      */
205     SGPath resolve_maybe_aircraft_path(const std::string& branch) const;
206     
207     /**
208      * Search in the following directories:
209      *
210      *  1. Root directory of current aircraft (defined by /sim/aircraft-dir)
211      *  2. All aircraft directories if branch starts with Aircraft/
212      *  3. fg_data directory
213      */
214     SGPath resolve_resource_path(const std::string& branch) const;
215
216     inline const std::string &get_browser () const { return browser; }
217     void set_browser (const std::string &b) { browser = b; }
218
219     long int get_warp() const;
220     void set_warp( long int w );
221
222     long int get_warp_delta() const;
223     void set_warp_delta( long int d );
224
225     inline SGTime *get_time_params() const { return time_params; }
226     inline void set_time_params( SGTime *t ) { time_params = t; }
227
228     inline SGEphemeris *get_ephem() const { return ephem; }
229     inline void set_ephem( SGEphemeris *e ) { ephem = e; }
230
231     inline SGMaterialLib *get_matlib() const { return matlib; }
232     inline void set_matlib( SGMaterialLib *m ) { matlib = m; }
233
234     inline FGATISMgr *get_ATIS_mgr() const { return ATIS_mgr; }
235     inline void set_ATIS_mgr( FGATISMgr *a ) {ATIS_mgr = a; }
236
237     inline FGControls *get_controls() const { return controls; }
238     inline void set_controls( FGControls *c ) { controls = c; }
239
240     inline FGViewMgr *get_viewmgr() const { return viewmgr; }
241     inline void set_viewmgr( FGViewMgr *vm ) { viewmgr = vm; }
242     FGViewer *get_current_view() const;
243
244     inline SGPropertyNode *get_props () { return props; }
245     inline void set_props( SGPropertyNode *n ) { props = n; }
246
247     inline FGLocale* get_locale () { return locale; }
248
249     inline SGCommandMgr *get_commands () { return commands; }
250
251     SGGeod get_aircraft_position() const;
252
253     SGVec3d get_aircraft_position_cart() const;
254
255     void get_aircraft_orientation(double& heading, double& pitch, double& roll);
256   
257     SGGeod get_view_position() const;
258   
259     SGVec3d get_view_position_cart() const;
260   
261     inline string_list *get_channel_options_list () {
262         return channel_options_list;
263     }
264     inline void set_channel_options_list( string_list *l ) {
265         channel_options_list = l;
266     }
267
268     inline string_list *get_initial_waypoints () {
269         return initial_waypoints;
270     }
271   
272     inline void set_initial_waypoints (string_list *list) {
273         initial_waypoints = list;
274     }
275
276     inline FGScenery * get_scenery () const { return scenery; }
277     inline void set_scenery ( FGScenery *s ) { scenery = s; }
278
279     inline FGTileMgr * get_tile_mgr () const { return tile_mgr; }
280     inline void set_tile_mgr ( FGTileMgr *t ) { tile_mgr = t; }
281
282     inline FGFontCache *get_fontcache() const { return fontcache; }
283   
284     inline FGTACANList *get_channellist() const { return channellist; }
285     inline void set_channellist( FGTACANList *c ) { channellist = c; }
286   
287    /**
288      * Save the current state as the initial state.
289      */
290     void saveInitialState ();
291
292
293     /**
294      * Restore the saved initial state, if any.
295      */
296     void restoreInitialState ();
297
298     /**
299      * Load user settings from autosave.xml
300      */
301     void loadUserSettings(const SGPath& datapath);
302
303     /**
304      * Save user settings in autosave.xml
305      */
306     void saveUserSettings();
307 };
308
309
310 extern FGGlobals *globals;
311
312
313 #endif // _GLOBALS_HXX