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