]> git.mxchange.org Git - flightgear.git/blob - src/Main/globals.hxx
Use a pointer to a structure instead of a large number of variables when calling...
[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 - curt@flightgear.org
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., 675 Mass Ave, Cambridge, MA 02139, USA.
20 //
21 // $Id$
22
23
24 #ifndef _GLOBALS_HXX
25 #define _GLOBALS_HXX
26
27 #include <simgear/compiler.h>
28
29 #include <vector>
30 #include STL_STRING
31
32 #include "fgfs.hxx"
33
34
35 SG_USING_STD( vector );
36 SG_USING_STD( string );
37
38 typedef vector<string> string_list;
39
40
41 // Forward declarations
42
43 // This file is included, directly or indirectly, almost everywhere in
44 // FlightGear, so if any of its dependencies changes, most of the sim
45 // has to be recompiled.  Using these forward declarations helps us to
46 // avoid including a lot of header files (and thus, a lot of
47 // dependencies).  Since Most of the methods simply set or return
48 // pointers, we don't need to know anything about the class details
49 // anyway.
50
51 class SGEphemeris;
52
53 class SGCommandMgr;
54 class SGMagVar;
55 class SGMaterialLib;
56 class SGModelLib;
57 class SGPropertyNode;
58 class SGRoute;
59 class SGTime;
60 class SGSoundMgr;
61
62 class FGAIMgr;
63 class FGATCMgr;
64 class FGATCDisplay;
65 class FGAircraftModel;
66 class FGAutopilot;
67 class FGControls;
68 class FGIO;
69 class FGModelMgr;
70 class FGScenery;
71 #ifdef FG_MPLAYER_AS
72 class FGMultiplayRxMgr;
73 class FGMultiplayTxMgr;
74 #endif
75 class FGPanel;
76 class FGTileMgr;
77 class FGViewMgr;
78 class FGViewer;
79
80
81 /**
82  * Bucket for subsystem pointers representing the sim's state.
83  */
84 class FGGlobals
85 {
86
87 private:
88
89     FGSubsystemMgr * subsystem_mgr;
90
91     // Number of milliseconds elapsed since the start of the program.
92     double sim_time_sec;
93
94     // Root of FlightGear data tree
95     string fg_root;
96
97     // Root of FlightGear scenery tree
98     string fg_scenery;
99
100     // Fullscreen mode for old 3DFX cards.
101 #if defined(FX) && defined(XMESA)
102     bool fullscreen;
103 #endif
104
105     // An offset in seconds from the true time.  Allows us to adjust
106     // the effective time of day.
107     long int warp;
108
109     // How much to change the value of warp each iteration.  Allows us
110     // to make time progress faster than normal (or even run in reverse.)
111     long int warp_delta;
112
113     // Time structure
114     SGTime *time_params;
115
116     // Sky structures
117     SGEphemeris *ephem;
118
119     // Magnetic Variation
120     SGMagVar *mag;
121
122     // Material properties library
123     SGMaterialLib *matlib;
124
125     // Current autopilot
126     FGAutopilot *autopilot;
127
128     // Global autopilot "route"
129     SGRoute *route;
130
131     // 2D panel
132     FGPanel *current_panel;
133
134     // sound manager
135     SGSoundMgr *soundmgr;
136
137     // ATC manager
138     FGATCMgr *ATC_mgr;
139
140     // ATC Renderer
141     FGATCDisplay *ATC_display;
142
143     // AI manager
144     FGAIMgr *AI_mgr;
145
146     // control input state
147     FGControls *controls;
148
149     // viewer manager
150     FGViewMgr *viewmgr;
151
152     // properties
153     SGPropertyNode *props;
154     SGPropertyNode *initial_state;
155
156     // localization
157     SGPropertyNode *locale;
158
159     SGCommandMgr *commands;
160
161     SGModelLib *model_lib;
162
163     FGAircraftModel *acmodel;
164
165     FGModelMgr * model_mgr;
166
167     // list of serial port-like configurations
168     string_list *channel_options_list;
169
170     // FlightGear scenery manager
171     FGScenery *scenery;
172
173     // Tile manager
174     FGTileMgr *tile_mgr;
175
176     FGIO* io;
177
178 #ifdef FG_MPLAYER_AS
179     //Mulitplayer managers
180     FGMultiplayTxMgr *multiplayer_tx_mgr;
181
182     FGMultiplayRxMgr *multiplayer_rx_mgr;
183 #endif
184
185 public:
186
187     FGGlobals();
188     virtual ~FGGlobals();
189
190     virtual FGSubsystemMgr * get_subsystem_mgr () const;
191
192     virtual FGSubsystem * get_subsystem (const char * name);
193
194     virtual void add_subsystem (const char * name,
195                                 FGSubsystem * subsystem,
196                                 FGSubsystemMgr::GroupType
197                                   type = FGSubsystemMgr::GENERAL,
198                                 double min_time_sec = 0);
199
200     inline double get_sim_time_sec () const { return sim_time_sec; }
201     inline void inc_sim_time_sec (double dt) { sim_time_sec += dt; }
202     inline void set_sim_time_sec (double t) { sim_time_sec = t; }
203
204     inline const string &get_fg_root () const { return fg_root; }
205     void set_fg_root (const string &root);
206
207     inline const string &get_fg_scenery () const { return fg_scenery; }
208     inline void set_fg_scenery (const string &scenery) {
209       fg_scenery = scenery;
210     }
211
212 #if defined(FX) && defined(XMESA)
213     inline bool get_fullscreen() const { return fullscreen; }
214     inline bool set_fullscreen( bool f ) { fullscreen = f; }
215 #endif
216
217     inline long int get_warp() const { return warp; }
218     inline void set_warp( long int w ) { warp = w; }
219     inline void inc_warp( long int w ) { warp += w; }
220
221     inline long int get_warp_delta() const { return warp_delta; }
222     inline void set_warp_delta( long int d ) { warp_delta = d; }
223     inline void inc_warp_delta( long int d ) { warp_delta += d; }
224
225     inline SGTime *get_time_params() const { return time_params; }
226     inline void set_time_params( SGTime *t ) { time_params = t; }
227
228     inline SGEphemeris *get_ephem() const { return ephem; }
229     inline void set_ephem( SGEphemeris *e ) { ephem = e; }
230
231     inline SGMagVar *get_mag() const { return mag; }
232     inline void set_mag( SGMagVar *m ) { mag = m; }
233
234     inline SGMaterialLib *get_matlib() const { return matlib; }
235     inline void set_matlib( SGMaterialLib *m ) { matlib = m; }
236
237     inline FGAutopilot *get_autopilot() const { return autopilot; }
238     inline void set_autopilot( FGAutopilot *ap) { autopilot = ap; }
239
240     inline SGRoute *get_route() const { return route; }
241     inline void set_route( SGRoute *r ) { route = r; }
242
243     inline FGATCMgr *get_ATC_mgr() const { return ATC_mgr; }
244     inline void set_ATC_mgr( FGATCMgr *a ) {ATC_mgr = a; }
245
246     inline FGATCDisplay *get_ATC_display() const { return ATC_display; }
247     inline void set_ATC_display( FGATCDisplay *d ) {ATC_display = d; }
248
249     inline FGAIMgr *get_AI_mgr() const { return AI_mgr; }
250     inline void set_AI_mgr( FGAIMgr *a ) {AI_mgr = a; }
251
252     inline FGPanel *get_current_panel() const { return current_panel; }
253     inline void set_current_panel( FGPanel *cp ) { current_panel = cp; }
254
255     inline SGSoundMgr *get_soundmgr() const { return soundmgr; }
256     inline void set_soundmgr( SGSoundMgr *sm ) { soundmgr = sm; }
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 SGModelLib * get_model_lib () { return model_lib; }
274
275     inline void set_model_lib (SGModelLib *m) {
276         model_lib = m;
277     }
278
279     inline FGAircraftModel *get_aircraft_model () { return acmodel; }
280
281     inline void set_aircraft_model (FGAircraftModel * model)
282     {
283         acmodel = model;
284     }
285
286     inline FGModelMgr *get_model_mgr () { return model_mgr; }
287
288     inline void set_model_mgr (FGModelMgr * mgr)
289     {
290       model_mgr = mgr;
291     }
292
293 #ifdef FG_MPLAYER_AS
294     inline FGMultiplayTxMgr *get_multiplayer_tx_mgr () { return multiplayer_tx_mgr; }
295
296     inline void set_multiplayer_tx_mgr (FGMultiplayTxMgr * mgr)
297     {
298       multiplayer_tx_mgr = mgr;
299     }
300
301     inline FGMultiplayRxMgr *get_multiplayer_rx_mgr () { return multiplayer_rx_mgr; }
302
303     inline void set_multiplayer_rx_mgr (FGMultiplayRxMgr * mgr)
304     {
305       multiplayer_rx_mgr = mgr;
306     }
307 #endif
308
309     inline string_list *get_channel_options_list () {
310         return channel_options_list;
311     }
312     inline void set_channel_options_list( string_list *l ) {
313         channel_options_list = l;
314     }
315
316     inline FGScenery * get_scenery () const { return scenery; }
317     inline void set_scenery ( FGScenery *s ) { scenery = s; }
318
319     inline FGTileMgr * get_tile_mgr () const { return tile_mgr; }
320     inline void set_tile_mgr ( FGTileMgr *t ) { tile_mgr = t; }
321
322     FGIO* get_io() const { return io; }
323
324
325     /**
326      * Save the current state as the initial state.
327      */
328     void saveInitialState ();
329
330
331     /**
332      * Restore the saved initial state, if any.
333      */
334     void restoreInitialState ();
335
336 };
337
338
339 extern FGGlobals *globals;
340
341
342 #endif // _GLOBALS_HXX