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