]> git.mxchange.org Git - flightgear.git/blob - src/Main/globals.hxx
Reset: clear effects cache
[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 typedef std::vector<SGPath> PathList;
37
38 // Forward declarations
39
40 // This file is included, directly or indirectly, almost everywhere in
41 // FlightGear, so if any of its dependencies changes, most of the sim
42 // has to be recompiled.  Using these forward declarations helps us to
43 // avoid including a lot of header files (and thus, a lot of
44 // dependencies).  Since Most of the methods simply set or return
45 // pointers, we don't need to know anything about the class details
46 // anyway.
47
48 class SGEphemeris;
49 class SGCommandMgr;
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 FGControls;
60 class FGTACANList;
61 class FGLocale;
62 class FGRouteMgr;
63 class FGScenery;
64 class FGTileMgr;
65 class FGViewMgr;
66 class FGViewer;
67 class FGRenderer;
68 class FGFontCache;
69 class FGSampleQueue;
70
71 /**
72  * Bucket for subsystem pointers representing the sim's state.
73  */
74
75 class FGGlobals
76 {
77
78 private:
79
80     // properties, destroy last
81     SGPropertyNode_ptr props;
82     SGPropertyNode_ptr initial_state;
83
84     // localization
85     FGLocale* locale;
86
87     FGRenderer *renderer;
88     SGSubsystemMgr *subsystem_mgr;
89     SGEventMgr *event_mgr;
90
91     // Number of milliseconds elapsed since the start of the program.
92     double sim_time_sec;
93
94     // Root of FlightGear data tree
95     std::string fg_root;
96
97     /**
98      * locations to search for (non-scenery) data. 
99      */
100     PathList additional_data_paths;
101     
102     // Users home directory for data
103     std::string fg_home;
104
105     // Roots of FlightGear scenery tree
106     string_list fg_scenery;
107
108     std::string browser;
109
110     // Time structure
111     SGTime *time_params;
112
113     // Sky structures
114     SGEphemeris *ephem;
115
116     // Material properties library
117     SGMaterialLib *matlib;
118
119     // Global autopilot "route"
120     FGRouteMgr *route_mgr;
121
122     // ATC manager
123     FGATISMgr *ATIS_mgr;
124
125     // control input state
126     FGControls *controls;
127
128     // viewer manager
129     FGViewMgr *viewmgr;
130
131     SGCommandMgr *commands;
132
133     // list of serial port-like configurations
134     string_list *channel_options_list;
135
136     // A list of initial waypoints that are read from the command line
137     // and or flight-plan file during initialization
138     string_list *initial_waypoints;
139
140     // FlightGear scenery manager
141     SGSharedPtr<FGScenery> _scenery;
142
143     // Tile manager
144     SGSharedPtr<FGTileMgr> _tile_mgr;
145
146     FGFontCache *fontcache;
147
148     // Navigational Aids
149     FGTACANList *channellist;
150
151     /// roots of Aircraft trees
152     string_list fg_aircraft_dirs;
153
154     bool haveUserSettings;
155
156     SGPropertyNode_ptr positionLon, positionLat, positionAlt;
157     SGPropertyNode_ptr viewLon, viewLat, viewAlt;
158     SGPropertyNode_ptr orientHeading, orientPitch, orientRoll;
159     
160     /**
161      * helper to initialise standard properties on a new property tree
162      */
163     void initProperties();
164     
165     SGSharedPtr<FGSampleQueue> _chatter_queue;
166 public:
167
168     FGGlobals();
169     virtual ~FGGlobals();
170
171     virtual FGRenderer *get_renderer () const;
172     void set_renderer(FGRenderer* render);
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     /**
196      * Get list of data locations. fg_root is always the final item in the
197      * result.
198      */
199     PathList get_data_paths() const;
200     
201     /**
202      * Get data locations which contain the file path suffix. Eg pass ing
203      * 'AI/Traffic' to get all data paths which define <path>/AI/Traffic subdir
204      */
205     PathList get_data_paths(const std::string& suffix) const;
206     
207     void append_data_path(const SGPath& path);
208     
209     /**
210      * Given a path suffix (eg 'Textures' or 'AI/Traffic'), find the
211      * first data directory which defines it.
212      */
213     SGPath find_data_dir(const std::string& pathSuffix) const;
214     
215     inline const std::string &get_fg_home () const { return fg_home; }
216     void set_fg_home (const std::string &home);
217
218     inline const string_list &get_fg_scenery () const { return fg_scenery; }
219     void append_fg_scenery (const std::string &scenery);
220
221     const string_list& get_aircraft_paths() const { return fg_aircraft_dirs; }
222     void append_aircraft_path(const std::string& path);
223     void append_aircraft_paths(const std::string& path);
224     
225     /**
226      * Given a path to an aircraft-related resource file, resolve it
227      * against the appropriate root. This means looking at the location
228      * defined by /sim/aircraft-dir, and then aircraft_path in turn,
229      * finishing with fg_root/Aircraft.
230      *
231      * if the path could not be resolved, an empty path is returned.
232      */
233     SGPath resolve_aircraft_path(const std::string& branch) const;
234     
235     /**
236      * Same as above, but test for non 'Aircraft/' branch paths, and
237      * always resolve them against fg_root.
238      */
239     SGPath resolve_maybe_aircraft_path(const std::string& branch) const;
240     
241     /**
242      * Search in the following directories:
243      *
244      *  1. Root directory of current aircraft (defined by /sim/aircraft-dir)
245      *  2. All aircraft directories if branch starts with Aircraft/
246      *  3. fg_data directory
247      */
248     SGPath resolve_resource_path(const std::string& branch) const;
249
250     inline const std::string &get_browser () const { return browser; }
251     void set_browser (const std::string &b) { browser = b; }
252
253     long int get_warp() const;
254     void set_warp( long int w );
255
256     long int get_warp_delta() const;
257     void set_warp_delta( long int d );
258
259     inline SGTime *get_time_params() const { return time_params; }
260     inline void set_time_params( SGTime *t ) { time_params = t; }
261
262     inline SGEphemeris *get_ephem() const { return ephem; }
263     inline void set_ephem( SGEphemeris *e ) { ephem = e; }
264
265     inline SGMaterialLib *get_matlib() const { return matlib; }
266     void set_matlib( SGMaterialLib *m );
267
268     inline FGATISMgr *get_ATIS_mgr() const { return ATIS_mgr; }
269     inline void set_ATIS_mgr( FGATISMgr *a ) {ATIS_mgr = a; }
270
271     inline FGControls *get_controls() const { return controls; }
272     inline void set_controls( FGControls *c ) { controls = c; }
273
274     inline FGViewMgr *get_viewmgr() const { return viewmgr; }
275     inline void set_viewmgr( FGViewMgr *vm ) { viewmgr = vm; }
276     FGViewer *get_current_view() const;
277
278     inline SGPropertyNode *get_props () { return props; }
279
280     /**
281      * @brief reset the property tree to new, empty tree. Ensure all
282      * subsystems are shutdown and unbound before call this.
283      */
284     void resetPropertyRoot();
285     
286     inline FGLocale* get_locale () { return locale; }
287
288     inline SGCommandMgr *get_commands () { return commands; }
289
290     SGGeod get_aircraft_position() const;
291
292     SGVec3d get_aircraft_position_cart() const;
293
294     void get_aircraft_orientation(double& heading, double& pitch, double& roll);
295   
296     SGGeod get_view_position() const;
297   
298     SGVec3d get_view_position_cart() const;
299   
300     inline string_list *get_channel_options_list () {
301         return channel_options_list;
302     }
303     inline void set_channel_options_list( string_list *l ) {
304         channel_options_list = l;
305     }
306
307     inline string_list *get_initial_waypoints () {
308         return initial_waypoints;
309     }
310   
311     inline void set_initial_waypoints (string_list *list) {
312         initial_waypoints = list;
313     }
314
315     FGScenery * get_scenery () const;
316     void set_scenery ( FGScenery *s );
317
318     FGTileMgr * get_tile_mgr () const;
319     void set_tile_mgr ( FGTileMgr *t );
320
321     inline FGFontCache *get_fontcache() const { return fontcache; }
322   
323     inline FGTACANList *get_channellist() const { return channellist; }
324     inline void set_channellist( FGTACANList *c ) { channellist = c; }
325   
326    /**
327      * Save the current state as the initial state.
328      */
329     void saveInitialState ();
330
331
332     /**
333      * Restore the saved initial state, if any.
334      */
335     void restoreInitialState ();
336
337     /**
338      * Load user settings from autosave.xml
339      */
340     void loadUserSettings(const SGPath& datapath);
341
342     /**
343      * Save user settings in autosave.xml
344      */
345     void saveUserSettings();
346     
347     FGSampleQueue* get_chatter_queue() const;
348     void set_chatter_queue(FGSampleQueue* queue);
349 };
350
351
352 extern FGGlobals *globals;
353
354
355 #endif // _GLOBALS_HXX