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