]> git.mxchange.org Git - flightgear.git/blob - src/Main/globals.hxx
Canvas: update for new bounding box getters.
[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
82     // localization
83     FGLocale* locale;
84
85     FGRenderer *renderer;
86     SGSubsystemMgr *subsystem_mgr;
87     SGEventMgr *event_mgr;
88
89     // Number of milliseconds elapsed since the start of the program.
90     double sim_time_sec;
91
92     // Root of FlightGear data tree
93     std::string fg_root;
94
95     /**
96      * locations to search for (non-scenery) data. 
97      */
98     PathList additional_data_paths;
99     
100     // Users home directory for data
101     std::string fg_home;
102
103     // Roots of FlightGear scenery tree
104     string_list fg_scenery;
105
106     std::string browser;
107
108     // Time structure
109     SGTime *time_params;
110
111     // Sky structures
112     SGEphemeris *ephem;
113
114     // Material properties library
115     SGSharedPtr<SGMaterialLib> matlib;
116
117     // Global autopilot "route"
118     FGRouteMgr *route_mgr;
119
120     // control input state
121     FGControls *controls;
122
123     // viewer manager
124     FGViewMgr *viewmgr;
125
126     SGCommandMgr *commands;
127
128     // list of serial port-like configurations
129     string_list *channel_options_list;
130
131     // A list of initial waypoints that are read from the command line
132     // and or flight-plan file during initialization
133     string_list *initial_waypoints;
134
135     // FlightGear scenery manager
136     SGSharedPtr<FGScenery> _scenery;
137
138     // Tile manager
139     SGSharedPtr<FGTileMgr> _tile_mgr;
140
141     FGFontCache *fontcache;
142
143     // Navigational Aids
144     FGTACANList *channellist;
145
146     /// roots of Aircraft trees
147     string_list fg_aircraft_dirs;
148
149     bool haveUserSettings;
150
151     SGPropertyNode_ptr positionLon, positionLat, positionAlt;
152     SGPropertyNode_ptr viewLon, viewLat, viewAlt;
153     SGPropertyNode_ptr orientHeading, orientPitch, orientRoll;
154     
155     /**
156      * helper to initialise standard properties on a new property tree
157      */
158     void initProperties();
159     
160     SGSharedPtr<FGSampleQueue> _chatter_queue;
161     
162     void cleanupListeners();
163     
164     typedef std::vector<SGPropertyChangeListener*> SGPropertyChangeListenerVec;
165     SGPropertyChangeListenerVec _listeners_to_cleanup;
166     
167 public:
168
169     FGGlobals();
170     virtual ~FGGlobals();
171
172     virtual FGRenderer *get_renderer () const;
173     void set_renderer(FGRenderer* render);
174     
175     virtual SGSubsystemMgr *get_subsystem_mgr () const;
176
177     virtual SGSubsystem *get_subsystem (const char * name);
178
179     virtual void add_subsystem (const char * name,
180                                 SGSubsystem * subsystem,
181                                 SGSubsystemMgr::GroupType
182                                 type = SGSubsystemMgr::GENERAL,
183                                 double min_time_sec = 0);
184
185     virtual SGEventMgr *get_event_mgr () const;
186
187     virtual SGSoundMgr *get_soundmgr () const;
188
189     inline double get_sim_time_sec () const { return sim_time_sec; }
190     inline void inc_sim_time_sec (double dt) { sim_time_sec += dt; }
191     inline void set_sim_time_sec (double t) { sim_time_sec = t; }
192
193     inline const std::string &get_fg_root () const { return fg_root; }
194     void set_fg_root (const std::string &root);
195
196     /**
197      * Get list of data locations. fg_root is always the final item in the
198      * result.
199      */
200     PathList get_data_paths() const;
201     
202     /**
203      * Get data locations which contain the file path suffix. Eg pass ing
204      * 'AI/Traffic' to get all data paths which define <path>/AI/Traffic subdir
205      */
206     PathList get_data_paths(const std::string& suffix) const;
207     
208     void append_data_path(const SGPath& path);
209     
210     /**
211      * Given a path suffix (eg 'Textures' or 'AI/Traffic'), find the
212      * first data directory which defines it.
213      */
214     SGPath find_data_dir(const std::string& pathSuffix) const;
215     
216     inline const std::string &get_fg_home () const { return fg_home; }
217     void set_fg_home (const std::string &home);
218
219     inline const string_list &get_fg_scenery () const { return fg_scenery; }
220     void append_fg_scenery (const std::string &scenery);
221
222     void clear_fg_scenery();
223   
224     const string_list& get_aircraft_paths() const { return fg_aircraft_dirs; }
225     void append_aircraft_path(const std::string& path);
226     void append_aircraft_paths(const std::string& path);
227     
228     /**
229      * Given a path to an aircraft-related resource file, resolve it
230      * against the appropriate root. This means looking at the location
231      * defined by /sim/aircraft-dir, and then aircraft_path in turn,
232      * finishing with fg_root/Aircraft.
233      *
234      * if the path could not be resolved, an empty path is returned.
235      */
236     SGPath resolve_aircraft_path(const std::string& branch) const;
237     
238     /**
239      * Same as above, but test for non 'Aircraft/' branch paths, and
240      * always resolve them against fg_root.
241      */
242     SGPath resolve_maybe_aircraft_path(const std::string& branch) const;
243     
244     /**
245      * Search in the following directories:
246      *
247      *  1. Root directory of current aircraft (defined by /sim/aircraft-dir)
248      *  2. All aircraft directories if branch starts with Aircraft/
249      *  3. fg_data directory
250      */
251     SGPath resolve_resource_path(const std::string& branch) const;
252
253     inline const std::string &get_browser () const { return browser; }
254     void set_browser (const std::string &b) { browser = b; }
255
256     long int get_warp() const;
257     void set_warp( long int w );
258
259     long int get_warp_delta() const;
260     void set_warp_delta( long int d );
261
262     inline SGTime *get_time_params() const { return time_params; }
263     inline void set_time_params( SGTime *t ) { time_params = t; }
264
265     inline SGEphemeris *get_ephem() const { return ephem; }
266     inline void set_ephem( SGEphemeris *e ) { ephem = e; }
267
268     inline SGMaterialLib *get_matlib() const { return matlib; }
269     void set_matlib( SGMaterialLib *m );
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      * Load user settings from autosave.xml
328      */
329     void loadUserSettings(const SGPath& datapath);
330
331     /**
332      * Save user settings in autosave.xml
333      */
334     void saveUserSettings();
335     
336     FGSampleQueue* get_chatter_queue() const;
337     void set_chatter_queue(FGSampleQueue* queue);
338     
339     void addListenerToCleanup(SGPropertyChangeListener* l);
340 };
341
342
343 extern FGGlobals *globals;
344
345
346 #endif // _GLOBALS_HXX