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