]> git.mxchange.org Git - flightgear.git/blob - src/Main/globals.hxx
Make FGAircraftModel behave like a standarrd subsystem.
[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 #include <simgear/misc/sg_path.hxx>
31
32 #include <vector>
33 #include <string>
34
35 typedef std::vector<std::string> string_list;
36
37 // Forward declarations
38
39 // This file is included, directly or indirectly, almost everywhere in
40 // FlightGear, so if any of its dependencies changes, most of the sim
41 // has to be recompiled.  Using these forward declarations helps us to
42 // avoid including a lot of header files (and thus, a lot of
43 // dependencies).  Since Most of the methods simply set or return
44 // pointers, we don't need to know anything about the class details
45 // anyway.
46
47 class SGEphemeris;
48 class SGCommandMgr;
49 class SGMagVar;
50 class SGMaterialLib;
51 class SGPropertyNode;
52 class SGTime;
53 class SGEventMgr;
54 class SGSubsystemMgr;
55 class SGSubsystem;
56 class SGSoundMgr;
57
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     SGSoundMgr *soundmgr;
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     // ATC manager
137     FGATCMgr *ATC_mgr;
138
139     // control input state
140     FGControls *controls;
141
142     // viewer manager
143     FGViewMgr *viewmgr;
144
145     SGCommandMgr *commands;
146
147   //FGFlightPlanDispatcher *fpDispatcher;
148
149     FGAircraftModel *acmodel;
150
151     FGModelMgr * model_mgr;
152
153     // list of serial port-like configurations
154     string_list *channel_options_list;
155
156     // A list of initial waypoints that are read from the command line
157     // and or flight-plan file during initialization
158     string_list *initial_waypoints;
159
160     // FlightGear scenery manager
161     FGScenery *scenery;
162
163     // Tile manager
164     FGTileMgr *tile_mgr;
165
166     FGFontCache *fontcache;
167
168     // Navigational Aids
169     FGNavList *navlist;
170     FGNavList *loclist;
171     FGNavList *gslist;
172     FGNavList *dmelist;
173     FGNavList *tacanlist;
174     FGNavList *carrierlist;
175     FGTACANList *channellist;
176     FGAirwayNetwork *airwaynet;
177
178     //Mulitplayer managers
179     FGMultiplayMgr *multiplayer_mgr;
180
181     /// roots of Aircraft trees
182     string_list fg_aircraft_dirs;
183 public:
184
185     FGGlobals();
186     virtual ~FGGlobals();
187
188     virtual FGRenderer *get_renderer () const;
189
190     virtual SGSubsystemMgr *get_subsystem_mgr () const;
191
192     virtual SGSubsystem *get_subsystem (const char * name);
193
194     virtual void add_subsystem (const char * name,
195                                 SGSubsystem * subsystem,
196                                 SGSubsystemMgr::GroupType
197                                 type = SGSubsystemMgr::GENERAL,
198                                 double min_time_sec = 0);
199
200     virtual SGEventMgr *get_event_mgr () const;
201
202     virtual SGSoundMgr *get_soundmgr () const;
203
204     inline double get_sim_time_sec () const { return sim_time_sec; }
205     inline void inc_sim_time_sec (double dt) { sim_time_sec += dt; }
206     inline void set_sim_time_sec (double t) { sim_time_sec = t; }
207
208     inline const std::string &get_fg_root () const { return fg_root; }
209     void set_fg_root (const std::string &root);
210
211     inline const string_list &get_fg_scenery () const { return fg_scenery; }
212     void set_fg_scenery (const std::string &scenery);
213
214     const string_list& get_aircraft_paths() const { return fg_aircraft_dirs; }
215     void append_aircraft_path(const std::string& path);
216     void append_aircraft_paths(const std::string& path);
217     
218     /**
219      * Given a path to an aircraft-related resource file, resolve it
220      * against the appropriate root. This means looking at the location
221      * defined by /sim/aircraft-dir, and then aircraft_path in turn,
222      * finishing with fg_root/Aircraft.
223      *
224      * if the path could not be resolved, an empty path is returned.
225      */
226     SGPath resolve_aircraft_path(const std::string& branch) const;
227     
228     /**
229      * Same as above, but test for non 'Aircraft/' branch paths, and
230      * always resolve them against fg_root.
231      */
232     SGPath resolve_maybe_aircraft_path(const std::string& branch) const;
233     
234     inline const std::string &get_browser () const { return browser; }
235     void set_browser (const std::string &b) { browser = b; }
236
237     inline long int get_warp() const { return warp; }
238     inline void set_warp( long int w ) { warp = w; }
239     inline void inc_warp( long int w ) { warp += w; }
240
241     inline long int get_warp_delta() const { return warp_delta; }
242     inline void set_warp_delta( long int d ) { warp_delta = d; }
243     inline void inc_warp_delta( long int d ) { warp_delta += d; }
244
245     inline SGTime *get_time_params() const { return time_params; }
246     inline void set_time_params( SGTime *t ) { time_params = t; }
247
248     inline SGEphemeris *get_ephem() const { return ephem; }
249     inline void set_ephem( SGEphemeris *e ) { ephem = e; }
250
251     inline SGMagVar *get_mag() const { return mag; }
252     inline void set_mag( SGMagVar *m ) { mag = m; }
253
254     inline SGMaterialLib *get_matlib() const { return matlib; }
255     inline void set_matlib( SGMaterialLib *m ) { matlib = m; }
256
257     inline FGATCMgr *get_ATC_mgr() const { return ATC_mgr; }
258     inline void set_ATC_mgr( FGATCMgr *a ) {ATC_mgr = a; }
259
260     inline FGPanel *get_current_panel() const { return current_panel; }
261     inline void set_current_panel( FGPanel *cp ) { current_panel = cp; }
262
263     inline FGControls *get_controls() const { return controls; }
264     inline void set_controls( FGControls *c ) { controls = c; }
265
266     inline FGViewMgr *get_viewmgr() const { return viewmgr; }
267     inline void set_viewmgr( FGViewMgr *vm ) { viewmgr = vm; }
268     FGViewer *get_current_view() const;
269
270     inline SGPropertyNode *get_props () { return props; }
271     inline void set_props( SGPropertyNode *n ) { props = n; }
272
273     inline SGPropertyNode *get_locale () { return locale; }
274     inline void set_locale( SGPropertyNode *n ) { locale = n; }
275
276     inline SGCommandMgr *get_commands () { return commands; }
277
278     inline FGAircraftModel *get_aircraft_model () { return acmodel; }
279
280     inline void set_aircraft_model (FGAircraftModel * model)
281     {
282         acmodel = model;
283     }
284
285     inline FGModelMgr *get_model_mgr () { return model_mgr; }
286
287     inline void set_model_mgr (FGModelMgr * mgr)
288     {
289       model_mgr = mgr;
290     }
291
292     inline FGMultiplayMgr *get_multiplayer_mgr () { return multiplayer_mgr; }
293
294     inline void set_multiplayer_mgr (FGMultiplayMgr * mgr)
295     {
296       multiplayer_mgr = mgr;
297     }
298
299     inline string_list *get_channel_options_list () {
300         return channel_options_list;
301     }
302     inline void set_channel_options_list( string_list *l ) {
303         channel_options_list = l;
304     }
305
306     inline string_list *get_initial_waypoints () {
307         return initial_waypoints;
308     }
309   
310     inline void set_initial_waypoints (string_list *list) {
311         initial_waypoints = list;
312     }
313
314     inline FGScenery * get_scenery () const { return scenery; }
315     inline void set_scenery ( FGScenery *s ) { scenery = s; }
316
317     inline FGTileMgr * get_tile_mgr () const { return tile_mgr; }
318     inline void set_tile_mgr ( FGTileMgr *t ) { tile_mgr = t; }
319
320     inline FGFontCache *get_fontcache() const { return fontcache; }
321
322     inline FGNavList *get_navlist() const { return navlist; }
323     inline void set_navlist( FGNavList *n ) { navlist = n; }
324     inline FGNavList *get_loclist() const { return loclist; }
325     inline void set_loclist( FGNavList *n ) { loclist = n; }
326     inline FGNavList *get_gslist() const { return gslist; }
327     inline void set_gslist( FGNavList *n ) { gslist = n; }
328     inline FGNavList *get_dmelist() const { return dmelist; }
329     inline void set_dmelist( FGNavList *n ) { dmelist = n; }
330     inline FGNavList *get_tacanlist() const { return tacanlist; }
331     inline void set_tacanlist( FGNavList *n ) { tacanlist = n; }
332     inline FGNavList *get_carrierlist() const { return carrierlist; }
333     inline void set_carrierlist( FGNavList *n ) { carrierlist = n; }
334     inline FGTACANList *get_channellist() const { return channellist; }
335     inline void set_channellist( FGTACANList *c ) { channellist = c; }
336
337     inline FGAirwayNetwork *get_airwaynet() const { return airwaynet; }
338     inline void set_airwaynet( FGAirwayNetwork *a ) { airwaynet = a; }
339
340
341    /**
342      * Save the current state as the initial state.
343      */
344     void saveInitialState ();
345
346
347     /**
348      * Restore the saved initial state, if any.
349      */
350     void restoreInitialState ();
351
352 };
353
354
355 extern FGGlobals *globals;
356
357
358 #endif // _GLOBALS_HXX