]> git.mxchange.org Git - flightgear.git/blob - src/Main/globals.hxx
fd81b0b50e59eca3dcd876df89124e2c7a5cfcef
[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 SGMagVar;
50 class SGMaterialLib;
51 class SGPropertyNode;
52 class SGTime;
53 class SGEventMgr;
54 class SGSubsystemMgr;
55 class SGSubsystem;
56 class SGSoundMgr;
57
58 class FGATCMgr;
59 class FGAircraftModel;
60 class FGControls;
61 class FGFlightPlanDispatcher;
62 class FGNavList;
63 class FGTACANList;
64 class FGModelMgr;
65 class FGRouteMgr;
66 class FGScenery;
67 class FGPanel;
68 class FGTileMgr;
69 class FGViewMgr;
70 class FGViewer;
71 class FGRenderer;
72 class FGFontCache;
73
74
75 /**
76  * Bucket for subsystem pointers representing the sim's state.
77  */
78
79 class FGGlobals
80 {
81
82 private:
83
84     // properties, destroy last
85     SGPropertyNode_ptr props;
86     SGPropertyNode_ptr initial_state;
87
88     // localization
89     SGPropertyNode_ptr locale;
90
91     FGRenderer *renderer;
92     SGSubsystemMgr *subsystem_mgr;
93     SGEventMgr *event_mgr;
94
95     // Number of milliseconds elapsed since the start of the program.
96     double sim_time_sec;
97
98     // Root of FlightGear data tree
99     std::string fg_root;
100
101     // Roots of FlightGear scenery tree
102     string_list fg_scenery;
103
104     std::string browser;
105
106     // Time structure
107     SGTime *time_params;
108
109     // Sky structures
110     SGEphemeris *ephem;
111
112     // Magnetic Variation
113     SGMagVar *mag;
114
115     // Material properties library
116     SGMaterialLib *matlib;
117
118     // Global autopilot "route"
119     FGRouteMgr *route_mgr;
120
121     // 2D panel
122     FGPanel *current_panel;
123
124     // ATC manager
125     FGATCMgr *ATC_mgr;
126
127     // control input state
128     FGControls *controls;
129
130     // viewer manager
131     FGViewMgr *viewmgr;
132
133     SGCommandMgr *commands;
134
135   //FGFlightPlanDispatcher *fpDispatcher;
136
137     FGAircraftModel *acmodel;
138
139     FGModelMgr * model_mgr;
140
141     // list of serial port-like configurations
142     string_list *channel_options_list;
143
144     // A list of initial waypoints that are read from the command line
145     // and or flight-plan file during initialization
146     string_list *initial_waypoints;
147
148     // FlightGear scenery manager
149     FGScenery *scenery;
150
151     // Tile manager
152     FGTileMgr *tile_mgr;
153
154     FGFontCache *fontcache;
155
156     // Navigational Aids
157     FGNavList *navlist;
158     FGNavList *loclist;
159     FGNavList *gslist;
160     FGNavList *dmelist;
161     FGNavList *tacanlist;
162     FGNavList *carrierlist;
163     FGTACANList *channellist;
164
165     /// roots of Aircraft trees
166     string_list fg_aircraft_dirs;
167
168     bool haveUserSettings;
169
170 public:
171
172     FGGlobals();
173     virtual ~FGGlobals();
174
175     virtual FGRenderer *get_renderer () const;
176
177     virtual SGSubsystemMgr *get_subsystem_mgr () const;
178
179     virtual SGSubsystem *get_subsystem (const char * name);
180
181     virtual void add_subsystem (const char * name,
182                                 SGSubsystem * subsystem,
183                                 SGSubsystemMgr::GroupType
184                                 type = SGSubsystemMgr::GENERAL,
185                                 double min_time_sec = 0);
186
187     virtual SGEventMgr *get_event_mgr () const;
188
189     virtual SGSoundMgr *get_soundmgr () const;
190
191     inline double get_sim_time_sec () const { return sim_time_sec; }
192     inline void inc_sim_time_sec (double dt) { sim_time_sec += dt; }
193     inline void set_sim_time_sec (double t) { sim_time_sec = t; }
194
195     inline const std::string &get_fg_root () const { return fg_root; }
196     void set_fg_root (const std::string &root);
197
198     inline const string_list &get_fg_scenery () const { return fg_scenery; }
199     void append_fg_scenery (const std::string &scenery);
200
201     const string_list& get_aircraft_paths() const { return fg_aircraft_dirs; }
202     void append_aircraft_path(const std::string& path);
203     void append_aircraft_paths(const std::string& path);
204     
205     /**
206      * Given a path to an aircraft-related resource file, resolve it
207      * against the appropriate root. This means looking at the location
208      * defined by /sim/aircraft-dir, and then aircraft_path in turn,
209      * finishing with fg_root/Aircraft.
210      *
211      * if the path could not be resolved, an empty path is returned.
212      */
213     SGPath resolve_aircraft_path(const std::string& branch) const;
214     
215     /**
216      * Same as above, but test for non 'Aircraft/' branch paths, and
217      * always resolve them against fg_root.
218      */
219     SGPath resolve_maybe_aircraft_path(const std::string& branch) const;
220     
221     inline const std::string &get_browser () const { return browser; }
222     void set_browser (const std::string &b) { browser = b; }
223
224     long int get_warp() const;
225     void set_warp( long int w );
226
227     long int get_warp_delta() const;
228     void set_warp_delta( long int d );
229
230     inline SGTime *get_time_params() const { return time_params; }
231     inline void set_time_params( SGTime *t ) { time_params = t; }
232
233     inline SGEphemeris *get_ephem() const { return ephem; }
234     inline void set_ephem( SGEphemeris *e ) { ephem = e; }
235
236     inline SGMagVar *get_mag() const { return mag; }
237     inline void set_mag( SGMagVar *m ) { mag = m; }
238
239     inline SGMaterialLib *get_matlib() const { return matlib; }
240     inline void set_matlib( SGMaterialLib *m ) { matlib = m; }
241
242     inline FGATCMgr *get_ATC_mgr() const { return ATC_mgr; }
243     inline void set_ATC_mgr( FGATCMgr *a ) {ATC_mgr = a; }
244
245     inline FGPanel *get_current_panel() const { return current_panel; }
246     inline void set_current_panel( FGPanel *cp ) { current_panel = cp; }
247
248     inline FGControls *get_controls() const { return controls; }
249     inline void set_controls( FGControls *c ) { controls = c; }
250
251     inline FGViewMgr *get_viewmgr() const { return viewmgr; }
252     inline void set_viewmgr( FGViewMgr *vm ) { viewmgr = vm; }
253     FGViewer *get_current_view() const;
254
255     inline SGPropertyNode *get_props () { return props; }
256     inline void set_props( SGPropertyNode *n ) { props = n; }
257
258     inline SGPropertyNode *get_locale () { return locale; }
259     inline void set_locale( SGPropertyNode *n ) { locale = n; }
260
261     inline SGCommandMgr *get_commands () { return commands; }
262
263     inline FGAircraftModel *get_aircraft_model () { return acmodel; }
264
265     inline void set_aircraft_model (FGAircraftModel * model)
266     {
267         acmodel = model;
268     }
269
270     const SGGeod & get_aircraft_position() const;
271
272     SGVec3d get_aircraft_positon_cart() const;
273     
274     inline FGModelMgr *get_model_mgr () { return model_mgr; }
275
276     inline void set_model_mgr (FGModelMgr * mgr)
277     {
278       model_mgr = mgr;
279     }
280
281     inline string_list *get_channel_options_list () {
282         return channel_options_list;
283     }
284     inline void set_channel_options_list( string_list *l ) {
285         channel_options_list = l;
286     }
287
288     inline string_list *get_initial_waypoints () {
289         return initial_waypoints;
290     }
291   
292     inline void set_initial_waypoints (string_list *list) {
293         initial_waypoints = list;
294     }
295
296     inline FGScenery * get_scenery () const { return scenery; }
297     inline void set_scenery ( FGScenery *s ) { scenery = s; }
298
299     inline FGTileMgr * get_tile_mgr () const { return tile_mgr; }
300     inline void set_tile_mgr ( FGTileMgr *t ) { tile_mgr = t; }
301
302     inline FGFontCache *get_fontcache() const { return fontcache; }
303
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; }
318
319    /**
320      * Save the current state as the initial state.
321      */
322     void saveInitialState ();
323
324
325     /**
326      * Restore the saved initial state, if any.
327      */
328     void restoreInitialState ();
329
330     /**
331      * Load user settings from autosave.xml
332      */
333     void loadUserSettings();
334
335     /**
336      * Save user settings in autosave.xml
337      */
338     void saveUserSettings();
339 };
340
341
342 extern FGGlobals *globals;
343
344
345 #endif // _GLOBALS_HXX