]> git.mxchange.org Git - flightgear.git/blob - src/Main/globals.hxx
Improve timing statistics
[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     // Time structure
108     SGTime *time_params;
109
110     // Sky structures
111     SGEphemeris *ephem;
112
113     // Magnetic Variation
114     SGMagVar *mag;
115
116     // Material properties library
117     SGMaterialLib *matlib;
118
119     // Global autopilot "route"
120     FGRouteMgr *route_mgr;
121
122     // 2D panel
123     FGPanel *current_panel;
124
125     // ATC manager
126     FGATCMgr *ATC_mgr;
127
128     // control input state
129     FGControls *controls;
130
131     // viewer manager
132     FGViewMgr *viewmgr;
133
134     SGCommandMgr *commands;
135
136   //FGFlightPlanDispatcher *fpDispatcher;
137
138     FGAircraftModel *acmodel;
139
140     FGModelMgr * model_mgr;
141
142     // list of serial port-like configurations
143     string_list *channel_options_list;
144
145     // A list of initial waypoints that are read from the command line
146     // and or flight-plan file during initialization
147     string_list *initial_waypoints;
148
149     // FlightGear scenery manager
150     FGScenery *scenery;
151
152     // Tile manager
153     FGTileMgr *tile_mgr;
154
155     FGFontCache *fontcache;
156
157     // Navigational Aids
158     FGNavList *navlist;
159     FGNavList *loclist;
160     FGNavList *gslist;
161     FGNavList *dmelist;
162     FGNavList *tacanlist;
163     FGNavList *carrierlist;
164     FGTACANList *channellist;
165
166     /// roots of Aircraft trees
167     string_list fg_aircraft_dirs;
168 public:
169
170     FGGlobals();
171     virtual ~FGGlobals();
172
173     virtual FGRenderer *get_renderer () const;
174
175     virtual SGSubsystemMgr *get_subsystem_mgr () const;
176
177     virtual SGSubsystem *get_subsystem (const char * name);
178
179     virtual void add_subsystem (const char * name,
180                                 SGSubsystem * subsystem,
181                                 SGSubsystemMgr::GroupType
182                                 type = SGSubsystemMgr::GENERAL,
183                                 double min_time_sec = 0);
184
185     virtual SGEventMgr *get_event_mgr () const;
186
187     virtual SGSoundMgr *get_soundmgr () const;
188
189     inline double get_sim_time_sec () const { return sim_time_sec; }
190     inline void inc_sim_time_sec (double dt) { sim_time_sec += dt; }
191     inline void set_sim_time_sec (double t) { sim_time_sec = t; }
192
193     inline const std::string &get_fg_root () const { return fg_root; }
194     void set_fg_root (const std::string &root);
195
196     inline const string_list &get_fg_scenery () const { return fg_scenery; }
197     void set_fg_scenery (const std::string &scenery);
198
199     const string_list& get_aircraft_paths() const { return fg_aircraft_dirs; }
200     void append_aircraft_path(const std::string& path);
201     void append_aircraft_paths(const std::string& path);
202     
203     /**
204      * Given a path to an aircraft-related resource file, resolve it
205      * against the appropriate root. This means looking at the location
206      * defined by /sim/aircraft-dir, and then aircraft_path in turn,
207      * finishing with fg_root/Aircraft.
208      *
209      * if the path could not be resolved, an empty path is returned.
210      */
211     SGPath resolve_aircraft_path(const std::string& branch) const;
212     
213     /**
214      * Same as above, but test for non 'Aircraft/' branch paths, and
215      * always resolve them against fg_root.
216      */
217     SGPath resolve_maybe_aircraft_path(const std::string& branch) const;
218     
219     inline const std::string &get_browser () const { return browser; }
220     void set_browser (const std::string &b) { browser = b; }
221
222     long int get_warp() const;
223     void set_warp( long int w );
224
225     long int get_warp_delta() const;
226     void set_warp_delta( long int d );
227
228     inline SGTime *get_time_params() const { return time_params; }
229     inline void set_time_params( SGTime *t ) { time_params = t; }
230
231     inline SGEphemeris *get_ephem() const { return ephem; }
232     inline void set_ephem( SGEphemeris *e ) { ephem = e; }
233
234     inline SGMagVar *get_mag() const { return mag; }
235     inline void set_mag( SGMagVar *m ) { mag = m; }
236
237     inline SGMaterialLib *get_matlib() const { return matlib; }
238     inline void set_matlib( SGMaterialLib *m ) { matlib = m; }
239
240     inline FGATCMgr *get_ATC_mgr() const { return ATC_mgr; }
241     inline void set_ATC_mgr( FGATCMgr *a ) {ATC_mgr = a; }
242
243     inline FGPanel *get_current_panel() const { return current_panel; }
244     inline void set_current_panel( FGPanel *cp ) { current_panel = cp; }
245
246     inline FGControls *get_controls() const { return controls; }
247     inline void set_controls( FGControls *c ) { controls = c; }
248
249     inline FGViewMgr *get_viewmgr() const { return viewmgr; }
250     inline void set_viewmgr( FGViewMgr *vm ) { viewmgr = vm; }
251     FGViewer *get_current_view() const;
252
253     inline SGPropertyNode *get_props () { return props; }
254     inline void set_props( SGPropertyNode *n ) { props = n; }
255
256     inline SGPropertyNode *get_locale () { return locale; }
257     inline void set_locale( SGPropertyNode *n ) { locale = n; }
258
259     inline SGCommandMgr *get_commands () { return commands; }
260
261     inline FGAircraftModel *get_aircraft_model () { return acmodel; }
262
263     inline void set_aircraft_model (FGAircraftModel * model)
264     {
265         acmodel = model;
266     }
267
268     inline FGModelMgr *get_model_mgr () { return model_mgr; }
269
270     inline void set_model_mgr (FGModelMgr * mgr)
271     {
272       model_mgr = mgr;
273     }
274
275     inline string_list *get_channel_options_list () {
276         return channel_options_list;
277     }
278     inline void set_channel_options_list( string_list *l ) {
279         channel_options_list = l;
280     }
281
282     inline string_list *get_initial_waypoints () {
283         return initial_waypoints;
284     }
285   
286     inline void set_initial_waypoints (string_list *list) {
287         initial_waypoints = list;
288     }
289
290     inline FGScenery * get_scenery () const { return scenery; }
291     inline void set_scenery ( FGScenery *s ) { scenery = s; }
292
293     inline FGTileMgr * get_tile_mgr () const { return tile_mgr; }
294     inline void set_tile_mgr ( FGTileMgr *t ) { tile_mgr = t; }
295
296     inline FGFontCache *get_fontcache() const { return fontcache; }
297
298     inline FGNavList *get_navlist() const { return navlist; }
299     inline void set_navlist( FGNavList *n ) { navlist = n; }
300     inline FGNavList *get_loclist() const { return loclist; }
301     inline void set_loclist( FGNavList *n ) { loclist = n; }
302     inline FGNavList *get_gslist() const { return gslist; }
303     inline void set_gslist( FGNavList *n ) { gslist = n; }
304     inline FGNavList *get_dmelist() const { return dmelist; }
305     inline void set_dmelist( FGNavList *n ) { dmelist = n; }
306     inline FGNavList *get_tacanlist() const { return tacanlist; }
307     inline void set_tacanlist( FGNavList *n ) { tacanlist = n; }
308     inline FGNavList *get_carrierlist() const { return carrierlist; }
309     inline void set_carrierlist( FGNavList *n ) { carrierlist = n; }
310     inline FGTACANList *get_channellist() const { return channellist; }
311     inline void set_channellist( FGTACANList *c ) { channellist = c; }
312
313    /**
314      * Save the current state as the initial state.
315      */
316     void saveInitialState ();
317
318
319     /**
320      * Restore the saved initial state, if any.
321      */
322     void restoreInitialState ();
323
324 };
325
326
327 extern FGGlobals *globals;
328
329
330 #endif // _GLOBALS_HXX