]> git.mxchange.org Git - flightgear.git/blob - src/Main/globals.hxx
Canvas: First version of new Canvas GUI system.
[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 FGATISMgr;
59 class FGAircraftModel;
60 class FGControls;
61 class FGFlightPlanDispatcher;
62 class FGNavList;
63 class FGTACANList;
64 class FGLocale;
65 class FGModelMgr;
66 class FGRouteMgr;
67 class FGScenery;
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     FGLocale* locale;
90
91     FGRenderer *renderer;
92     SGSubsystemMgr *subsystem_mgr;
93     SGEventMgr *event_mgr;
94
95     // Number of milliseconds elapsed since the start of the program.
96     double sim_time_sec;
97
98     // Root of FlightGear data tree
99     std::string fg_root;
100
101     // Roots of FlightGear scenery tree
102     string_list fg_scenery;
103
104     std::string browser;
105
106     // Time structure
107     SGTime *time_params;
108
109     // Sky structures
110     SGEphemeris *ephem;
111
112     // Magnetic Variation
113     SGMagVar *mag;
114
115     // Material properties library
116     SGMaterialLib *matlib;
117
118     // Global autopilot "route"
119     FGRouteMgr *route_mgr;
120
121     // ATC manager
122     FGATISMgr *ATIS_mgr;
123
124     // control input state
125     FGControls *controls;
126
127     // viewer manager
128     FGViewMgr *viewmgr;
129
130     SGCommandMgr *commands;
131
132   //FGFlightPlanDispatcher *fpDispatcher;
133
134     FGAircraftModel *acmodel;
135
136     FGModelMgr * model_mgr;
137
138     // list of serial port-like configurations
139     string_list *channel_options_list;
140
141     // A list of initial waypoints that are read from the command line
142     // and or flight-plan file during initialization
143     string_list *initial_waypoints;
144
145     // FlightGear scenery manager
146     FGScenery *scenery;
147
148     // Tile manager
149     FGTileMgr *tile_mgr;
150
151     FGFontCache *fontcache;
152
153     // Navigational Aids
154     FGNavList *navlist;
155     FGNavList *loclist;
156     FGNavList *gslist;
157     FGNavList *dmelist;
158     FGNavList *tacanlist;
159     FGNavList *carrierlist;
160     FGTACANList *channellist;
161
162     /// roots of Aircraft trees
163     string_list fg_aircraft_dirs;
164
165     bool haveUserSettings;
166
167 public:
168
169     FGGlobals();
170     virtual ~FGGlobals();
171
172     virtual FGRenderer *get_renderer () const;
173
174     virtual SGSubsystemMgr *get_subsystem_mgr () const;
175
176     virtual SGSubsystem *get_subsystem (const char * name);
177
178     virtual void add_subsystem (const char * name,
179                                 SGSubsystem * subsystem,
180                                 SGSubsystemMgr::GroupType
181                                 type = SGSubsystemMgr::GENERAL,
182                                 double min_time_sec = 0);
183
184     virtual SGEventMgr *get_event_mgr () const;
185
186     virtual SGSoundMgr *get_soundmgr () const;
187
188     inline double get_sim_time_sec () const { return sim_time_sec; }
189     inline void inc_sim_time_sec (double dt) { sim_time_sec += dt; }
190     inline void set_sim_time_sec (double t) { sim_time_sec = t; }
191
192     inline const std::string &get_fg_root () const { return fg_root; }
193     void set_fg_root (const std::string &root);
194
195     inline const string_list &get_fg_scenery () const { return fg_scenery; }
196     void append_fg_scenery (const std::string &scenery);
197
198     const string_list& get_aircraft_paths() const { return fg_aircraft_dirs; }
199     void append_aircraft_path(const std::string& path);
200     void append_aircraft_paths(const std::string& path);
201     
202     /**
203      * Given a path to an aircraft-related resource file, resolve it
204      * against the appropriate root. This means looking at the location
205      * defined by /sim/aircraft-dir, and then aircraft_path in turn,
206      * finishing with fg_root/Aircraft.
207      *
208      * if the path could not be resolved, an empty path is returned.
209      */
210     SGPath resolve_aircraft_path(const std::string& branch) const;
211     
212     /**
213      * Same as above, but test for non 'Aircraft/' branch paths, and
214      * always resolve them against fg_root.
215      */
216     SGPath resolve_maybe_aircraft_path(const std::string& branch) const;
217     
218     /**
219      * Search in the following directories:
220      *
221      *  1. Root directory of current aircraft (defined by /sim/aircraft-dir)
222      *  2. All aircraft directories if branch starts with Aircraft/
223      *  3. fg_data directory
224      */
225     SGPath resolve_ressource_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     long int get_warp() const;
231     void set_warp( long int w );
232
233     long int get_warp_delta() const;
234     void set_warp_delta( long int d );
235
236     inline SGTime *get_time_params() const { return time_params; }
237     inline void set_time_params( SGTime *t ) { time_params = t; }
238
239     inline SGEphemeris *get_ephem() const { return ephem; }
240     inline void set_ephem( SGEphemeris *e ) { ephem = e; }
241
242     inline SGMagVar *get_mag() const { return mag; }
243     inline void set_mag( SGMagVar *m ) { mag = m; }
244
245     inline SGMaterialLib *get_matlib() const { return matlib; }
246     inline void set_matlib( SGMaterialLib *m ) { matlib = m; }
247
248     inline FGATISMgr *get_ATIS_mgr() const { return ATIS_mgr; }
249     inline void set_ATIS_mgr( FGATISMgr *a ) {ATIS_mgr = a; }
250
251     inline FGControls *get_controls() const { return controls; }
252     inline void set_controls( FGControls *c ) { controls = c; }
253
254     inline FGViewMgr *get_viewmgr() const { return viewmgr; }
255     inline void set_viewmgr( FGViewMgr *vm ) { viewmgr = vm; }
256     FGViewer *get_current_view() const;
257
258     inline SGPropertyNode *get_props () { return props; }
259     inline void set_props( SGPropertyNode *n ) { props = n; }
260
261     inline FGLocale* get_locale () { return locale; }
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     const SGGeod & get_aircraft_position() const;
273
274     SGVec3d get_aircraft_positon_cart() const;
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 string_list *get_channel_options_list () {
284         return channel_options_list;
285     }
286     inline void set_channel_options_list( string_list *l ) {
287         channel_options_list = l;
288     }
289
290     inline string_list *get_initial_waypoints () {
291         return initial_waypoints;
292     }
293   
294     inline void set_initial_waypoints (string_list *list) {
295         initial_waypoints = list;
296     }
297
298     inline FGScenery * get_scenery () const { return scenery; }
299     inline void set_scenery ( FGScenery *s ) { scenery = s; }
300
301     inline FGTileMgr * get_tile_mgr () const { return tile_mgr; }
302     inline void set_tile_mgr ( FGTileMgr *t ) { tile_mgr = t; }
303
304     inline FGFontCache *get_fontcache() const { return fontcache; }
305
306     inline FGNavList *get_navlist() const { return navlist; }
307     inline void set_navlist( FGNavList *n ) { navlist = n; }
308     inline FGNavList *get_loclist() const { return loclist; }
309     inline void set_loclist( FGNavList *n ) { loclist = n; }
310     inline FGNavList *get_gslist() const { return gslist; }
311     inline void set_gslist( FGNavList *n ) { gslist = n; }
312     inline FGNavList *get_dmelist() const { return dmelist; }
313     inline void set_dmelist( FGNavList *n ) { dmelist = n; }
314     inline FGNavList *get_tacanlist() const { return tacanlist; }
315     inline void set_tacanlist( FGNavList *n ) { tacanlist = n; }
316     inline FGNavList *get_carrierlist() const { return carrierlist; }
317     inline void set_carrierlist( FGNavList *n ) { carrierlist = n; }
318     inline FGTACANList *get_channellist() const { return channellist; }
319     inline void set_channellist( FGTACANList *c ) { channellist = c; }
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      * Load user settings from autosave.xml
334      */
335     void loadUserSettings(const SGPath& datapath);
336
337     /**
338      * Save user settings in autosave.xml
339      */
340     void saveUserSettings();
341 };
342
343
344 extern FGGlobals *globals;
345
346
347 #endif // _GLOBALS_HXX