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