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