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