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