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