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