]> git.mxchange.org Git - flightgear.git/blob - src/Main/globals.hxx
9182326ee245bd0f01545bdb33ae3af4e139a137
[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 STL_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     // Fullscreen mode for old 3DFX cards.
120 #if defined(FX) && defined(XMESA)
121     bool fullscreen;
122 #endif
123
124     // An offset in seconds from the true time.  Allows us to adjust
125     // the effective time of day.
126     long int warp;
127
128     // How much to change the value of warp each iteration.  Allows us
129     // to make time progress faster than normal (or even run in reverse.)
130     long int warp_delta;
131
132     // Time structure
133     SGTime *time_params;
134
135     // Sky structures
136     SGEphemeris *ephem;
137
138     // Magnetic Variation
139     SGMagVar *mag;
140
141     // Material properties library
142     SGMaterialLib *matlib;
143
144     // Global autopilot "route"
145     FGRouteMgr *route_mgr;
146
147     // 2D panel
148     FGPanel *current_panel;
149
150     // sound manager
151     SGSoundMgr *soundmgr;
152
153     // Simple Airport List
154     FGAirportList *airports;
155
156     // Runway List
157     FGRunwayList *runways;
158
159     // ATC manager
160     FGATCMgr *ATC_mgr;
161
162     // AI manager
163     FGAIMgr *AI_mgr;
164
165     // control input state
166     FGControls *controls;
167
168     // viewer manager
169     FGViewMgr *viewmgr;
170
171     SGCommandMgr *commands;
172
173   //FGFlightPlanDispatcher *fpDispatcher;
174
175     FGAircraftModel *acmodel;
176
177     FGModelMgr * model_mgr;
178
179     // list of serial port-like configurations
180     string_list *channel_options_list;
181
182     // A list of initial waypoints that are read from the command line
183     // and or flight-plan file during initialization
184     string_list *initial_waypoints;
185
186     // FlightGear scenery manager
187     FGScenery *scenery;
188
189     // Tile manager
190     FGTileMgr *tile_mgr;
191
192     // Input/Ouput subsystem
193     FGIO *io;
194
195     FGFontCache *fontcache;
196
197     // Navigational Aids
198     FGNavList *navlist;
199     FGNavList *loclist;
200     FGNavList *gslist;
201     FGNavList *dmelist;
202     FGNavList *mkrlist;
203     FGNavList *tacanlist;
204     FGNavList *carrierlist;
205     FGTACANList *channellist;
206     FGFixList *fixlist;
207     FGAirwayNetwork *airwaynet;
208
209     //Mulitplayer managers
210     FGMultiplayMgr *multiplayer_mgr;
211
212 public:
213
214     FGGlobals();
215     virtual ~FGGlobals();
216
217     virtual FGRenderer *get_renderer () const;
218
219     virtual SGSubsystemMgr *get_subsystem_mgr () const;
220
221     virtual SGSubsystem *get_subsystem (const char * name);
222
223     virtual void add_subsystem (const char * name,
224                                 SGSubsystem * subsystem,
225                                 SGSubsystemMgr::GroupType
226                                 type = SGSubsystemMgr::GENERAL,
227                                 double min_time_sec = 0);
228
229     virtual SGEventMgr *get_event_mgr () const;
230
231     inline double get_sim_time_sec () const { return sim_time_sec; }
232     inline void inc_sim_time_sec (double dt) { sim_time_sec += dt; }
233     inline void set_sim_time_sec (double t) { sim_time_sec = t; }
234
235     inline const string &get_fg_root () const { return fg_root; }
236     void set_fg_root (const string &root);
237
238     inline const string_list &get_fg_scenery () const { return fg_scenery; }
239     void set_fg_scenery (const string &scenery);
240
241 #if defined(FX) && defined(XMESA)
242     inline bool get_fullscreen() const { return fullscreen; }
243     inline bool set_fullscreen( bool f ) { fullscreen = f; }
244 #endif
245
246     inline long int get_warp() const { return warp; }
247     inline void set_warp( long int w ) { warp = w; }
248     inline void inc_warp( long int w ) { warp += w; }
249
250     inline long int get_warp_delta() const { return warp_delta; }
251     inline void set_warp_delta( long int d ) { warp_delta = d; }
252     inline void inc_warp_delta( long int d ) { warp_delta += d; }
253
254     inline SGTime *get_time_params() const { return time_params; }
255     inline void set_time_params( SGTime *t ) { time_params = t; }
256
257     inline SGEphemeris *get_ephem() const { return ephem; }
258     inline void set_ephem( SGEphemeris *e ) { ephem = e; }
259
260     inline SGMagVar *get_mag() const { return mag; }
261     inline void set_mag( SGMagVar *m ) { mag = m; }
262
263     inline SGMaterialLib *get_matlib() const { return matlib; }
264     inline void set_matlib( SGMaterialLib *m ) { matlib = m; }
265
266     inline FGAirportList *get_airports() const { return airports; }
267     inline void set_airports( FGAirportList *a ) {airports = a; }
268
269     inline FGRunwayList *get_runways() const { return runways; }
270     inline void set_runways( FGRunwayList *r ) {runways = r; }
271
272     inline FGATCMgr *get_ATC_mgr() const { return ATC_mgr; }
273     inline void set_ATC_mgr( FGATCMgr *a ) {ATC_mgr = a; }
274
275     inline FGAIMgr *get_AI_mgr() const { return AI_mgr; }
276     inline void set_AI_mgr( FGAIMgr *a ) {AI_mgr = a; }
277
278     inline FGPanel *get_current_panel() const { return current_panel; }
279     inline void set_current_panel( FGPanel *cp ) { current_panel = cp; }
280
281     inline SGSoundMgr *get_soundmgr() const { return soundmgr; }
282     inline void set_soundmgr( SGSoundMgr *sm ) { soundmgr = sm; }
283
284     inline FGControls *get_controls() const { return controls; }
285     inline void set_controls( FGControls *c ) { controls = c; }
286
287     inline FGViewMgr *get_viewmgr() const { return viewmgr; }
288     inline void set_viewmgr( FGViewMgr *vm ) { viewmgr = vm; }
289     FGViewer *get_current_view() const;
290
291     inline SGPropertyNode *get_props () { return props; }
292     inline void set_props( SGPropertyNode *n ) { props = n; }
293
294     inline SGPropertyNode *get_locale () { return locale; }
295     inline void set_locale( SGPropertyNode *n ) { locale = n; }
296
297     inline SGCommandMgr *get_commands () { return commands; }
298
299     inline FGAircraftModel *get_aircraft_model () { return acmodel; }
300
301     inline void set_aircraft_model (FGAircraftModel * model)
302     {
303         acmodel = model;
304     }
305
306     inline FGModelMgr *get_model_mgr () { return model_mgr; }
307
308     inline void set_model_mgr (FGModelMgr * mgr)
309     {
310       model_mgr = mgr;
311     }
312
313     inline FGMultiplayMgr *get_multiplayer_mgr () { return multiplayer_mgr; }
314
315     inline void set_multiplayer_mgr (FGMultiplayMgr * mgr)
316     {
317       multiplayer_mgr = mgr;
318     }
319
320     inline string_list *get_channel_options_list () {
321         return channel_options_list;
322     }
323     inline void set_channel_options_list( string_list *l ) {
324         channel_options_list = l;
325     }
326
327     inline string_list *get_initial_waypoints () {
328         return initial_waypoints;
329     }
330   
331     inline void set_initial_waypoints (string_list *list) {
332         initial_waypoints = list;
333     }
334
335     inline FGScenery * get_scenery () const { return scenery; }
336     inline void set_scenery ( FGScenery *s ) { scenery = s; }
337
338     inline FGTileMgr * get_tile_mgr () const { return tile_mgr; }
339     inline void set_tile_mgr ( FGTileMgr *t ) { tile_mgr = t; }
340
341     inline FGIO* get_io() const { return io; }
342     inline FGFontCache *get_fontcache() const { return fontcache; }
343     
344     inline FGNavList *get_navlist() const { return navlist; }
345     inline void set_navlist( FGNavList *n ) { navlist = n; }
346     inline FGNavList *get_loclist() const { return loclist; }
347     inline void set_loclist( FGNavList *n ) { loclist = n; }
348     inline FGNavList *get_gslist() const { return gslist; }
349     inline void set_gslist( FGNavList *n ) { gslist = n; }
350     inline FGNavList *get_dmelist() const { return dmelist; }
351     inline void set_dmelist( FGNavList *n ) { dmelist = n; }
352     inline FGNavList *get_tacanlist() const { return tacanlist; }
353     inline void set_tacanlist( FGNavList *n ) { tacanlist = n; }
354     inline FGNavList *get_carrierlist() const { return carrierlist; }
355     inline void set_carrierlist( FGNavList *n ) { carrierlist = n; }
356     inline FGNavList *get_mkrlist() const { return mkrlist; }
357     inline void set_mkrlist( FGNavList *n ) { mkrlist = n; }
358     inline FGFixList *get_fixlist() const { return fixlist; }
359     inline void set_fixlist( FGFixList *f ) { fixlist = f; }
360     inline FGTACANList *get_channellist() const { return channellist; }
361     inline void set_channellist( FGTACANList *c ) { channellist = c; }
362
363     inline FGAirwayNetwork *get_airwaynet() const { return airwaynet; }
364     inline void set_airwaynet( FGAirwayNetwork *a ) { airwaynet = a; }
365
366
367    /**
368      * Save the current state as the initial state.
369      */
370     void saveInitialState ();
371
372
373     /**
374      * Restore the saved initial state, if any.
375      */
376     void restoreInitialState ();
377
378 };
379
380
381 extern FGGlobals *globals;
382
383
384 #endif // _GLOBALS_HXX