]> git.mxchange.org Git - flightgear.git/blob - src/Main/globals.hxx
7fec6d02b5813b0d6f5bb762e91a13ddf6b342d6
[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 #ifdef HAVE_CONFIG_H
28 #  include <config.h>
29 #endif
30
31 #include <simgear/compiler.h>
32 #include <simgear/structure/callback.hxx>
33 #include <simgear/structure/subsystem_mgr.hxx>
34 #include <simgear/structure/event_mgr.hxx>
35
36 #include <vector>
37 #include <string>
38
39 SG_USING_STD( vector );
40 SG_USING_STD( string );
41
42 typedef vector<string> string_list;
43
44
45 // Forward declarations
46
47 // This file is included, directly or indirectly, almost everywhere in
48 // FlightGear, so if any of its dependencies changes, most of the sim
49 // has to be recompiled.  Using these forward declarations helps us to
50 // avoid including a lot of header files (and thus, a lot of
51 // dependencies).  Since Most of the methods simply set or return
52 // pointers, we don't need to know anything about the class details
53 // anyway.
54
55 class SGEphemeris;
56
57 class SGCommandMgr;
58 class SGMagVar;
59 class SGMaterialLib;
60 class SGPropertyNode;
61 class SGTime;
62 class SGSoundMgr;
63
64
65 class FGAirportList;
66 class FGRunwayList;
67 class FGAIMgr;
68 class FGATCMgr;
69 class FGAircraftModel;
70 class FGControls;
71 class FGFlightPlanDispatcher;
72 class FGIO;
73 class FGNavList;
74 class FGAirwayNetwork;
75 class FGTACANList;
76 class FGFixList;
77 class FGLight;
78 class FGModelMgr;
79 class FGRouteMgr;
80 class FGScenery;
81 class FGMultiplayMgr;
82 class FGPanel;
83 class FGTileMgr;
84 class FGViewMgr;
85 class FGViewer;
86 class FGRenderer;
87 class FGFontCache;
88
89
90 /**
91  * Bucket for subsystem pointers representing the sim's state.
92  */
93
94 class FGGlobals
95 {
96
97 private:
98
99     // properties, destroy last
100     SGPropertyNode_ptr props;
101     SGPropertyNode_ptr initial_state;
102
103     // localization
104     SGPropertyNode_ptr locale;
105
106     FGRenderer *renderer;
107     SGSubsystemMgr *subsystem_mgr;
108     SGEventMgr *event_mgr;
109
110     // Number of milliseconds elapsed since the start of the program.
111     double sim_time_sec;
112
113     // Root of FlightGear data tree
114     string fg_root;
115
116     // Roots of FlightGear scenery tree
117     string_list fg_scenery;
118
119     string browser;
120
121     // An offset in seconds from the true time.  Allows us to adjust
122     // the effective time of day.
123     long int warp;
124
125     // How much to change the value of warp each iteration.  Allows us
126     // to make time progress faster than normal (or even run in reverse.)
127     long int warp_delta;
128
129     // Time structure
130     SGTime *time_params;
131
132     // Sky structures
133     SGEphemeris *ephem;
134
135     // Magnetic Variation
136     SGMagVar *mag;
137
138     // Material properties library
139     SGMaterialLib *matlib;
140
141     // Global autopilot "route"
142     FGRouteMgr *route_mgr;
143
144     // 2D panel
145     FGPanel *current_panel;
146
147     // sound manager
148     SGSoundMgr *soundmgr;
149
150     // Simple Airport List
151     FGAirportList *airports;
152
153     // Runway List
154     FGRunwayList *runways;
155
156     // ATC manager
157     FGATCMgr *ATC_mgr;
158
159     // AI manager
160     FGAIMgr *AI_mgr;
161
162     // control input state
163     FGControls *controls;
164
165     // viewer manager
166     FGViewMgr *viewmgr;
167
168     SGCommandMgr *commands;
169
170   //FGFlightPlanDispatcher *fpDispatcher;
171
172     FGAircraftModel *acmodel;
173
174     FGModelMgr * model_mgr;
175
176     // list of serial port-like configurations
177     string_list *channel_options_list;
178
179     // A list of initial waypoints that are read from the command line
180     // and or flight-plan file during initialization
181     string_list *initial_waypoints;
182
183     // FlightGear scenery manager
184     FGScenery *scenery;
185
186     // Tile manager
187     FGTileMgr *tile_mgr;
188
189     // Input/Ouput subsystem
190     FGIO *io;
191
192     FGFontCache *fontcache;
193
194     // Navigational Aids
195     FGNavList *navlist;
196     FGNavList *loclist;
197     FGNavList *gslist;
198     FGNavList *dmelist;
199     FGNavList *mkrlist;
200     FGNavList *tacanlist;
201     FGNavList *carrierlist;
202     FGTACANList *channellist;
203     FGFixList *fixlist;
204     FGAirwayNetwork *airwaynet;
205
206     //Mulitplayer managers
207     FGMultiplayMgr *multiplayer_mgr;
208
209 public:
210
211     FGGlobals();
212     virtual ~FGGlobals();
213
214     virtual FGRenderer *get_renderer () const;
215
216     virtual SGSubsystemMgr *get_subsystem_mgr () const;
217
218     virtual SGSubsystem *get_subsystem (const char * name);
219
220     virtual void add_subsystem (const char * name,
221                                 SGSubsystem * subsystem,
222                                 SGSubsystemMgr::GroupType
223                                 type = SGSubsystemMgr::GENERAL,
224                                 double min_time_sec = 0);
225
226     virtual SGEventMgr *get_event_mgr () const;
227
228     inline double get_sim_time_sec () const { return sim_time_sec; }
229     inline void inc_sim_time_sec (double dt) { sim_time_sec += dt; }
230     inline void set_sim_time_sec (double t) { sim_time_sec = t; }
231
232     inline const string &get_fg_root () const { return fg_root; }
233     void set_fg_root (const string &root);
234
235     inline const string_list &get_fg_scenery () const { return fg_scenery; }
236     void set_fg_scenery (const string &scenery);
237
238     inline const string &get_browser () const { return browser; }
239     void set_browser (const string &b) { browser = b; }
240
241     inline long int get_warp() const { return warp; }
242     inline void set_warp( long int w ) { warp = w; }
243     inline void inc_warp( long int w ) { warp += w; }
244
245     inline long int get_warp_delta() const { return warp_delta; }
246     inline void set_warp_delta( long int d ) { warp_delta = d; }
247     inline void inc_warp_delta( long int d ) { warp_delta += d; }
248
249     inline SGTime *get_time_params() const { return time_params; }
250     inline void set_time_params( SGTime *t ) { time_params = t; }
251
252     inline SGEphemeris *get_ephem() const { return ephem; }
253     inline void set_ephem( SGEphemeris *e ) { ephem = e; }
254
255     inline SGMagVar *get_mag() const { return mag; }
256     inline void set_mag( SGMagVar *m ) { mag = m; }
257
258     inline SGMaterialLib *get_matlib() const { return matlib; }
259     inline void set_matlib( SGMaterialLib *m ) { matlib = m; }
260
261     inline FGAirportList *get_airports() const { return airports; }
262     inline void set_airports( FGAirportList *a ) {airports = a; }
263
264     inline FGRunwayList *get_runways() const { return runways; }
265     inline void set_runways( FGRunwayList *r ) {runways = r; }
266
267     inline FGATCMgr *get_ATC_mgr() const { return ATC_mgr; }
268     inline void set_ATC_mgr( FGATCMgr *a ) {ATC_mgr = a; }
269
270     inline FGAIMgr *get_AI_mgr() const { return AI_mgr; }
271     inline void set_AI_mgr( FGAIMgr *a ) {AI_mgr = a; }
272
273     inline FGPanel *get_current_panel() const { return current_panel; }
274     inline void set_current_panel( FGPanel *cp ) { current_panel = cp; }
275
276     inline SGSoundMgr *get_soundmgr() const { return soundmgr; }
277     inline void set_soundmgr( SGSoundMgr *sm ) { soundmgr = sm; }
278
279     inline FGControls *get_controls() const { return controls; }
280     inline void set_controls( FGControls *c ) { controls = c; }
281
282     inline FGViewMgr *get_viewmgr() const { return viewmgr; }
283     inline void set_viewmgr( FGViewMgr *vm ) { viewmgr = vm; }
284     FGViewer *get_current_view() const;
285
286     inline SGPropertyNode *get_props () { return props; }
287     inline void set_props( SGPropertyNode *n ) { props = n; }
288
289     inline SGPropertyNode *get_locale () { return locale; }
290     inline void set_locale( SGPropertyNode *n ) { locale = n; }
291
292     inline SGCommandMgr *get_commands () { return commands; }
293
294     inline FGAircraftModel *get_aircraft_model () { return acmodel; }
295
296     inline void set_aircraft_model (FGAircraftModel * model)
297     {
298         acmodel = model;
299     }
300
301     inline FGModelMgr *get_model_mgr () { return model_mgr; }
302
303     inline void set_model_mgr (FGModelMgr * mgr)
304     {
305       model_mgr = mgr;
306     }
307
308     inline FGMultiplayMgr *get_multiplayer_mgr () { return multiplayer_mgr; }
309
310     inline void set_multiplayer_mgr (FGMultiplayMgr * mgr)
311     {
312       multiplayer_mgr = mgr;
313     }
314
315     inline string_list *get_channel_options_list () {
316         return channel_options_list;
317     }
318     inline void set_channel_options_list( string_list *l ) {
319         channel_options_list = l;
320     }
321
322     inline string_list *get_initial_waypoints () {
323         return initial_waypoints;
324     }
325   
326     inline void set_initial_waypoints (string_list *list) {
327         initial_waypoints = list;
328     }
329
330     inline FGScenery * get_scenery () const { return scenery; }
331     inline void set_scenery ( FGScenery *s ) { scenery = s; }
332
333     inline FGTileMgr * get_tile_mgr () const { return tile_mgr; }
334     inline void set_tile_mgr ( FGTileMgr *t ) { tile_mgr = t; }
335
336     inline FGIO* get_io() const { return io; }
337     inline FGFontCache *get_fontcache() const { return fontcache; }
338     
339     inline FGNavList *get_navlist() const { return navlist; }
340     inline void set_navlist( FGNavList *n ) { navlist = n; }
341     inline FGNavList *get_loclist() const { return loclist; }
342     inline void set_loclist( FGNavList *n ) { loclist = n; }
343     inline FGNavList *get_gslist() const { return gslist; }
344     inline void set_gslist( FGNavList *n ) { gslist = n; }
345     inline FGNavList *get_dmelist() const { return dmelist; }
346     inline void set_dmelist( FGNavList *n ) { dmelist = n; }
347     inline FGNavList *get_tacanlist() const { return tacanlist; }
348     inline void set_tacanlist( FGNavList *n ) { tacanlist = n; }
349     inline FGNavList *get_carrierlist() const { return carrierlist; }
350     inline void set_carrierlist( FGNavList *n ) { carrierlist = n; }
351     inline FGNavList *get_mkrlist() const { return mkrlist; }
352     inline void set_mkrlist( FGNavList *n ) { mkrlist = n; }
353     inline FGFixList *get_fixlist() const { return fixlist; }
354     inline void set_fixlist( FGFixList *f ) { fixlist = f; }
355     inline FGTACANList *get_channellist() const { return channellist; }
356     inline void set_channellist( FGTACANList *c ) { channellist = c; }
357
358     inline FGAirwayNetwork *get_airwaynet() const { return airwaynet; }
359     inline void set_airwaynet( FGAirwayNetwork *a ) { airwaynet = a; }
360
361
362    /**
363      * Save the current state as the initial state.
364      */
365     void saveInitialState ();
366
367
368     /**
369      * Restore the saved initial state, if any.
370      */
371     void restoreInitialState ();
372
373 };
374
375
376 extern FGGlobals *globals;
377
378
379 #endif // _GLOBALS_HXX