1 // globals.hxx -- Global state that needs to be shared among the sim modules
3 // Written by Curtis Olson, started July 2000.
5 // Copyright (C) 2000 Curtis L. Olson - http://www.flightgear.org/~curt
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.
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.
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.
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>
36 typedef std::vector<std::string> string_list;
37 typedef std::vector<SGPath> PathList;
39 // Forward declarations
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
71 namespace simgear { namespace pkg {
76 * Bucket for subsystem pointers representing the sim's state.
84 // properties, destroy last
85 SGPropertyNode_ptr props;
91 SGSubsystemMgr *subsystem_mgr;
92 SGEventMgr *event_mgr;
94 // Number of milliseconds elapsed since the start of the program.
97 // Root of FlightGear data tree
101 * locations to search for (non-scenery) data.
103 PathList additional_data_paths;
105 // Users home directory for data
108 // Roots of FlightGear scenery tree
109 string_list fg_scenery;
110 string_list secure_fg_scenery;
120 // Material properties library
121 SGSharedPtr<SGMaterialLib> matlib;
123 // Global autopilot "route"
124 FGRouteMgr *route_mgr;
126 // control input state
127 FGControls *controls;
132 SGCommandMgr *commands;
134 // list of serial port-like configurations
135 string_list *channel_options_list;
137 // A list of initial waypoints that are read from the command line
138 // and or flight-plan file during initialization
139 string_list *initial_waypoints;
141 // FlightGear scenery manager
142 SGSharedPtr<FGScenery> _scenery;
145 SGSharedPtr<FGTileMgr> _tile_mgr;
147 FGFontCache *fontcache;
150 FGTACANList *channellist;
152 /// roots of Aircraft trees
153 string_list fg_aircraft_dirs;
154 SGPath catalog_aircraft_dir;
156 bool haveUserSettings;
158 SGPropertyNode_ptr positionLon, positionLat, positionAlt;
159 SGPropertyNode_ptr viewLon, viewLat, viewAlt;
160 SGPropertyNode_ptr orientHeading, orientPitch, orientRoll;
163 * helper to initialise standard properties on a new property tree
165 void initProperties();
167 SGSharedPtr<FGSampleQueue> _chatter_queue;
169 void cleanupListeners();
171 typedef std::vector<SGPropertyChangeListener*> SGPropertyChangeListenerVec;
172 SGPropertyChangeListenerVec _listeners_to_cleanup;
174 SGSharedPtr<simgear::pkg::Root> _packageRoot;
178 virtual ~FGGlobals();
180 virtual FGRenderer *get_renderer () const;
181 void set_renderer(FGRenderer* render);
183 virtual SGSubsystemMgr *get_subsystem_mgr () const;
185 virtual SGSubsystem *get_subsystem (const char * name);
187 virtual void add_subsystem (const char * name,
188 SGSubsystem * subsystem,
189 SGSubsystemMgr::GroupType
190 type = SGSubsystemMgr::GENERAL,
191 double min_time_sec = 0);
193 virtual SGEventMgr *get_event_mgr () const;
195 virtual SGSoundMgr *get_soundmgr () const;
197 inline double get_sim_time_sec () const { return sim_time_sec; }
198 inline void inc_sim_time_sec (double dt) { sim_time_sec += dt; }
199 inline void set_sim_time_sec (double t) { sim_time_sec = t; }
201 inline const std::string &get_fg_root () const { return fg_root; }
202 void set_fg_root (const std::string &root);
205 * Get list of data locations. fg_root is always the final item in the
208 PathList get_data_paths() const;
211 * Get data locations which contain the file path suffix. Eg pass ing
212 * 'AI/Traffic' to get all data paths which define <path>/AI/Traffic subdir
214 PathList get_data_paths(const std::string& suffix) const;
216 void append_data_path(const SGPath& path);
219 * Given a path suffix (eg 'Textures' or 'AI/Traffic'), find the
220 * first data directory which defines it.
222 SGPath find_data_dir(const std::string& pathSuffix) const;
224 inline const std::string &get_fg_home () const { return fg_home; }
225 void set_fg_home (const std::string &home);
227 inline const string_list &get_fg_scenery () const { return fg_scenery; }
228 inline const string_list &get_secure_fg_scenery () const { return secure_fg_scenery; }
230 * Add a scenery directory
232 * secure = allow Nasal to read this directory; to avoid
233 * can-read-any-file security holes, do NOT set this on directories
234 * obtained from the property tree (e.g. /sim/terrasync/scenery-dir)
235 * or other Nasal-writable places
237 void append_fg_scenery (const std::string &scenery, bool secure = false);
239 void clear_fg_scenery();
242 * specify a path we'll prepend to the aircraft paths list if non-empty.
243 * This is used with packaged aircraft, to ensure their catalog (and hence,
244 * dependency packages) are found correctly.
246 void set_catalog_aircraft_path(const SGPath& path);
248 string_list get_aircraft_paths() const;
250 void append_aircraft_path(const std::string& path);
251 void append_aircraft_paths(const std::string& path);
254 * Given a path to an aircraft-related resource file, resolve it
255 * against the appropriate root. This means looking at the location
256 * defined by /sim/aircraft-dir, and then aircraft_path in turn,
257 * finishing with fg_root/Aircraft.
259 * if the path could not be resolved, an empty path is returned.
261 SGPath resolve_aircraft_path(const std::string& branch) const;
264 * Same as above, but test for non 'Aircraft/' branch paths, and
265 * always resolve them against fg_root.
267 SGPath resolve_maybe_aircraft_path(const std::string& branch) const;
270 * Search in the following directories:
272 * 1. Root directory of current aircraft (defined by /sim/aircraft-dir)
273 * 2. All aircraft directories if branch starts with Aircraft/
274 * 3. fg_data directory
276 SGPath resolve_resource_path(const std::string& branch) const;
278 inline const std::string &get_browser () const { return browser; }
279 void set_browser (const std::string &b) { browser = b; }
281 long int get_warp() const;
282 void set_warp( long int w );
284 long int get_warp_delta() const;
285 void set_warp_delta( long int d );
287 inline SGTime *get_time_params() const { return time_params; }
288 inline void set_time_params( SGTime *t ) { time_params = t; }
290 inline SGEphemeris *get_ephem() const { return ephem; }
291 inline void set_ephem( SGEphemeris *e ) { ephem = e; }
293 inline SGMaterialLib *get_matlib() const { return matlib; }
294 void set_matlib( SGMaterialLib *m );
296 inline FGControls *get_controls() const { return controls; }
297 inline void set_controls( FGControls *c ) { controls = c; }
299 inline FGViewMgr *get_viewmgr() const { return viewmgr; }
300 inline void set_viewmgr( FGViewMgr *vm ) { viewmgr = vm; }
301 FGViewer *get_current_view() const;
303 inline SGPropertyNode *get_props () { return props; }
306 * @brief reset the property tree to new, empty tree. Ensure all
307 * subsystems are shutdown and unbound before call this.
309 void resetPropertyRoot();
311 inline FGLocale* get_locale () { return locale; }
313 inline SGCommandMgr *get_commands () { return commands; }
315 SGGeod get_aircraft_position() const;
317 SGVec3d get_aircraft_position_cart() const;
319 void get_aircraft_orientation(double& heading, double& pitch, double& roll);
321 SGGeod get_view_position() const;
323 SGVec3d get_view_position_cart() const;
325 inline string_list *get_channel_options_list () {
326 return channel_options_list;
328 inline void set_channel_options_list( string_list *l ) {
329 channel_options_list = l;
332 inline string_list *get_initial_waypoints () {
333 return initial_waypoints;
336 inline void set_initial_waypoints (string_list *list) {
337 initial_waypoints = list;
340 FGScenery * get_scenery () const;
341 void set_scenery ( FGScenery *s );
343 FGTileMgr * get_tile_mgr () const;
344 void set_tile_mgr ( FGTileMgr *t );
346 inline FGFontCache *get_fontcache() const { return fontcache; }
348 inline FGTACANList *get_channellist() const { return channellist; }
349 inline void set_channellist( FGTACANList *c ) { channellist = c; }
352 * Load user settings from autosave.xml
354 void loadUserSettings(const SGPath& datapath);
357 * Save user settings in autosave.xml
359 void saveUserSettings();
361 FGSampleQueue* get_chatter_queue() const;
362 void set_chatter_queue(FGSampleQueue* queue);
364 void addListenerToCleanup(SGPropertyChangeListener* l);
366 simgear::pkg::Root* packageRoot();
367 void setPackageRoot(const SGSharedPtr<simgear::pkg::Root>& p);
371 extern FGGlobals *globals;
374 #endif // _GLOBALS_HXX