]> git.mxchange.org Git - flightgear.git/blob - src/Main/globals.hxx
Initial package-system integration.
[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 SGEphemeris;
50 class SGCommandMgr;
51 class SGMaterialLib;
52 class SGPropertyNode;
53 class SGTime;
54 class SGEventMgr;
55 class SGSubsystemMgr;
56 class SGSubsystem;
57 class SGSoundMgr;
58
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 namespace simgear { namespace pkg {
72   class Root;
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
87     // localization
88     FGLocale* locale;
89
90     FGRenderer *renderer;
91     SGSubsystemMgr *subsystem_mgr;
92     SGEventMgr *event_mgr;
93
94     // Number of milliseconds elapsed since the start of the program.
95     double sim_time_sec;
96
97     // Root of FlightGear data tree
98     std::string fg_root;
99
100     /**
101      * locations to search for (non-scenery) data. 
102      */
103     PathList additional_data_paths;
104     
105     // Users home directory for data
106     std::string fg_home;
107
108     // Roots of FlightGear scenery tree
109     string_list fg_scenery;
110
111     std::string browser;
112
113     // Time structure
114     SGTime *time_params;
115
116     // Sky structures
117     SGEphemeris *ephem;
118
119     // Material properties library
120     SGSharedPtr<SGMaterialLib> matlib;
121
122     // Global autopilot "route"
123     FGRouteMgr *route_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     
167     void cleanupListeners();
168     
169     typedef std::vector<SGPropertyChangeListener*> SGPropertyChangeListenerVec;
170     SGPropertyChangeListenerVec _listeners_to_cleanup;
171   
172     SGSharedPtr<simgear::pkg::Root> _packageRoot;
173 public:
174
175     FGGlobals();
176     virtual ~FGGlobals();
177
178     virtual FGRenderer *get_renderer () const;
179     void set_renderer(FGRenderer* render);
180     
181     virtual SGSubsystemMgr *get_subsystem_mgr () const;
182
183     virtual SGSubsystem *get_subsystem (const char * name);
184
185     virtual void add_subsystem (const char * name,
186                                 SGSubsystem * subsystem,
187                                 SGSubsystemMgr::GroupType
188                                 type = SGSubsystemMgr::GENERAL,
189                                 double min_time_sec = 0);
190
191     virtual SGEventMgr *get_event_mgr () const;
192
193     virtual 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     void append_fg_scenery (const std::string &scenery);
227
228     void clear_fg_scenery();
229   
230     const string_list& get_aircraft_paths() const { return fg_aircraft_dirs; }
231     void append_aircraft_path(const std::string& path);
232     void append_aircraft_paths(const std::string& path);
233     
234     /**
235      * Given a path to an aircraft-related resource file, resolve it
236      * against the appropriate root. This means looking at the location
237      * defined by /sim/aircraft-dir, and then aircraft_path in turn,
238      * finishing with fg_root/Aircraft.
239      *
240      * if the path could not be resolved, an empty path is returned.
241      */
242     SGPath resolve_aircraft_path(const std::string& branch) const;
243     
244     /**
245      * Same as above, but test for non 'Aircraft/' branch paths, and
246      * always resolve them against fg_root.
247      */
248     SGPath resolve_maybe_aircraft_path(const std::string& branch) const;
249     
250     /**
251      * Search in the following directories:
252      *
253      *  1. Root directory of current aircraft (defined by /sim/aircraft-dir)
254      *  2. All aircraft directories if branch starts with Aircraft/
255      *  3. fg_data directory
256      */
257     SGPath resolve_resource_path(const std::string& branch) const;
258
259     inline const std::string &get_browser () const { return browser; }
260     void set_browser (const std::string &b) { browser = b; }
261
262     long int get_warp() const;
263     void set_warp( long int w );
264
265     long int get_warp_delta() const;
266     void set_warp_delta( long int d );
267
268     inline SGTime *get_time_params() const { return time_params; }
269     inline void set_time_params( SGTime *t ) { time_params = t; }
270
271     inline SGEphemeris *get_ephem() const { return ephem; }
272     inline void set_ephem( SGEphemeris *e ) { ephem = e; }
273
274     inline SGMaterialLib *get_matlib() const { return matlib; }
275     void set_matlib( SGMaterialLib *m );
276
277     inline FGControls *get_controls() const { return controls; }
278     inline void set_controls( FGControls *c ) { controls = c; }
279
280     inline FGViewMgr *get_viewmgr() const { return viewmgr; }
281     inline void set_viewmgr( FGViewMgr *vm ) { viewmgr = vm; }
282     FGViewer *get_current_view() const;
283
284     inline SGPropertyNode *get_props () { return props; }
285
286     /**
287      * @brief reset the property tree to new, empty tree. Ensure all
288      * subsystems are shutdown and unbound before call this.
289      */
290     void resetPropertyRoot();
291     
292     inline FGLocale* get_locale () { return locale; }
293
294     inline SGCommandMgr *get_commands () { return commands; }
295
296     SGGeod get_aircraft_position() const;
297
298     SGVec3d get_aircraft_position_cart() const;
299
300     void get_aircraft_orientation(double& heading, double& pitch, double& roll);
301   
302     SGGeod get_view_position() const;
303   
304     SGVec3d get_view_position_cart() const;
305   
306     inline string_list *get_channel_options_list () {
307         return channel_options_list;
308     }
309     inline void set_channel_options_list( string_list *l ) {
310         channel_options_list = l;
311     }
312
313     inline string_list *get_initial_waypoints () {
314         return initial_waypoints;
315     }
316   
317     inline void set_initial_waypoints (string_list *list) {
318         initial_waypoints = list;
319     }
320
321     FGScenery * get_scenery () const;
322     void set_scenery ( FGScenery *s );
323
324     FGTileMgr * get_tile_mgr () const;
325     void set_tile_mgr ( FGTileMgr *t );
326
327     inline FGFontCache *get_fontcache() const { return fontcache; }
328   
329     inline FGTACANList *get_channellist() const { return channellist; }
330     inline void set_channellist( FGTACANList *c ) { channellist = c; }
331
332     /**
333      * Load user settings from autosave.xml
334      */
335     void loadUserSettings(const SGPath& datapath);
336
337     /**
338      * Save user settings in autosave.xml
339      */
340     void saveUserSettings();
341     
342     FGSampleQueue* get_chatter_queue() const;
343     void set_chatter_queue(FGSampleQueue* queue);
344     
345     void addListenerToCleanup(SGPropertyChangeListener* l);
346   
347     simgear::pkg::Root* packageRoot();
348     void setPackageRoot(const SGSharedPtr<simgear::pkg::Root>& p);
349 };
350
351
352 extern FGGlobals *globals;
353
354
355 #endif // _GLOBALS_HXX