]> git.mxchange.org Git - flightgear.git/blob - src/Main/globals.hxx
a057abc0813fdec96277fff532e5e4f52bf2e128
[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 SGMaterialLib;
50 class SGPropertyNode;
51 class SGTime;
52 class SGEventMgr;
53 class SGSubsystemMgr;
54 class SGSubsystem;
55 class SGSoundMgr;
56
57 class FGATISMgr;
58 class FGAircraftModel;
59 class FGControls;
60 class FGFlightPlanDispatcher;
61 class FGNavList;
62 class FGTACANList;
63 class FGLocale;
64 class FGModelMgr;
65 class FGRouteMgr;
66 class FGScenery;
67 class FGTileMgr;
68 class FGViewMgr;
69 class FGViewer;
70 class FGRenderer;
71 class FGFontCache;
72
73
74 /**
75  * Bucket for subsystem pointers representing the sim's state.
76  */
77
78 class FGGlobals
79 {
80
81 private:
82
83     // properties, destroy last
84     SGPropertyNode_ptr props;
85     SGPropertyNode_ptr initial_state;
86
87     // localization
88     FGLocale* locale;
89
90     FGRenderer *renderer;
91     SGSubsystemMgr *subsystem_mgr;
92     SGEventMgr *event_mgr;
93
94     // Number of milliseconds elapsed since the start of the program.
95     double sim_time_sec;
96
97     // Root of FlightGear data tree
98     std::string fg_root;
99
100     // Users home directory for data
101     std::string fg_home;
102
103     // Roots of FlightGear scenery tree
104     string_list fg_scenery;
105
106     std::string browser;
107
108     // Time structure
109     SGTime *time_params;
110
111     // Sky structures
112     SGEphemeris *ephem;
113
114     // Material properties library
115     SGMaterialLib *matlib;
116
117     // Global autopilot "route"
118     FGRouteMgr *route_mgr;
119
120     // ATC manager
121     FGATISMgr *ATIS_mgr;
122
123     // control input state
124     FGControls *controls;
125
126     // viewer manager
127     FGViewMgr *viewmgr;
128
129     SGCommandMgr *commands;
130
131   //FGFlightPlanDispatcher *fpDispatcher;
132
133     FGAircraftModel *acmodel;
134
135     FGModelMgr * model_mgr;
136
137     // list of serial port-like configurations
138     string_list *channel_options_list;
139
140     // A list of initial waypoints that are read from the command line
141     // and or flight-plan file during initialization
142     string_list *initial_waypoints;
143
144     // FlightGear scenery manager
145     FGScenery *scenery;
146
147     // Tile manager
148     FGTileMgr *tile_mgr;
149
150     FGFontCache *fontcache;
151
152     // Navigational Aids
153     FGNavList *navlist;
154     FGNavList *loclist;
155     FGNavList *gslist;
156     FGNavList *dmelist;
157     FGNavList *tacanlist;
158     FGNavList *carrierlist;
159     FGTACANList *channellist;
160
161     /// roots of Aircraft trees
162     string_list fg_aircraft_dirs;
163
164     bool haveUserSettings;
165
166 public:
167
168     FGGlobals();
169     virtual ~FGGlobals();
170
171     virtual FGRenderer *get_renderer () const;
172
173     virtual SGSubsystemMgr *get_subsystem_mgr () const;
174
175     virtual SGSubsystem *get_subsystem (const char * name);
176
177     virtual void add_subsystem (const char * name,
178                                 SGSubsystem * subsystem,
179                                 SGSubsystemMgr::GroupType
180                                 type = SGSubsystemMgr::GENERAL,
181                                 double min_time_sec = 0);
182
183     virtual SGEventMgr *get_event_mgr () const;
184
185     virtual SGSoundMgr *get_soundmgr () const;
186
187     inline double get_sim_time_sec () const { return sim_time_sec; }
188     inline void inc_sim_time_sec (double dt) { sim_time_sec += dt; }
189     inline void set_sim_time_sec (double t) { sim_time_sec = t; }
190
191     inline const std::string &get_fg_root () const { return fg_root; }
192     void set_fg_root (const std::string &root);
193
194     inline const std::string &get_fg_home () const { return fg_home; }
195     void set_fg_home (const std::string &home);
196
197     inline const string_list &get_fg_scenery () const { return fg_scenery; }
198     void append_fg_scenery (const std::string &scenery);
199
200     const string_list& get_aircraft_paths() const { return fg_aircraft_dirs; }
201     void append_aircraft_path(const std::string& path);
202     void append_aircraft_paths(const std::string& path);
203     
204     /**
205      * Given a path to an aircraft-related resource file, resolve it
206      * against the appropriate root. This means looking at the location
207      * defined by /sim/aircraft-dir, and then aircraft_path in turn,
208      * finishing with fg_root/Aircraft.
209      *
210      * if the path could not be resolved, an empty path is returned.
211      */
212     SGPath resolve_aircraft_path(const std::string& branch) const;
213     
214     /**
215      * Same as above, but test for non 'Aircraft/' branch paths, and
216      * always resolve them against fg_root.
217      */
218     SGPath resolve_maybe_aircraft_path(const std::string& branch) const;
219     
220     /**
221      * Search in the following directories:
222      *
223      *  1. Root directory of current aircraft (defined by /sim/aircraft-dir)
224      *  2. All aircraft directories if branch starts with Aircraft/
225      *  3. fg_data directory
226      */
227     SGPath resolve_ressource_path(const std::string& branch) const;
228
229     inline const std::string &get_browser () const { return browser; }
230     void set_browser (const std::string &b) { browser = b; }
231
232     long int get_warp() const;
233     void set_warp( long int w );
234
235     long int get_warp_delta() const;
236     void set_warp_delta( long int 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 SGMaterialLib *get_matlib() const { return matlib; }
245     inline void set_matlib( SGMaterialLib *m ) { matlib = m; }
246
247     inline FGATISMgr *get_ATIS_mgr() const { return ATIS_mgr; }
248     inline void set_ATIS_mgr( FGATISMgr *a ) {ATIS_mgr = a; }
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 FGLocale* get_locale () { return locale; }
261
262     inline SGCommandMgr *get_commands () { return commands; }
263
264     inline FGAircraftModel *get_aircraft_model () { return acmodel; }
265
266     inline void set_aircraft_model (FGAircraftModel * model)
267     {
268         acmodel = model;
269     }
270
271     SGGeod get_aircraft_position() const;
272
273     SGVec3d get_aircraft_positon_cart() const;
274     
275     inline FGModelMgr *get_model_mgr () { return model_mgr; }
276
277     inline void set_model_mgr (FGModelMgr * mgr)
278     {
279       model_mgr = mgr;
280     }
281
282     inline string_list *get_channel_options_list () {
283         return channel_options_list;
284     }
285     inline void set_channel_options_list( string_list *l ) {
286         channel_options_list = l;
287     }
288
289     inline string_list *get_initial_waypoints () {
290         return initial_waypoints;
291     }
292   
293     inline void set_initial_waypoints (string_list *list) {
294         initial_waypoints = list;
295     }
296
297     inline FGScenery * get_scenery () const { return scenery; }
298     inline void set_scenery ( FGScenery *s ) { scenery = s; }
299
300     inline FGTileMgr * get_tile_mgr () const { return tile_mgr; }
301     inline void set_tile_mgr ( FGTileMgr *t ) { tile_mgr = t; }
302
303     inline FGFontCache *get_fontcache() const { return fontcache; }
304
305 #if 0
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 #endif
319   
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      * Load user settings from autosave.xml
336      */
337     void loadUserSettings(const SGPath& datapath);
338
339     /**
340      * Save user settings in autosave.xml
341      */
342     void saveUserSettings();
343 };
344
345
346 extern FGGlobals *globals;
347
348
349 #endif // _GLOBALS_HXX