]> git.mxchange.org Git - flightgear.git/blob - src/Main/globals.hxx
75b18e6b0d48bdc7274d7571a29b63d0086408eb
[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 FGAirportList;
63 class FGRunwayList;
64 class FGAIMgr;
65 class FGATCMgr;
66 class FGATCDisplay;
67 class FGAircraftModel;
68 class FGAutopilot;
69 class FGControls;
70 class FGIO;
71 class FGLight;
72 class FGModelMgr;
73 class FGScenery;
74 #ifdef FG_MPLAYER_AS
75 class FGMultiplayRxMgr;
76 class FGMultiplayTxMgr;
77 #endif
78 class FGPanel;
79 class FGTileMgr;
80 class FGViewMgr;
81 class FGViewer;
82
83
84 /**
85  * Bucket for subsystem pointers representing the sim's state.
86  */
87 class FGGlobals
88 {
89
90 private:
91
92     FGSubsystemMgr * subsystem_mgr;
93
94     // Number of milliseconds elapsed since the start of the program.
95     double sim_time_sec;
96
97     // Root of FlightGear data tree
98     string fg_root;
99
100     // Root of FlightGear scenery tree
101     string fg_scenery;
102
103     // Fullscreen mode for old 3DFX cards.
104 #if defined(FX) && defined(XMESA)
105     bool fullscreen;
106 #endif
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     // Current autopilot
129     FGAutopilot *autopilot;
130
131     // Global autopilot "route"
132     SGRoute *route;
133
134     // 2D panel
135     FGPanel *current_panel;
136
137     // sound manager
138     SGSoundMgr *soundmgr;
139
140     // Simple Airport List
141     FGAirportList *airports;
142
143     // Runway List
144     FGRunwayList *runways;
145
146     // ATC manager
147     FGATCMgr *ATC_mgr;
148
149     // ATC Renderer
150     FGATCDisplay *ATC_display;
151
152     // AI manager
153     FGAIMgr *AI_mgr;
154
155     // control input state
156     FGControls *controls;
157
158     // viewer manager
159     FGViewMgr *viewmgr;
160
161     // properties
162     SGPropertyNode *props;
163     SGPropertyNode *initial_state;
164
165     // localization
166     SGPropertyNode *locale;
167
168     SGCommandMgr *commands;
169
170     SGModelLib *model_lib;
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     // FlightGear scenery manager
180     FGScenery *scenery;
181
182     // Tile manager
183     FGTileMgr *tile_mgr;
184
185     // Input/Ouput subsystem
186     FGIO *io;
187
188     // light parameters
189     FGLight *cur_light_params;
190
191 #ifdef FG_MPLAYER_AS
192     //Mulitplayer managers
193     FGMultiplayTxMgr *multiplayer_tx_mgr;
194
195     FGMultiplayRxMgr *multiplayer_rx_mgr;
196 #endif
197
198 public:
199
200     FGGlobals();
201     virtual ~FGGlobals();
202
203     virtual FGSubsystemMgr * get_subsystem_mgr () const;
204
205     virtual FGSubsystem * get_subsystem (const char * name);
206
207     virtual void add_subsystem (const char * name,
208                                 FGSubsystem * subsystem,
209                                 FGSubsystemMgr::GroupType
210                                   type = FGSubsystemMgr::GENERAL,
211                                 double min_time_sec = 0);
212
213     inline double get_sim_time_sec () const { return sim_time_sec; }
214     inline void inc_sim_time_sec (double dt) { sim_time_sec += dt; }
215     inline void set_sim_time_sec (double t) { sim_time_sec = t; }
216
217     inline const string &get_fg_root () const { return fg_root; }
218     void set_fg_root (const string &root);
219
220     inline const string &get_fg_scenery () const { return fg_scenery; }
221     inline void set_fg_scenery (const string &scenery) {
222       fg_scenery = scenery;
223     }
224
225 #if defined(FX) && defined(XMESA)
226     inline bool get_fullscreen() const { return fullscreen; }
227     inline bool set_fullscreen( bool f ) { fullscreen = f; }
228 #endif
229
230     inline long int get_warp() const { return warp; }
231     inline void set_warp( long int w ) { warp = w; }
232     inline void inc_warp( long int w ) { warp += w; }
233
234     inline long int get_warp_delta() const { return warp_delta; }
235     inline void set_warp_delta( long int d ) { warp_delta = d; }
236     inline void inc_warp_delta( long int d ) { warp_delta += d; }
237
238     inline SGTime *get_time_params() const { return time_params; }
239     inline void set_time_params( SGTime *t ) { time_params = t; }
240
241     inline SGEphemeris *get_ephem() const { return ephem; }
242     inline void set_ephem( SGEphemeris *e ) { ephem = e; }
243
244     inline SGMagVar *get_mag() const { return mag; }
245     inline void set_mag( SGMagVar *m ) { mag = m; }
246
247     inline SGMaterialLib *get_matlib() const { return matlib; }
248     inline void set_matlib( SGMaterialLib *m ) { matlib = m; }
249
250     inline FGAutopilot *get_autopilot() const { return autopilot; }
251     inline void set_autopilot( FGAutopilot *ap) { autopilot = ap; }
252
253     inline SGRoute *get_route() const { return route; }
254     inline void set_route( SGRoute *r ) { route = r; }
255
256     inline FGAirportList *get_airports() const { return airports; }
257     inline void set_airports( FGAirportList *a ) {airports = a; }
258
259     inline FGRunwayList *get_runways() const { return runways; }
260     inline void set_runways( FGRunwayList *r ) {runways = r; }
261
262     inline FGATCMgr *get_ATC_mgr() const { return ATC_mgr; }
263     inline void set_ATC_mgr( FGATCMgr *a ) {ATC_mgr = a; }
264
265     inline FGATCDisplay *get_ATC_display() const { return ATC_display; }
266     inline void set_ATC_display( FGATCDisplay *d ) {ATC_display = d; }
267
268     inline FGAIMgr *get_AI_mgr() const { return AI_mgr; }
269     inline void set_AI_mgr( FGAIMgr *a ) {AI_mgr = a; }
270
271     inline FGPanel *get_current_panel() const { return current_panel; }
272     inline void set_current_panel( FGPanel *cp ) { current_panel = cp; }
273
274     inline SGSoundMgr *get_soundmgr() const { return soundmgr; }
275     inline void set_soundmgr( SGSoundMgr *sm ) { soundmgr = sm; }
276
277     inline FGControls *get_controls() const { return controls; }
278     inline void set_controls( FGControls *c ) { controls = c; }
279
280     inline FGViewMgr *get_viewmgr() const { return viewmgr; }
281     inline void set_viewmgr( FGViewMgr *vm ) { viewmgr = vm; }
282     FGViewer *get_current_view() const;
283
284     inline SGPropertyNode *get_props () { return props; }
285     inline void set_props( SGPropertyNode *n ) { props = n; }
286
287     inline SGPropertyNode *get_locale () { return locale; }
288     inline void set_locale( SGPropertyNode *n ) { locale = n; }
289
290     inline SGCommandMgr *get_commands () { return commands; }
291
292     inline SGModelLib * get_model_lib () { return model_lib; }
293
294     inline void set_model_lib (SGModelLib *m) {
295         model_lib = m;
296     }
297
298     inline FGAircraftModel *get_aircraft_model () { return acmodel; }
299
300     inline void set_aircraft_model (FGAircraftModel * model)
301     {
302         acmodel = model;
303     }
304
305     inline FGModelMgr *get_model_mgr () { return model_mgr; }
306
307     inline void set_model_mgr (FGModelMgr * mgr)
308     {
309       model_mgr = mgr;
310     }
311
312 #ifdef FG_MPLAYER_AS
313     inline FGMultiplayTxMgr *get_multiplayer_tx_mgr () { return multiplayer_tx_mgr; }
314
315     inline void set_multiplayer_tx_mgr (FGMultiplayTxMgr * mgr)
316     {
317       multiplayer_tx_mgr = mgr;
318     }
319
320     inline FGMultiplayRxMgr *get_multiplayer_rx_mgr () { return multiplayer_rx_mgr; }
321
322     inline void set_multiplayer_rx_mgr (FGMultiplayRxMgr * mgr)
323     {
324       multiplayer_rx_mgr = mgr;
325     }
326 #endif
327
328     inline string_list *get_channel_options_list () {
329         return channel_options_list;
330     }
331     inline void set_channel_options_list( string_list *l ) {
332         channel_options_list = l;
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
343     /**
344      * Save the current state as the initial state.
345      */
346     void saveInitialState ();
347
348
349     /**
350      * Restore the saved initial state, if any.
351      */
352     void restoreInitialState ();
353
354 };
355
356
357 extern FGGlobals *globals;
358
359
360 #endif // _GLOBALS_HXX